hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r569687 - /jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java
Date Sat, 25 Aug 2007 15:23:14 GMT
Author: rolandw
Date: Sat Aug 25 08:23:14 2007
New Revision: 569687

URL: http://svn.apache.org/viewvc?rev=569687&view=rev
Log:
refined length estimation for request and status line

Modified:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java?rev=569687&r1=569686&r2=569687&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java
Sat Aug 25 08:23:14 2007
@@ -119,8 +119,7 @@
 
         // can't use initBuffer, that would clear the argument!
         CharArrayBuffer result = buffer;
-        //@@@ guess the length in an extra method
-        final int len = 8; // room for "HTTP/1.1"
+        final int len = estimateProtocolVersionLen(version);
         if (result == null) {
             result = new CharArrayBuffer(len);
         } else {
@@ -136,6 +135,19 @@
     }
 
 
+    /**
+     * Guesses the length of a formatted protocol version.
+     * Needed to guess the length of a formatted request or status line.
+     *
+     * @param version   the protocol version to format, or <code>null</code>
+     *
+     * @return  the estimated length of the formatted protocol version,
+     *          in characters
+     */
+    protected int estimateProtocolVersionLen(HttpVersion version) {
+        return 8; // room for "HTTP/1.1"
+    }
+
 
     /**
      * Formats a request line.
@@ -182,10 +194,10 @@
                                        RequestLine reqline) {
         final String method = reqline.getMethod();
         final String uri    = reqline.getUri();
-        //@@@ let the protocol version length be guessed elsewhere
-        //@@@ guess the length in an extra method?
+
         // room for "GET /index.html HTTP/1.1"
-        int len = method.length() + 1 + uri.length() + 1 + 8;
+        int len = method.length() + 1 + uri.length() + 1 + 
+            estimateProtocolVersionLen(reqline.getHttpVersion());
         buffer.ensureCapacity(len);
 
         buffer.append(method);
@@ -240,9 +252,9 @@
      */
     protected void doFormatStatusLine(CharArrayBuffer buffer,
                                       StatusLine statline) {
-        //@@@ let the protocol version length be guessed elsewhere
-        //@@@ guess the length in an extra method?
-        int len = 8 + 1 + 3 + 1; // room for "HTTP/1.1 200 "
+
+        int len = estimateProtocolVersionLen(statline.getHttpVersion())
+            + 1 + 3 + 1; // room for "HTTP/1.1 200 "
         final String reason = statline.getReasonPhrase();
         if (reason != null) {
             len += reason.length();



Mime
View raw message