use of io.servicetalk.http.api.HttpHeaderNames.CONTENT_TYPE 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;
});
}
use of io.servicetalk.http.api.HttpHeaderNames.CONTENT_TYPE in project servicetalk by apple.
the class TestServiceStreaming method newEchoResponse.
private static StreamingHttpResponse newEchoResponse(final StreamingHttpRequest req, final StreamingHttpResponseFactory factory) {
final StreamingHttpResponse response = factory.ok().version(req.version()).transformMessageBody(pub -> pub.ignoreElements().merge(req.messageBody())).transform(new StatelessTrailersTransformer<>());
final CharSequence contentLength = req.headers().get(CONTENT_LENGTH);
if (contentLength != null) {
response.addHeader(CONTENT_LENGTH, contentLength);
}
final CharSequence contentType = req.headers().get(CONTENT_TYPE);
if (contentType != null) {
response.addHeader(CONTENT_TYPE, contentType);
}
final CharSequence transferEncoding = req.headers().get(TRANSFER_ENCODING);
if (transferEncoding != null) {
response.addHeader(TRANSFER_ENCODING, transferEncoding);
}
return response;
}
use of io.servicetalk.http.api.HttpHeaderNames.CONTENT_TYPE in project servicetalk by apple.
the class SslProvidersTest method setUp.
private void setUp(SslProvider serverSslProvider, SslProvider clientSslProvider, int payloadLength) throws Exception {
payloadBody = randomString(payloadLength);
serverContext = HttpServers.forAddress(localAddress(0)).sslConfig(new ServerSslConfigBuilder(DefaultTestCerts::loadServerPem, DefaultTestCerts::loadServerKey).provider(serverSslProvider).build()).listenBlockingAndAwait((ctx, request, responseFactory) -> {
assertThat(ctx.sslSession(), is(notNullValue()));
assertThat(request.path(), is("/path"));
assertThat(request.headers().get(CONTENT_TYPE), is(TEXT_PLAIN_UTF_8));
assertThat(request.payloadBody(textSerializerUtf8()), is("request-payload-body-" + payloadBody));
return responseFactory.ok().payloadBody("response-payload-body-" + payloadBody, textSerializerUtf8());
});
client = HttpClients.forSingleAddress(serverHostAndPort(serverContext)).ioExecutor(NettyIoExecutors.createIoExecutor("client-io")).sslConfig(new ClientSslConfigBuilder(DefaultTestCerts::loadServerCAPem).peerHost(serverPemHostname()).provider(clientSslProvider).build()).buildBlocking();
}
use of io.servicetalk.http.api.HttpHeaderNames.CONTENT_TYPE in project servicetalk by apple.
the class HeaderUtilsTest method checkContentTypeCases.
@Test
void checkContentTypeCases() {
final String invalidContentType = "invalid";
final Predicate<HttpHeaders> jsonContentTypeValidator = headers -> headers.contains(CONTENT_TYPE, APPLICATION_JSON);
checkContentType(headersWithContentType(APPLICATION_JSON), jsonContentTypeValidator);
SerializationException e = assertThrows(SerializationException.class, () -> checkContentType(headersWithContentType(of(invalidContentType)), jsonContentTypeValidator));
assertThat(e.getMessage(), containsString(invalidContentType));
}
Aggregations