Browse Source

SimpleClientHttpRequest uses fixed-length streaming mode (always sets content-length header); partial backport from 3.1 M2

3.0.x
Juergen Hoeller 15 years ago
parent
commit
210c77ddb0
  1. 10
      org.springframework.web/src/main/java/org/springframework/http/client/AbstractClientHttpRequest.java
  2. 9
      org.springframework.web/src/main/java/org/springframework/http/client/SimpleClientHttpRequest.java

10
org.springframework.web/src/main/java/org/springframework/http/client/AbstractClientHttpRequest.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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 { @@ -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;
}

9
org.springframework.web/src/main/java/org/springframework/http/client/SimpleClientHttpRequest.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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);
}

Loading…
Cancel
Save