hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r418728 - in /jakarta/httpcomponents/httpcore/trunk/src: java/org/apache/http/impl/ java/org/apache/http/message/ java/org/apache/http/util/ test/org/apache/http/util/
Date Mon, 03 Jul 2006 09:55:57 GMT
Author: olegk
Date: Mon Jul  3 02:55:56 2006
New Revision: 418728

URL: http://svn.apache.org/viewvc?rev=418728&view=rev
Log:
[HTTPCORE-6] When transmitting HTTP messages, re-use Header buffers whenever possible. 

Modified:
    jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
    jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/DefaultHttpServerConnection.java
    jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/message/BufferedHeader.java
    jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/util/HeaderUtils.java
    jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/util/TestHeaderUtils.java

Modified: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/DefaultHttpClientConnection.java?rev=418728&r1=418727&r2=418728&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/DefaultHttpClientConnection.java
Mon Jul  3 02:55:56 2006
@@ -55,6 +55,7 @@
 import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicRequestLine;
 import org.apache.http.message.BasicStatusLine;
+import org.apache.http.message.BufferedHeader;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
@@ -207,9 +208,15 @@
     protected void sendRequestHeaders(final HttpRequest request) 
             throws HttpException, IOException {
         for (Iterator it = request.headerIterator(); it.hasNext(); ) {
-            this.buffer.clear();
-            BasicHeader.format(this.buffer, (Header) it.next());
-            this.datatransmitter.writeLine(this.buffer);
+            Header header = (Header) it.next();
+            if (header instanceof BufferedHeader) {
+                // If the header is backed by a buffer, re-use the buffer
+                this.datatransmitter.writeLine(((BufferedHeader)header).getBuffer());
+            } else {
+                this.buffer.clear();
+                BasicHeader.format(this.buffer, header);
+                this.datatransmitter.writeLine(this.buffer);
+            }
         }
         this.buffer.clear();
         this.datatransmitter.writeLine(this.buffer);

Modified: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/DefaultHttpServerConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/DefaultHttpServerConnection.java?rev=418728&r1=418727&r2=418728&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/DefaultHttpServerConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/DefaultHttpServerConnection.java
Mon Jul  3 02:55:56 2006
@@ -51,6 +51,7 @@
 import org.apache.http.message.BasicHeader;
 import org.apache.http.message.BasicRequestLine;
 import org.apache.http.message.BasicStatusLine;
+import org.apache.http.message.BufferedHeader;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.util.HeaderUtils;
@@ -188,9 +189,15 @@
     protected void sendResponseHeaders(final HttpResponse response) 
             throws HttpException, IOException {
         for (Iterator it = response.headerIterator(); it.hasNext(); ) {
-            this.buffer.clear();
-            BasicHeader.format(this.buffer, (Header) it.next());
-            this.datatransmitter.writeLine(this.buffer);
+            Header header = (Header) it.next();
+            if (header instanceof BufferedHeader) {
+                // If the header is backed by a buffer, re-use the buffer
+                this.datatransmitter.writeLine(((BufferedHeader)header).getBuffer());
+            } else {
+                this.buffer.clear();
+                BasicHeader.format(this.buffer, header);
+                this.datatransmitter.writeLine(this.buffer);
+            }
         }
         this.buffer.clear();
         this.datatransmitter.writeLine(this.buffer);

Modified: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/message/BufferedHeader.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/message/BufferedHeader.java?rev=418728&r1=418727&r2=418728&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/message/BufferedHeader.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/message/BufferedHeader.java
Mon Jul  3 02:55:56 2006
@@ -31,7 +31,6 @@
 
 import org.apache.http.Header;
 import org.apache.http.HeaderElement;
-import org.apache.http.ProtocolException;
 import org.apache.http.io.CharArrayBuffer;
 
 /**
@@ -62,18 +61,18 @@
      * @param name the header name
      * @param value the header value
      */
-    public BufferedHeader(final CharArrayBuffer buffer) throws ProtocolException {
+    public BufferedHeader(final CharArrayBuffer buffer) {
         super();
         if (buffer == null) {
             throw new IllegalArgumentException("Char array buffer may not be null");
         }
         int colon = buffer.indexOf(':');
         if (colon == -1) {
-            throw new ProtocolException("Invalid header: " + buffer.toString());
+            throw new IllegalArgumentException("Invalid header: " + buffer.toString());
         }
         String s = buffer.substringTrimmed(0, colon);
         if (s.equals("")) {
-            throw new ProtocolException("Invalid header: " + buffer.toString());
+            throw new IllegalArgumentException("Invalid header: " + buffer.toString());
         }
         this.buffer = buffer;
         this.name = s;
@@ -92,6 +91,10 @@
         return BasicHeaderElement.parseAll(this.buffer, this.valuePos, this.buffer.length());
     }
 
+    public int getValuePos() {
+        return this.valuePos;
+    }
+    
     public CharArrayBuffer getBuffer() {
         return this.buffer;
     }

Modified: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/util/HeaderUtils.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/util/HeaderUtils.java?rev=418728&r1=418727&r2=418728&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/util/HeaderUtils.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/util/HeaderUtils.java Mon
Jul  3 02:55:56 2006
@@ -34,6 +34,7 @@
 
 import org.apache.http.Header;
 import org.apache.http.HttpException;
+import org.apache.http.ProtocolException;
 import org.apache.http.io.CharArrayBuffer;
 import org.apache.http.io.HttpDataReceiver;
 import org.apache.http.message.BufferedHeader;
@@ -111,7 +112,11 @@
         Header[] headers = new Header[headerLines.size()];
         for (int i = 0; i < headerLines.size(); i++) {
             CharArrayBuffer buffer = (CharArrayBuffer) headerLines.get(i);
-            headers[i] = new BufferedHeader(buffer);
+            try {
+                headers[i] = new BufferedHeader(buffer);
+            } catch (IllegalArgumentException ex) {
+                throw new ProtocolException(ex.getMessage());
+            }
         }
         return headers;
     }

Modified: jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/util/TestHeaderUtils.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/util/TestHeaderUtils.java?rev=418728&r1=418727&r2=418728&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/util/TestHeaderUtils.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/util/TestHeaderUtils.java
Mon Jul  3 02:55:56 2006
@@ -103,6 +103,7 @@
         assertTrue(h instanceof BufferedHeader);
         assertNotNull(((BufferedHeader)h).getBuffer());
         assertEquals("header1: stuff", ((BufferedHeader)h).toString());
+        assertEquals(8, ((BufferedHeader)h).getValuePos());
     }
 
     public void testBufferedHeader() throws Exception {



Mime
View raw message