SimpleClientHttpRequest uses fixed-length streaming mode (always sets content-length header); partial backport from 3.1 M2
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,7 +39,7 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest {
|
||||
|
||||
|
||||
public final HttpHeaders getHeaders() {
|
||||
return executed ? HttpHeaders.readOnlyHttpHeaders(headers) : this.headers;
|
||||
return (this.executed ? HttpHeaders.readOnlyHttpHeaders(this.headers) : this.headers);
|
||||
}
|
||||
|
||||
public final OutputStream getBody() throws IOException {
|
||||
@@ -49,7 +49,11 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest {
|
||||
|
||||
public final ClientHttpResponse execute() throws IOException {
|
||||
checkExecuted();
|
||||
ClientHttpResponse result = executeInternal(this.headers, this.bufferedOutput.toByteArray());
|
||||
byte[] bytes = this.bufferedOutput.toByteArray();
|
||||
if (this.headers.getContentLength() == -1) {
|
||||
this.headers.setContentLength(bytes.length);
|
||||
}
|
||||
ClientHttpResponse result = executeInternal(this.headers, bytes);
|
||||
this.executed = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,10 +66,15 @@ final class SimpleClientHttpRequest extends AbstractClientHttpRequest {
|
||||
this.connection.addRequestProperty(headerName, headerValue);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.connection.getDoOutput()) {
|
||||
this.connection.setFixedLengthStreamingMode(bufferedOutput.length);
|
||||
}
|
||||
this.connection.connect();
|
||||
if (bufferedOutput.length > 0) {
|
||||
if (this.connection.getDoOutput()) {
|
||||
FileCopyUtils.copy(bufferedOutput, this.connection.getOutputStream());
|
||||
}
|
||||
|
||||
return new SimpleClientHttpResponse(this.connection);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user