@Test void testConvertRequestSetsFetchOptions() throws IOException { HttpRequest request = HttpRequest.builder().method(HttpMethod.GET).endpoint(endPoint).build(); HTTPRequest gaeRequest = req.apply(request); assert gaeRequest.getFetchOptions() != null; }
@Override public HTTPRequest apply(HttpRequest request) { URL url = null; try { url = request.getEndpoint().toURL(); } catch (MalformedURLException e) { Throwables.propagate(e); } FetchOptions options = disallowTruncate(); options.doNotFollowRedirects(); if (utils.relaxHostname() || utils.trustAllCerts()) options.doNotFollowRedirects(); options.setDeadline(10.0); HTTPRequest gaeRequest = new HTTPRequest(url, HTTPMethod.valueOf(request.getMethod().toString()), options); for (Entry<String, String> entry : request.getHeaders().entries()) { String header = entry.getKey(); if (!prohibitedHeaders.contains(header)) gaeRequest.addHeader(new HTTPHeader(header, entry.getValue())); } gaeRequest.addHeader(new HTTPHeader(HttpHeaders.USER_AGENT, USER_AGENT)); if (request.getPayload() != null) { InputStream input = request.getPayload().getInput(); try { byte[] array = ByteStreams.toByteArray(input); if (!request.getPayload().isRepeatable()) { Payload oldPayload = request.getPayload(); request.setPayload(array); HttpUtils.copy(oldPayload.getContentMetadata(), request.getPayload().getContentMetadata()); } gaeRequest.setPayload(array); if (array.length > 0) { gaeRequest.setHeader(new HTTPHeader("Expect", "100-continue")); } } catch (IOException e) { Throwables.propagate(e); } finally { Closeables2.closeQuietly(input); } for (Entry<String, String> header : contentMetadataCodec.toHeaders( request.getPayload().getContentMetadata()).entries()) { if (!prohibitedHeaders.contains(header.getKey())) gaeRequest.setHeader(new HTTPHeader(header.getKey(), header.getValue())); } } return gaeRequest; }
ConvertToGaeRequest implements Function<HttpRequest, HTTPRequest> { @Override public HTTPRequest apply(HttpRequest request) { URL url = null; try { url = request.getEndpoint().toURL(); } catch (MalformedURLException e) { Throwables.propagate(e); } FetchOptions options = disallowTruncate(); options.doNotFollowRedirects(); if (utils.relaxHostname() || utils.trustAllCerts()) options.doNotFollowRedirects(); options.setDeadline(10.0); HTTPRequest gaeRequest = new HTTPRequest(url, HTTPMethod.valueOf(request.getMethod().toString()), options); for (Entry<String, String> entry : request.getHeaders().entries()) { String header = entry.getKey(); if (!prohibitedHeaders.contains(header)) gaeRequest.addHeader(new HTTPHeader(header, entry.getValue())); } gaeRequest.addHeader(new HTTPHeader(HttpHeaders.USER_AGENT, USER_AGENT)); if (request.getPayload() != null) { InputStream input = request.getPayload().getInput(); try { byte[] array = ByteStreams.toByteArray(input); if (!request.getPayload().isRepeatable()) { Payload oldPayload = request.getPayload(); request.setPayload(array); HttpUtils.copy(oldPayload.getContentMetadata(), request.getPayload().getContentMetadata()); } gaeRequest.setPayload(array); if (array.length > 0) { gaeRequest.setHeader(new HTTPHeader("Expect", "100-continue")); } } catch (IOException e) { Throwables.propagate(e); } finally { Closeables2.closeQuietly(input); } for (Entry<String, String> header : contentMetadataCodec.toHeaders( request.getPayload().getContentMetadata()).entries()) { if (!prohibitedHeaders.contains(header.getKey())) gaeRequest.setHeader(new HTTPHeader(header.getKey(), header.getValue())); } } return gaeRequest; } }
ConvertToGaeRequest implements Function<HttpRequest, HTTPRequest> { @Override public HTTPRequest apply(HttpRequest request) { URL url = null; try { url = request.getEndpoint().toURL(); } catch (MalformedURLException e) { Throwables.propagate(e); } FetchOptions options = disallowTruncate(); options.doNotFollowRedirects(); if (utils.relaxHostname() || utils.trustAllCerts()) options.doNotFollowRedirects(); options.setDeadline(10.0); HTTPRequest gaeRequest = new HTTPRequest(url, HTTPMethod.valueOf(request.getMethod().toString()), options); for (Entry<String, String> entry : request.getHeaders().entries()) { String header = entry.getKey(); if (!prohibitedHeaders.contains(header)) gaeRequest.addHeader(new HTTPHeader(header, entry.getValue())); } gaeRequest.addHeader(new HTTPHeader(HttpHeaders.USER_AGENT, USER_AGENT)); if (request.getPayload() != null) { InputStream input = request.getPayload().getInput(); try { byte[] array = ByteStreams.toByteArray(input); if (!request.getPayload().isRepeatable()) { Payload oldPayload = request.getPayload(); request.setPayload(array); HttpUtils.copy(oldPayload.getContentMetadata(), request.getPayload().getContentMetadata()); } gaeRequest.setPayload(array); if (array.length > 0) { gaeRequest.setHeader(new HTTPHeader("Expect", "100-continue")); } } catch (IOException e) { Throwables.propagate(e); } finally { Closeables2.closeQuietly(input); } for (Entry<String, String> header : contentMetadataCodec.toHeaders( request.getPayload().getContentMetadata()).entries()) { if (!prohibitedHeaders.contains(header.getKey())) gaeRequest.setHeader(new HTTPHeader(header.getKey(), header.getValue())); } } return gaeRequest; } @Inject  ConvertToGaeRequest(HttpUtils utils, ContentMetadataCodec contentMetadataCodec); }
ConvertToGaeRequest implements Function<HttpRequest, HTTPRequest> { @Override public HTTPRequest apply(HttpRequest request) { URL url = null; try { url = request.getEndpoint().toURL(); } catch (MalformedURLException e) { Throwables.propagate(e); } FetchOptions options = disallowTruncate(); options.doNotFollowRedirects(); if (utils.relaxHostname() || utils.trustAllCerts()) options.doNotFollowRedirects(); options.setDeadline(10.0); HTTPRequest gaeRequest = new HTTPRequest(url, HTTPMethod.valueOf(request.getMethod().toString()), options); for (Entry<String, String> entry : request.getHeaders().entries()) { String header = entry.getKey(); if (!prohibitedHeaders.contains(header)) gaeRequest.addHeader(new HTTPHeader(header, entry.getValue())); } gaeRequest.addHeader(new HTTPHeader(HttpHeaders.USER_AGENT, USER_AGENT)); if (request.getPayload() != null) { InputStream input = request.getPayload().getInput(); try { byte[] array = ByteStreams.toByteArray(input); if (!request.getPayload().isRepeatable()) { Payload oldPayload = request.getPayload(); request.setPayload(array); HttpUtils.copy(oldPayload.getContentMetadata(), request.getPayload().getContentMetadata()); } gaeRequest.setPayload(array); if (array.length > 0) { gaeRequest.setHeader(new HTTPHeader("Expect", "100-continue")); } } catch (IOException e) { Throwables.propagate(e); } finally { Closeables2.closeQuietly(input); } for (Entry<String, String> header : contentMetadataCodec.toHeaders( request.getPayload().getContentMetadata()).entries()) { if (!prohibitedHeaders.contains(header.getKey())) gaeRequest.setHeader(new HTTPHeader(header.getKey(), header.getValue())); } } return gaeRequest; } @Inject  ConvertToGaeRequest(HttpUtils utils, ContentMetadataCodec contentMetadataCodec); @Override HTTPRequest apply(HttpRequest request); }
ConvertToGaeRequest implements Function<HttpRequest, HTTPRequest> { @Override public HTTPRequest apply(HttpRequest request) { URL url = null; try { url = request.getEndpoint().toURL(); } catch (MalformedURLException e) { Throwables.propagate(e); } FetchOptions options = disallowTruncate(); options.doNotFollowRedirects(); if (utils.relaxHostname() || utils.trustAllCerts()) options.doNotFollowRedirects(); options.setDeadline(10.0); HTTPRequest gaeRequest = new HTTPRequest(url, HTTPMethod.valueOf(request.getMethod().toString()), options); for (Entry<String, String> entry : request.getHeaders().entries()) { String header = entry.getKey(); if (!prohibitedHeaders.contains(header)) gaeRequest.addHeader(new HTTPHeader(header, entry.getValue())); } gaeRequest.addHeader(new HTTPHeader(HttpHeaders.USER_AGENT, USER_AGENT)); if (request.getPayload() != null) { InputStream input = request.getPayload().getInput(); try { byte[] array = ByteStreams.toByteArray(input); if (!request.getPayload().isRepeatable()) { Payload oldPayload = request.getPayload(); request.setPayload(array); HttpUtils.copy(oldPayload.getContentMetadata(), request.getPayload().getContentMetadata()); } gaeRequest.setPayload(array); if (array.length > 0) { gaeRequest.setHeader(new HTTPHeader("Expect", "100-continue")); } } catch (IOException e) { Throwables.propagate(e); } finally { Closeables2.closeQuietly(input); } for (Entry<String, String> header : contentMetadataCodec.toHeaders( request.getPayload().getContentMetadata()).entries()) { if (!prohibitedHeaders.contains(header.getKey())) gaeRequest.setHeader(new HTTPHeader(header.getKey(), header.getValue())); } } return gaeRequest; } @Inject  ConvertToGaeRequest(HttpUtils utils, ContentMetadataCodec contentMetadataCodec); @Override HTTPRequest apply(HttpRequest request); static final String USER_AGENT; final Set<String> prohibitedHeaders; }