Search in sources :

Example 56 with HttpRequest

use of org.apache.flink.shaded.netty4.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 57 with HttpRequest

use of org.apache.flink.shaded.netty4.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 58 with HttpRequest

use of org.apache.flink.shaded.netty4.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 59 with HttpRequest

use of org.apache.flink.shaded.netty4.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 60 with HttpRequest

use of org.apache.flink.shaded.netty4.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)332 Test (org.junit.Test)115 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)111 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)102 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)71 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)67 HttpResponse (io.netty.handler.codec.http.HttpResponse)65 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)51 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)45 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)36 ByteBuf (io.netty.buffer.ByteBuf)35 HttpContent (io.netty.handler.codec.http.HttpContent)34 Test (org.junit.jupiter.api.Test)34 Channel (io.netty.channel.Channel)31 HttpMethod (io.netty.handler.codec.http.HttpMethod)31 URI (java.net.URI)30 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)28 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)26 IOException (java.io.IOException)25 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)22