Refine search
@Override public HttpHeaders getHeaders() { if (this.headers == null) { this.headers = new HttpHeaders(); for (Header header : this.httpResponse.getAllHeaders()) { this.headers.add(header.getName(), header.getValue()); } } return this.headers; }
@Override public HttpHeaders getHeaders() { if (this.headers == null) { this.headers = new HttpHeaders(); for (Header header : this.httpResponse.getAllHeaders()) { this.headers.add(header.getName(), header.getValue()); } } return this.headers; }
@Override public HttpHeaders getHeaders() { if (this.headers == null) { this.headers = new HttpHeaders(); for (Header header : this.httpResponse.getAllHeaders()) { this.headers.add(header.getName(), header.getValue()); } } return this.headers; }
@Override public HttpHeaders getHeaders() { if (this.headers == null) { this.headers = new HttpHeaders(); for (Header header : this.httpResponse.getAllHeaders()) { this.headers.add(header.getName(), header.getValue()); } } return this.headers; }
static String getHTTPResponseTrace(HttpResponse response) { StringBuilder sb = new StringBuilder(); sb.append(response.getStatusLine()).append('\n'); for (Header h : response.getAllHeaders()) { sb.append(h.getName()).append(": ").append(h.getValue()).append('\n'); } sb.append('\n'); HttpEntity e = response.getEntity(); if (e != null) { appendHttpEntity(sb, e); } return sb.toString(); }
protected String getFileName(String fileToDownloadLocation, HttpResponse response) { for (Header header : response.getAllHeaders()) { Optional<String> fileName = httpHelper.getFileNameFromContentDisposition(header.getName(), header.getValue()); if (fileName.isPresent()) { return fileName.get(); } } log.info("Cannot extract file name from http headers. Found headers: "); for (Header header : response.getAllHeaders()) { log.info(header.getName() + '=' + header.getValue()); } String fullFileName = FilenameUtils.getName(fileToDownloadLocation); return isBlank(fullFileName) ? downloader.randomFileName() : trimQuery(fullFileName); }
private static HttpResp response(HttpResponse response) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter printer = new PrintWriter(baos); printer.print(response.getStatusLine() + ""); printer.print("\n"); Map<String, String> headers = U.map(); for (Header hdr : response.getAllHeaders()) { printer.print(hdr.getName()); printer.print(": "); printer.print(hdr.getValue()); printer.print("\n"); headers.put(hdr.getName(), hdr.getValue()); } printer.print("\n"); printer.flush(); HttpEntity entity = response.getEntity(); byte[] body = entity != null ? IO.loadBytes(response.getEntity().getContent()) : new byte[0]; baos.write(body); byte[] raw = baos.toByteArray(); return new HttpResp(raw, response.getStatusLine().getStatusCode(), headers, body); }
/** * This method populates <code>curi</code> with response status and * content type. * * @param curi * CrawlURI to populate. * @param response * Method to get response status and headers from. */ protected void addResponseContent(HttpResponse response, CrawlURI curi) { curi.setFetchStatus(response.getStatusLine().getStatusCode()); Header ct = response.getLastHeader("content-type"); curi.setContentType(ct == null ? null : ct.getValue()); for (Header h: response.getAllHeaders()) { curi.putHttpResponseHeader(h.getName(), h.getValue()); } }
public Response headers(final BiConsumer<String, String> headers) throws Exception { for (Header header : rsp.getAllHeaders()) { headers.accept(header.getName(), header.getValue()); } return this; }
/** * Creates and initializes an HttpResponse object suitable to be passed to an HTTP response * handler object. * * @param request Marshalled request object. * @param method The HTTP method that was invoked to get the response. * @param context The HTTP context associated with the request and response. * @return The new, initialized HttpResponse object ready to be passed to an HTTP response * handler object. * @throws IOException If there were any problems getting any response information from the * HttpClient method object. */ public static HttpResponse createResponse(Request<?> request, HttpRequestBase method, org.apache.http.HttpResponse apacheHttpResponse, HttpContext context) throws IOException { HttpResponse httpResponse = new HttpResponse(request, method, context); if (apacheHttpResponse.getEntity() != null) { httpResponse.setContent(apacheHttpResponse.getEntity().getContent()); } httpResponse.setStatusCode(apacheHttpResponse.getStatusLine().getStatusCode()); httpResponse.setStatusText(apacheHttpResponse.getStatusLine().getReasonPhrase()); for (Header header : apacheHttpResponse.getAllHeaders()) { httpResponse.addHeader(header.getName(), header.getValue()); } return httpResponse; }
private HttpResponse setupNormalResponse(final org.apache.http.HttpResponse remoteResponse) throws IOException { HttpVersion httpVersion = HttpVersion.valueOf(remoteResponse.getProtocolVersion().toString()); HttpResponseStatus status = HttpResponseStatus.valueOf(remoteResponse.getStatusLine().getStatusCode()); FullHttpResponse response = new DefaultFullHttpResponse(httpVersion, status); response.setStatus(status); Header[] allHeaders = remoteResponse.getAllHeaders(); for (Header header : allHeaders) { if (isResponseHeader(header)) { response.headers().set(header.getName(), header.getValue()); } } HttpEntity entity = remoteResponse.getEntity(); if (entity != null) { byte[] content = toByteArray(entity); if (content.length > 0) { ByteBuf buffer = Unpooled.copiedBuffer(content); response.content().writeBytes(buffer); } } return newResponse(response); }
ObjectMapper objectMapper = (ObjectMapper) Options.getOption(Option.OBJECT_MAPPER); Header[] allHeaders = response.getAllHeaders(); for (Header header : allHeaders) { String headerName = header.getName(); List<String> list = headers.get(headerName); if (list == null)
response.setStatusLine(http_res.getStatusLine().toString()); final Header[] responseHeaders = http_res.getAllHeaders(); for (Header header : responseHeaders) { response.addHeader(header.getName(), header.getValue());
@Override public Map<String, List<String>> getAllHeaders() { Map<String, List<String>> headers = new HashMap<>(); if (myResponse.getAllHeaders() != null) { for (Header next : myResponse.getAllHeaders()) { String name = next.getName().toLowerCase(); List<String> list = headers.get(name); if (list == null) { list = new ArrayList<>(); headers.put(name, list); } list.add(next.getValue()); } } return headers; }
public static CaseInsensitiveMap<String> extractHeaders(HttpResponse response) { final CaseInsensitiveMap<String> headers = new CaseInsensitiveMap<String>(); for (Header header : response.getAllHeaders()) { headers.add(header.getName(), header.getValue()); } return headers; }
@Override public HttpHeaders getHeaders() { if (headers == null) { headers = new HttpHeaders(); Header[] headers = httpResponse.getAllHeaders(); for (Header header : headers) { this.headers.add(header.getName(), header.getValue()); } } return headers; }
private static void copyResponse(HttpResponse httpResponse, ClientResponse clientResponse) { clientResponse.setStatus(httpResponse.getStatusLine().getStatusCode()); CaseInsensitiveMap<String> headers = new CaseInsensitiveMap<String>(); for (Header header : httpResponse.getAllHeaders()) { headers.add(header.getName(), header.getValue()); } clientResponse.setHeaders(headers); }
String body = EntityUtils.toString(entity); HashMap<String, String> m = new HashMap<String, String>(); for (Header h : response.getAllHeaders()) { m.put(h.getName(), h.getValue());
@Override public HttpResponse execute(HttpRequest request) throws IOException { HttpUriRequest httpRequest = createHttpRequest(request); org.apache.http.HttpResponse httpResponse = httpClient.execute(httpRequest); String statusText = httpResponse.getStatusLine().getReasonPhrase(); int statusCode = httpResponse.getStatusLine().getStatusCode(); InputStream content = null; if (httpResponse.getEntity() != null) { content = httpResponse.getEntity().getContent(); } HttpResponse.Builder builder = HttpResponse.builder() .statusCode(statusCode) .statusText(statusText) .content(content); for (Header header : httpResponse.getAllHeaders()) { builder.header(header.getName(), header.getValue()); } return builder.build(); }
/** * Creates and initializes an HttpResponse object suitable to be passed to an HTTP response * handler object. * * @param request Marshalled request object. * @param method The HTTP method that was invoked to get the response. * @param context The HTTP context associated with the request and response. * @return The new, initialized HttpResponse object ready to be passed to an HTTP response * handler object. * @throws IOException If there were any problems getting any response information from the * HttpClient method object. */ public static HttpResponse createResponse(Request<?> request, HttpRequestBase method, org.apache.http.HttpResponse apacheHttpResponse, HttpContext context) throws IOException { HttpResponse httpResponse = new HttpResponse(request, method, context); if (apacheHttpResponse.getEntity() != null) { httpResponse.setContent(apacheHttpResponse.getEntity().getContent()); } httpResponse.setStatusCode(apacheHttpResponse.getStatusLine().getStatusCode()); httpResponse.setStatusText(apacheHttpResponse.getStatusLine().getReasonPhrase()); for (Header header : apacheHttpResponse.getAllHeaders()) { httpResponse.addHeader(header.getName(), header.getValue()); } return httpResponse; }