You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2012/09/12 23:48:32 UTC
svn commit: r1384142 - in /httpcomponents/httpcore/branches/4.2.x: ./
httpcore-nio/src/main/java/org/apache/http/nio/protocol/
httpcore-nio/src/test/java/org/apache/http/nio/protocol/
Author: olegk
Date: Wed Sep 12 21:48:31 2012
New Revision: 1384142
URL: http://svn.apache.org/viewvc?rev=1384142&view=rev
Log:
HTTPCORE-309: Fixed regression causing HttpAsyncRequestExecutor to handle 204, 205, 304 responses incorrectly by returning a message with an enclosed content body
Modified:
httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt
httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java
httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java
httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
Modified: httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt?rev=1384142&r1=1384141&r2=1384142&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt Wed Sep 12 21:48:31 2012
@@ -1,5 +1,9 @@
Changes since 4.2.1
+* [HTTPCORE-309] Fixed regression causing HttpAsyncRequestExecutor to handle 204, 205, 304
+ responses incorrectly by returning a message with an enclosed content body.
+ Contributed by Oleg Kalnichevski <olegk at apache.org>
+
* [HTTPCORE-306] I/O reactor TCP_NODELAY parameter now defaults to true.
Contributed by Oleg Kalnichevski <olegk at apache.org>
Modified: httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java?rev=1384142&r1=1384141&r2=1384142&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java (original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestConsumer.java Wed Sep 12 21:48:31 2012
@@ -61,25 +61,21 @@ public class BasicAsyncRequestConsumer e
@Override
protected void onRequestReceived(final HttpRequest request) throws IOException {
this.request = request;
- if (request instanceof HttpEntityEnclosingRequest) {
- HttpEntity entity = ((HttpEntityEnclosingRequest) this.request).getEntity();
- if (entity != null) {
- long len = entity.getContentLength();
- if (len > Integer.MAX_VALUE) {
- throw new ContentTooLongException("Entity content is too long: " + len);
- }
- if (len < 0) {
- len = 4096;
- }
- this.buf = new SimpleInputBuffer((int) len, new HeapByteBufferAllocator());
- ((HttpEntityEnclosingRequest) this.request).setEntity(
- new ContentBufferEntity(entity, this.buf));
- }
- }
}
@Override
- protected void onEntityEnclosed(final HttpEntity entity, final ContentType contentType) {
+ protected void onEntityEnclosed(
+ final HttpEntity entity, final ContentType contentType) throws IOException {
+ long len = entity.getContentLength();
+ if (len > Integer.MAX_VALUE) {
+ throw new ContentTooLongException("Entity content is too long: " + len);
+ }
+ if (len < 0) {
+ len = 4096;
+ }
+ this.buf = new SimpleInputBuffer((int) len, new HeapByteBufferAllocator());
+ ((HttpEntityEnclosingRequest) this.request).setEntity(
+ new ContentBufferEntity(entity, this.buf));
}
@Override
Modified: httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java?rev=1384142&r1=1384141&r2=1384142&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java (original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncResponseConsumer.java Wed Sep 12 21:48:31 2012
@@ -60,22 +60,20 @@ public class BasicAsyncResponseConsumer
@Override
protected void onResponseReceived(final HttpResponse response) throws IOException {
this.response = response;
- HttpEntity entity = this.response.getEntity();
- if (entity != null) {
- long len = entity.getContentLength();
- if (len > Integer.MAX_VALUE) {
- throw new ContentTooLongException("Entity content is too long: " + len);
- }
- if (len < 0) {
- len = 4096;
- }
- this.buf = new SimpleInputBuffer((int) len, new HeapByteBufferAllocator());
- response.setEntity(new ContentBufferEntity(entity, this.buf));
- }
}
@Override
- protected void onEntityEnclosed(final HttpEntity entity, final ContentType contentType) {
+ protected void onEntityEnclosed(
+ final HttpEntity entity, final ContentType contentType) throws IOException {
+ long len = entity.getContentLength();
+ if (len > Integer.MAX_VALUE) {
+ throw new ContentTooLongException("Entity content is too long: " + len);
+ }
+ if (len < 0) {
+ len = 4096;
+ }
+ this.buf = new SimpleInputBuffer((int) len, new HeapByteBufferAllocator());
+ this.response.setEntity(new ContentBufferEntity(entity, this.buf));
}
@Override
Modified: httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java?rev=1384142&r1=1384141&r2=1384142&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java (original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestExecutor.java Wed Sep 12 21:48:31 2012
@@ -235,6 +235,7 @@ public class HttpAsyncRequestExecutor im
state.setResponseState(MessageState.BODY_STREAM);
if (!canResponseHaveBody(request, response)) {
+ response.setEntity(null);
conn.resetInput();
processResponse(conn, state, handler);
}
Modified: httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java?rev=1384142&r1=1384141&r2=1384142&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java (original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestHttpAsyncRequestExecutor.java Wed Sep 12 21:48:31 2012
@@ -38,6 +38,7 @@ import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpStatus;
import org.apache.http.HttpVersion;
+import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.message.BasicHttpRequest;
import org.apache.http.message.BasicHttpResponse;
@@ -443,6 +444,7 @@ public class TestHttpAsyncRequestExecuto
this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
HttpStatus.SC_NOT_MODIFIED, "Not modified");
+ response.setEntity(new BasicHttpEntity());
Mockito.when(this.conn.getHttpResponse()).thenReturn(response);
Mockito.when(this.reuseStrategy.keepAlive(response, this.exchangeContext)).thenReturn(true);
@@ -452,6 +454,7 @@ public class TestHttpAsyncRequestExecuto
Assert.assertEquals(MessageState.READY, state.getRequestState());
Assert.assertNull(state.getRequest());
Assert.assertNull(state.getResponse());
+ Assert.assertNull(response.getEntity());
Mockito.verify(this.exchangeHandler).responseReceived(response);
Mockito.verify(this.conn).resetInput();
Mockito.verify(this.conn, Mockito.never()).close();