Merge pull request #1493 from maginatics/http-put-zero-content-length-1.6.x

Emit Content-Length: 0 for empty PUTs
This commit is contained in:
Adrian Cole 2013-04-03 18:10:10 -07:00
commit 35e9dcc36d
1 changed files with 3 additions and 2 deletions

View File

@ -231,8 +231,9 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe
protected void writeNothing(HttpURLConnection connection) {
if (!HttpRequest.NON_PAYLOAD_METHODS.contains(connection.getRequestMethod())) {
connection.setRequestProperty(CONTENT_LENGTH, "0");
// support zero length posts.
if ("POST".equals(connection.getRequestMethod())) {
// HttpUrlConnection strips Content-Length: 0 without setDoOutput(true)
String method = connection.getRequestMethod();
if ("POST".equals(method) || "PUT".equals(method)) {
connection.setFixedLengthStreamingMode(0);
connection.setDoOutput(true);
}