hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r410884 - in /jakarta/httpcomponents/httpcore/trunk/src: java/org/apache/http/impl/ java/org/apache/http/impl/io/ java/org/apache/http/params/ test/org/apache/http/impl/
Date Thu, 01 Jun 2006 16:35:04 GMT
Author: olegk
Date: Thu Jun  1 09:35:03 2006
New Revision: 410884

URL: http://svn.apache.org/viewvc?rev=410884&view=rev
Log:
Fix for bug HTTPCORE-4

Contributed by Oleg Kalnichevski

Modified:
    jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/AbstractHttpConnection.java
    jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java
    jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/params/HttpConnectionParams.java
    jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/impl/TestHttpDataReceiverAndTransmitter.java

Modified: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/AbstractHttpConnection.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/AbstractHttpConnection.java?rev=410884&r1=410883&r2=410884&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/AbstractHttpConnection.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/AbstractHttpConnection.java
Thu Jun  1 09:35:03 2006
@@ -128,6 +128,8 @@
         } else {
             this.datareceiver = new SocketHttpDataReceiver(this.socket, buffersize);
         }
+        this.datatransmitter.reset(params);
+        this.datareceiver.reset(params);
     }
 
     public boolean isOpen() {

Modified: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java?rev=410884&r1=410883&r2=410884&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/impl/io/AbstractHttpDataReceiver.java
Thu Jun  1 09:35:03 2006
@@ -35,6 +35,7 @@
 import org.apache.http.io.ByteArrayBuffer;
 import org.apache.http.io.CharArrayBuffer;
 import org.apache.http.io.HttpDataReceiver;
+import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.protocol.HTTP;
@@ -56,6 +57,7 @@
     
     private String charset = HTTP.US_ASCII;
     private boolean ascii = true;
+    private int maxLineLen = 0;
     
     protected void init(final InputStream instream, int buffersize) {
         if (instream == null) {
@@ -180,6 +182,9 @@
                     retry = false;
                 }
             }
+            if (this.maxLineLen > 0 && this.linebuffer.length() >= this.maxLineLen)
{
+                throw new IOException("Maximum line length limit exceeded");
+            }
         }
         if (noRead == -1 && this.linebuffer.isEmpty()) {
             // indicate the end of stream
@@ -252,6 +257,7 @@
         this.charset = HttpProtocolParams.getHttpElementCharset(params);
         this.ascii = this.charset.equalsIgnoreCase(HTTP.US_ASCII)
                      || this.charset.equalsIgnoreCase(HTTP.ASCII);
+        this.maxLineLen = params.getIntParameter(HttpConnectionParams.MAX_LINE_LENGTH, 0);
     }
     
 }

Modified: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/params/HttpConnectionParams.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/params/HttpConnectionParams.java?rev=410884&r1=410883&r2=410884&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/params/HttpConnectionParams.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/params/HttpConnectionParams.java
Thu Jun  1 09:35:03 2006
@@ -108,6 +108,15 @@
     public static final String STALE_CONNECTION_CHECK = "http.connection.stalecheck"; 
 
     /**
+     * Determines the maximum line length limit. if set, any HTTP line exceeding this
+     * limit will cause an IOException
+     * <p>
+     * This parameter expects a value of type {@link Integer}.
+     * </p>
+     */
+    public static final String MAX_LINE_LENGTH = "http.connection.max-line-length";
+    
+    /**
      */
     private HttpConnectionParams() {
         super();
@@ -275,4 +284,5 @@
         }
         params.setBooleanParameter(STALE_CONNECTION_CHECK, value);
     }
+    
 }

Modified: jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/impl/TestHttpDataReceiverAndTransmitter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/impl/TestHttpDataReceiverAndTransmitter.java?rev=410884&r1=410883&r2=410884&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/impl/TestHttpDataReceiverAndTransmitter.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/impl/TestHttpDataReceiverAndTransmitter.java
Thu Jun  1 09:35:03 2006
@@ -30,6 +30,7 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 
 import junit.framework.Test;
@@ -40,6 +41,7 @@
 import org.apache.http.io.CharArrayBuffer;
 import org.apache.http.mockup.HttpDataReceiverMockup;
 import org.apache.http.mockup.HttpDataTransmitterMockup;
+import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
 import org.apache.http.params.HttpProtocolParams;
 import org.apache.http.protocol.HTTP;
@@ -306,6 +308,28 @@
         }
         assertEquals(-1, receiver.read());
         assertEquals(-1, receiver.read());
+    }
+
+    public void testLineLimit() throws Exception {
+        HttpParams params = new DefaultHttpParams();
+        String s = "a very looooooooooooooooooooooooooooooooooooooong line\r\n     ";
+        byte[] tmp = s.getBytes("US-ASCII"); 
+        HttpDataReceiverMockup receiver1 = new HttpDataReceiverMockup(tmp, 5);
+        // no limit
+        params.setIntParameter(HttpConnectionParams.MAX_LINE_LENGTH, 0);
+        receiver1.reset(params);
+        assertNotNull(receiver1.readLine());
+        
+        HttpDataReceiverMockup receiver2 = new HttpDataReceiverMockup(tmp, 5);
+        // 15 char limit
+        params.setIntParameter(HttpConnectionParams.MAX_LINE_LENGTH, 15);
+        receiver2.reset(params);
+        try {
+            receiver2.readLine();
+            fail("IOException should have been thrown");
+        } catch (IOException ex) {
+            // expected
+        }
     }
 
     static final int SWISS_GERMAN_HELLO [] = {



Mime
View raw message