hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1666697 - in /httpcomponents/httpcore/trunk/httpcore/src: main/java/org/apache/http/ test/java/org/apache/http/impl/entity/ test/java/org/apache/http/message/
Date Sat, 14 Mar 2015 15:49:35 GMT
Author: olegk
Date: Sat Mar 14 15:49:34 2015
New Revision: 1666697

URL: http://svn.apache.org/r1666697
Log:
HTTP/2: added immutable MessageHead interface common for both HTTP/1.1 and HTTP/2 messages

Added:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageHead.java
      - copied, changed from r1666696, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpMessage.java
Removed:
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/DummyHttpMessage.java
Modified:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpMessage.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
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestAbstractMessage.java

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpMessage.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpMessage.java?rev=1666697&r1=1666696&r2=1666697&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpMessage.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpMessage.java
Sat Mar 14 15:49:34 2015
@@ -27,15 +27,13 @@
 
 package org.apache.http;
 
-import java.util.Iterator;
-
 /**
  * HTTP messages consist of requests from client to server and responses
  * from server to client.
  *
  * @since 4.0
  */
-public interface HttpMessage<T> {
+public interface HttpMessage<T> extends MessageHead {
 
     /**
      * Returns the protocol version this message is compatible with.
@@ -43,58 +41,6 @@ public interface HttpMessage<T> {
     ProtocolVersion getProtocolVersion();
 
     /**
-     * Checks if a certain header is present in this message. Header values are
-     * ignored.
-     *
-     * @param name the header name to check for.
-     * @return true if at least one header with this name is present.
-     */
-    boolean containsHeader(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.
-     *
-     * @param name the name of the headers to return.
-     * @return the headers whose name property equals {@code name}.
-     */
-    Header[] getHeaders(String name);
-
-    /**
-     * Returns the first header with a specified name of this message. Header
-     * values are ignored. If there is more than one matching header in the
-     * message the first element of {@link #getHeaders(String)} is returned.
-     * If there is no matching header in the message {@code null} is
-     * returned.
-     *
-     * @param name the name of the header to return.
-     * @return the first header whose name property equals {@code name}
-     *   or {@code null} if no such header could be found.
-     */
-    Header getFirstHeader(String name);
-
-    /**
-     * Returns the last header with a specified name of this message. Header values
-     * are ignored. If there is more than one matching header in the message the
-     * last element of {@link #getHeaders(String)} is returned. If there is no
-     * matching header in the message {@code null} is returned.
-     *
-     * @param name the name of the header to return.
-     * @return the last header whose name property equals {@code name}.
-     *   or {@code null} if no such header could be found.
-     */
-    Header getLastHeader(String name);
-
-    /**
-     * Returns all the headers of this message. Headers are orderd in the sequence
-     * they will be sent over a connection.
-     *
-     * @return all the headers of this message
-     */
-    Header[] getAllHeaders();
-
-    /**
      * Adds a header to this message. The header will be appended to the end of
      * the list.
      *
@@ -150,25 +96,6 @@ public interface HttpMessage<T> {
     void removeHeaders(String name);
 
     /**
-     * Returns an iterator of all the headers.
-     *
-     * @return Iterator that returns Header objects in the sequence they are
-     *         sent over a connection.
-     */
-    Iterator<Header> headerIterator();
-
-    /**
-     * Returns an iterator of the headers with a given name.
-     *
-     * @param name      the name of the headers over which to iterate, or
-     *                  {@code null} for all headers
-     *
-     * @return Iterator that returns Header objects with the argument name
-     *         in the sequence they are sent over a connection.
-     */
-    Iterator<Header> headerIterator(String name);
-
-    /**
      * Obtains the message entity, if available.
      *
      * @return  the message entity, or {@code null} if not available

Copied: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageHead.java
(from r1666696, httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpMessage.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageHead.java?p2=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageHead.java&p1=httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpMessage.java&r1=1666696&r2=1666697&rev=1666697&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/HttpMessage.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/MessageHead.java
Sat Mar 14 15:49:34 2015
@@ -30,17 +30,11 @@ package org.apache.http;
 import java.util.Iterator;
 
 /**
- * HTTP messages consist of requests from client to server and responses
- * from server to client.
+ * HTTP messages head consisting of multiple message headers.
  *
- * @since 4.0
+ * @since 5.0
  */
-public interface HttpMessage<T> {
-
-    /**
-     * Returns the protocol version this message is compatible with.
-     */
-    ProtocolVersion getProtocolVersion();
+public interface MessageHead {
 
     /**
      * Checks if a certain header is present in this message. Header values are
@@ -95,61 +89,6 @@ public interface HttpMessage<T> {
     Header[] getAllHeaders();
 
     /**
-     * Adds a header to this message. The header will be appended to the end of
-     * the list.
-     *
-     * @param header the header to append.
-     */
-    void addHeader(Header header);
-
-    /**
-     * Adds a header to this message. The header will be appended to the end of
-     * the list.
-     *
-     * @param name the name of the header.
-     * @param value the value of the header.
-     */
-    void addHeader(String name, String value);
-
-    /**
-     * Overwrites the first header with the same name. The new header will be appended to
-     * the end of the list, if no header with the given name can be found.
-     *
-     * @param header the header to set.
-     */
-    void setHeader(Header header);
-
-    /**
-     * Overwrites the first header with the same name. The new header will be appended to
-     * the end of the list, if no header with the given name can be found.
-     *
-     * @param name the name of the header.
-     * @param value the value of the header.
-     */
-    void setHeader(String name, String value);
-
-    /**
-     * Overwrites all the headers in the message.
-     *
-     * @param headers the array of headers to set.
-     */
-    void setHeaders(Header[] headers);
-
-    /**
-     * Removes a header from this message.
-     *
-     * @param header the header to remove.
-     */
-    void removeHeader(Header header);
-
-    /**
-     * Removes all headers with a certain name from this message.
-     *
-     * @param name The name of the headers to remove.
-     */
-    void removeHeaders(String name);
-
-    /**
      * Returns an iterator of all the headers.
      *
      * @return Iterator that returns Header objects in the sequence they are
@@ -168,25 +107,4 @@ public interface HttpMessage<T> {
      */
     Iterator<Header> headerIterator(String name);
 
-    /**
-     * Obtains the message entity, if available.
-     *
-     * @return  the message entity, or {@code null} if not available
-     *
-     * @since 5.0
-     */
-    T getEntity();
-
-    /**
-     * Sets an entity for this message.
-     * <p>
-     * Please note that if an entity has already been set it is responsibility of the caller
-     * to ensure release of the resources that may be associated with that entity.
-     *
-     * @param entity    the entity to set of this message, or {@code null} to unset
-     *
-     * @since 5.0
-     */
-    void setEntity(T entity);
-
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestLaxContentLengthStrategy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestLaxContentLengthStrategy.java?rev=1666697&r1=1666696&r2=1666697&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestLaxContentLengthStrategy.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/impl/entity/TestLaxContentLengthStrategy.java
Sat Mar 14 15:49:34 2015
@@ -28,17 +28,29 @@
 package org.apache.http.impl.entity;
 
 import org.apache.http.HttpMessage;
+import org.apache.http.HttpVersion;
 import org.apache.http.ProtocolException;
+import org.apache.http.ProtocolVersion;
 import org.apache.http.entity.ContentLengthStrategy;
+import org.apache.http.message.AbstractHttpMessage;
 import org.junit.Assert;
 import org.junit.Test;
 
 public class TestLaxContentLengthStrategy {
 
+    static class TestHttpMessage extends AbstractHttpMessage {
+
+        @Override
+        public ProtocolVersion getProtocolVersion() {
+            return HttpVersion.HTTP_1_1;
+        }
+
+    }
+
     @Test
     public void testEntityWithTransferEncoding() throws Exception {
         final ContentLengthStrategy lenStrategy = new LaxContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
 
         message.addHeader("Content-Type", "unknown");
         message.addHeader("Transfer-Encoding", "chunked");
@@ -49,7 +61,7 @@ public class TestLaxContentLengthStrateg
     @Test
     public void testEntityWithIdentityTransferEncoding() throws Exception {
         final ContentLengthStrategy lenStrategy = new LaxContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
 
         message.addHeader("Content-Type", "unknown");
         message.addHeader("Transfer-Encoding", "identity");
@@ -60,7 +72,7 @@ public class TestLaxContentLengthStrateg
     @Test(expected=ProtocolException.class)
     public void testEntityWithUnsupportedTransferEncoding() throws Exception {
         final ContentLengthStrategy lenStrategy = new LaxContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
 
         message.addHeader("Content-Type", "unknown");
         message.addHeader("Transfer-Encoding", "whatever; param=value, chunked");
@@ -71,7 +83,7 @@ public class TestLaxContentLengthStrateg
     @Test(expected=ProtocolException.class)
     public void testChunkedTransferEncodingMustBeLast() throws Exception {
         final ContentLengthStrategy lenStrategy = new LaxContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
 
         message.addHeader("Content-Type", "unknown");
         message.addHeader("Transfer-Encoding", "chunked, identity");
@@ -82,7 +94,7 @@ public class TestLaxContentLengthStrateg
     @Test
     public void testEntityWithContentLength() throws Exception {
         final ContentLengthStrategy lenStrategy = new LaxContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
 
         message.addHeader("Content-Type", "unknown");
         message.addHeader("Content-Length", "0");
@@ -92,7 +104,7 @@ public class TestLaxContentLengthStrateg
     @Test
     public void testEntityWithMultipleContentLength() throws Exception {
         final ContentLengthStrategy lenStrategy = new LaxContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
 
         message.addHeader("Content-Type", "unknown");
         message.addHeader("Content-Length", "0");
@@ -104,7 +116,7 @@ public class TestLaxContentLengthStrateg
     @Test
     public void testEntityWithMultipleContentLengthSomeWrong() throws Exception {
         final ContentLengthStrategy lenStrategy = new LaxContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
 
         message.addHeader("Content-Type", "unknown");
         message.addHeader("Content-Length", "1");
@@ -116,7 +128,7 @@ public class TestLaxContentLengthStrateg
     @Test(expected=ProtocolException.class)
     public void testEntityWithMultipleContentLengthAllWrong() throws Exception {
         final ContentLengthStrategy lenStrategy = new LaxContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
 
         message.addHeader("Content-Type", "unknown");
         message.addHeader("Content-Length", "yyy");
@@ -127,7 +139,7 @@ public class TestLaxContentLengthStrateg
     @Test(expected=ProtocolException.class)
     public void testEntityWithInvalidContentLength() throws Exception {
         final ContentLengthStrategy lenStrategy = new LaxContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
 
         message.addHeader("Content-Type", "unknown");
         message.addHeader("Content-Length", "xxx");
@@ -137,7 +149,7 @@ public class TestLaxContentLengthStrateg
     @Test
     public void testEntityNeitherContentLengthNorTransferEncoding() throws Exception {
         final ContentLengthStrategy lenStrategy = new LaxContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
 
         // lenient mode
         Assert.assertEquals(ContentLengthStrategy.UNDEFINED, lenStrategy.determineLength(message));

Modified: 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/TestStrictContentLengthStrategy.java?rev=1666697&r1=1666696&r2=1666697&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/TestStrictContentLengthStrategy.java
Sat Mar 14 15:49:34 2015
@@ -28,17 +28,29 @@
 package org.apache.http.impl.entity;
 
 import org.apache.http.HttpMessage;
+import org.apache.http.HttpVersion;
 import org.apache.http.ProtocolException;
+import org.apache.http.ProtocolVersion;
 import org.apache.http.entity.ContentLengthStrategy;
+import org.apache.http.message.AbstractHttpMessage;
 import org.junit.Assert;
 import org.junit.Test;
 
 public class TestStrictContentLengthStrategy {
 
+    static class TestHttpMessage extends AbstractHttpMessage {
+
+        @Override
+        public ProtocolVersion getProtocolVersion() {
+            return HttpVersion.HTTP_1_1;
+        }
+
+    }
+
     @Test
     public void testEntityWithChunkTransferEncoding() throws Exception {
         final ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
         message.addHeader("Transfer-Encoding", "Chunked");
 
         Assert.assertEquals(ContentLengthStrategy.CHUNKED, lenStrategy.determineLength(message));
@@ -47,7 +59,7 @@ public class TestStrictContentLengthStra
     @Test
     public void testEntityWithIdentityTransferEncoding() throws Exception {
         final ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
         message.addHeader("Transfer-Encoding", "Identity");
 
         Assert.assertEquals(ContentLengthStrategy.IDENTITY, lenStrategy.determineLength(message));
@@ -56,7 +68,7 @@ public class TestStrictContentLengthStra
     @Test(expected=ProtocolException.class)
     public void testEntityWithInvalidTransferEncoding() throws Exception {
         final ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
         message.addHeader("Transfer-Encoding", "whatever");
         lenStrategy.determineLength(message);
     }
@@ -64,7 +76,7 @@ public class TestStrictContentLengthStra
     @Test
     public void testEntityWithContentLength() throws Exception {
         final ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
         message.addHeader("Content-Length", "100");
         Assert.assertEquals(100, lenStrategy.determineLength(message));
     }
@@ -72,7 +84,7 @@ public class TestStrictContentLengthStra
     @Test(expected=ProtocolException.class)
     public void testEntityWithInvalidContentLength() throws Exception {
         final ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
         message.addHeader("Content-Length", "whatever");
         lenStrategy.determineLength(message);
     }
@@ -80,7 +92,7 @@ public class TestStrictContentLengthStra
     @Test(expected=ProtocolException.class)
     public void testEntityWithNegativeContentLength() throws Exception {
         final ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
         message.addHeader("Content-Length", "-10");
         lenStrategy.determineLength(message);
     }
@@ -88,7 +100,7 @@ public class TestStrictContentLengthStra
     @Test
     public void testEntityNoContentDelimiter() throws Exception {
         final ContentLengthStrategy lenStrategy = new StrictContentLengthStrategy();
-        final HttpMessage message = new DummyHttpMessage();
+        final HttpMessage message = new TestHttpMessage();
         Assert.assertEquals(ContentLengthStrategy.UNDEFINED, lenStrategy.determineLength(message));
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestAbstractMessage.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestAbstractMessage.java?rev=1666697&r1=1666696&r2=1666697&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestAbstractMessage.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/message/TestAbstractMessage.java
Sat Mar 14 15:49:34 2015
@@ -41,20 +41,9 @@ public class TestAbstractMessage {
 
     static class TestHttpMessage extends AbstractHttpMessage {
 
-        private final ProtocolVersion ver;
-
-        public TestHttpMessage(final ProtocolVersion ver) {
-            super();
-            this.ver = ver != null ? ver : HttpVersion.HTTP_1_1;
-        }
-
-        public TestHttpMessage() {
-            this(HttpVersion.HTTP_1_1);
-        }
-
         @Override
         public ProtocolVersion getProtocolVersion() {
-            return ver;
+            return HttpVersion.HTTP_1_1;
         }
 
     }



Mime
View raw message