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/03/18 16:48:22 UTC
svn commit: r1302143 - in /httpcomponents/httpcore/branches/4.1.x:
httpcore-nio/src/main/java/org/apache/http/impl/nio/
httpcore/src/main/java/org/apache/http/impl/
httpcore/src/main/java/org/apache/http/impl/entity/
httpcore/src/test/java/org/apache/h...
Author: olegk
Date: Sun Mar 18 15:48:22 2012
New Revision: 1302143
URL: http://svn.apache.org/viewvc?rev=1302143&view=rev
Log:
Fully merged the fix for HTTPCORE-296
Modified:
httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java
httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java
httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java
httpcomponents/httpcore/branches/4.1.x/httpcore/src/test/java/org/apache/http/protocol/TestHttpServiceAndExecutor.java
Modified: httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java?rev=1302143&r1=1302142&r2=1302143&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java (original)
+++ httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java Sun Mar 18 15:48:22 2012
@@ -97,7 +97,7 @@ public class DefaultNHttpServerConnectio
@Override
protected ContentLengthStrategy createIncomingContentStrategy() {
- return new DisallowIdentityContentLengthStrategy(new LaxContentLengthStrategy());
+ return new DisallowIdentityContentLengthStrategy(new LaxContentLengthStrategy(0));
}
/**
Modified: httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java?rev=1302143&r1=1302142&r2=1302143&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java (original)
+++ httpcomponents/httpcore/branches/4.1.x/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java Sun Mar 18 15:48:22 2012
@@ -159,38 +159,15 @@ public class NHttpConnectionBase
this.remote = this.session.getRemoteAddress();
}
- /**
-<<<<<<< HEAD
-=======
- * Binds the connection to a different {@link IOSession}. This may be necessary
- * when the underlying I/O session gets upgraded with SSL/TLS encryption.
- *
- * @since 4.2
- */
- protected void bind(final IOSession session) {
- if (session == null) {
- throw new IllegalArgumentException("I/O session may not be null");
- }
- this.session.setBufferStatus(null);
- setSession(session);
- }
-
- /**
- * @since 4.2
- */
protected ContentLengthStrategy createIncomingContentStrategy() {
return new LaxContentLengthStrategy();
}
- /**
- * @since 4.2
- */
protected ContentLengthStrategy createOutgoingContentStrategy() {
return new StrictContentLengthStrategy();
}
/**
->>>>>>> 74acee1... HTTPCORE-296: server side connections (both blocking and non-blocking) can now handle entity enclosing requests without Content-Length and Transfer-Encoding headers
* @since 4.1
*/
protected HttpTransportMetricsImpl createTransportMetrics() {
Modified: httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java?rev=1302143&r1=1302142&r2=1302143&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java (original)
+++ httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java Sun Mar 18 15:48:22 2012
@@ -116,7 +116,7 @@ public abstract class AbstractHttpServer
*/
protected EntityDeserializer createEntityDeserializer() {
return new EntityDeserializer(new DisallowIdentityContentLengthStrategy(
- new LaxContentLengthStrategy()));
+ new LaxContentLengthStrategy(0)));
}
/**
Modified: httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java?rev=1302143&r1=1302142&r2=1302143&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java (original)
+++ httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/DisallowIdentityContentLengthStrategy.java Sun Mar 18 15:48:22 2012
@@ -35,8 +35,6 @@ import org.apache.http.entity.ContentLen
/**
* Decorator for {@link ContentLengthStrategy} implementations that disallows the use of
* identity transfer encoding.
- *
- * @since 4.2
*/
public class DisallowIdentityContentLengthStrategy implements ContentLengthStrategy {
Modified: httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java?rev=1302143&r1=1302142&r2=1302143&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java (original)
+++ httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java Sun Mar 18 15:48:22 2012
@@ -55,8 +55,25 @@ import org.apache.http.protocol.HTTP;
*/
public class LaxContentLengthStrategy implements ContentLengthStrategy {
- public LaxContentLengthStrategy() {
+ private final int implicitLen;
+
+ /**
+ * Creates <tt>LaxContentLengthStrategy</tt> instance with the given length used per default
+ * when content length is not explicitly specified in the message.
+ *
+ * @param implicit implicit content length.
+ */
+ public LaxContentLengthStrategy(int implicitLen) {
super();
+ this.implicitLen = implicitLen;
+ }
+
+ /**
+ * Creates <tt>LaxContentLengthStrategy</tt> instance. {@link ContentLengthStrategy#IDENTITY}
+ * is used per default when content length is not explicitly specified in the message.
+ */
+ public LaxContentLengthStrategy() {
+ this(IDENTITY);
}
public long determineLength(final HttpMessage message) throws HttpException {
@@ -68,7 +85,6 @@ public class LaxContentLengthStrategy im
boolean strict = params.isParameterTrue(CoreProtocolPNames.STRICT_TRANSFER_ENCODING);
Header transferEncodingHeader = message.getFirstHeader(HTTP.TRANSFER_ENCODING);
- Header contentLengthHeader = message.getFirstHeader(HTTP.CONTENT_LEN);
// We use Transfer-Encoding if present and ignore Content-Length.
// RFC2616, 4.4 item number 3
if (transferEncodingHeader != null) {
@@ -104,7 +120,9 @@ public class LaxContentLengthStrategy im
}
return IDENTITY;
}
- } else if (contentLengthHeader != null) {
+ }
+ Header contentLengthHeader = message.getFirstHeader(HTTP.CONTENT_LEN);
+ if (contentLengthHeader != null) {
long contentlen = -1;
Header[] headers = message.getHeaders(HTTP.CONTENT_LEN);
if (strict && headers.length > 1) {
@@ -127,9 +145,8 @@ public class LaxContentLengthStrategy im
} else {
return IDENTITY;
}
- } else {
- return IDENTITY;
}
+ return this.implicitLen;
}
}
Modified: httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java?rev=1302143&r1=1302142&r2=1302143&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java (original)
+++ httpcomponents/httpcore/branches/4.1.x/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java Sun Mar 18 15:48:22 2012
@@ -47,8 +47,25 @@ import org.apache.http.protocol.HTTP;
*/
public class StrictContentLengthStrategy implements ContentLengthStrategy {
- public StrictContentLengthStrategy() {
+ private final int implicitLen;
+
+ /**
+ * Creates <tt>StrictContentLengthStrategy</tt> instance with the given length used per default
+ * when content length is not explicitly specified in the message.
+ *
+ * @param implicit implicit content length.
+ */
+ public StrictContentLengthStrategy(int implicitLen) {
super();
+ this.implicitLen = implicitLen;
+ }
+
+ /**
+ * Creates <tt>StrictContentLengthStrategy</tt> instance. {@link ContentLengthStrategy#IDENTITY}
+ * is used per default when content length is not explicitly specified in the message.
+ */
+ public StrictContentLengthStrategy() {
+ this(IDENTITY);
}
public long determineLength(final HttpMessage message) throws HttpException {
@@ -59,7 +76,6 @@ public class StrictContentLengthStrategy
// it is either missing or has the single value "chunked". So we
// treat it as a single-valued header here.
Header transferEncodingHeader = message.getFirstHeader(HTTP.TRANSFER_ENCODING);
- Header contentLengthHeader = message.getFirstHeader(HTTP.CONTENT_LEN);
if (transferEncodingHeader != null) {
String s = transferEncodingHeader.getValue();
if (HTTP.CHUNK_CODING.equalsIgnoreCase(s)) {
@@ -75,7 +91,9 @@ public class StrictContentLengthStrategy
throw new ProtocolException(
"Unsupported transfer encoding: " + s);
}
- } else if (contentLengthHeader != null) {
+ }
+ Header contentLengthHeader = message.getFirstHeader(HTTP.CONTENT_LEN);
+ if (contentLengthHeader != null) {
String s = contentLengthHeader.getValue();
try {
long len = Long.parseLong(s);
@@ -86,9 +104,8 @@ public class StrictContentLengthStrategy
} catch (NumberFormatException e) {
throw new ProtocolException("Invalid content length: " + s);
}
- } else {
- return IDENTITY;
}
+ return this.implicitLen;
}
}
Modified: httpcomponents/httpcore/branches/4.1.x/httpcore/src/test/java/org/apache/http/protocol/TestHttpServiceAndExecutor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.1.x/httpcore/src/test/java/org/apache/http/protocol/TestHttpServiceAndExecutor.java?rev=1302143&r1=1302142&r2=1302143&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.1.x/httpcore/src/test/java/org/apache/http/protocol/TestHttpServiceAndExecutor.java (original)
+++ httpcomponents/httpcore/branches/4.1.x/httpcore/src/test/java/org/apache/http/protocol/TestHttpServiceAndExecutor.java Sun Mar 18 15:48:22 2012
@@ -851,7 +851,7 @@ public class TestHttpServiceAndExecutor
new RequestExpectContinue() }));
HttpResponse response = this.client.execute(post, host, conn);
- assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusLine().getStatusCode());
+ assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
} finally {
conn.close();
this.server.shutdown();