Search in sources :

Example 21 with HttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest in project camel by apache.

the class HttpServerChannelHandler method beforeProcess.

@Override
protected void beforeProcess(Exchange exchange, final ChannelHandlerContext ctx, final Object message) {
    if (consumer.getConfiguration().isBridgeEndpoint()) {
        exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
        exchange.setProperty(Exchange.SKIP_WWW_FORM_URLENCODED, Boolean.TRUE);
    }
    HttpRequest request = (HttpRequest) message;
    // setup the connection property in case of the message header is removed
    boolean keepAlive = HttpUtil.isKeepAlive(request);
    if (!keepAlive) {
        // Just make sure we close the connection this time.
        exchange.setProperty(HttpHeaderNames.CONNECTION.toString(), HttpHeaderValues.CLOSE.toString());
    }
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest)

Example 22 with HttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest in project camel by apache.

the class HttpServerMultiplexChannelHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
    // store request, as this channel handler is created per pipeline
    HttpRequest request = (HttpRequest) msg;
    LOG.debug("Message received: {}", request);
    HttpServerChannelHandler handler = getHandler(request);
    if (handler != null) {
        Attribute<HttpServerChannelHandler> attr = ctx.channel().attr(SERVER_HANDLER_KEY);
        // store handler as attachment
        attr.set(handler);
        if (msg instanceof HttpContent) {
            // need to hold the reference of content
            HttpContent httpContent = (HttpContent) msg;
            httpContent.content().retain();
        }
        handler.channelRead(ctx, request);
    } else {
        // this resource is not found, so send empty response back
        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
        response.headers().set(Exchange.CONTENT_TYPE, "text/plain");
        response.headers().set(Exchange.CONTENT_LENGTH, 0);
        ctx.writeAndFlush(response);
        ctx.close();
    }
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) HttpContent(io.netty.handler.codec.http.HttpContent)

Example 23 with HttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest in project proxyee-down by monkeyWie.

the class HttpDownHandleInterceptFactory method create.

@Override
public HttpProxyIntercept create() {
    return new HttpProxyIntercept() {

        @Override
        public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) throws Exception {
            HttpRequest httpRequest = pipeline.getHttpRequest();
            ProxyConfig proxyConfig = ContentManager.CONFIG.get().getSecProxyConfig();
            TaskInfo taskInfo = HttpDownUtil.getTaskInfo(httpRequest, httpResponse.headers(), proxyConfig, HttpDownConstant.clientSslContext, HttpDownConstant.clientLoopGroup);
            HttpDownInfo httpDownInfo = new HttpDownInfo(taskInfo, httpRequest, proxyConfig);
            ContentManager.DOWN.putBoot(httpDownInfo);
            httpResponse.setStatus(HttpResponseStatus.OK);
            httpResponse.headers().clear();
            httpResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/html");
            byte[] content;
            if (HttpUtil.checkHead(httpRequest, HttpHeaderNames.HOST, "^.*\\.baidupcs\\.com.*$")) {
                content = "<script>window.close();</script>".getBytes();
            } else {
                content = "<script>window.history.go(-1);</script>".getBytes();
            }
            httpResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, content.length);
            clientChannel.writeAndFlush(httpResponse);
            HttpContent httpContent = new DefaultLastHttpContent();
            httpContent.content().writeBytes(content);
            clientChannel.writeAndFlush(httpContent);
            clientChannel.close();
            httpDownDispatch.dispatch(httpDownInfo);
        }
    };
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) TaskInfo(lee.study.down.model.TaskInfo) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Channel(io.netty.channel.Channel) HttpResponse(io.netty.handler.codec.http.HttpResponse) HttpProxyIntercept(lee.study.proxyee.intercept.HttpProxyIntercept) ProxyConfig(lee.study.proxyee.proxy.ProxyConfig) HttpDownInfo(lee.study.down.model.HttpDownInfo) HttpProxyInterceptPipeline(lee.study.proxyee.intercept.HttpProxyInterceptPipeline) HttpContent(io.netty.handler.codec.http.HttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent)

Example 24 with HttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest in project td-client-java by treasure-data.

the class TestProxyAccess method setUp.

@Before
public void setUp() throws Exception {
    proxyAccessCount.set(0);
    this.proxyPort = findAvailablePort();
    this.proxyServer = DefaultHttpProxyServer.bootstrap().withPort(proxyPort).withProxyAuthenticator(new org.littleshoot.proxy.ProxyAuthenticator() {

        @Override
        public boolean authenticate(String user, String pass) {
            boolean isValid = user.equals(PROXY_USER) && pass.equals(PROXY_PASS);
            logger.debug("Proxy Authentication: " + (isValid ? "success" : "failure"));
            return isValid;
        }
    }).withFiltersSource(new HttpFiltersSourceAdapter() {

        @Override
        public HttpFilters filterRequest(HttpRequest httpRequest, ChannelHandlerContext channelHandlerContext) {
            proxyAccessCount.incrementAndGet();
            return super.filterRequest(httpRequest, channelHandlerContext);
        }
    }).start();
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) HttpFiltersSourceAdapter(org.littleshoot.proxy.HttpFiltersSourceAdapter) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpFilters(org.littleshoot.proxy.HttpFilters) Before(org.junit.Before)

Example 25 with HttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest in project td-client-java by treasure-data.

the class TestSSLProxyAccess method setUp.

@Before
public void setUp() throws Exception {
    proxyAccessCount.set(0);
    this.proxyPort = TestProxyAccess.findAvailablePort();
    this.proxyServer = DefaultHttpProxyServer.bootstrap().withPort(proxyPort).withProxyAuthenticator(new org.littleshoot.proxy.ProxyAuthenticator() {

        public boolean authenticate(String user, String pass) {
            boolean isValid = user.equals(PROXY_USER) && pass.equals(PROXY_PASS);
            logger.debug("Proxy Authentication: " + (isValid ? "success" : "failure"));
            return isValid;
        }
    }).withFiltersSource(new HttpFiltersSourceAdapter() {

        @Override
        public HttpFilters filterRequest(HttpRequest httpRequest, ChannelHandlerContext channelHandlerContext) {
            proxyAccessCount.incrementAndGet();
            return super.filterRequest(httpRequest, channelHandlerContext);
        }
    }).start();
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) HttpFiltersSourceAdapter(org.littleshoot.proxy.HttpFiltersSourceAdapter) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpFilters(org.littleshoot.proxy.HttpFilters) Before(org.junit.Before)

Aggregations

HttpRequest (io.netty.handler.codec.http.HttpRequest)283 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)104 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)95 Test (org.junit.Test)83 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)66 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)50 HttpResponse (io.netty.handler.codec.http.HttpResponse)49 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)34 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)34 ByteBuf (io.netty.buffer.ByteBuf)32 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)31 HttpContent (io.netty.handler.codec.http.HttpContent)30 Test (org.junit.jupiter.api.Test)30 URI (java.net.URI)29 Channel (io.netty.channel.Channel)28 HttpMethod (io.netty.handler.codec.http.HttpMethod)26 IOException (java.io.IOException)25 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)24 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)19 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)19