use of com.github.ljtfreitas.julian.http.HTTPStatus in project julian-http-client by ljtfreitas.
the class DefaultHTTPClientResponse method valueOf.
static DefaultHTTPClientResponse valueOf(HttpResponse<Publisher<List<ByteBuffer>>> response) {
HTTPStatus status = HTTPStatusCode.select(response.statusCode()).map(HTTPStatus::new).orElseGet(() -> HTTPStatus.valueOf(response.statusCode()));
HTTPHeaders headers = response.headers().map().entrySet().stream().map(e -> HTTPHeader.create(e.getKey(), e.getValue())).reduce(HTTPHeaders.empty(), HTTPHeaders::join, (a, b) -> b);
HTTPResponseBody body = HTTPResponseBody.optional(status, headers, () -> HTTPResponseBody.lazy(response.body()));
return new DefaultHTTPClientResponse(status, headers, body);
}
use of com.github.ljtfreitas.julian.http.HTTPStatus in project julian-http-client by ljtfreitas.
the class WebClientHTTPRequest method read.
Mono<HTTPResponse<T>> read(ClientResponse response) {
HTTPStatus status = new HTTPStatus(response.rawStatusCode(), response.statusCode().getReasonPhrase());
HTTPHeaders headers = response.headers().asHttpHeaders().entrySet().stream().reduce(HTTPHeaders.empty(), (h, e) -> h.join(new HTTPHeader(e.getKey(), e.getValue())), (a, b) -> b);
if (response.statusCode().isError()) {
return response.createException().map(e -> failure(status, headers, e));
} else {
return success(status, headers, response);
}
}
use of com.github.ljtfreitas.julian.http.HTTPStatus in project julian-http-client by ljtfreitas.
the class VertxHTTPClientResponse method valueOf.
static Single<VertxHTTPClientResponse> valueOf(HttpClientResponse response) {
HTTPStatus status = HTTPStatusCode.select(response.statusCode()).map(HTTPStatus::new).orElseGet(() -> new HTTPStatus(response.statusCode(), response.statusMessage()));
HTTPHeaders headers = response.headers().names().stream().map(name -> HTTPHeader.create(name, response.headers().getAll(name))).reduce(HTTPHeaders.empty(), HTTPHeaders::join, (a, b) -> b);
Maybe<byte[]> bodyAsBytes = response.body().map(Buffer::getBytes).toMaybe();
return bodyAsBytes.map(body -> HTTPResponseBody.optional(status, headers, () -> HTTPResponseBody.some(body))).map(body -> new VertxHTTPClientResponse(HTTPClientResponse.create(status, headers, body))).switchIfEmpty(Single.fromCallable(() -> new VertxHTTPClientResponse(HTTPClientResponse.empty(status, headers))));
}
use of com.github.ljtfreitas.julian.http.HTTPStatus in project julian-http-client by ljtfreitas.
the class ReactorNettyHTTPClientResponse method valueOf.
static Mono<ReactorNettyHTTPClientResponse> valueOf(HttpClientResponse response, ByteBufMono bodyAsBuffer) {
HTTPStatus status = HTTPStatusCode.select(response.status().code()).map(HTTPStatus::new).orElseGet(() -> new HTTPStatus(response.status().code(), response.status().reasonPhrase()));
HTTPHeaders headers = response.responseHeaders().names().stream().map(name -> HTTPHeader.create(name, response.responseHeaders().getAll(name))).reduce(HTTPHeaders.empty(), HTTPHeaders::join, (a, b) -> b);
return bodyAsBuffer.asByteArray().map(bodyAsBytes -> HTTPResponseBody.optional(status, headers, () -> HTTPResponseBody.some(bodyAsBytes))).map(body -> new ReactorNettyHTTPClientResponse(HTTPClientResponse.create(status, headers, body))).switchIfEmpty(Mono.fromCallable(() -> new ReactorNettyHTTPClientResponse(HTTPClientResponse.empty(status, headers))));
}
Aggregations