use of com.hotels.styx.api.ByteStream in project styx by ExpediaGroup.
the class NettyToStyxRequestDecoder method makeAStyxRequestFrom.
@VisibleForTesting
LiveHttpRequest.Builder makeAStyxRequestFrom(HttpRequest request, Observable<ByteBuf> content) {
Url url = UrlDecoder.decodeUrl(unwiseCharEncoder, request);
LiveHttpRequest.Builder requestBuilder = new LiveHttpRequest.Builder().method(toStyxMethod(request.method())).url(url).version(toStyxVersion(request.protocolVersion())).id(uniqueIdSupplier.get()).body(new ByteStream(toPublisher(content.map(Buffers::fromByteBuf))));
stream(request.headers().spliterator(), false).forEach(entry -> requestBuilder.addHeader(entry.getKey(), entry.getValue()));
return requestBuilder;
}
use of com.hotels.styx.api.ByteStream in project styx by ExpediaGroup.
the class HttpPipelineHandler method exceptionToResponse.
private LiveHttpResponse exceptionToResponse(Throwable cause, LiveHttpRequest request, CharSequence originsHeaderName) {
HttpResponseStatus status = status(cause instanceof PluginException ? cause.getCause() : cause);
String message = status.code() >= 500 ? "Site temporarily unavailable." : status.description();
LiveHttpResponse.Transformer builder = responseEnhancer.enhance(response(status).body(new ByteStream(Flux.just(new Buffer(message, UTF_8)))).build().newBuilder(), request).header(CONTENT_LENGTH, message.getBytes(UTF_8).length).header(CONNECTION, "close");
if (originsHeaderName != null && originFromException(cause) != null) {
return builder.header(originsHeaderName, originFromException(cause)).build();
} else {
return builder.build();
}
}
Aggregations