Search in sources :

Example 16 with DefaultFullHttpRequest

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

the class NettyHttpClientRequest method createRequest.

public void createRequest(ByteBuf content) {
    this.request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.valueOf(method), uri.getPath().toString(), content);
    // setup the default headers
    request.headers().set("Connection", "keep-alive");
    request.headers().set("Host", uri.getHost() + ":" + (uri.getPort() != -1 ? uri.getPort() : "http".equals(uri.getScheme()) ? 80 : 443));
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest)

Example 17 with DefaultFullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project riposte by Nike-Inc.

the class RequestInfoImpl method getMultipartParts.

/**
 * {@inheritDoc}
 */
@Override
public synchronized List<InterfaceHttpData> getMultipartParts() {
    if (!isMultipartRequest() || !isCompleteRequestWithAllChunks())
        return null;
    if (multipartData == null) {
        byte[] contentBytes = getRawContentBytes();
        HttpRequest fullHttpRequestForMultipartDecoder = (contentBytes == null) ? new DefaultFullHttpRequest(getProtocolVersion(), getMethod(), getUri()) : new DefaultFullHttpRequest(getProtocolVersion(), getMethod(), getUri(), Unpooled.wrappedBuffer(contentBytes));
        fullHttpRequestForMultipartDecoder.headers().add(getHeaders());
        multipartData = new HttpPostMultipartRequestDecoder(new DefaultHttpDataFactory(false), fullHttpRequestForMultipartDecoder, getContentCharset());
    }
    return multipartData.getBodyHttpDatas();
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) HttpPostMultipartRequestDecoder(io.netty.handler.codec.http.multipart.HttpPostMultipartRequestDecoder) DefaultHttpDataFactory(io.netty.handler.codec.http.multipart.DefaultHttpDataFactory)

Example 18 with DefaultFullHttpRequest

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

the class OcspBenchRequestor method ask.

public void ask(BigInteger[] serialNumbers) throws OcspRequestorException {
    byte[] ocspReq = buildRequest(serialNumbers);
    int size = ocspReq.length;
    FullHttpRequest request;
    if (size <= MAX_LEN_GET && requestOptions.isUseHttpGetForRequest()) {
        String b64Request = Base64.encodeToString(ocspReq);
        String urlEncodedReq;
        try {
            urlEncodedReq = URLEncoder.encode(b64Request, "UTF-8");
        } catch (UnsupportedEncodingException ex) {
            throw new OcspRequestorException(ex.getMessage());
        }
        String newRawpath = StringUtil.concat(responderRawPathGet, urlEncodedReq);
        request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, newRawpath);
    } else {
        ByteBuf content = Unpooled.wrappedBuffer(ocspReq);
        request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, responderRawPathPost, content);
        request.headers().addInt("Content-Length", content.readableBytes());
    }
    request.headers().add("Content-Type", "application/ocsp-request");
    httpClient.send(request);
}
Also used : OcspRequestorException(org.xipki.ocsp.client.api.OcspRequestorException) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DEROctetString(org.bouncycastle.asn1.DEROctetString) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) ByteBuf(io.netty.buffer.ByteBuf)

Example 19 with DefaultFullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project jocean-http by isdom.

the class DefaultHttpClientTestCase method testInitiatorInteractionSuccessAsHttps10ConnectionClose.

@Test(timeout = 5000)
public void testInitiatorInteractionSuccessAsHttps10ConnectionClose() throws Exception {
    // 配置 池化分配器 为 取消缓存,使用 Heap
    configDefaultAllocator();
    final PooledByteBufAllocator allocator = defaultAllocator();
    final BlockingQueue<HttpTrade> trades = new ArrayBlockingQueue<>(1);
    final String addr = UUID.randomUUID().toString();
    final Subscription server = TestHttpUtil.createTestServerWith(addr, trades, enableSSL4ServerWithSelfSigned(), Feature.ENABLE_LOGGING_OVER_SSL);
    final DefaultHttpClient client = new DefaultHttpClient(new TestChannelCreator(), enableSSL4Client(), Feature.ENABLE_LOGGING_OVER_SSL);
    try {
        final HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "/");
        request.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
        startInteraction(client.initiator().remoteAddress(new LocalAddress(addr)), Observable.just(request), new Interaction() {

            @Override
            public void interact(final HttpInitiator initiator, final Observable<DisposableWrapper<FullHttpResponse>> getresp) throws Exception {
                final Observable<DisposableWrapper<FullHttpResponse>> cached = getresp.cache();
                cached.subscribe();
                // server side recv req
                final HttpTrade trade = trades.take();
                // recv all request
                trade.inbound().toCompletable().await();
                final ByteBuf svrRespContent = allocator.buffer(CONTENT.length).writeBytes(CONTENT);
                // for HTTP 1.0 Connection: Close response behavior
                final FullHttpResponse fullrespfromsvr = new DefaultFullHttpResponse(HttpVersion.HTTP_1_0, HttpResponseStatus.OK, svrRespContent);
                fullrespfromsvr.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain");
                // missing Content-Length
                // response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
                fullrespfromsvr.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
                trade.outbound(Observable.just(fullrespfromsvr));
                // wait for recv all resp at client side
                cached.toCompletable().await();
                svrRespContent.release();
                assertTrue(Arrays.equals(dumpResponseContentAsBytes(cached), CONTENT));
            }
        });
    } finally {
        assertEquals(0, allActiveAllocationsCount(allocator));
        client.close();
        server.unsubscribe();
    }
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) LocalAddress(io.netty.channel.local.LocalAddress) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DisposableWrapper(org.jocean.idiom.DisposableWrapper) ByteBuf(io.netty.buffer.ByteBuf) SSLException(javax.net.ssl.SSLException) TransportException(org.jocean.http.TransportException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) ConnectableObservable(rx.observables.ConnectableObservable) Observable(rx.Observable) PooledByteBufAllocator(io.netty.buffer.PooledByteBufAllocator) HttpInitiator(org.jocean.http.client.HttpClient.HttpInitiator) HttpTrade(org.jocean.http.server.HttpServerBuilder.HttpTrade) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) Subscription(rx.Subscription) Test(org.junit.Test)

Example 20 with DefaultFullHttpRequest

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project jocean-http by isdom.

the class DefaultHttpTradeTestCase method testTradeForCallAbortBeforeRequestPublish.

// TODO: fix
@Test
public final void testTradeForCallAbortBeforeRequestPublish() {
    final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/", Nettys4Test.buildByteBuf("testcontent"));
    final EmbeddedChannel channel = new EmbeddedChannel();
    final HttpTrade trade = new DefaultHttpTrade(channel);
    final TestSubscriber<DisposableWrapper<HttpObject>> reqSubscriber = new TestSubscriber<>();
    trade.inbound().subscribe(reqSubscriber);
    trade.close();
    assertTrue(!trade.isActive());
    reqSubscriber.assertTerminalEvent();
    reqSubscriber.assertError(Exception.class);
    writeToInboundAndFlush(channel, request);
    reqSubscriber.assertValueCount(0);
}
Also used : HttpTrade(org.jocean.http.server.HttpServerBuilder.HttpTrade) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) DisposableWrapper(org.jocean.idiom.DisposableWrapper) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) TestSubscriber(rx.observers.TestSubscriber) Nettys4Test(org.jocean.http.util.Nettys4Test) Test(org.junit.Test)

Aggregations

DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)206 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)110 Test (org.junit.jupiter.api.Test)72 Test (org.junit.Test)56 ByteBuf (io.netty.buffer.ByteBuf)54 HttpRequest (io.netty.handler.codec.http.HttpRequest)45 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)42 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)40 AsciiString (io.netty.util.AsciiString)30 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)23 Channel (io.netty.channel.Channel)19 ChannelPromise (io.netty.channel.ChannelPromise)19 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)18 IOException (java.io.IOException)17 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)14 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)14 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)13 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)12 FullHttpMessage (io.netty.handler.codec.http.FullHttpMessage)11 Bootstrap (io.netty.bootstrap.Bootstrap)10