Search in sources :

Example 1 with HttpClientResponse

use of io.vertx.rxjava3.core.http.HttpClientResponse 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))));
}
Also used : Single(io.reactivex.rxjava3.core.Single) Function(java.util.function.Function) HTTPResponseBody(com.github.ljtfreitas.julian.http.HTTPResponseBody) HTTPStatusCode(com.github.ljtfreitas.julian.http.HTTPStatusCode) Maybe(io.reactivex.rxjava3.core.Maybe) Response(com.github.ljtfreitas.julian.Response) HTTPHeader(com.github.ljtfreitas.julian.http.HTTPHeader) HTTPHeaders(com.github.ljtfreitas.julian.http.HTTPHeaders) HTTPStatus(com.github.ljtfreitas.julian.http.HTTPStatus) Optional(java.util.Optional) Buffer(io.vertx.rxjava3.core.buffer.Buffer) HTTPClientResponse(com.github.ljtfreitas.julian.http.client.HTTPClientResponse) HttpClientResponse(io.vertx.rxjava3.core.http.HttpClientResponse) HTTPHeaders(com.github.ljtfreitas.julian.http.HTTPHeaders) HTTPStatus(com.github.ljtfreitas.julian.http.HTTPStatus)

Aggregations

Response (com.github.ljtfreitas.julian.Response)1 HTTPHeader (com.github.ljtfreitas.julian.http.HTTPHeader)1 HTTPHeaders (com.github.ljtfreitas.julian.http.HTTPHeaders)1 HTTPResponseBody (com.github.ljtfreitas.julian.http.HTTPResponseBody)1 HTTPStatus (com.github.ljtfreitas.julian.http.HTTPStatus)1 HTTPStatusCode (com.github.ljtfreitas.julian.http.HTTPStatusCode)1 HTTPClientResponse (com.github.ljtfreitas.julian.http.client.HTTPClientResponse)1 Maybe (io.reactivex.rxjava3.core.Maybe)1 Single (io.reactivex.rxjava3.core.Single)1 Buffer (io.vertx.rxjava3.core.buffer.Buffer)1 HttpClientResponse (io.vertx.rxjava3.core.http.HttpClientResponse)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1