FetchOptions.Builder.doNotFollowRedirects().disallowTruncate().validateCertificate(); switch (certificateValidationBehavior) { case VALIDATE: fetchOptions.validateCertificate(); break; case DO_NOT_VALIDATE:
/** * Returns a new instance of the default {@link FetchOptions} used by this requestor. This * method exists primarily since {@link FetchOptions} provides no copy methods. * * @return new instance of default fetch options used by this requestor. */ public static FetchOptions newDefaultOptions() { return FetchOptions.Builder.withDefaults() .validateCertificate() .doNotFollowRedirects() .disallowTruncate() // seconds .setDeadline((DEFAULT_CONNECT_TIMEOUT_MILLIS + DEFAULT_READ_TIMEOUT_MILLIS)/1000.0); }
@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; }
@Test public void testValidateCertificate() throws Exception { FetchOptions options = buildFetchOptions(); options.validateCertificate(); testOptions(options); }
.getReadTimeout() / 1000).validateCertificate(); HTTPRequest request = new HTTPRequest(url, HTTPMethod.POST, fetchOptions);
.getReadTimeout() / 1000).validateCertificate(); HTTPRequest request = new HTTPRequest(url, HTTPMethod.POST, fetchOptions);