[grizzly~git:a33be423] [master] + fix issue #1549

  • From: oleksiys@...
  • To: commits@...
  • Subject: [grizzly~git:a33be423] [master] + fix issue #1549
  • Date: Thu, 18 Jul 2013 20:53:39 +0000

Project:    grizzly
Repository: git
Revision:   a33be4236de934a79ba15512d501ddf05b97b209
Author:     oleksiys
Date:       2013-07-18 20:39:35 UTC
Link:       

Log Message:
------------
[master] + fix issue #1549
https://java.net/jira/browse/GRIZZLY-1549
"HttpServletRequest.getServerName() returns null for websocket connection 
initialization GET requests "



Revisions:
----------
a33be4236de934a79ba15512d501ddf05b97b209


Modified Paths:
---------------
modules/http/src/main/java/org/glassfish/grizzly/http/HttpServerFilter.java
modules/http/src/test/java/org/glassfish/grizzly/http/core/HttpSemanticsTest.java


Diffs:
------
--- 
a/modules/http/src/main/java/org/glassfish/grizzly/http/HttpServerFilter.java
+++ 
b/modules/http/src/main/java/org/glassfish/grizzly/http/HttpServerFilter.java
@@ -618,27 +618,11 @@ public class HttpServerFilter extends HttpCodecFilter {
         // set the default chunking mode
         request.getResponse().setChunkingAllowed(isUpgraded || 
isChunkingEnabled());
         
-        // If it's upgraded HTTP - don't check semantics
-        if (isUpgraded) {
-            return;
-        }
-
-        final Method method = request.getMethod();
-        
-        final PayloadExpectation payloadExpectation = 
method.getPayloadExpectation();
-        if (payloadExpectation != PayloadExpectation.NOT_ALLOWED) {
-            request.setExpectContent(
-                    request.getContentLength() != -1 || request.isChunked());
-        } else {
-            request.setExpectContent(method == Method.CONNECT);
-        }
-        
-        
         if (request.getHeaderParsingState().contentLengthsDiffer) {
             request.getProcessingState().error = true;
             return;
         }
-
+        
         final MimeHeaders headers = request.getHeaders();
         
         DataChunk hostDC = null;
@@ -670,28 +654,14 @@ public class HttpServerFilter extends HttpCodecFilter {
 
         }
 
-        final boolean isHttp11 = protocol == Protocol.HTTP_1_1;
-
-        // ------ Set keep-alive flag
-        if (method == Method.CONNECT) {
-            state.keepAlive = false;
-        } else {
-            final DataChunk connectionValueDC = 
headers.getValue(Header.Connection);
-            final boolean isConnectionClose = (connectionValueDC != null &&
-                    
connectionValueDC.equalsIgnoreCaseLowerCase(CLOSE_BYTES));
-
-            if (!isConnectionClose) {
-                state.keepAlive = isHttp11 ||
-                        (connectionValueDC != null &&
-                        
connectionValueDC.equalsIgnoreCaseLowerCase(KEEPALIVE_BYTES));
-            }
-        }
         // --------------------------
 
         if (hostDC == null) {
             hostDC = headers.getValue(Header.Host);
         }
 
+        final boolean isHttp11 = protocol == Protocol.HTTP_1_1;
+        
         // Check host header
         if (hostDC == null && isHttp11) {
             state.error = true;
@@ -705,6 +675,36 @@ public class HttpServerFilter extends HttpCodecFilter {
             return;
         }
         
+        // If it's upgraded HTTP - don't check semantics
+        if (isUpgraded) {
+            return;
+        }
+
+        final Method method = request.getMethod();
+        
+        final PayloadExpectation payloadExpectation = 
method.getPayloadExpectation();
+        if (payloadExpectation != PayloadExpectation.NOT_ALLOWED) {
+            request.setExpectContent(
+                    request.getContentLength() != -1 || request.isChunked());
+        } else {
+            request.setExpectContent(method == Method.CONNECT);
+        }
+        
+        // ------ Set keep-alive flag
+        if (method == Method.CONNECT) {
+            state.keepAlive = false;
+        } else {
+            final DataChunk connectionValueDC = 
headers.getValue(Header.Connection);
+            final boolean isConnectionClose = (connectionValueDC != null &&
+                    
connectionValueDC.equalsIgnoreCaseLowerCase(CLOSE_BYTES));
+
+            if (!isConnectionClose) {
+                state.keepAlive = isHttp11 ||
+                        (connectionValueDC != null &&
+                        
connectionValueDC.equalsIgnoreCaseLowerCase(KEEPALIVE_BYTES));
+            }
+        }
+        
         if (request.requiresAcknowledgement()) {
             // if we have any request content, we can ignore the Expect
             // request--- 
a/modules/http/src/test/java/org/glassfish/grizzly/http/core/HttpSemanticsTest.java
+++ 
b/modules/http/src/test/java/org/glassfish/grizzly/http/core/HttpSemanticsTest.java
@@ -400,7 +400,7 @@ public class HttpSemanticsTest extends TestCase {
                 .uri("/path")
                 .contentLength(1)
                 .header(Header.TransferEncoding, "chunked")
-                .header(Header.Host, "localhost:" + PORT)
+                .header(Header.Host, "somehost:" + PORT)
                 .header(Header.Upgrade, "test")
                 .protocol("HTTP/1.1")
                 .build();
@@ -422,6 +422,7 @@ public class HttpSemanticsTest extends TestCase {
         result.setStatusMessage("Switching Protocols");
         result.addHeader("Connection", "Upgrade");
         result.addHeader("Upgrade", "test");
+        result.addHeader("X-Request-Server-Name", "somehost");
         result.addHeader("!Transfer-Encoding", "");
         result.addHeader("!ContentLength", "");
         result.appendContent(testMsg);
@@ -440,6 +441,7 @@ public class HttpSemanticsTest extends TestCase {
                 if (packetCounter++ == 0) {
                     response.setStatus(HttpStatus.SWITCHING_PROTOCOLS_101);
                     response.setHeader(Header.Connection, "Upgrade");
+                    response.setHeader("X-Request-Server-Name", 
request.serverName().toString());
                     response.setHeader(Header.Upgrade, 
request.getHeader(Header.Upgrade));
                 }
                 





[grizzly~git:a33be423] [master] + fix issue #1549

oleksiys 07/18/2013
Terms of Use; Privacy Policy; Copyright ©2013-2015 (revision 20150226.965aeb8)
 
 
Close
loading
Please Confirm
Close