hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r413503 - in /jakarta/httpcomponents/httpcore/trunk/src: java/org/apache/http/protocol/RequestTargetHost.java test/org/apache/http/protocol/TestStandardInterceptors.java
Date Sun, 11 Jun 2006 18:33:55 GMT
Author: olegk
Date: Sun Jun 11 11:33:54 2006
New Revision: 413503

URL: http://svn.apache.org/viewvc?rev=413503&view=rev
Log:
HTTP/1.1 requests must always have a 'Host' header

Modified:
    jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/protocol/RequestTargetHost.java
    jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/protocol/TestStandardInterceptors.java

Modified: jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/protocol/RequestTargetHost.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/protocol/RequestTargetHost.java?rev=413503&r1=413502&r2=413503&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/protocol/RequestTargetHost.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/java/org/apache/http/protocol/RequestTargetHost.java
Sun Jun 11 11:33:54 2006
@@ -35,6 +35,8 @@
 import org.apache.http.HttpHost;
 import org.apache.http.HttpRequest;
 import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.HttpVersion;
+import org.apache.http.ProtocolException;
 import org.apache.http.params.HttpProtocolParams;
 
 /**
@@ -64,7 +66,12 @@
             HttpHost targethost = (HttpHost) context
                 .getAttribute(HttpExecutionContext.HTTP_TARGET_HOST);
             if (targethost == null) {
-            	return;
+                HttpVersion ver = request.getRequestLine().getHttpVersion();
+                if (ver.lessEquals(HttpVersion.HTTP_1_0)) {
+                    return;
+                } else {
+                    throw new ProtocolException("Target host missing");
+                }
             }
             String virtualhost = HttpProtocolParams.getVirtualHost(request.getParams());
             if (virtualhost != null) {

Modified: jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/protocol/TestStandardInterceptors.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/protocol/TestStandardInterceptors.java?rev=413503&r1=413502&r2=413503&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/protocol/TestStandardInterceptors.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/src/test/org/apache/http/protocol/TestStandardInterceptors.java
Sun Jun 11 11:33:54 2006
@@ -372,13 +372,26 @@
         assertFalse(header instanceof GeneratedHeader);
     }
 
-    public void testRequestTargetHostMissingHost() throws Exception {
+    public void testRequestTargetHostMissingHostHTTP10() throws Exception {
         HttpContext context = new HttpExecutionContext(null);
-        BasicHttpRequest request = new BasicHttpRequest("GET", "/");
+        BasicHttpRequest request = new BasicHttpRequest(
+                new RequestLine("GET", "/", HttpVersion.HTTP_1_0));
         RequestTargetHost interceptor = new RequestTargetHost();
         interceptor.process(request, context);
         Header header = request.getFirstHeader(HTTP.TARGET_HOST);
         assertNull(header);
+    }
+
+    public void testRequestTargetHostMissingHostHTTP11() throws Exception {
+        HttpContext context = new HttpExecutionContext(null);
+        BasicHttpRequest request = new BasicHttpRequest("GET", "/");
+        RequestTargetHost interceptor = new RequestTargetHost();
+        try {
+            interceptor.process(request, context);
+            fail("ProtocolException should have been thrown");
+        } catch (ProtocolException ex) {
+            // expected
+        }
     }
 
     public void testRequestTargetHostVirtualHost() throws Exception {



Mime
View raw message