use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpVersion in project xipki by xipki.
the class HttpRestServlet method service.
@Override
public FullHttpResponse service(FullHttpRequest request, ServletURI servletUri, SSLSession sslSession, SslReverseProxyMode sslReverseProxyMode) {
HttpVersion version = request.protocolVersion();
HttpMethod method = request.method();
if (method != HttpMethod.POST && method != HttpMethod.GET) {
return createErrorResponse(version, HttpResponseStatus.METHOD_NOT_ALLOWED);
}
AuditEvent event = new AuditEvent(new Date());
try {
Rest rest = responderManager.getRest();
HttpRequestMetadataRetriever httpRetriever = new HttpRequestMetadataRetrieverImpl(request, servletUri, sslSession, sslReverseProxyMode);
byte[] requestBytes = readContent(request);
RestResponse response = rest.service(servletUri.getPath(), event, requestBytes, httpRetriever);
HttpResponseStatus status = HttpResponseStatus.valueOf(response.getStatusCode());
FullHttpResponse resp = createResponse(version, status, response.getContentType(), response.getBody());
for (String headerName : response.getHeaders().keySet()) {
resp.headers().add(headerName, response.getHeaders().get(headerName));
}
return resp;
} finally {
event.finish();
auditServiceRegister.getAuditService().logEvent(event);
}
}
use of org.apache.flink.shaded.netty4.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 org.apache.flink.shaded.netty4.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);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpVersion in project moco by dreamhead.
the class AbstractProxyResponseHandler method setupNormalResponse.
private HttpResponse setupNormalResponse(final org.apache.http.HttpResponse remoteResponse) throws IOException {
HttpVersion httpVersion = HttpVersion.valueOf(remoteResponse.getProtocolVersion().toString());
HttpResponseStatus status = HttpResponseStatus.valueOf(remoteResponse.getStatusLine().getStatusCode());
FullHttpResponse response = new DefaultFullHttpResponse(httpVersion, status);
response.setStatus(status);
Arrays.stream(remoteResponse.getAllHeaders()).filter(this::isResponseHeader).forEach(header -> response.headers().set(header.getName(), header.getValue()));
HttpEntity entity = remoteResponse.getEntity();
if (entity != null) {
byte[] content = toByteArray(entity);
if (content.length > 0) {
ByteBuf buffer = Unpooled.copiedBuffer(content);
response.content().writeBytes(buffer);
}
}
return newResponse(response);
}
Aggregations