Example usage for io.netty.handler.codec DecoderResult UNFINISHED

List of usage examples for io.netty.handler.codec DecoderResult UNFINISHED

Introduction

In this page you can find the example usage for io.netty.handler.codec DecoderResult UNFINISHED.

Prototype

DecoderResult UNFINISHED

To view the source code for io.netty.handler.codec DecoderResult UNFINISHED.

Click Source Link

Usage

From source file:com.twitter.http2.HttpStreamDecoder.java

License:Apache License

private StreamedHttpRequest createHttpRequest(HttpHeadersFrame httpHeadersFrame) throws Exception {
    // Create the first line of the request from the name/value pairs
    HttpMethod method = HttpMethod.valueOf(httpHeadersFrame.headers().get(":method"));
    String url = httpHeadersFrame.headers().get(":path");

    httpHeadersFrame.headers().remove(":method");
    httpHeadersFrame.headers().remove(":path");

    StreamedHttpRequest request = new StreamedHttpRequest(HttpVersion.HTTP_1_1, method, url);

    // Remove the scheme header
    httpHeadersFrame.headers().remove(":scheme");

    // Replace the SPDY host header with the HTTP host header
    String host = httpHeadersFrame.headers().get(":authority");
    httpHeadersFrame.headers().remove(":authority");
    httpHeadersFrame.headers().set("host", host);

    for (Map.Entry<String, String> e : httpHeadersFrame.headers()) {
        String name = e.getKey();
        String value = e.getValue();
        if (name.charAt(0) != ':') {
            request.headers().add(name, value);
        }//from  w ww.j a  va  2s .  co  m
    }

    // Set the Stream-ID as a header
    request.headers().set("X-SPDY-Stream-ID", httpHeadersFrame.getStreamId());

    // The Connection and Keep-Alive headers are no longer valid
    HttpHeaders.setKeepAlive(request, true);

    // Transfer-Encoding header is not valid
    request.headers().remove(HttpHeaders.Names.TRANSFER_ENCODING);

    if (httpHeadersFrame.isLast()) {
        request.getContent().close();
        request.setDecoderResult(DecoderResult.SUCCESS);
    } else {
        request.setDecoderResult(DecoderResult.UNFINISHED);
    }

    return request;
}

From source file:com.twitter.http2.HttpStreamDecoder.java

License:Apache License

private StreamedHttpResponse createHttpResponse(HttpHeadersFrame httpHeadersFrame) throws Exception {
    // Create the first line of the request from the name/value pairs
    HttpResponseStatus status = HttpResponseStatus
            .valueOf(Integer.parseInt(httpHeadersFrame.headers().get(":status")));

    httpHeadersFrame.headers().remove(":status");

    StreamedHttpResponse response = new StreamedHttpResponse(HttpVersion.HTTP_1_1, status);
    for (Map.Entry<String, String> e : httpHeadersFrame.headers()) {
        String name = e.getKey();
        String value = e.getValue();
        if (name.charAt(0) != ':') {
            response.headers().add(name, value);
        }/*from  w ww  .j a v  a 2s .  c  om*/
    }

    // Set the Stream-ID as a header
    response.headers().set("X-SPDY-Stream-ID", httpHeadersFrame.getStreamId());

    // The Connection and Keep-Alive headers are no longer valid
    HttpHeaders.setKeepAlive(response, true);

    // Transfer-Encoding header is not valid
    response.headers().remove(HttpHeaders.Names.TRANSFER_ENCODING);
    response.headers().remove(HttpHeaders.Names.TRAILER);

    if (httpHeadersFrame.isLast()) {
        response.getContent().close();
        response.setDecoderResult(DecoderResult.SUCCESS);
    } else {
        response.setDecoderResult(DecoderResult.UNFINISHED);
    }

    return response;
}