Search in sources :

Example 76 with HttpRequest

use of io.netty.handler.codec.http.HttpRequest in project selenium_java by sergueik.

the class UtilsTest method whenRequestedTypeIsNotHTMLThenNotChangingURLRequest.

@Test
public void whenRequestedTypeIsNotHTMLThenNotChangingURLRequest() throws URISyntaxException {
    URI uri = new URI("http://tenniskafe.com");
    HttpHeaders httpHeaders = mock(HttpHeaders.class);
    when(httpHeaders.get("Accept")).thenReturn("application/json");
    HttpRequest httpRequest = mock(HttpRequest.class);
    when(httpRequest.getUri()).thenReturn("http://google.com");
    when(httpRequest.headers()).thenReturn(httpHeaders);
    assertFalse(Utils.isUrlChangingRequest(uri, httpRequest));
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) URI(java.net.URI) Test(org.junit.Test)

Example 77 with HttpRequest

use of io.netty.handler.codec.http.HttpRequest in project selenium_java by sergueik.

the class UtilsTest method whenTheHostIsTheSameThenNotChangingURLRequest.

@Test
public void whenTheHostIsTheSameThenNotChangingURLRequest() throws URISyntaxException {
    URI uri = new URI("http://tenniskafe.com");
    HttpHeaders httpHeaders = mock(HttpHeaders.class);
    when(httpHeaders.get("Accept")).thenReturn("application/json");
    HttpRequest httpRequest = mock(HttpRequest.class);
    when(httpRequest.getUri()).thenReturn("http://tenniskafe.com/atp");
    when(httpRequest.headers()).thenReturn(httpHeaders);
    assertFalse(Utils.isUrlChangingRequest(uri, httpRequest));
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) HttpHeaders(io.netty.handler.codec.http.HttpHeaders) URI(java.net.URI) Test(org.junit.Test)

Example 78 with HttpRequest

use of io.netty.handler.codec.http.HttpRequest in project xian by happyyangyuan.

the class RequestDecoderAux method decode.

@Override
protected void decode(ChannelHandlerContext ctx, FullHttpRequest msg, List<Object> out) throws Exception {
    LOG.debug("    httpRequest  ---->   UnitRequest Pojo");
    /*if (!HttpMethod.POST.equals(msg.method())) {
            throw new BadRequestException(new IllegalArgumentException("拒绝非POST请求!"));
        }*/
    DecoderResult result = msg.decoderResult();
    if (!result.isSuccess()) {
        throw new BadRequestException(result.cause());
    }
    updateLongConnectionStatus(msg, ctx);
    Request request = new Request(msg, MsgIdHolder.get());
    offerReqQueue(ctx, request);
    out.add(request);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) Request(info.xiancloud.nettyhttpserver.http.bean.Request) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DecoderResult(io.netty.handler.codec.DecoderResult) BadRequestException(info.xiancloud.nettyhttpserver.http.bean.BadRequestException)

Example 79 with HttpRequest

use of io.netty.handler.codec.http.HttpRequest in project incubator-pulsar by apache.

the class BrokerServiceLookupTest method getHttpClient.

private AsyncHttpClient getHttpClient(String version) {
    DefaultAsyncHttpClientConfig.Builder confBuilder = new DefaultAsyncHttpClientConfig.Builder();
    confBuilder.setFollowRedirect(true);
    confBuilder.setUserAgent(version);
    confBuilder.setKeepAliveStrategy(new DefaultKeepAliveStrategy() {

        @Override
        public boolean keepAlive(Request ahcRequest, HttpRequest request, HttpResponse response) {
            // Close connection upon a server error or per HTTP spec
            return (response.status().code() / 100 != 5) && super.keepAlive(ahcRequest, request, response);
        }
    });
    AsyncHttpClientConfig config = confBuilder.build();
    return new DefaultAsyncHttpClient(config);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultKeepAliveStrategy(org.asynchttpclient.channel.DefaultKeepAliveStrategy) BoundRequestBuilder(org.asynchttpclient.BoundRequestBuilder) Request(org.asynchttpclient.Request) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultAsyncHttpClientConfig(org.asynchttpclient.DefaultAsyncHttpClientConfig) HttpResponse(io.netty.handler.codec.http.HttpResponse) AsyncHttpClientConfig(org.asynchttpclient.AsyncHttpClientConfig) DefaultAsyncHttpClientConfig(org.asynchttpclient.DefaultAsyncHttpClientConfig) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient)

Example 80 with HttpRequest

use of io.netty.handler.codec.http.HttpRequest in project jbossws-cxf by jbossws.

the class HTTPProxyTestCaseForked method initProxyServer.

private void initProxyServer() throws Exception {
    org.littleshoot.proxy.ProxyAuthenticator proxyAuthenticator = new org.littleshoot.proxy.ProxyAuthenticator() {

        @Override
        public boolean authenticate(String user, String pwd) {
            return (PROXY_USER.equals(user) && PROXY_PWD.equals(pwd));
        }
    };
    InetSocketAddress address = new InetSocketAddress(getServerHost(), ++proxyPort);
    ChainedProxyManager chainProxyManager = new ChainedProxyManager() {

        @Override
        public void lookupChainedProxies(HttpRequest httpRequest, Queue<ChainedProxy> chainedProxies) {
            chainedProxies.add(new ChainedProxyAdapter() {

                @Override
                public InetSocketAddress getChainedProxyAddress() {
                    return new InetSocketAddress(getServerHost(), getServerPort());
                }
            });
        }
    };
    proxyServer = org.littleshoot.proxy.impl.DefaultHttpProxyServer.bootstrap().withChainProxyManager(chainProxyManager).withAddress(address).withProxyAuthenticator(proxyAuthenticator).start();
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) ChainedProxyManager(org.littleshoot.proxy.ChainedProxyManager) InetSocketAddress(java.net.InetSocketAddress) Queue(java.util.Queue) ChainedProxyAdapter(org.littleshoot.proxy.ChainedProxyAdapter)

Aggregations

HttpRequest (io.netty.handler.codec.http.HttpRequest)292 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)105 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)95 Test (org.junit.Test)86 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)67 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)53 HttpResponse (io.netty.handler.codec.http.HttpResponse)50 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)38 ByteBuf (io.netty.buffer.ByteBuf)35 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)35 Test (org.junit.jupiter.api.Test)34 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)31 HttpContent (io.netty.handler.codec.http.HttpContent)30 Channel (io.netty.channel.Channel)29 URI (java.net.URI)27 HttpMethod (io.netty.handler.codec.http.HttpMethod)26 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)25 IOException (java.io.IOException)23 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)19 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)19