use of io.vertx.rxjava3.core.buffer.Buffer 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 io.vertx.rxjava3.core.buffer.Buffer in project julian-http-client by ljtfreitas.
the class RxVertxHTTPClient method request.
@Override
public HTTPClientRequest request(HTTPRequestDefinition request) {
RequestOptions options = new RequestOptions().setAbsoluteURI(request.path().toString()).setMethod(HttpMethod.valueOf(request.method().name())).setHeaders(request.headers().all().stream().reduce(MultiMap.caseInsensitiveMultiMap(), (m, h) -> m.add(h.name(), h.values()), (a, b) -> b));
Flowable<Buffer> bodyAsFlowable = request.body().map(b -> FlowAdapters.toPublisher(b.serialize())).map(Flowable::fromPublisher).orElseGet(Flowable::empty).map(buf -> Buffer.buffer(buf.array()));
return new VertxHTTPClientRequest(client, options, bodyAsFlowable);
}
Aggregations