List of usage examples for io.vertx.core.http HttpClientResponse headers
@CacheReturn MultiMap headers();
From source file:examples.HTTPExamples.java
License:Open Source License
public void example46(HttpClientResponse response) { String contentType = response.headers().get("content-type"); String contentLength = response.headers().get("content-lengh"); }
From source file:io.advantageous.qbit.vertx.http.client.HttpVertxClient.java
License:Apache License
private void handleResponse(final HttpRequest request, final HttpClientResponse httpClientResponse) { final int statusCode = httpClientResponse.statusCode(); final MultiMap<String, String> headers = httpClientResponse.headers().size() == 0 ? MultiMap.empty() : new MultiMapWrapper(httpClientResponse.headers()); if (debug) {//from w w w. j a v a 2 s. c o m responseCount++; puts("status code", httpClientResponse.statusCode(), responseCount); } httpClientResponse.bodyHandler(buffer -> { if (request.getReceiver().isText()) { final String body = buffer.toString("UTF-8"); if (debug) { puts("got body", "BODY"); } handleResponseFromServer(request, statusCode, headers, body); } else { final byte[] body = buffer.getBytes(); handleResponseFromServerBytes(request, statusCode, headers, body); } }); }
From source file:io.apiman.gateway.platforms.vertx3.http.HttpApiFactory.java
License:Apache License
public static ApiResponse buildResponse(HttpClientResponse response, Set<String> suppressHeaders) { ApiResponse apimanResponse = new ApiResponse(); apimanResponse.setCode(response.statusCode()); apimanResponse.setMessage(response.statusMessage()); multimapToMap(apimanResponse.getHeaders(), response.headers(), suppressHeaders); return apimanResponse; }
From source file:io.apiman.gateway.platforms.vertx3.http.HttpServiceFactory.java
License:Apache License
public static VertxServiceResponse buildResponse(HttpClientResponse response, Set<String> suppressHeaders) { VertxServiceResponse apimanResponse = new VertxServiceResponse(); apimanResponse.setCode(response.statusCode()); apimanResponse.setMessage(response.statusMessage()); multimapToMap(apimanResponse.getHeaders(), response.headers(), suppressHeaders); return apimanResponse; }
From source file:io.gravitee.gateway.http.connector.VertxHttpClient.java
License:Apache License
private void handleClientResponse(final VertxProxyConnection proxyConnection, final HttpClientResponse clientResponse, final HttpClientRequest clientRequest) { VertxProxyResponse proxyClientResponse = new VertxProxyResponse(clientResponse); proxyConnection.setProxyResponse(proxyClientResponse); // Copy HTTP headers clientResponse.headers().names().forEach(headerName -> proxyClientResponse.headers().put(headerName, clientResponse.headers().getAll(headerName))); proxyClientResponse.pause();//from ww w .j a va2 s. c o m // Copy body content clientResponse.handler(event -> proxyClientResponse.bodyHandler().handle(Buffer.buffer(event.getBytes()))); // Signal end of the response clientResponse.endHandler(v -> proxyClientResponse.endHandler().handle(null)); clientResponse.exceptionHandler(throwable -> { LOGGER.error("Unexpected error while handling backend response for request {} {} - {}", clientRequest.method(), clientRequest.absoluteURI(), throwable.getMessage()); ProxyResponse clientResponse1 = new EmptyProxyResponse(HttpStatusCode.BAD_GATEWAY_502); proxyConnection.handleResponse(clientResponse1); }); proxyConnection.handleResponse(proxyClientResponse); }
From source file:io.gravitee.gateway.http.vertx.VertxHttpClient.java
License:Apache License
private void handleClientResponse(HttpClientResponse clientResponse, Handler<ClientResponse> clientResponseHandler) { VertxClientResponse proxyClientResponse = new VertxClientResponse(clientResponse.statusCode()); // Copy HTTP headers clientResponse.headers().names().forEach(headerName -> proxyClientResponse.headers().put(headerName, clientResponse.headers().getAll(headerName))); // Copy body content clientResponse.handler(event -> proxyClientResponse.bodyHandler().handle(Buffer.buffer(event.getBytes()))); // Signal end of the response clientResponse.endHandler(v -> proxyClientResponse.endHandler().handle(null)); clientResponseHandler.handle(proxyClientResponse); }
From source file:io.gravitee.gateway.services.healthcheck.http.el.EvaluableHttpResponse.java
License:Apache License
public EvaluableHttpResponse(final HttpClientResponse response, final String content) { this.statusCode = response.statusCode(); this.content = content; // Copy HTTP headers response.headers().names() .forEach(headerName -> httpHeaders.put(headerName, response.headers().getAll(headerName))); }
From source file:io.nitor.api.backend.msgraph.GraphQueryHandler.java
License:Apache License
private void mapResponse(HttpClientResponse cres, HttpServerResponse sres, String clientRequestId) { cres.exceptionHandler(t -> {/* w ww .ja va 2 s .c o m*/ logger.error("Error processing graph request [" + clientRequestId + "]", t); if (!sres.ended()) { sres.setStatusCode(BAD_GATEWAY.code()); sres.end(); } }); // TODO Together with the client-request-id always log the request-id, timestamp and x-ms-ags-diagnostic from the HTTP response headers sres.setStatusCode(cres.statusCode()); sres.setStatusMessage(cres.statusMessage()); MultiMap headers = sres.headers(); cres.headers().forEach(entry -> { String key = entry.getKey(); String lKey = key.toLowerCase(); if ("server".equals(lKey) || "accept-ranges".equals(lKey) || "transfer-encoding".equals(lKey) || "date".equals(lKey) || "connection".equals(lKey)) { return; } headers.add(key, entry.getValue()); }); if (!headers.contains("content-length")) { sres.setChunked(true); } Pump resPump = Pump.pump(cres, sres); cres.endHandler(v -> { if (!sres.ended()) sres.end(); }); resPump.start(); }
From source file:io.nitor.api.backend.proxy.SimpleLogProxyTracer.java
License:Apache License
String dumpCRes(HttpClientResponse res) { return "\n\t" + res.statusCode() + " " + res.statusMessage() + dumpHeaders(res.headers(), "\t"); }
From source file:io.nitor.api.backend.s3.S3Handler.java
License:Apache License
private void mapResponse(HttpClientResponse cres, HttpServerResponse sres) { cres.exceptionHandler(t -> {// w ww . j a va2s . c om logger.error("Error processing s3 request", t); if (!sres.ended()) { sres.setStatusCode(502); sres.end(); } }); sres.setStatusCode(cres.statusCode()); sres.setStatusMessage(cres.statusMessage()); if (cres.statusCode() != 200 && cres.statusCode() != 206) { sres.end(); return; } MultiMap headers = sres.headers(); cres.headers().forEach(entry -> { String key = entry.getKey(); if (key.startsWith("x-amz-")) { return; } String lKey = key.toLowerCase(); if ("server".equals(lKey) || "accept-ranges".equals(lKey) || "transfer-encoding".equals(lKey) || "date".equals(lKey) || "connection".equals(lKey)) { return; } headers.add(key, entry.getValue()); }); // TODO handle http 1.0 that requires connection header Pump resPump = Pump.pump(cres, sres); cres.endHandler(v -> sres.end()); resPump.start(); }