Hans Leidekker : wininet: Add zero value content length header to POST requests only.

Alexandre Julliard julliard at winehq.org
Mon Feb 4 08:43:15 CST 2008


Module: wine
Branch: master
Commit: b0912d11511a19031cfe6ba12e4dd422a7b5d73c
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=b0912d11511a19031cfe6ba12e4dd422a7b5d73c

Author: Hans Leidekker <hans at it.vu.nl>
Date:   Sat Feb  2 16:08:28 2008 +0100

wininet: Add zero value content length header to POST requests only.

---

 dlls/wininet/http.c       |    9 ++++++---
 dlls/wininet/tests/http.c |   23 ++++++++++++++---------
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index 015f663..71dcc51 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -2565,6 +2565,7 @@ BOOL WINAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
     BOOL loop_next;
     INTERNET_ASYNC_RESULT iar;
     static const WCHAR szClose[] = { 'C','l','o','s','e',0 };
+    static const WCHAR szPost[] = { 'P','O','S','T',0 };
     static const WCHAR szContentLength[] =
         { 'C','o','n','t','e','n','t','-','L','e','n','g','t','h',':',' ','%','l','i','\r','\n',0 };
     WCHAR contentLengthStr[sizeof szContentLength/2 /* includes \r\n */ + 20 /* int */ ];
@@ -2577,9 +2578,11 @@ BOOL WINAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
     INTERNET_SetLastError(0);
 
     HTTP_FixVerb(lpwhr);
-    
-    sprintfW(contentLengthStr, szContentLength, dwContentLength);
-    HTTP_HttpAddRequestHeadersW(lpwhr, contentLengthStr, -1L, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REPLACE);
+    if (dwContentLength || !strcmpW(lpwhr->lpszVerb, szPost))
+    {
+        sprintfW(contentLengthStr, szContentLength, dwContentLength);
+        HTTP_HttpAddRequestHeadersW(lpwhr, contentLengthStr, -1L, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REPLACE);
+    }
 
     do
     {
diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c
index 88369cf..f48f61f 100644
--- a/dlls/wininet/tests/http.c
+++ b/dlls/wininet/tests/http.c
@@ -1285,8 +1285,13 @@ static DWORD CALLBACK server_thread(LPVOID param)
 
         if (strstr(buffer, "GET /test1"))
         {
-            send(c, okmsg, sizeof okmsg-1, 0);
-            send(c, page1, sizeof page1-1, 0);
+            if (!strstr(buffer, "Content-Length: 0"))
+            {
+                send(c, okmsg, sizeof okmsg-1, 0);
+                send(c, page1, sizeof page1-1, 0);
+            }
+            else
+                send(c, notokmsg, sizeof notokmsg-1, 0);
         }
 
         if (strstr(buffer, "/test2"))
@@ -1316,7 +1321,7 @@ static DWORD CALLBACK server_thread(LPVOID param)
                 send(c, notokmsg, sizeof notokmsg-1, 0);
         }
 
-        if (strstr(buffer, "/test5"))
+        if (strstr(buffer, "POST /test5"))
         {
             if (strstr(buffer, "Content-Length: 0"))
             {
@@ -1327,7 +1332,7 @@ static DWORD CALLBACK server_thread(LPVOID param)
                 send(c, notokmsg, sizeof notokmsg-1, 0);
         }
 
-        if (strstr(buffer, "/quit"))
+        if (strstr(buffer, "GET /quit"))
         {
             send(c, okmsg, sizeof okmsg-1, 0);
             send(c, page1, sizeof page1-1, 0);
@@ -1343,7 +1348,7 @@ static DWORD CALLBACK server_thread(LPVOID param)
     return 0;
 }
 
-static void test_basic_request(int port, const char *url)
+static void test_basic_request(int port, const char *verb, const char *url)
 {
     HINTERNET hi, hc, hr;
     DWORD r, count;
@@ -1355,7 +1360,7 @@ static void test_basic_request(int port, const char *url)
     hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
     ok(hc != NULL, "connect failed\n");
 
-    hr = HttpOpenRequest(hc, NULL, url, NULL, NULL, NULL, 0, 0);
+    hr = HttpOpenRequest(hc, verb, url, NULL, NULL, NULL, 0, 0);
     ok(hr != NULL, "HttpOpenRequest failed\n");
 
     r = HttpSendRequest(hr, NULL, 0, NULL, 0);
@@ -1550,14 +1555,14 @@ static void test_http_connection(void)
     if (r != WAIT_OBJECT_0)
         return;
 
-    test_basic_request(si.port, "/test1");
+    test_basic_request(si.port, "GET", "/test1");
     test_proxy_indirect(si.port);
     test_proxy_direct(si.port);
     test_header_handling_order(si.port);
-    test_basic_request(si.port, "/test5");
+    test_basic_request(si.port, "POST", "/test5");
 
     /* send the basic request again to shutdown the server thread */
-    test_basic_request(si.port, "/quit");
+    test_basic_request(si.port, "GET", "/quit");
 
     r = WaitForSingleObject(hThread, 3000);
     ok( r == WAIT_OBJECT_0, "thread wait failed\n");




More information about the wine-cvs mailing list