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));
}
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()));
}
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));
}
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);
}
}
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;
});
}
Aggregations