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 2015/06/03 20:21:11 UTC
svn commit: r1683404 - in /httpcomponents/httpcore/trunk:
httpcore-nio/src/main/java/org/apache/http/impl/nio/
httpcore/src/main/java/org/apache/http/
httpcore/src/main/java/org/apache/http/entity/
httpcore/src/main/java/org/apache/http/impl/ httpcore/...
Author: olegk
Date: Wed Jun 3 18:21:10 2015
New Revision: 1683404
URL: http://svn.apache.org/r1683404
Log:
RFC 7230: disallow multiple Content-Length headers / header elements
Added:
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/NotImplementedException.java
- copied, changed from r1682617, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/UnsupportedHttpVersionException.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/DefaultContentLengthStrategy.java (contents, props changed)
- copied, changed from r1682617, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestDefaultContentLengthStrategy.java (contents, props changed)
- copied, changed from r1682617, httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestStrictContentLengthStrategy.java
Removed:
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/LaxContentLengthStrategy.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestLaxContentLengthStrategy.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestStrictContentLengthStrategy.java
Modified:
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageHead.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/UnsupportedHttpVersionException.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentLengthStrategy.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultBHttpClientConnection.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultBHttpServerConnection.java
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java?rev=1683404&r1=1683403&r2=1683404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpClientConnection.java Wed Jun 3 18:21:10 2015
@@ -40,8 +40,7 @@ import org.apache.http.ProtocolException
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.config.MessageConstraints;
import org.apache.http.entity.ContentLengthStrategy;
-import org.apache.http.impl.entity.LaxContentLengthStrategy;
-import org.apache.http.impl.entity.StrictContentLengthStrategy;
+import org.apache.http.impl.entity.DefaultContentLengthStrategy;
import org.apache.http.impl.nio.codecs.DefaultHttpRequestWriterFactory;
import org.apache.http.impl.nio.codecs.DefaultHttpResponseParserFactory;
import org.apache.http.nio.NHttpClientConnection;
@@ -89,7 +88,7 @@ public class DefaultNHttpClientConnectio
* @param incomingContentStrategy incoming content length strategy. If {@code null}
* {@link org.apache.http.impl.entity.LaxContentLengthStrategy#INSTANCE} will be used.
* @param outgoingContentStrategy outgoing content length strategy. If {@code null}
- * {@link org.apache.http.impl.entity.StrictContentLengthStrategy#INSTANCE} will be used.
+ * {@link DefaultContentLengthStrategy#INSTANCE} will be used.
*
* @since 4.3
*/
@@ -111,9 +110,9 @@ public class DefaultNHttpClientConnectio
this.responseParser = (responseParserFactory != null ? responseParserFactory :
DefaultHttpResponseParserFactory.INSTANCE).create(constraints);
this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
- LaxContentLengthStrategy.INSTANCE;
+ DefaultContentLengthStrategy.INSTANCE;
this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
- StrictContentLengthStrategy.INSTANCE;
+ DefaultContentLengthStrategy.INSTANCE;
}
/**
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java?rev=1683404&r1=1683403&r2=1683404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/DefaultNHttpServerConnection.java Wed Jun 3 18:21:10 2015
@@ -40,8 +40,7 @@ import org.apache.http.ProtocolException
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.config.MessageConstraints;
import org.apache.http.entity.ContentLengthStrategy;
-import org.apache.http.impl.entity.LaxContentLengthStrategy;
-import org.apache.http.impl.entity.StrictContentLengthStrategy;
+import org.apache.http.impl.entity.DefaultContentLengthStrategy;
import org.apache.http.impl.nio.codecs.DefaultHttpRequestParserFactory;
import org.apache.http.impl.nio.codecs.DefaultHttpResponseWriterFactory;
import org.apache.http.nio.NHttpMessageParser;
@@ -86,9 +85,9 @@ public class DefaultNHttpServerConnectio
* @param constraints Message constraints. If {@code null}
* {@link MessageConstraints#DEFAULT} will be used.
* @param incomingContentStrategy incoming content length strategy. If {@code null}
- * {@link org.apache.http.impl.entity.LaxContentLengthStrategy#INSTANCE} will be used.
+ * {@link DefaultContentLengthStrategy#INSTANCE} will be used.
* @param outgoingContentStrategy outgoing content length strategy. If {@code null}
- * {@link StrictContentLengthStrategy#INSTANCE} will be used.
+ * {@link DefaultContentLengthStrategy#INSTANCE} will be used.
* @param requestParserFactory request parser factory. If {@code null}
* {@link DefaultHttpRequestParserFactory#INSTANCE} will be used.
* @param responseWriterFactory response writer factory. If {@code null}
@@ -114,9 +113,9 @@ public class DefaultNHttpServerConnectio
this.responseWriter = (responseWriterFactory != null ? responseWriterFactory :
DefaultHttpResponseWriterFactory.INSTANCE).create();
this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
- LaxContentLengthStrategy.INSTANCE;
+ DefaultContentLengthStrategy.INSTANCE;
this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
- StrictContentLengthStrategy.INSTANCE;
+ DefaultContentLengthStrategy.INSTANCE;
}
/**
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageHead.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageHead.java?rev=1683404&r1=1683403&r2=1683404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageHead.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageHead.java Wed Jun 3 18:21:10 2015
@@ -46,6 +46,14 @@ public interface MessageHead {
boolean containsHeader(String name);
/**
+ * Checks if a certain header is present in this message and how many times.
+ *
+ * @param name the header name to check for.
+ * @return number of occurrences of the header in the message.
+ */
+ int containsHeaders(String name);
+
+ /**
* Returns all the headers with a specified name of this message. Header values
* are ignored. Headers are orderd in the sequence they will be sent over a
* connection.
Copied: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/NotImplementedException.java (from r1682617, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/UnsupportedHttpVersionException.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/NotImplementedException.java?p2=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/NotImplementedException.java&p1=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/UnsupportedHttpVersionException.java&r1=1682617&r2=1683404&rev=1683404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/UnsupportedHttpVersionException.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/NotImplementedException.java Wed Jun 3 18:21:10 2015
@@ -27,21 +27,19 @@
package org.apache.http;
-
/**
- * Signals an unsupported version of the HTTP protocol.
+ * Signals an unsupported / unimplemented feature of the HTTP protocol.
*
* @since 4.0
*/
-public class UnsupportedHttpVersionException extends ProtocolException {
-
- private static final long serialVersionUID = -1348448090193107031L;
+public class NotImplementedException extends ProtocolException {
+ private static final long serialVersionUID = 7929295893253266373L;
/**
* Creates an exception without a detail message.
*/
- public UnsupportedHttpVersionException() {
+ public NotImplementedException() {
super();
}
@@ -50,7 +48,7 @@ public class UnsupportedHttpVersionExcep
*
* @param message The exception detail message
*/
- public UnsupportedHttpVersionException(final String message) {
+ public NotImplementedException(final String message) {
super(message);
}
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/UnsupportedHttpVersionException.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/UnsupportedHttpVersionException.java?rev=1683404&r1=1683403&r2=1683404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/UnsupportedHttpVersionException.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/UnsupportedHttpVersionException.java Wed Jun 3 18:21:10 2015
@@ -27,7 +27,6 @@
package org.apache.http;
-
/**
* Signals an unsupported version of the HTTP protocol.
*
@@ -37,7 +36,6 @@ public class UnsupportedHttpVersionExcep
private static final long serialVersionUID = -1348448090193107031L;
-
/**
* Creates an exception without a detail message.
*/
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentLengthStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentLengthStrategy.java?rev=1683404&r1=1683403&r2=1683404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentLengthStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentLengthStrategy.java Wed Jun 3 18:21:10 2015
@@ -42,18 +42,18 @@ public interface ContentLengthStrategy {
* Identity transfer encoding. Message content is delineated
* by the end of connection.
*/
- public static final int IDENTITY = -1;
+ int IDENTITY = -1;
/**
* Message body chunk coded
*/
- public static final long CHUNKED = -2;
+ long CHUNKED = -2;
/**
* Message body not explicitly delineated. Legal for HTTP response messages
* and illegal for HTTP request messages.
*/
- public static final long UNDEFINED = -Long.MAX_VALUE;
+ long UNDEFINED = -Long.MAX_VALUE;
/**
* Returns length of the given message in bytes. The returned value
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java?rev=1683404&r1=1683403&r2=1683404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpClientConnection.java Wed Jun 3 18:21:10 2015
@@ -43,8 +43,7 @@ import org.apache.http.ProtocolException
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.config.MessageConstraints;
import org.apache.http.entity.ContentLengthStrategy;
-import org.apache.http.impl.entity.LaxContentLengthStrategy;
-import org.apache.http.impl.entity.StrictContentLengthStrategy;
+import org.apache.http.impl.entity.DefaultContentLengthStrategy;
import org.apache.http.impl.io.DefaultHttpRequestWriterFactory;
import org.apache.http.impl.io.DefaultHttpResponseParserFactory;
import org.apache.http.io.HttpMessageParser;
@@ -79,9 +78,9 @@ public class DefaultBHttpClientConnectio
* @param constraints Message constraints. If {@code null}
* {@link MessageConstraints#DEFAULT} will be used.
* @param incomingContentStrategy incoming content length strategy. If {@code null}
- * {@link org.apache.http.impl.entity.LaxContentLengthStrategy#INSTANCE} will be used.
+ * {@link DefaultContentLengthStrategy#INSTANCE} will be used.
* @param outgoingContentStrategy outgoing content length strategy. If {@code null}
- * {@link org.apache.http.impl.entity.StrictContentLengthStrategy#INSTANCE} will be used.
+ * {@link DefaultContentLengthStrategy#INSTANCE} will be used.
* @param requestWriterFactory request writer factory. If {@code null}
* {@link DefaultHttpRequestWriterFactory#INSTANCE} will be used.
* @param responseParserFactory response parser factory. If {@code null}
@@ -103,9 +102,9 @@ public class DefaultBHttpClientConnectio
this.responseParser = (responseParserFactory != null ? responseParserFactory :
DefaultHttpResponseParserFactory.INSTANCE).create(constraints);
this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
- LaxContentLengthStrategy.INSTANCE;
+ DefaultContentLengthStrategy.INSTANCE;
this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
- StrictContentLengthStrategy.INSTANCE;
+ DefaultContentLengthStrategy.INSTANCE;
}
public DefaultBHttpClientConnection(
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java?rev=1683404&r1=1683403&r2=1683404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultBHttpServerConnection.java Wed Jun 3 18:21:10 2015
@@ -42,8 +42,7 @@ import org.apache.http.ProtocolException
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.config.MessageConstraints;
import org.apache.http.entity.ContentLengthStrategy;
-import org.apache.http.impl.entity.LaxContentLengthStrategy;
-import org.apache.http.impl.entity.StrictContentLengthStrategy;
+import org.apache.http.impl.entity.DefaultContentLengthStrategy;
import org.apache.http.impl.io.DefaultHttpRequestParserFactory;
import org.apache.http.impl.io.DefaultHttpResponseWriterFactory;
import org.apache.http.io.HttpMessageParser;
@@ -78,9 +77,9 @@ public class DefaultBHttpServerConnectio
* @param constraints Message constraints. If {@code null}
* {@link MessageConstraints#DEFAULT} will be used.
* @param incomingContentStrategy incoming content length strategy. If {@code null}
- * {@link org.apache.http.impl.entity.LaxContentLengthStrategy#INSTANCE} will be used.
+ * {@link DefaultContentLengthStrategy#INSTANCE} will be used.
* @param outgoingContentStrategy outgoing content length strategy. If {@code null}
- * {@link org.apache.http.impl.entity.StrictContentLengthStrategy#INSTANCE} will be used.
+ * {@link DefaultContentLengthStrategy#INSTANCE} will be used.
* @param requestParserFactory request parser factory. If {@code null}
* {@link DefaultHttpRequestParserFactory#INSTANCE} will be used.
* @param responseWriterFactory response writer factory. If {@code null}
@@ -102,9 +101,9 @@ public class DefaultBHttpServerConnectio
this.responseWriter = (responseWriterFactory != null ? responseWriterFactory :
DefaultHttpResponseWriterFactory.INSTANCE).create();
this.incomingContentStrategy = incomingContentStrategy != null ? incomingContentStrategy :
- LaxContentLengthStrategy.INSTANCE;
+ DefaultContentLengthStrategy.INSTANCE;
this.outgoingContentStrategy = outgoingContentStrategy != null ? outgoingContentStrategy :
- StrictContentLengthStrategy.INSTANCE;
+ DefaultContentLengthStrategy.INSTANCE;
}
public DefaultBHttpServerConnection(
Copied: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/DefaultContentLengthStrategy.java (from r1682617, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/DefaultContentLengthStrategy.java?p2=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/DefaultContentLengthStrategy.java&p1=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java&r1=1682617&r2=1683404&rev=1683404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/StrictContentLengthStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/DefaultContentLengthStrategy.java Wed Jun 3 18:21:10 2015
@@ -32,31 +32,32 @@ import org.apache.http.HeaderElements;
import org.apache.http.HttpException;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpMessage;
+import org.apache.http.NotImplementedException;
import org.apache.http.ProtocolException;
import org.apache.http.annotation.Immutable;
import org.apache.http.entity.ContentLengthStrategy;
import org.apache.http.util.Args;
/**
- * The strict implementation of the content length strategy. This class
+ * The default implementation of the content length strategy. This class
* will throw {@link ProtocolException} if it encounters an unsupported
- * transfer encoding or a malformed {@code Content-Length} header
- * value.
+ * transfer encoding, multiple {@code Content-Length} header
+ * values or a malformed {@code Content-Length} header value.
* <p>
* This class recognizes "chunked" transfer-coding only.
*
- * @since 4.0
+ * @since 5.0
*/
@Immutable
-public class StrictContentLengthStrategy implements ContentLengthStrategy {
+public class DefaultContentLengthStrategy implements ContentLengthStrategy {
- public static final StrictContentLengthStrategy INSTANCE = new StrictContentLengthStrategy();
+ public static final DefaultContentLengthStrategy INSTANCE = new DefaultContentLengthStrategy();
/**
- * Creates {@code StrictContentLengthStrategy} instance. {@link ContentLengthStrategy#UNDEFINED}
+ * Creates {@code DefaultContentLengthStrategy} instance. {@link ContentLengthStrategy#UNDEFINED}
* is used per default when content length is not explicitly specified in the message.
*/
- public StrictContentLengthStrategy() {
+ public DefaultContentLengthStrategy() {
}
@Override
@@ -73,9 +74,12 @@ public class StrictContentLengthStrategy
} else if (HeaderElements.IDENTITY_ENCODING.equalsIgnoreCase(s)) {
return IDENTITY;
} else {
- throw new ProtocolException("Unsupported transfer encoding: " + s);
+ throw new NotImplementedException("Unsupported transfer encoding: " + s);
}
}
+ if (message.containsHeaders(HttpHeaders.CONTENT_LENGTH) > 1) {
+ throw new ProtocolException("Multiple Content-Length headers");
+ }
final Header contentLengthHeader = message.getFirstHeader(HttpHeaders.CONTENT_LENGTH);
if (contentLengthHeader != null) {
final String s = contentLengthHeader.getValue();
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/DefaultContentLengthStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/DefaultContentLengthStrategy.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/entity/DefaultContentLengthStrategy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java?rev=1683404&r1=1683403&r2=1683404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/message/HeaderGroup.java Wed Jun 3 18:21:10 2015
@@ -267,6 +267,27 @@ public class HeaderGroup implements Seri
}
/**
+ * Checks if a certain header is present in this message and how many times.
+ * <p>Header name comparison is case insensitive.
+ *
+ * @param name the header name to check for.
+ * @return number of occurrences of the header in the message.
+ */
+ public int containsHeaders(final String name) {
+ // HTTPCORE-361 : we don't use the for-each syntax, i.e.
+ // for (Header header : headers)
+ // as that creates an Iterator that needs to be garbage-collected
+ int count = 0;
+ for (int i = 0; i < this.headers.size(); i++) {
+ final Header header = this.headers.get(i);
+ if (header.getName().equalsIgnoreCase(name)) {
+ count++;
+ }
+ }
+ return count;
+ }
+
+ /**
* Returns an iterator over this group of headers.
*
* @return iterator over this group of headers.
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultBHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultBHttpClientConnection.java?rev=1683404&r1=1683403&r2=1683404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultBHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultBHttpClientConnection.java Wed Jun 3 18:21:10 2015
@@ -40,8 +40,7 @@ import org.apache.http.ProtocolException
import org.apache.http.config.MessageConstraints;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.entity.LaxContentLengthStrategy;
-import org.apache.http.impl.entity.StrictContentLengthStrategy;
+import org.apache.http.impl.entity.DefaultContentLengthStrategy;
import org.apache.http.impl.io.ChunkedInputStream;
import org.apache.http.impl.io.ContentLengthInputStream;
import org.apache.http.impl.io.DefaultHttpRequestWriterFactory;
@@ -68,8 +67,8 @@ public class TestDefaultBHttpClientConne
conn = new DefaultBHttpClientConnection(1024, 1024,
null, null,
MessageConstraints.DEFAULT,
- LaxContentLengthStrategy.INSTANCE,
- StrictContentLengthStrategy.INSTANCE,
+ DefaultContentLengthStrategy.INSTANCE,
+ DefaultContentLengthStrategy.INSTANCE,
DefaultHttpRequestWriterFactory.INSTANCE,
DefaultHttpResponseParserFactory.INSTANCE);
}
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultBHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultBHttpServerConnection.java?rev=1683404&r1=1683403&r2=1683404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultBHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/TestDefaultBHttpServerConnection.java Wed Jun 3 18:21:10 2015
@@ -40,8 +40,7 @@ import org.apache.http.ProtocolException
import org.apache.http.config.MessageConstraints;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.entity.LaxContentLengthStrategy;
-import org.apache.http.impl.entity.StrictContentLengthStrategy;
+import org.apache.http.impl.entity.DefaultContentLengthStrategy;
import org.apache.http.impl.io.ChunkedInputStream;
import org.apache.http.impl.io.ContentLengthInputStream;
import org.apache.http.impl.io.DefaultHttpRequestParserFactory;
@@ -67,8 +66,8 @@ public class TestDefaultBHttpServerConne
conn = new DefaultBHttpServerConnection(1024, 1024,
null, null,
MessageConstraints.DEFAULT,
- LaxContentLengthStrategy.INSTANCE,
- StrictContentLengthStrategy.INSTANCE,
+ DefaultContentLengthStrategy.INSTANCE,
+ DefaultContentLengthStrategy.INSTANCE,
DefaultHttpRequestParserFactory.INSTANCE,
DefaultHttpResponseWriterFactory.INSTANCE);
}
Copied: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestDefaultContentLengthStrategy.java (from r1682617, httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestStrictContentLengthStrategy.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestDefaultContentLengthStrategy.java?p2=httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestDefaultContentLengthStrategy.java&p1=httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestStrictContentLengthStrategy.java&r1=1682617&r2=1683404&rev=1683404&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestStrictContentLengthStrategy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestDefaultContentLengthStrategy.java Wed Jun 3 18:21:10 2015
@@ -36,7 +36,7 @@ import org.apache.http.message.AbstractH
import org.junit.Assert;
import org.junit.Test;
-public class TestStrictContentLengthStrategy {
+public class TestDefaultContentLengthStrategy {
static class TestHttpMessage extends AbstractHttpMessage {
@@ -49,7 +49,7 @@ public class TestStrictContentLengthStra
@Test
public void testEntityWithChunkTransferEncoding() throws Exception {
- final ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
+ final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy();
final HttpMessage message = new TestHttpMessage();
message.addHeader("Transfer-Encoding", "Chunked");
@@ -58,7 +58,7 @@ public class TestStrictContentLengthStra
@Test
public void testEntityWithIdentityTransferEncoding() throws Exception {
- final ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
+ final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy();
final HttpMessage message = new TestHttpMessage();
message.addHeader("Transfer-Encoding", "Identity");
@@ -67,7 +67,7 @@ public class TestStrictContentLengthStra
@Test(expected=ProtocolException.class)
public void testEntityWithInvalidTransferEncoding() throws Exception {
- final ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
+ final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy();
final HttpMessage message = new TestHttpMessage();
message.addHeader("Transfer-Encoding", "whatever");
lenStrategy.determineLength(message);
@@ -75,7 +75,7 @@ public class TestStrictContentLengthStra
@Test
public void testEntityWithContentLength() throws Exception {
- final ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
+ final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy();
final HttpMessage message = new TestHttpMessage();
message.addHeader("Content-Length", "100");
Assert.assertEquals(100, lenStrategy.determineLength(message));
@@ -83,7 +83,7 @@ public class TestStrictContentLengthStra
@Test(expected=ProtocolException.class)
public void testEntityWithInvalidContentLength() throws Exception {
- final ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
+ final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy();
final HttpMessage message = new TestHttpMessage();
message.addHeader("Content-Length", "whatever");
lenStrategy.determineLength(message);
@@ -91,7 +91,7 @@ public class TestStrictContentLengthStra
@Test(expected=ProtocolException.class)
public void testEntityWithNegativeContentLength() throws Exception {
- final ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
+ final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy();
final HttpMessage message = new TestHttpMessage();
message.addHeader("Content-Length", "-10");
lenStrategy.determineLength(message);
@@ -99,7 +99,7 @@ public class TestStrictContentLengthStra
@Test
public void testEntityNoContentDelimiter() throws Exception {
- final ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
+ final ContentLengthStrategy lenStrategy = new DefaultContentLengthStrategy();
final HttpMessage message = new TestHttpMessage();
Assert.assertEquals(ContentLengthStrategy.UNDEFINED, lenStrategy.determineLength(message));
}
Propchange: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestDefaultContentLengthStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestDefaultContentLengthStrategy.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestDefaultContentLengthStrategy.java
------------------------------------------------------------------------------
svn:mime-type = text/plain