use of io.netty.handler.codec.http.HttpVersion in project netty by netty.
the class SpdyHttpDecoder method createHttpRequest.
private static FullHttpRequest createHttpRequest(SpdyHeadersFrame requestFrame, ByteBufAllocator alloc) throws Exception {
// Create the first line of the request from the name/value pairs
SpdyHeaders headers = requestFrame.headers();
HttpMethod method = HttpMethod.valueOf(headers.getAsString(METHOD));
String url = headers.getAsString(PATH);
HttpVersion httpVersion = HttpVersion.valueOf(headers.getAsString(VERSION));
headers.remove(METHOD);
headers.remove(PATH);
headers.remove(VERSION);
boolean release = true;
ByteBuf buffer = alloc.buffer();
try {
FullHttpRequest req = new DefaultFullHttpRequest(httpVersion, method, url, buffer);
// Remove the scheme header
headers.remove(SCHEME);
// Replace the SPDY host header with the HTTP host header
CharSequence host = headers.get(HOST);
headers.remove(HOST);
req.headers().set(HttpHeaderNames.HOST, host);
for (Map.Entry<CharSequence, CharSequence> e : requestFrame.headers()) {
req.headers().add(e.getKey(), e.getValue());
}
// The Connection and Keep-Alive headers are no longer valid
HttpUtil.setKeepAlive(req, true);
// Transfer-Encoding header is not valid
req.headers().remove(HttpHeaderNames.TRANSFER_ENCODING);
release = false;
return req;
} finally {
if (release) {
buffer.release();
}
}
}
use of io.netty.handler.codec.http.HttpVersion in project graylog2-server by Graylog2.
the class HttpHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpRequest request) throws Exception {
final Channel channel = ctx.channel();
final boolean keepAlive = HttpUtil.isKeepAlive(request);
final HttpVersion httpRequestVersion = request.protocolVersion();
final String origin = request.headers().get(HttpHeaderNames.ORIGIN);
// to allow for future changes, let's be at least a little strict in what we accept here.
if (HttpMethod.OPTIONS.equals(request.method())) {
writeResponse(channel, keepAlive, httpRequestVersion, HttpResponseStatus.OK, origin);
return;
} else if (!HttpMethod.POST.equals(request.method())) {
writeResponse(channel, keepAlive, httpRequestVersion, HttpResponseStatus.METHOD_NOT_ALLOWED, origin);
return;
}
final boolean correctPath = "/gelf".equals(request.uri());
if (correctPath && request instanceof FullHttpRequest) {
final FullHttpRequest fullHttpRequest = (FullHttpRequest) request;
final ByteBuf buffer = fullHttpRequest.content();
// send on to raw message handler
writeResponse(channel, keepAlive, httpRequestVersion, HttpResponseStatus.ACCEPTED, origin);
ctx.fireChannelRead(buffer.retain());
} else {
writeResponse(channel, keepAlive, httpRequestVersion, HttpResponseStatus.NOT_FOUND, origin);
}
}
Aggregations