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));
/**
* byte [] content is replayable and the only content type supportable by GAE. As such, we
* convert the original request content to a byte array.
*/
if (request.getPayload() != null) {
InputStream input = request.getPayload().getInput();
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
request.getPayload().writeTo(out);
byte[] array = out.toByteArray();
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;
}