Example usage for io.netty.handler.codec.http HttpHeaderValues CONTINUE

List of usage examples for io.netty.handler.codec.http HttpHeaderValues CONTINUE

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpHeaderValues CONTINUE.

Prototype

AsciiString CONTINUE

To view the source code for io.netty.handler.codec.http HttpHeaderValues CONTINUE.

Click Source Link

Document

"100-continue"

Usage

From source file:com.github.thinker0.mesos.MesosHealthCheckerServer.java

License:Apache License

public boolean is100ContinueExpected(HttpMessage message) {
    if (!(message instanceof HttpRequest)) {
        return false;
    } else if (message.protocolVersion().compareTo(HttpVersion.HTTP_1_1) < 0) {
        return false;
    } else {//from   w w w. j  a v a  2  s  . c om
        CharSequence value = (CharSequence) message.headers().get(HttpHeaderNames.EXPECT);
        return value == null ? false
                : (HttpHeaderValues.CONTINUE.contentEqualsIgnoreCase(value) ? true
                        : message.headers().contains(HttpHeaderNames.EXPECT, HttpHeaderValues.CONTINUE, true));
    }
}

From source file:io.vertx.core.http.impl.Http2ServerConnection.java

License:Open Source License

@Override
public synchronized void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers,
        int padding, boolean endOfStream) {
    VertxHttp2Stream stream = streams.get(streamId);
    if (stream == null) {
        if (isMalformedRequest(headers)) {
            handler.writeReset(streamId, Http2Error.PROTOCOL_ERROR.code());
            return;
        }/*from w  w w .j  av  a 2  s  . c  om*/
        String contentEncoding = options.isCompressionSupported() ? HttpUtils.determineContentEncoding(headers)
                : null;
        Http2Stream s = handler.connection().stream(streamId);
        boolean writable = handler.encoder().flowController().isWritable(s);
        Http2ServerRequestImpl req = new Http2ServerRequestImpl(this, s, metrics, serverOrigin, headers,
                contentEncoding, writable);
        stream = req;
        CharSequence value = headers.get(HttpHeaderNames.EXPECT);
        if (options.isHandle100ContinueAutomatically()
                && ((value != null && HttpHeaderValues.CONTINUE.equals(value))
                        || headers.contains(HttpHeaderNames.EXPECT, HttpHeaderValues.CONTINUE))) {
            req.response().writeContinue();
        }
        streams.put(streamId, req);
        context.executeFromIO(() -> {
            Http2ServerResponseImpl resp = req.response();
            resp.beginRequest();
            requestHandler.handle(req);
            boolean hasPush = resp.endRequest();
            if (hasPush) {
                ctx.flush();
            }
        });
    } else {
        // Http server request trailer - not implemented yet (in api)
    }
    if (endOfStream) {
        context.executeFromIO(stream::onEnd);
    }
}

From source file:org.ballerinalang.test.service.http.sample.ExpectContinueTestCase.java

License:Open Source License

@Test(description = "Test multipart form data request with expect:100-continue header")
public void testMultipartWith100ContinueHeader() throws IOException {
    Map<String, String> headers = new HashMap<>();
    headers.put(HttpHeaderNames.EXPECT.toString(), HttpHeaderValues.CONTINUE.toString());

    Map<String, String> formData = new HashMap<>();
    formData.put("person", "engineer");
    formData.put("team", "ballerina");

    HttpResponse response = HttpClientRequest.doMultipartFormData(
            serverInstance.getServiceURLHttp(servicePort, "continue/getFormParam"), headers, formData);
    Assert.assertNotNull(response);/*from w w w. j a v a2s .  c  o m*/
    Assert.assertEquals(response.getResponseCode(), 200, "Response code mismatched");
    Assert.assertEquals(response.getData(), "Result = Key:person Value: engineer Key:team Value: ballerina");
}

From source file:org.ballerinalang.test.util.client.HttpClient.java

License:Open Source License

public List<FullHttpResponse> sendExpectContinueRequest(DefaultHttpRequest httpRequest,
        DefaultLastHttpContent httpContent) {
    CountDownLatch latch = new CountDownLatch(1);
    this.waitForConnectionClosureLatch = new CountDownLatch(1);
    this.responseHandler.setLatch(latch);
    this.responseHandler.setWaitForConnectionClosureLatch(this.waitForConnectionClosureLatch);

    httpRequest.headers().set(HttpHeaderNames.HOST, host + ":" + port);
    httpRequest.headers().set(HttpHeaderNames.EXPECT, HttpHeaderValues.CONTINUE);
    this.connectedChannel.writeAndFlush(httpRequest);

    try {//from  ww w  .ja  va2  s.c o m
        latch.await();
    } catch (InterruptedException e) {
        log.warn("Interrupted before receiving the response.");
    }

    FullHttpResponse response100Continue = this.responseHandler.getHttpFullResponse();

    if (response100Continue.status().equals(HttpResponseStatus.CONTINUE)) {
        latch = new CountDownLatch(1);
        this.responseHandler.setLatch(latch);
        this.connectedChannel.writeAndFlush(httpContent);
        try {
            latch.await();
        } catch (InterruptedException e) {
            log.warn("Interrupted before receiving the response.");
        }
    }

    return responseHandler.getHttpFullResponses();
}

From source file:org.elasticsearch.http.nio.NioHttpServerTransportTests.java

License:Apache License

/**
 * Test that {@link NioHttpServerTransport} supports the "Expect: 100-continue" HTTP header
 * @throws InterruptedException if the client communication with the server is interrupted
 *///from w ww  .  j  a  v  a  2 s  . com
public void testExpectContinueHeader() throws InterruptedException {
    final Settings settings = Settings.EMPTY;
    final int contentLength = randomIntBetween(1,
            HttpTransportSettings.SETTING_HTTP_MAX_CONTENT_LENGTH.get(settings).bytesAsInt());
    runExpectHeaderTest(settings, HttpHeaderValues.CONTINUE.toString(), contentLength,
            HttpResponseStatus.CONTINUE);
}

From source file:org.elasticsearch.http.nio.NioHttpServerTransportTests.java

License:Apache License

/**
 * Test that {@link NioHttpServerTransport} responds to a
 * 100-continue expectation with too large a content-length
 * with a 413 status./*  w  w  w .  j  ava2s.  c  o  m*/
 * @throws InterruptedException if the client communication with the server is interrupted
 */
public void testExpectContinueHeaderContentLengthTooLong() throws InterruptedException {
    final String key = HttpTransportSettings.SETTING_HTTP_MAX_CONTENT_LENGTH.getKey();
    final int maxContentLength = randomIntBetween(1, 104857600);
    final Settings settings = Settings.builder().put(key, maxContentLength + "b").build();
    final int contentLength = randomIntBetween(maxContentLength + 1, Integer.MAX_VALUE);
    runExpectHeaderTest(settings, HttpHeaderValues.CONTINUE.toString(), contentLength,
            HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE);
}