Merge "Fix HttpClientConnection leaking temporary buffer files"

This commit is contained in:
Shawn Pearce 2016-08-25 22:31:08 -04:00 committed by Gerrit Code Review @ Eclipse.org
commit c29363046d
2 changed files with 33 additions and 12 deletions

View File

@ -226,17 +226,25 @@ public String getResponseMessage() throws IOException {
}
private void execute() throws IOException, ClientProtocolException {
if (resp == null)
if (entity != null) {
if (req instanceof HttpEntityEnclosingRequest) {
HttpEntityEnclosingRequest eReq = (HttpEntityEnclosingRequest) req;
eReq.setEntity(entity);
}
resp = getClient().execute(req);
entity.getBuffer().close();
entity = null;
} else
resp = getClient().execute(req);
if (resp != null) {
return;
}
if (entity == null) {
resp = getClient().execute(req);
return;
}
try {
if (req instanceof HttpEntityEnclosingRequest) {
HttpEntityEnclosingRequest eReq = (HttpEntityEnclosingRequest) req;
eReq.setEntity(entity);
}
resp = getClient().execute(req);
} finally {
entity.close();
entity = null;
}
}
public Map<String, List<String>> getHeaderFields() {

View File

@ -55,7 +55,8 @@
*
* @since 3.3
*/
public class TemporaryBufferEntity extends AbstractHttpEntity {
public class TemporaryBufferEntity extends AbstractHttpEntity
implements AutoCloseable {
private TemporaryBuffer buffer;
private Integer contentLength;
@ -106,4 +107,16 @@ public boolean isStreaming() {
public void setContentLength(int contentLength) {
this.contentLength = new Integer(contentLength);
}
/**
* Close destroys the associated buffer used to buffer the entity
*
* @since 4.5
*/
@Override
public void close() {
if (buffer != null) {
buffer.destroy();
}
}
}