Author: rjung
Date: Mon Mar  7 12:50:31 2011
New Revision: 1078762

URL: http://svn.apache.org/viewvc?rev=1078762&view=rev
Log:
NSAPI: Use lower case header names for responses.
Otherwise the web server might add chunked transfer encoding header
in addition to our content length header.

Problem reported on dev list by Jon Forster.

Modified:
    tomcat/jk/trunk/native/netscape/jk_nsapi_plugin.c
    tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml

Modified: tomcat/jk/trunk/native/netscape/jk_nsapi_plugin.c
URL: 
http://svn.apache.org/viewvc/tomcat/jk/trunk/native/netscape/jk_nsapi_plugin.c?rev=1078762&r1=1078761&r2=1078762&view=diff
==============================================================================
--- tomcat/jk/trunk/native/netscape/jk_nsapi_plugin.c (original)
+++ tomcat/jk/trunk/native/netscape/jk_nsapi_plugin.c Mon Mar  7 12:50:31 2011
@@ -125,6 +125,28 @@ static void init_workers_on_other_thread
     init_on_other_thread_is_done = JK_TRUE;
 }
 
+/*
+ * Convert string to lower case.
+ * If string is longer than the provided buffer,
+ * just return the original string.
+ */
+static const char *to_lower(const char *str, char *buf, int bufsz)
+{
+    const char *from = str;
+    char *to = buf;
+    char *end = buf + (bufsz - 1);
+    while (to != end && *from) {
+        *to = (char)tolower(*from);
+        to++;
+        from++;
+    }
+    if (to != end) {
+        *to = '\0';
+        return buf;
+    }
+    return str;
+}
+
 static int JK_METHOD start_response(jk_ws_service_t *s,
                                     int status,
                                     const char *reason,
@@ -143,8 +165,16 @@ static int JK_METHOD start_response(jk_w
             param_free(pblock_remove("content-type", p->rq->srvhdrs));
 
             if (num_of_headers) {
+                /*
+                 * NSAPI expects http header names to be lower case.
+                 * This is only relevant for the server itself or other
+                 * plugins searching for headers in the pblock.
+                 * We use a buffer of limited length, because conforming
+                 * with this rule should only matter for well-known headers.
+                 */
+                char name_buf[64];
                 for (i = 0; i < (int)num_of_headers; i++) {
-                    pblock_nvinsert(header_names[i],
+                    pblock_nvinsert(to_lower(header_names[i], name_buf, 64),
                                     header_values[i], p->rq->srvhdrs);
                 }
             }

Modified: tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml?rev=1078762&r1=1078761&r2=1078762&view=diff
==============================================================================
--- tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml (original)
+++ tomcat/jk/trunk/xdocs/miscellaneous/changelog.xml Mon Mar  7 12:50:31 2011
@@ -54,6 +54,11 @@
         bodies for 204, 205 and 304 responses. (timw)
       </fix>
       <fix>
+        NSAPI: Use lower case header names for responses.
+        Otherwise the web server might add chunked transfer encoding header
+        in addition to our content length header.
+      </fix>
+      <fix>
         <bug>50339</bug>: Fix whitespace trimming when parsing attribute
         lists. (rjung)
       </fix>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to