if (connection.getRequestProperty(USER_AGENT) == null) {
connection.setRequestProperty(USER_AGENT, DEFAULT_USER_AGENT);
}
Payload payload = request.getPayload();
if (payload != null) {
MutableContentMetadata md = payload.getContentMetadata();
for (Map.Entry<String,String> entry : contentMetadataCodec.toHeaders(md).entries()) {
connection.setRequestProperty(entry.getKey(), entry.getValue());
}
if (chunked) {
connection.setChunkedStreamingMode(8196);
writePayloadToConnection(payload, "streaming", connection);
} else {
Long length = checkNotNull(md.getContentLength(), "payload.getContentLength");
// TODO: remove check after moving to JDK 7.
checkArgument(length <= Integer.MAX_VALUE,
"Cannot transfer 2 GB or larger chunks due to JDK 1.6 limitations." +
" Use chunked encoding or multi-part upload, if possible." +
" For more information: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6755625");