hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r230691 - in /jakarta/httpclient/trunk/http-common/src: examples/org/apache/http/examples/ java/org/apache/http/ java/org/apache/http/impl/
Date Sun, 07 Aug 2005 19:30:59 GMT
Author: olegk
Date: Sun Aug  7 12:30:48 2005
New Revision: 230691

URL: http://svn.apache.org/viewcvs?rev=230691&view=rev
Log:
Server-side 'expect: 100-continue' code refactored

Removed:
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/RequestValidationException.java
Modified:
    jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpEchoServer.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntityEnclosingRequest.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpServerConnection.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpEntityEnclosingRequest.java
    jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpServerConnection.java

Modified: jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpEchoServer.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpEchoServer.java?rev=230691&r1=230690&r2=230691&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpEchoServer.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/examples/org/apache/http/examples/ElementalHttpEchoServer.java
Sun Aug  7 12:30:48 2005
@@ -45,6 +45,7 @@
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpServerConnection;
 import org.apache.http.HttpStatus;
+import org.apache.http.HttpVersion;
 import org.apache.http.MethodNotSupportedException;
 import org.apache.http.ProtocolException;
 import org.apache.http.entity.EntityConsumer;
@@ -56,6 +57,7 @@
 import org.apache.http.impl.DefaultHttpServerConnection;
 import org.apache.http.params.HttpConnectionParams;
 import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
 
 /**
  * <p>
@@ -220,8 +222,27 @@
             System.out.println("New connection thread");
             while (!Thread.interrupted()) {
                 BasicHttpResponse response = new BasicHttpResponse();
+                response.getParams().setDefaults(this.params);
                 try {
                     HttpRequest request = this.conn.receiveRequest(this.params);
+                    HttpVersion ver = request.getRequestLine().getHttpVersion();
+                    if (ver.greaterEquals(HttpVersion.HTTP_1_1)) {
+                    	ver = HttpVersion.HTTP_1_1;
+                    }
+                    HttpProtocolParams.setVersion(response.getParams(), ver);
+                    
+                    if (request instanceof HttpEntityEnclosingRequest) {
+                    	if (((HttpEntityEnclosingRequest) request).expectContinue()) {
+
+                    		System.out.println("Expected 100 (Continue)");
+                    		
+                            BasicHttpResponse ack = new BasicHttpResponse();
+                            ack.getParams().setDefaults(this.params);
+                            ack.setStatusCode(HttpStatus.SC_CONTINUE);
+                            this.conn.sendResponse(ack);
+                            this.conn.continueRequest((HttpEntityEnclosingRequest) request);
+                    	}
+                    }
                     System.out.println("Request received");
                     this.handler.handleRequest(request, response);
                 } catch (ConnectionClosedException ex) {

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntityEnclosingRequest.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntityEnclosingRequest.java?rev=230691&r1=230690&r2=230691&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntityEnclosingRequest.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpEntityEnclosingRequest.java
Sun Aug  7 12:30:48 2005
@@ -40,6 +40,8 @@
  */
 public interface HttpEntityEnclosingRequest extends HttpRequest {
 
+	boolean expectContinue();
+	
     HttpEntity getEntity();
     
 }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpServerConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpServerConnection.java?rev=230691&r1=230690&r2=230691&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpServerConnection.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/HttpServerConnection.java
Sun Aug  7 12:30:48 2005
@@ -49,6 +49,8 @@
     
     HttpRequest receiveRequest(HttpParams params) throws HttpException, IOException;
 
+    void continueRequest(HttpEntityEnclosingRequest request) throws HttpException, IOException;
+
     void sendResponse(HttpResponse response) throws HttpException, IOException;
     
 }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpEntityEnclosingRequest.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpEntityEnclosingRequest.java?rev=230691&r1=230690&r2=230691&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpEntityEnclosingRequest.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/BasicHttpEntityEnclosingRequest.java
Sun Aug  7 12:30:48 2005
@@ -29,6 +29,7 @@
 
 package org.apache.http.impl;
 
+import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpMutableEntityEnclosingRequest;
 import org.apache.http.RequestLine;
@@ -45,6 +46,9 @@
 public class BasicHttpEntityEnclosingRequest 
             extends BasicHttpRequest implements HttpMutableEntityEnclosingRequest {
     
+    private static final String EXPECT_DIRECTIVE = "Expect";
+    private static final String EXPECT_CONTINUE = "100-Continue";
+
     private HttpEntity entity = null;
     
     protected BasicHttpEntityEnclosingRequest(final String method, final String uri) {
@@ -62,4 +66,10 @@
     public void setEntity(final HttpEntity entity) {
         this.entity = entity;
     }
+    
+	public boolean expectContinue() {
+        Header expect = getFirstHeader(EXPECT_DIRECTIVE);
+        return expect != null && EXPECT_CONTINUE.equalsIgnoreCase(expect.getValue());
+	}
+    
 }

Modified: jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpServerConnection.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpServerConnection.java?rev=230691&r1=230690&r2=230691&view=diff
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpServerConnection.java
(original)
+++ jakarta/httpclient/trunk/http-common/src/java/org/apache/http/impl/DefaultHttpServerConnection.java
Sun Aug  7 12:30:48 2005
@@ -34,20 +34,16 @@
 
 import org.apache.http.ConnectionClosedException;
 import org.apache.http.Header;
+import org.apache.http.HttpEntityEnclosingRequest;
 import org.apache.http.HttpException;
 import org.apache.http.HttpMutableEntity;
 import org.apache.http.HttpMutableEntityEnclosingRequest;
 import org.apache.http.HttpMutableRequest;
-import org.apache.http.HttpMutableResponse;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestFactory;
 import org.apache.http.HttpResponse;
-import org.apache.http.HttpResponseFactory;
 import org.apache.http.HttpServerConnection;
-import org.apache.http.HttpStatus;
-import org.apache.http.HttpVersion;
 import org.apache.http.RequestLine;
-import org.apache.http.RequestValidationException;
 import org.apache.http.impl.entity.DefaultEntityGenerator;
 import org.apache.http.impl.entity.DefaultEntityWriter;
 import org.apache.http.impl.entity.EntityGenerator;
@@ -67,19 +63,14 @@
 public class DefaultHttpServerConnection 
         extends AbstractHttpConnection implements HttpServerConnection {
 
-    private static final String EXPECT_DIRECTIVE = "Expect";
-    private static final String EXPECT_CONTINUE = "100-Continue";
-
     /*
      * Dependent interfaces
      */
     private HttpRequestFactory requestfactory = null; 
-    private HttpResponseFactory responsefactory = null; 
 
     public DefaultHttpServerConnection() {
         super();
         this.requestfactory = new DefaultHttpRequestFactory();
-        this.responsefactory = new DefaultHttpResponseFactory();
     }
     
     public void setRequestFactory(final HttpRequestFactory requestfactory) {
@@ -89,13 +80,6 @@
         this.requestfactory = requestfactory;
     }
 
-    public void setResponseFactory(final HttpResponseFactory responsefactory) {
-        if (responsefactory == null) {
-            throw new IllegalArgumentException("Factory may not be null");
-        }
-        this.responsefactory = responsefactory;
-    }
-
     public void bind(final Socket socket, final HttpParams params) throws IOException {
         super.bind(socket, params);
     }
@@ -112,22 +96,12 @@
         HttpMutableRequest request = receiveRequestLine(params);
         receiveRequestHeaders(request);
 
-        HttpVersion responsever = request.getRequestLine().getHttpVersion();
-        if (responsever.greaterEquals(HttpVersion.HTTP_1_1)) {
-            responsever = HttpVersion.HTTP_1_1;
-        }
-
-        boolean validated = false;
         if (request instanceof HttpMutableEntityEnclosingRequest) {
-            if (expectContinue(request)) {
-                validateRequest(request);
-                validated = true;
-                sendContinue(responsever);
-            }
-            receiveRequestBody((HttpMutableEntityEnclosingRequest)request);
-        }
-        if (!validated) {
-            validateRequest(request);
+        	if (((HttpMutableEntityEnclosingRequest) request).expectContinue()) {
+            	// return and let the caller validate the request
+                return request;
+        	}
+            receiveRequestBody((HttpMutableEntityEnclosingRequest) request);
         }
         return request;
     }
@@ -159,22 +133,6 @@
         wirelog(">> [\\r][\\n]");
     }
 
-    protected boolean expectContinue(final HttpRequest request) {
-        Header expect = request.getFirstHeader(EXPECT_DIRECTIVE);
-        return expect != null && EXPECT_CONTINUE.equalsIgnoreCase(expect.getValue());
-    }
-
-    protected void validateRequest(final HttpRequest request)
-            throws RequestValidationException {
-    }
-    
-    protected void sendContinue(final HttpVersion ver) 
-            throws IOException, HttpException {
-        HttpMutableResponse response = this.responsefactory.newHttpResponse(
-                ver, HttpStatus.SC_CONTINUE);
-        sendResponse(response);
-    }
-
     protected void receiveRequestBody(final HttpMutableEntityEnclosingRequest request)
             throws HttpException, IOException {
         EntityGenerator entitygen = new DefaultEntityGenerator();
@@ -182,8 +140,14 @@
         request.setEntity(entity);
     }
     
-    
-    public void sendResponse(final HttpResponse response) 
+    public void continueRequest(final HttpEntityEnclosingRequest request) 
+    		throws HttpException, IOException {
+    	if (request.expectContinue() && request.getEntity() == null) {
+            receiveRequestBody((HttpMutableEntityEnclosingRequest) request);
+    	}
+	}
+
+	public void sendResponse(final HttpResponse response) 
             throws HttpException, IOException {
         if (response == null) {
             throw new IllegalArgumentException("HTTP response may not be null");



Mime
View raw message