hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r418730 - in /jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl: CoyoteHttpConnectionImpl.java HttpConnectionProcessor.java
Date Mon, 03 Jul 2006 10:02:38 GMT
Author: olegk
Date: Mon Jul  3 03:02:35 2006
New Revision: 418730

URL: http://svn.apache.org/viewvc?rev=418730&view=rev
Log:
Re-use Coyote primitives to minimize buffer copying and reduce intermediate garbage

Modified:
    jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/CoyoteHttpConnectionImpl.java
    jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/HttpConnectionProcessor.java

Modified: jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/CoyoteHttpConnectionImpl.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/CoyoteHttpConnectionImpl.java?rev=418730&r1=418729&r2=418730&view=diff
==============================================================================
--- jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/CoyoteHttpConnectionImpl.java
(original)
+++ jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/CoyoteHttpConnectionImpl.java
Mon Jul  3 03:02:35 2006
@@ -65,6 +65,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.protocol.HTTP;
@@ -236,9 +237,14 @@
         BasicStatusLine.format(this.charbuffer, response.getStatusLine());
         this.datatransmitter.writeLine(this.charbuffer);
         for (Iterator it = response.headerIterator(); it.hasNext(); ) {
-            this.charbuffer.clear();
-            BasicHeader.format(this.charbuffer, (Header) it.next());
-            this.datatransmitter.writeLine(this.charbuffer);
+            Header header = (Header) it.next();
+            if (header instanceof BufferedHeader) {
+                this.datatransmitter.writeLine(((BufferedHeader)header).getBuffer());
+            } else {
+                this.charbuffer.clear();
+                BasicHeader.format(this.charbuffer, header);
+                this.datatransmitter.writeLine(this.charbuffer);
+            }
         }
         this.charbuffer.clear();
         this.datatransmitter.writeLine(this.charbuffer);

Modified: jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/HttpConnectionProcessor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/HttpConnectionProcessor.java?rev=418730&r1=418729&r2=418730&view=diff
==============================================================================
--- jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/HttpConnectionProcessor.java
(original)
+++ jakarta/httpcomponents/tcconnector/trunk/src/java/org/apache/http/tcconnector/impl/HttpConnectionProcessor.java
Mon Jul  3 03:02:35 2006
@@ -60,10 +60,13 @@
 import org.apache.http.StatusLine;
 import org.apache.http.entity.BasicHttpEntity;
 import org.apache.http.impl.DefaultConnectionReuseStrategy;
+import org.apache.http.io.CharArrayBuffer;
 import org.apache.http.message.BasicHttpResponse;
 import org.apache.http.message.BasicStatusLine;
+import org.apache.http.message.BufferedHeader;
 import org.apache.http.params.HttpParams;
 import org.apache.http.protocol.AbstractHttpProcessor;
+import org.apache.http.protocol.HTTP;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.protocol.HttpExecutionContext;
 import org.apache.http.protocol.ResponseConnControl;
@@ -78,6 +81,9 @@
 import org.apache.http.tcconnector.NotImplementedException;
 import org.apache.http.tcconnector.UnsupportedHttpVersionException;
 import org.apache.http.tcconnector.params.CoyoteParams;
+import org.apache.tomcat.util.buf.ByteChunk;
+import org.apache.tomcat.util.buf.CharChunk;
+import org.apache.tomcat.util.buf.MessageBytes;
 import org.apache.tomcat.util.http.MimeHeaders;
 
 /**
@@ -342,8 +348,20 @@
 
         // Convert the request headers
         Header[] headers = httpreq.getAllHeaders();
+        MimeHeaders mimeheaders = this.coyotereq.getMimeHeaders();
         for (Header header: headers) {
-        	this.coyotereq.getMimeHeaders().addValue(header.getName()).setString(header.getValue());
+            MessageBytes mb = mimeheaders.addValue(header.getName());
+            if (header instanceof BufferedHeader) {
+                BufferedHeader bufheader = (BufferedHeader) header;
+                CharArrayBuffer buffer = bufheader.getBuffer();
+                int pos = bufheader.getValuePos();
+                while (pos < buffer.length() && HTTP.isWhitespace(buffer.charAt(pos)))
{
+                    pos++;
+                }
+                mb.setChars(buffer.buffer(), pos, buffer.length() - pos);
+            } else {
+                mb.setString(header.getValue());
+            }
         }
     }
         
@@ -379,7 +397,19 @@
             && status != HttpStatus.SC_NOT_MODIFIED
             && status != HttpStatus.SC_RESET_CONTENT; 
     }
-        
+
+    private static void addMessageBytes(final CharArrayBuffer buffer, final MessageBytes
mb) {
+        if (mb.getType() == MessageBytes.T_CHARS) {
+            CharChunk chunk = mb.getCharChunk();
+            buffer.append(chunk.getBuffer(), chunk.getStart(), chunk.getLength());
+        } else if (mb.getType() == MessageBytes.T_BYTES) {
+            ByteChunk chunk = mb.getByteChunk();
+            buffer.append(chunk.getBuffer(), chunk.getStart(), chunk.getLength());
+        } else if (mb.getType() == MessageBytes.T_STR) {
+            buffer.append(mb.getString());
+        }
+    }
+    
     private void prepareHttpResponse() throws IOException {
         this.coyotereq.getRequestProcessor().setStage(Constants.STAGE_ENDINPUT);
         if (this.httpres != null) {
@@ -403,9 +433,14 @@
         MimeHeaders headers = this.coyoteres.getMimeHeaders();
         int size = headers.size();
         for (int i = 0; i < size; i++) {
-            String name = headers.getName(i).getString();
-            String value = headers.getValue(i).getString();
-            this.httpres.addHeader(name, value);
+            MessageBytes n = headers.getName(i);
+            MessageBytes v = headers.getValue(i);
+            CharArrayBuffer buffer = new CharArrayBuffer(n.getLength() + v.getLength() +
2);
+            addMessageBytes(buffer, n);
+            buffer.append(": ");
+            addMessageBytes(buffer, v);
+            BufferedHeader header = new BufferedHeader(buffer);
+            this.httpres.addHeader(header);
         }
         String lang = this.coyoteres.getContentLanguage();
         if (lang != null) {



Mime
View raw message