WININET: fix HTTP POST requests

Mike McCormack mike at codeweavers.com
Wed Jul 21 06:22:33 CDT 2004


This patch fixes POST requests so they work again.  I broke them with a 
patch a few weeks ago :/

Mike


ChangeLog:
* fix HTTP POST requests

-------------- next part --------------
Index: dlls/wininet/http.c
===================================================================
RCS file: /home/wine/wine/dlls/wininet/http.c,v
retrieving revision 1.72
diff -u -r1.72 http.c
--- dlls/wininet/http.c	20 Jul 2004 01:21:08 -0000	1.72
+++ dlls/wininet/http.c	21 Jul 2004 10:05:58 -0000
@@ -1508,11 +1508,10 @@
         static const WCHAR szSetCookie[] = {'S','e','t','-','C','o','o','k','i','e',0 };
         static const WCHAR szColon[] = { ':',' ',0 };
         LPCWSTR *req;
-        LPWSTR p;
+        LPWSTR p, szCookedHeaders = NULL;
         int len, n;
         char *ascii_req;
 
-
         TRACE("Going to url %s %s\n", debugstr_w(lpwhr->lpszHostName), debugstr_w(lpwhr->lpszPath));
         loop_next = FALSE;
 
@@ -1532,8 +1531,22 @@
             lpwhr->lpszPath = fixurl;
         }
 
+        /* add the headers the caller supplied */
+        if( lpszHeaders )
+        {
+            len = strlenW(lpszHeaders)+3;
+            szCookedHeaders = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR)*len );
+            strcpyW( szCookedHeaders, lpszHeaders );
+
+            /* make sure there's exactly one linebreak at the end of the string */
+            p = &szCookedHeaders[len-4];
+            while( (szCookedHeaders <= p) && ((*p == '\n') || (*p == '\r')) )
+                p--;
+            p[1] = 0;
+        }
+
         /* allocate space for an array of all the string pointers to be added */
-        len = (2 + HTTP_QUERY_MAX + lpwhr->nCustHeaders)*4 + 3;
+        len = (2 + HTTP_QUERY_MAX + lpwhr->nCustHeaders)*4 + 5;
         req = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, len*sizeof(LPCWSTR) );
 
         /* add the verb, path and HTTP/1.0 */
@@ -1542,6 +1555,11 @@
         req[n++] = szSpace;
         req[n++] = lpwhr->lpszPath;
         req[n++] = HTTPHEADER;
+        if( szCookedHeaders )
+        {
+            req[n++] = szcrlf;
+            req[n++] = szCookedHeaders;
+        }
 
         /* Append standard request headers */
         for (i = 0; i <= HTTP_QUERY_MAX; i++)
@@ -1586,6 +1604,7 @@
 
         requestString = HTTP_build_req( req, 4 );
         HeapFree( GetProcessHeap(), 0, req );
+        HeapFree( GetProcessHeap(), 0, szCookedHeaders );
  
         /*
          * Set (header) termination string for request
@@ -1602,9 +1621,6 @@
         if (!HTTP_OpenConnection(lpwhr))
             goto lend;
 
-        SendAsyncCallback(hIC, &lpwhr->hdr, lpwhr->hdr.dwContext,
-                          INTERNET_STATUS_SENDING_REQUEST, NULL, 0);
-
         /* send the request as ASCII, tack on the optional data */
         if( !lpOptional )
             dwOptionalLength = 0;
@@ -1614,8 +1630,14 @@
         WideCharToMultiByte( CP_ACP, 0, requestString, -1,
                              ascii_req, len, NULL, NULL );
         if( lpOptional )
-            memcpy( &ascii_req[len], lpOptional, dwOptionalLength );
-        len += dwOptionalLength;
+            memcpy( &ascii_req[len-1], lpOptional, dwOptionalLength );
+        len = (len + dwOptionalLength - 1);
+        ascii_req[len] = 0;
+        TRACE("full request -> %s\n", ascii_req );
+
+        SendAsyncCallback(hIC, &lpwhr->hdr, lpwhr->hdr.dwContext,
+                          INTERNET_STATUS_SENDING_REQUEST, NULL, 0);
+
         NETCON_send(&lpwhr->netConnection, ascii_req, len, 0, &cnt);
         HeapFree( GetProcessHeap(), 0, ascii_req );
 


More information about the wine-patches mailing list