protected HttpResponse makeRequest(HttpRequest httpRequest, Collection<String> headersToIgnore) { int port = (httpRequest.isSecure() ? SERVER_HTTPS_PORT : SERVER_HTTP_PORT); HttpResponse httpResponse = httpClient.sendRequest(outboundRequest("localhost", port, "", httpRequest)); List<Header> headers = new ArrayList<Header>(); for (Header header : httpResponse.getHeaders()) { if (!headersToIgnore.contains(header.getName().getValue().toLowerCase())) { headers.add(header); } } httpResponse.withHeaders(headers); return httpResponse; }
private void setHeaders(HttpResponse response, DefaultFullHttpResponse httpServletResponse) { if (response.getHeaders() != null) { for (Header header : response.getHeaders()) { for (NottableString value : header.getValues()) { httpServletResponse.headers().add(header.getName().getValue(), value.getValue()); } } } if (Strings.isNullOrEmpty(response.getFirstHeader(CONTENT_TYPE))) { if (response.getBody() != null && !Strings.isNullOrEmpty(response.getBody().toString())) { Charset bodyCharset = response.getBody().getCharset(null); String bodyContentType = response.getBody().getContentType(); if (bodyCharset != null) { httpServletResponse .headers() .set(CONTENT_TYPE, bodyContentType + "; charset=" + bodyCharset.name().toLowerCase()); } else if (bodyContentType != null) { httpServletResponse.headers().set(CONTENT_TYPE, bodyContentType); } } } }