@Test public void testGetters() throws Exception { HTTPRequest request = new HTTPRequest(getFetchUrl(), HTTPMethod.PATCH, FetchOptions.Builder.withDefaults()); request.addHeader(new HTTPHeader("foo", "bar")); request.setPayload("qwerty".getBytes()); Assert.assertEquals(getFetchUrl(), request.getURL()); Assert.assertEquals(HTTPMethod.PATCH, request.getMethod()); Assert.assertNotNull(request.getFetchOptions()); Assert.assertNotNull(request.getHeaders()); Assert.assertEquals(1, request.getHeaders().size()); assertEquals(new HTTPHeader("foo", "bar"), request.getHeaders().get(0)); Assert.assertArrayEquals("qwerty".getBytes(), request.getPayload()); }
@Test(expected = IOException.class) public void fetchNonExistentLocalAppThrowsException() throws Exception { URL selfURL = new URL("BOGUS-" + appUrlBase + "/"); FetchOptions fetchOptions = FetchOptions.Builder.withDefaults() .doNotFollowRedirects() .setDeadline(10.0); HTTPRequest httpRequest = new HTTPRequest(selfURL, HTTPMethod.GET, fetchOptions); URLFetchService urlFetchService = URLFetchServiceFactory.getURLFetchService(); HTTPResponse httpResponse = urlFetchService.fetch(httpRequest); fail("expected exception, got " + httpResponse.getResponseCode()); }
protected FetchOptions buildFetchOptions() { return FetchOptions.Builder.withDefaults(); }
/** * 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); }
@Test public void testWithDefaults() throws Exception { FetchOptions options = FetchOptions.Builder.withDefaults(); testOptions(options); }
private FetchOptions createFetchOptions(HttpRequestImpl request) { FetchOptions fetchOptions = FetchOptions.Builder.withDefaults(); fetchOptions = fetchOptions.setDeadline((double) request.getTimeout() / (double) 1000); return fetchOptions = request.isFollowRedirects() ? fetchOptions.followRedirects() : fetchOptions.doNotFollowRedirects(); }