Search in sources :

Example 1 with HttpResponseStatus

use of io.servicetalk.http.api.HttpResponseStatus in project servicetalk by apple.

the class HttpResponseDecoderBenchmark method setup.

@Setup(Level.Trial)
public void setup() {
    final HttpResponseStatus status = status(statusCode);
    final Buffer responseBuffer = PREFER_DIRECT_ALLOCATOR.newBuffer(100);
    HTTP_1_1.writeTo(responseBuffer);
    responseBuffer.writeByte(SP);
    status.writeTo(responseBuffer);
    responseBuffer.writeShort(CRLF_SHORT);
    responseBuffer.writeBytes("content-length: 0".getBytes(US_ASCII));
    responseBuffer.writeShort(CRLF_SHORT);
    responseBuffer.writeShort(CRLF_SHORT);
    responseByteBuf = toByteBuf(responseBuffer.slice());
    channel = new EmbeddedChannel(new HttpResponseDecoder(new ArrayDeque<>(), new PollLikePeakArrayDeque<>(), getByteBufAllocator(DEFAULT_ALLOCATOR), DefaultHttpHeadersFactory.INSTANCE, 8192, 8192, false, false, UNSUPPORTED_PROTOCOL_CLOSE_HANDLER));
}
Also used : Buffer(io.servicetalk.buffer.api.Buffer) HttpResponseStatus(io.servicetalk.http.api.HttpResponseStatus) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Setup(org.openjdk.jmh.annotations.Setup)

Example 2 with HttpResponseStatus

use of io.servicetalk.http.api.HttpResponseStatus in project servicetalk by apple.

the class HttpResponseFactoryStatusCodeTest method testStatusCode.

@Test
void testStatusCode() {
    final HttpResponseFactory httpResponseFactory = new DefaultHttpResponseFactory(INSTANCE, DEFAULT_ALLOCATOR, HTTP_1_1);
    List<HttpResponseStatus> actualStatuses = buildHttpStatuses(httpResponseFactory, HttpResponseFactory.class, HttpResponse.class);
    assertThat("unexpected statuses", actualStatuses, containsInAnyOrder(expectedStatuses.toArray()));
}
Also used : HttpResponseStatus(io.servicetalk.http.api.HttpResponseStatus) BlockingStreamingHttpResponseFactory(io.servicetalk.http.api.BlockingStreamingHttpResponseFactory) HttpResponseFactory(io.servicetalk.http.api.HttpResponseFactory) StreamingHttpResponseFactory(io.servicetalk.http.api.StreamingHttpResponseFactory) Test(org.junit.jupiter.api.Test)

Example 3 with HttpResponseStatus

use of io.servicetalk.http.api.HttpResponseStatus in project servicetalk by apple.

the class InsufficientlySizedExecutorHttpTest method insufficientServerCapacityStreaming0.

private void insufficientServerCapacityStreaming0(final int capacity) throws Exception {
    assertNotNull(client);
    final HttpResponseStatus expectedResponseStatus = capacity > 0 ? OK : SERVICE_UNAVAILABLE;
    StreamingHttpResponse response = client.request(client.get("/")).toFuture().get();
    assertThat("Unexpected response code.", response.status(), is(expectedResponseStatus));
}
Also used : HttpResponseStatus(io.servicetalk.http.api.HttpResponseStatus) StreamingHttpResponse(io.servicetalk.http.api.StreamingHttpResponse)

Example 4 with HttpResponseStatus

use of io.servicetalk.http.api.HttpResponseStatus in project servicetalk by apple.

the class HttpResponseDecoder method onMetaDataRead.

@Override
protected void onMetaDataRead(final ChannelHandlerContext ctx, final HttpResponseMetaData msg) {
    final Object signal = signalsQueue.poll();
    assert signal != null;
    if (signal != REQUEST_WITH_EXPECT_CONTINUE_SIGNAL) {
        return;
    }
    // Process a response for "Expect: 100-continue" request.
    final HttpResponseStatus status = msg.status();
    if (status.code() == CONTINUE.code()) {
        ctx.fireUserEventTriggered(ContinueUserEvent.INSTANCE);
        // Offer REQUEST_SIGNAL to suppress any events for the final response.
        signalsQueue.offerLast(REQUEST_SIGNAL);
    } else if (status.statusClass() == SUCCESSFUL_2XX) {
        // Write of payload body can continue for either 100 or 2XX response code:
        ctx.fireUserEventTriggered(ContinueUserEvent.INSTANCE);
    } else if (!isInterim(msg)) {
        // All other non-interim responses should cancel ongoing write operation when write waits for continuation.
        ctx.fireUserEventTriggered(CancelWriteUserEvent.INSTANCE);
    }
}
Also used : HttpResponseStatus(io.servicetalk.http.api.HttpResponseStatus)

Example 5 with HttpResponseStatus

use of io.servicetalk.http.api.HttpResponseStatus in project servicetalk by apple.

the class HttpReporter method encodedSpansReporter.

private static Function<Buffer, Completable> encodedSpansReporter(final HttpClient client, final Codec codec) {
    final String path;
    final CharSequence contentType;
    switch(codec) {
        case JSON_V1:
            path = V1_PATH;
            contentType = APPLICATION_JSON;
            break;
        case JSON_V2:
            path = V2_PATH;
            contentType = APPLICATION_JSON;
            break;
        case THRIFT:
            path = V2_PATH;
            contentType = THRIFT_CONTENT_TYPE;
            break;
        case PROTO3:
            path = V2_PATH;
            contentType = PROTO_CONTENT_TYPE;
            break;
        default:
            throw new IllegalArgumentException("Unknown codec: " + codec);
    }
    return encodedSpans -> client.request(client.post(path).setHeader(CONTENT_TYPE, contentType).payloadBody(encodedSpans)).beforeOnSuccess(response -> {
        HttpResponseStatus status = response.status();
        if (status.statusClass() != SUCCESSFUL_2XX) {
            LOGGER.info("Unexpected response from the collector. Response headers: {}", response.toString((__, headerValue) -> headerValue));
        }
    }).ignoreElement().onErrorComplete(cause -> {
        LOGGER.error("Failed to send a span, ignoring.", cause);
        return true;
    });
}
Also used : APPLICATION_JSON(io.servicetalk.http.api.HttpHeaderValues.APPLICATION_JSON) Publisher(io.servicetalk.concurrent.api.Publisher) LoggerFactory(org.slf4j.LoggerFactory) Span(zipkin2.Span) CONTENT_TYPE(io.servicetalk.http.api.HttpHeaderNames.CONTENT_TYPE) CharSequences.newAsciiString(io.servicetalk.buffer.api.CharSequences.newAsciiString) Duration.ofSeconds(java.time.Duration.ofSeconds) Function(java.util.function.Function) ArrayList(java.util.ArrayList) SourceAdapters.fromSource(io.servicetalk.concurrent.api.SourceAdapters.fromSource) Duration(java.time.Duration) Objects.requireNonNull(java.util.Objects.requireNonNull) Component(zipkin2.Component) SpanBytesEncoder(zipkin2.codec.SpanBytesEncoder) HttpClient(io.servicetalk.http.api.HttpClient) AsyncCloseable(io.servicetalk.concurrent.api.AsyncCloseable) Reporter(zipkin2.reporter.Reporter) Nonnull(javax.annotation.Nonnull) Processors.newCompletableProcessor(io.servicetalk.concurrent.api.Processors.newCompletableProcessor) Accumulator(io.servicetalk.concurrent.api.BufferStrategy.Accumulator) Processors.newPublisherProcessorDropHeadOnOverflow(io.servicetalk.concurrent.api.Processors.newPublisherProcessorDropHeadOnOverflow) Logger(org.slf4j.Logger) FutureUtils.awaitTermination(io.servicetalk.concurrent.internal.FutureUtils.awaitTermination) PublisherSource(io.servicetalk.concurrent.PublisherSource) OK(zipkin2.CheckResult.OK) Completable(io.servicetalk.concurrent.api.Completable) CompositeCloseable(io.servicetalk.concurrent.api.CompositeCloseable) CheckResult.failed(zipkin2.CheckResult.failed) BufferStrategies.forCountOrTime(io.servicetalk.concurrent.api.BufferStrategies.forCountOrTime) AsyncCloseables.newCompositeCloseable(io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable) CheckResult(zipkin2.CheckResult) AsyncCloseables.toAsyncCloseable(io.servicetalk.concurrent.api.AsyncCloseables.toAsyncCloseable) SourceAdapters.toSource(io.servicetalk.concurrent.api.SourceAdapters.toSource) CompletableSource(io.servicetalk.concurrent.CompletableSource) SUCCESSFUL_2XX(io.servicetalk.http.api.HttpResponseStatus.StatusClass.SUCCESSFUL_2XX) SingleAddressHttpClientBuilder(io.servicetalk.http.api.SingleAddressHttpClientBuilder) List(java.util.List) Buffer(io.servicetalk.buffer.api.Buffer) BufferAllocator(io.servicetalk.buffer.api.BufferAllocator) Completable.completed(io.servicetalk.concurrent.api.Completable.completed) Collections(java.util.Collections) HttpResponseStatus(io.servicetalk.http.api.HttpResponseStatus) HttpResponseStatus(io.servicetalk.http.api.HttpResponseStatus) CharSequences.newAsciiString(io.servicetalk.buffer.api.CharSequences.newAsciiString)

Aggregations

HttpResponseStatus (io.servicetalk.http.api.HttpResponseStatus)14 StreamingHttpResponse (io.servicetalk.http.api.StreamingHttpResponse)4 Test (org.junit.jupiter.api.Test)4 Buffer (io.servicetalk.buffer.api.Buffer)3 AsyncCloseables.newCompositeCloseable (io.servicetalk.concurrent.api.AsyncCloseables.newCompositeCloseable)3 CompositeCloseable (io.servicetalk.concurrent.api.CompositeCloseable)3 Publisher (io.servicetalk.concurrent.api.Publisher)3 BlockingStreamingHttpResponseFactory (io.servicetalk.http.api.BlockingStreamingHttpResponseFactory)3 StreamingHttpResponseFactory (io.servicetalk.http.api.StreamingHttpResponseFactory)3 Completable (io.servicetalk.concurrent.api.Completable)2 Completable.completed (io.servicetalk.concurrent.api.Completable.completed)2 SourceAdapters.toSource (io.servicetalk.concurrent.api.SourceAdapters.toSource)2 CONTENT_LENGTH (io.servicetalk.http.api.HttpHeaderNames.CONTENT_LENGTH)2 HttpHeaders (io.servicetalk.http.api.HttpHeaders)2 HttpRequestMethod (io.servicetalk.http.api.HttpRequestMethod)2 ServerContext (io.servicetalk.transport.api.ServerContext)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1