hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r562713 - in /jakarta/httpcomponents/httpcore/trunk: ./ module-main/src/main/java/org/apache/http/impl/ module-main/src/main/java/org/apache/http/impl/io/ module-main/src/main/java/org/apache/http/params/
Date Sat, 04 Aug 2007 13:11:36 GMT
Author: olegk
Date: Sat Aug  4 06:11:35 2007
New Revision: 562713

URL: http://svn.apache.org/viewvc?view=rev&rev=562713
Log:
HTTPCORE-106: Moved garbage tolerant HTTP response parser to HttpClient

Modified:
    jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseParser.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/HttpConnectionParams.java

Modified: jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?view=diff&rev=562713&r1=562712&r2=562713
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Sat Aug  4 06:11:35 2007
@@ -1,5 +1,8 @@
 Changes since release 4.0 Alpha 5
 
+* [HTTPCORE-106] Pluggable HTTP message parsers and message writers
+  Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCORE-105] Consistent class names in base and NIO modules
   Oleg Kalnichevski <olegk at apache.org>
 

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java?view=diff&rev=562713&r1=562712&r2=562713
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpClientConnection.java
Sat Aug  4 06:11:35 2007
@@ -72,8 +72,7 @@
     private SessionOutputBuffer outbuffer = null;
     private HttpMessageParser responseParser = null;
     private HttpMessageWriter requestWriter = null;
-
-    private HttpConnectionMetricsImpl metrics;
+    private HttpConnectionMetricsImpl metrics = null;
     
     public AbstractHttpClientConnection() {
         super();
@@ -121,7 +120,9 @@
         this.inbuffer = inbuffer;
         this.outbuffer = outbuffer;
         this.responseParser = createResponseParser(
-                inbuffer, createHttpResponseFactory(), params);
+                inbuffer, 
+                createHttpResponseFactory(), 
+                params);
         this.requestWriter = createRequestWriter(
                 outbuffer, params);
         this.metrics = new HttpConnectionMetricsImpl(

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java?view=diff&rev=562713&r1=562712&r2=562713
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/AbstractHttpServerConnection.java
Sat Aug  4 06:11:35 2007
@@ -72,8 +72,7 @@
     private SessionOutputBuffer outbuffer = null;
     private HttpMessageParser requestParser = null;
     private HttpMessageWriter responseWriter = null;
-
-    private HttpConnectionMetricsImpl metrics;
+    private HttpConnectionMetricsImpl metrics = null;
     
     public AbstractHttpServerConnection() {
         super();
@@ -120,8 +119,10 @@
         }
         this.inbuffer = inbuffer;
         this.outbuffer = outbuffer;
-        this.requestParser = createRequestParser(inbuffer, 
-                createHttpRequestFactory(), params);
+        this.requestParser = createRequestParser(
+                inbuffer, 
+                createHttpRequestFactory(), 
+                params);
         this.responseWriter = createResponseWriter(
                 outbuffer, params);
         this.metrics = new HttpConnectionMetricsImpl(

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseParser.java?view=diff&rev=562713&r1=562712&r2=562713
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseParser.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseParser.java
Sat Aug  4 06:11:35 2007
@@ -37,20 +37,16 @@
 import org.apache.http.HttpMessage;
 import org.apache.http.HttpResponseFactory;
 import org.apache.http.NoHttpResponseException;
-import org.apache.http.ProtocolException;
 import org.apache.http.StatusLine;
 import org.apache.http.io.SessionInputBuffer;
 import org.apache.http.message.BasicStatusLine;
-import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.HTTP;
 import org.apache.http.util.CharArrayBuffer;
 
 public class HttpResponseParser extends AbstractMessageParser {
     
     private final HttpResponseFactory responseFactory;
     private final CharArrayBuffer lineBuf;
-    private final int maxGarbageLines;
     
     public HttpResponseParser(
             final SessionInputBuffer buffer,
@@ -62,53 +58,15 @@
         }
         this.responseFactory = responseFactory;
         this.lineBuf = new CharArrayBuffer(128);
-        this.maxGarbageLines = params.getIntParameter(
-                HttpConnectionParams.MAX_STATUS_LINE_GARBAGE, Integer.MAX_VALUE);
     }
 
-    /**
-     * Tests if the string starts with 'HTTP' signature.
-     * @param buffer buffer to test
-     * @return <tt>true</tt> if the line starts with 'HTTP' 
-     *   signature, <tt>false</tt> otherwise.
-     */
-    protected static boolean startsWithHTTP(final CharArrayBuffer buffer) {
-        try {
-            int i = 0;
-            while (HTTP.isWhitespace(buffer.charAt(i))) {
-                ++i;
-            }
-            return buffer.charAt(i) == 'H' 
-                && buffer.charAt(i + 1) == 'T'
-                && buffer.charAt(i + 2) == 'T'
-                && buffer.charAt(i + 3) == 'P';
-        } catch (IndexOutOfBoundsException e) {
-            return false;
-        }
-    }
-    
     protected HttpMessage parseHead(
             final SessionInputBuffer sessionBuffer) throws IOException, HttpException {
-        // clear the buffer
         this.lineBuf.clear();
-        //read out the HTTP status string
-        int count = 0;
-        do {
-            int i = sessionBuffer.readLine(this.lineBuf);
-            if (i == -1 && count == 0) {
-                // The server just dropped connection on us
-                throw new NoHttpResponseException("The target server failed to respond");
-            }
-            if (startsWithHTTP(this.lineBuf)) {
-                // Got one
-                break;
-            } else if (i == -1 || count >= this.maxGarbageLines) {
-                // Giving up
-                throw new ProtocolException("The server failed to respond with a " +
-                        "valid HTTP response");
-            }
-            count++;
-        } while(true);
+        int i = sessionBuffer.readLine(this.lineBuf);
+        if (i == -1) {
+            throw new NoHttpResponseException("The target server failed to respond");
+        }
         //create the status line from the status string
         StatusLine statusline = BasicStatusLine.parse(this.lineBuf, 0, this.lineBuf.length());
         return this.responseFactory.newHttpResponse(statusline, null);

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/HttpConnectionParams.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/HttpConnectionParams.java?view=diff&rev=562713&r1=562712&r2=562713
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/HttpConnectionParams.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/params/HttpConnectionParams.java
Sat Aug  4 06:11:35 2007
@@ -130,26 +130,6 @@
     public static final String MAX_HEADER_COUNT = "http.connection.max-header-count";
     
     /**
-     * Defines the maximum number of ignorable lines before we expect
-     * a HTTP response's status code.
-     * <p>
-     * With HTTP/1.1 persistent connections, the problem arises that
-     * broken scripts could return a wrong Content-Length
-     * (there are more bytes sent than specified).<br />
-     * Unfortunately, in some cases, this is not possible after the bad response,
-     * but only before the next one. <br />
-     * So, HttpClient must be able to skip those surplus lines this way.
-     * </p>
-     * <p>
-     * Set this to 0 to disallow any garbage/empty lines before the status line.<br />
-     * To specify no limit, use {@link java.lang.Integer#MAX_VALUE} (default in lenient mode).
-     * </p>
-     *  
-     * This parameter expects a value of type {@link Integer}.
-     */
-    public static final String MAX_STATUS_LINE_GARBAGE = "http.connection.max-status-line-garbage";
-
-    /**
      */
     private HttpConnectionParams() {
         super();



Mime
View raw message