public void sendRequestHeader(HttpRequest request) throws HttpException, IOException { try { HttpHost host = route.getTargetHost(); URI uri = new URI(host.getSchemeName() + "://" + host.getHostName() + ((host.getPort() == -1) ? "" : (":" + host.getPort())) + request.getRequestLine().getUri()); this.request = new HTTPRequest(uri.toURL(), HTTPMethod.valueOf(request.getRequestLine().getMethod()), FetchOptions.Builder.disallowTruncate().doNotFollowRedirects()); } catch (URISyntaxException ex) { throw new IOException("Malformed request URI: " + ex.getMessage(), ex); } catch (IllegalArgumentException ex) { throw new IOException("Unsupported HTTP method: " + ex.getMessage(), ex); } // System.err.println("SEND: " + this.request.getMethod() + " " + this.request.getURL()); for (Header h : request.getAllHeaders()) { // System.err.println("SEND: " + h.getName() + ": " + h.getValue()); this.request.addHeader(new HTTPHeader(h.getName(), h.getValue())); } }
public void sendRequestHeader(HttpRequest request) throws HttpException, IOException { try { HttpHost host = route.getTargetHost(); URI uri = new URI(host.getSchemeName() + "://" + host.getHostName() + ((host.getPort() == -1) ? "" : (":" + host.getPort())) + request.getRequestLine().getUri()); this.request = new HTTPRequest(uri.toURL(), HTTPMethod.valueOf(request.getRequestLine().getMethod()), FetchOptions.Builder.disallowTruncate().doNotFollowRedirects()); } catch (URISyntaxException ex) { throw new IOException("Malformed request URI: " + ex.getMessage(), ex); } catch (IllegalArgumentException ex) { throw new IOException("Unsupported HTTP method: " + ex.getMessage(), ex); } // System.err.println("SEND: " + this.request.getMethod() + " " + this.request.getURL()); for (Header h : request.getAllHeaders()) { // System.err.println("SEND: " + h.getName() + ": " + h.getValue()); this.request.addHeader(new HTTPHeader(h.getName(), h.getValue())); } }
@VisibleForTesting HTTPRequest makeRequest(GcsFilename filename, @Nullable Map<String, String> queryStrings, HTTPMethod method, long timeoutMillis, byte[] payload) { HTTPRequest request = new HTTPRequest(makeUrl(filename, queryStrings), method, FetchOptions.Builder.disallowTruncate() .doNotFollowRedirects() .validateCertificate() .setDeadline(timeoutMillis / 1000.0)); for (HTTPHeader header : headers) { request.addHeader(header); } request.addHeader(USER_AGENT); if (payload != null && payload.length > 0) { request.setHeader(new HTTPHeader(CONTENT_LENGTH, String.valueOf(payload.length))); try { request.setHeader(new HTTPHeader(CONTENT_MD5, BaseEncoding.base64().encode(MessageDigest.getInstance("MD5").digest(payload)))); } catch (NoSuchAlgorithmException e) { log.severe( "Unable to get a MessageDigest instance, no Content-MD5 header sent.\n" + e.toString()); } request.setPayload(payload); } else { request.setHeader(ZERO_CONTENT_LENGTH); } return request; }
FetchOptions options = disallowTruncate(); options.doNotFollowRedirects(); if (utils.relaxHostname() || utils.trustAllCerts())
FetchOptions options = disallowTruncate(); options.doNotFollowRedirects(); if (utils.relaxHostname() || utils.trustAllCerts())
@Test public void testDisallowTruncate() throws Exception { FetchOptions options = FetchOptions.Builder.disallowTruncate(); testOptions(options); }