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());
}
}
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();
}
}
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);
}
};
}
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();
}
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();
}
Aggregations