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 2016/11/09 20:30:55 UTC
svn commit: r1769013 -
/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/
Author: olegk
Date: Wed Nov 9 20:30:54 2016
New Revision: 1769013
URL: http://svn.apache.org/viewvc?rev=1769013&view=rev
Log:
Fixed content decoding by HTTP/1.1 stream duplexer
Modified:
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java?rev=1769013&r1=1769012&r2=1769013&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractHttp1StreamDuplexer.java Wed Nov 9 20:30:54 2016
@@ -141,7 +141,7 @@ abstract class AbstractHttp1StreamDuplex
SessionOutputBuffer buffer,
BasicHttpTransportMetrics metrics) throws HttpException;
- abstract void consumeData(ContentDecoder contentDecoder) throws HttpException, IOException;
+ abstract int consumeData(ContentDecoder contentDecoder) throws HttpException, IOException;
abstract boolean isOutputReady();
@@ -234,11 +234,14 @@ abstract class AbstractHttp1StreamDuplex
if (incomingMessage != null) {
final ContentDecoder contentDecoder = incomingMessage.getBody();
- consumeData(contentDecoder);
+ final int bytesRead = consumeData(contentDecoder);
if (contentDecoder.isCompleted()) {
incomingMessage = null;
inputEnd();
}
+ if (bytesRead == 0) {
+ break;
+ }
}
} while (connState.compareTo(ConnectionState.SHUTDOWN) < 0 && inbuf.hasData());
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java?rev=1769013&r1=1769012&r2=1769013&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamDuplexer.java Wed Nov 9 20:30:54 2016
@@ -332,9 +332,9 @@ public class ClientHttp1StreamDuplexer e
}
@Override
- void consumeData(final ContentDecoder contentDecoder) throws HttpException, IOException {
+ int consumeData(final ContentDecoder contentDecoder) throws HttpException, IOException {
Asserts.notNull(incoming, "Response stream handler");
- incoming.consumeData(contentDecoder);
+ return incoming.consumeData(contentDecoder);
}
@Override
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java?rev=1769013&r1=1769012&r2=1769013&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ClientHttp1StreamHandler.java Wed Nov 9 20:30:54 2016
@@ -255,11 +255,14 @@ class ClientHttp1StreamHandler implement
responseState = endStream ? MessageState.COMPLETE : MessageState.BODY;
}
- void consumeData(final ContentDecoder contentDecoder) throws HttpException, IOException {
+ int consumeData(final ContentDecoder contentDecoder) throws HttpException, IOException {
if (done.get() || responseState != MessageState.BODY) {
throw new ProtocolException("Unexpected message data");
}
- while (contentDecoder.read(inputBuffer) > 0) {
+ int total = 0;
+ int byteRead;
+ while ((byteRead = contentDecoder.read(inputBuffer)) > 0) {
+ total += byteRead;
inputBuffer.flip();
final int capacity = exchangeHandler.consume(inputBuffer);
inputBuffer.clear();
@@ -274,6 +277,9 @@ class ClientHttp1StreamHandler implement
if (contentDecoder.isCompleted()) {
responseState = MessageState.COMPLETE;
exchangeHandler.streamEnd(null);
+ return total > 0 ? total : -1;
+ } else {
+ return total;
}
}
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java?rev=1769013&r1=1769012&r2=1769013&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamDuplexer.java Wed Nov 9 20:30:54 2016
@@ -297,9 +297,9 @@ public class ServerHttp1StreamDuplexer e
}
@Override
- void consumeData(final ContentDecoder contentDecoder) throws HttpException, IOException {
+ int consumeData(final ContentDecoder contentDecoder) throws HttpException, IOException {
Asserts.notNull(incoming, "Request stream handler");
- incoming.consumeData(contentDecoder);
+ return incoming.consumeData(contentDecoder);
}
@Override
Modified: httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java?rev=1769013&r1=1769012&r2=1769013&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/ServerHttp1StreamHandler.java Wed Nov 9 20:30:54 2016
@@ -331,14 +331,17 @@ class ServerHttp1StreamHandler implement
}
}
- void consumeData(final ContentDecoder contentDecoder) throws HttpException, IOException {
+ int consumeData(final ContentDecoder contentDecoder) throws HttpException, IOException {
if (done.get() || requestState != MessageState.BODY) {
throw new ProtocolException("Unexpected message data");
}
if (responseState == MessageState.ACK) {
outputChannel.requestOutput();
}
- while (contentDecoder.read(inputBuffer) > 0) {
+ int total = 0;
+ int byteRead;
+ while ((byteRead = contentDecoder.read(inputBuffer)) > 0) {
+ total += byteRead;
inputBuffer.flip();
final int capacity = exchangeHandler.consume(inputBuffer);
inputBuffer.clear();
@@ -353,6 +356,9 @@ class ServerHttp1StreamHandler implement
if (contentDecoder.isCompleted()) {
requestState = MessageState.COMPLETE;
exchangeHandler.streamEnd(null);
+ return total > 0 ? total : -1;
+ } else {
+ return total;
}
}