List of usage examples for io.netty.handler.codec.http DefaultFullHttpRequest DefaultFullHttpRequest
public DefaultFullHttpRequest(HttpVersion httpVersion, HttpMethod method, String uri, ByteBuf content,
HttpHeaders headers, HttpHeaders trailingHeader)
From source file:com.otcdlink.chiron.downend.Http11ProxyHandler.java
License:Apache License
@Override protected Object newInitialMessage(ChannelHandlerContext ctx) throws Exception { InetSocketAddress raddr = destinationAddress(); String rhost;//from w w w.ja va2 s.co m if (raddr.isUnresolved()) { rhost = raddr.getHostString(); } else { rhost = raddr.getAddress().getHostAddress(); } FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.CONNECT, rhost + ':' + raddr.getPort(), Unpooled.EMPTY_BUFFER, new DefaultHttpHeaders().add(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE).add( HttpHeaderNames.PROXY_CONNECTION, HttpHeaderValues.KEEP_ALIVE), EmptyHttpHeaders.INSTANCE); SocketAddress proxyAddress = proxyAddress(); if (proxyAddress instanceof InetSocketAddress) { InetSocketAddress hostAddr = (InetSocketAddress) proxyAddress; // req.headers().set(HttpHeaderNames.HOST, hostAddr.getHostString() + ':' + hostAddr.getPort()); req.headers().set(HttpHeaderNames.HOST, rhost + ':' + raddr.getPort()); } if (authorization != null) { req.headers().set(HttpHeaderNames.PROXY_AUTHORIZATION, authorization); } return req; }
From source file:io.gatling.http.client.impl.request.WritableRequestBuilder.java
License:Apache License
private static WritableRequest buildRequestWithoutBody(String url, HttpMethod method, HttpHeaders headers) { // force content-length to 0 when method usually takes a body, some servers might break otherwise if (!headers.contains(CONTENT_LENGTH) && (method == POST || method == PUT || method == PATCH)) { headers.set(CONTENT_LENGTH, 0);/* ww w . j av a2 s . c o m*/ } FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, url, Unpooled.buffer(0), headers, EmptyHttpHeaders.INSTANCE); return new WritableRequest(nettyRequest, null); }
From source file:io.gatling.http.client.impl.request.WritableRequestBuilder.java
License:Apache License
private static WritableRequest buildRequestWithBody(String url, Uri uri, HttpMethod method, HttpHeaders headers, RequestBody<?> requestBody, ByteBufAllocator alloc, HttpClientConfig config) throws IOException { boolean zeroCopy = !uri.isSecured() && config.isEnableZeroCopy(); WritableContent writableContent = requestBody.build(zeroCopy, alloc); Object content = writableContent.getContent(); if (content instanceof ByteBuf) { ByteBuf bb = (ByteBuf) content;//from w ww.j a va 2s . c om if (!headers.contains(CONTENT_LENGTH)) { headers.set(CONTENT_LENGTH, bb.readableBytes()); } FullHttpRequest nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, url, bb, headers, EmptyHttpHeaders.INSTANCE); return new WritableRequest(nettyRequest, null); } else { if (!headers.contains(CONTENT_LENGTH) && !headers.contains(TRANSFER_ENCODING)) { if (writableContent.getContentLength() >= 0) { headers.set(CONTENT_LENGTH, writableContent.getContentLength()); } else { headers.set(TRANSFER_ENCODING, HttpHeaderValues.CHUNKED); } } HttpRequest nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, method, url, headers); return new WritableRequest(nettyRequest, content); } }
From source file:io.vertx.core.http.impl.WebSocketRequestHandler.java
License:Open Source License
/** * Handle the request once we have the full body. *//*from ww w . j a v a2s .co m*/ private void handle(HttpServerRequestImpl req, Buffer body) { DefaultHttpRequest nettyReq = req.getRequest(); nettyReq = new DefaultFullHttpRequest(nettyReq.protocolVersion(), nettyReq.method(), nettyReq.uri(), body.getByteBuf(), nettyReq.headers(), EmptyHttpHeaders.INSTANCE); req.setRequest(nettyReq); ServerWebSocketImpl ws = ((Http1xServerConnection) req.connection()).createWebSocket(req); if (METRICS_ENABLED && metrics != null) { ws.setMetric(metrics.connected(((Http1xServerConnection) req.connection()).metric(), ws)); } if (handlers.wsHandler != null) { handlers.wsHandler.handle(ws); if (!ws.isRejected()) { ws.connectNow(); } else { req.response().setStatusCode(ws.getRejectedStatus().code()).end(); } } else { handlers.requestHandler.handle(req); } }
From source file:org.elasticsearch.hadoop.http.netty4.Netty4HttpRequestHandler.java
License:Apache License
@Override protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { final FullHttpRequest request; final HttpPipelinedRequest pipelinedRequest; if (this.httpPipeliningEnabled && msg instanceof HttpPipelinedRequest) { pipelinedRequest = (HttpPipelinedRequest) msg; request = (FullHttpRequest) pipelinedRequest.last(); } else {/* w w w .j a va2 s.c om*/ pipelinedRequest = null; request = (FullHttpRequest) msg; } final FullHttpRequest copy = new DefaultFullHttpRequest(request.protocolVersion(), request.method(), request.uri(), Unpooled.copiedBuffer(request.content()), request.headers(), request.trailingHeaders()); final Netty4HttpRequest httpRequest = new Netty4HttpRequest(copy, ctx.channel()); serverTransport.dispatchRequest(httpRequest, new Netty4HttpChannel(serverTransport, httpRequest, pipelinedRequest, detailedErrorsEnabled, threadContext)); }
From source file:org.elasticsearch.http.nio.HttpReadWriteHandler.java
License:Apache License
@SuppressWarnings("unchecked") private void handleRequest(Object msg) { final HttpPipelinedRequest<FullHttpRequest> pipelinedRequest = (HttpPipelinedRequest<FullHttpRequest>) msg; FullHttpRequest request = pipelinedRequest.getRequest(); try {// w w w.j a v a 2 s . com final FullHttpRequest copiedRequest = new DefaultFullHttpRequest(request.protocolVersion(), request.method(), request.uri(), Unpooled.copiedBuffer(request.content()), request.headers(), request.trailingHeaders()); NioHttpRequest httpRequest = new NioHttpRequest(copiedRequest, pipelinedRequest.getSequence()); if (request.decoderResult().isFailure()) { Throwable cause = request.decoderResult().cause(); if (cause instanceof Error) { ExceptionsHelper.dieOnError(cause); transport.incomingRequestError(httpRequest, nioHttpChannel, new Exception(cause)); } else { transport.incomingRequestError(httpRequest, nioHttpChannel, (Exception) cause); } } else { transport.incomingRequest(httpRequest, nioHttpChannel); } } finally { // As we have copied the buffer, we can release the request request.release(); } }
From source file:org.elasticsearch.http.nio.NioHttpRequest.java
License:Apache License
@Override public HttpRequest removeHeader(String header) { HttpHeaders headersWithoutContentTypeHeader = new DefaultHttpHeaders(); headersWithoutContentTypeHeader.add(request.headers()); headersWithoutContentTypeHeader.remove(header); HttpHeaders trailingHeaders = new DefaultHttpHeaders(); trailingHeaders.add(request.trailingHeaders()); trailingHeaders.remove(header);//from w w w. j a v a 2 s . c om FullHttpRequest requestWithoutHeader = new DefaultFullHttpRequest(request.protocolVersion(), request.method(), request.uri(), request.content(), headersWithoutContentTypeHeader, trailingHeaders); return new NioHttpRequest(requestWithoutHeader, sequence); }
From source file:org.jooby.internal.netty.NettyPush.java
License:Apache License
@Override public void push(final String method, final String path, final Map<String, Object> headers) { ctx.channel().eventLoop().execute(() -> { AsciiString streamIdHeader = HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(); Http2Connection connection = encoder.connection(); int nextStreamId = connection.local().incrementAndGetNextStreamId(); Http2Headers h2headers = new DefaultHttp2Headers().path(path).method(method).authority(authority) .scheme(scheme);/*from w ww . j a v a 2 s . c o m*/ headers.forEach((n, v) -> h2headers.add(n, v.toString())); encoder.writePushPromise(ctx, streamId, nextStreamId, h2headers, 0, ctx.newPromise()); // TODO: Is there another way of handling a push promise? DefaultFullHttpRequest pushRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.valueOf(method.toUpperCase()), path, Unpooled.EMPTY_BUFFER, new DefaultHttpHeaders(false).set(streamIdHeader, nextStreamId), EmptyHttpHeaders.INSTANCE); ctx.pipeline().fireChannelRead(pushRequest); ctx.pipeline().fireChannelReadComplete(); }); }