Java Code Examples for io.netty.handler.codec.http.HttpHeaders#getIntHeader()

The following examples show how to use io.netty.handler.codec.http.HttpHeaders#getIntHeader() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpStreamEncoder.java    From netty-http2 with Apache License 2.0 6 votes vote down vote up
private HttpHeadersFrame createHttpHeadersFrame(HttpResponse httpResponse)
        throws Exception {
    // Get the Stream-ID from the headers
    int streamId = HttpHeaders.getIntHeader(httpResponse, "X-SPDY-Stream-ID");
    httpResponse.headers().remove("X-SPDY-Stream-ID");

    // The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
    // headers are not valid and MUST not be sent.
    httpResponse.headers().remove(HttpHeaders.Names.CONNECTION);
    httpResponse.headers().remove("Keep-Alive");
    httpResponse.headers().remove("Proxy-Connection");
    httpResponse.headers().remove(HttpHeaders.Names.TRANSFER_ENCODING);

    HttpHeadersFrame httpHeadersFrame = new DefaultHttpHeadersFrame(streamId);

    // Unfold the first line of the response into name/value pairs
    httpHeadersFrame.headers().set(":status", httpResponse.getStatus().code());

    // Transfer the remaining HTTP headers
    for (Map.Entry<String, String> entry : httpResponse.headers()) {
        httpHeadersFrame.headers().add(entry.getKey(), entry.getValue());
    }

    return httpHeadersFrame;
}
 
Example 2
Source File: HttpStreamEncoder.java    From netty-http2 with Apache License 2.0 5 votes vote down vote up
private HttpHeadersFrame createHttpHeadersFrame(HttpRequest httpRequest)
        throws Exception {
    // Get the Stream-ID from the headers
    int streamId = HttpHeaders.getIntHeader(httpRequest, "X-SPDY-Stream-ID");
    httpRequest.headers().remove("X-SPDY-Stream-ID");

    // The Connection, Keep-Alive, Proxy-Connection, and Transfer-Encoding
    // headers are not valid and MUST not be sent.
    httpRequest.headers().remove(HttpHeaders.Names.CONNECTION);
    httpRequest.headers().remove("Keep-Alive");
    httpRequest.headers().remove("Proxy-Connection");
    httpRequest.headers().remove(HttpHeaders.Names.TRANSFER_ENCODING);

    HttpHeadersFrame httpHeadersFrame = new DefaultHttpHeadersFrame(streamId);

    // Unfold the first line of the request into name/value pairs
    httpHeadersFrame.headers().add(":method", httpRequest.getMethod().name());
    httpHeadersFrame.headers().set(":scheme", "https");
    httpHeadersFrame.headers().add(":path", httpRequest.getUri());

    // Replace the HTTP host header with the SPDY host header
    String host = httpRequest.headers().get(HttpHeaders.Names.HOST);
    httpRequest.headers().remove(HttpHeaders.Names.HOST);
    httpHeadersFrame.headers().add(":authority", host);

    // Transfer the remaining HTTP headers
    for (Map.Entry<String, String> entry : httpRequest.headers()) {
        httpHeadersFrame.headers().add(entry.getKey(), entry.getValue());
    }

    return httpHeadersFrame;
}
 
Example 3
Source File: NettyHttpServletRequest.java    From Jinx with Apache License 2.0 4 votes vote down vote up
@Override
public int getIntHeader(String name) {
    return HttpHeaders.getIntHeader(this.request, name, -1);
}
 
Example 4
Source File: SpdyHttpHeaders.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the value of the {@code "X-SPDY-Stream-ID"} header.
 */
public static int getStreamId(HttpMessage message) {
    return HttpHeaders.getIntHeader(message, Names.STREAM_ID);
}
 
Example 5
Source File: SpdyHttpHeaders.java    From netty4.0.27Learn with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the value of the {@code "X-SPDY-Associated-To-Stream-ID"} header.
 *
 * @return the header value or {@code 0} if there is no such header or
 *         if the header value is not a number
 */
public static int getAssociatedToStreamId(HttpMessage message) {
    return HttpHeaders.getIntHeader(message, Names.ASSOCIATED_TO_STREAM_ID, 0);
}
 
Example 6
Source File: SpdyHttpHeaders.java    From netty4.0.27Learn with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the value of the {@code "X-SPDY-Priority"} header.
 *
 * @return the header value or {@code 0} if there is no such header or
 *         if the header value is not a number
 */
public static byte getPriority(HttpMessage message) {
    return (byte) HttpHeaders.getIntHeader(message, Names.PRIORITY, 0);
}