Search in sources :

Example 1 with HTTPResponseBody

use of com.github.ljtfreitas.julian.http.HTTPResponseBody 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);
}
Also used : HTTPStatusCode(com.github.ljtfreitas.julian.http.HTTPStatusCode) Response(com.github.ljtfreitas.julian.Response) List(java.util.List) Publisher(java.util.concurrent.Flow.Publisher) 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) Function(java.util.function.Function) ByteBuffer(java.nio.ByteBuffer) HTTPResponseBody(com.github.ljtfreitas.julian.http.HTTPResponseBody) HttpResponse(java.net.http.HttpResponse) HTTPResponseBody(com.github.ljtfreitas.julian.http.HTTPResponseBody) 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 HttpResponse (java.net.http.HttpResponse)1 ByteBuffer (java.nio.ByteBuffer)1 List (java.util.List)1 Optional (java.util.Optional)1 Publisher (java.util.concurrent.Flow.Publisher)1 Function (java.util.function.Function)1