WININET: fix the processing of the lpszHeaders field in HttpSendRequest

Mike McCormack mike at codeweavers.com
Tue Aug 10 03:39:13 CDT 2004


This patch obsoletes the previous one I sent (http-header-fix3.diff). It 
also fixes possible problems in the HTTP_HttpAddRequestHeadersW, as the 
dwHeaderLength field was being ignored in that function.  There will no 
longer be duplicate header fields (such as "Content-Length:").

Mike


ChangeLog:
* fix the processing of the lpszHeaders field in HttpSendRequest

-------------- next part --------------
Index: dlls/wininet/http.c
===================================================================
RCS file: /home/wine/wine/dlls/wininet/http.c,v
retrieving revision 1.76
diff -u -r1.76 http.c
--- dlls/wininet/http.c	9 Aug 2004 18:54:23 -0000	1.76
+++ dlls/wininet/http.c	10 Aug 2004 07:08:22 -0000
@@ -170,9 +170,18 @@
     LPWSTR buffer;
     WCHAR value[MAX_FIELD_VALUE_LEN], field[MAX_FIELD_LEN];
     BOOL bSuccess = FALSE;
+    DWORD len;
 
     TRACE("copying header: %s\n", debugstr_w(lpszHeader));
-    buffer = WININET_strdupW(lpszHeader);
+
+    if( dwHeaderLength == ~0UL )
+        len = strlenW(lpszHeader);
+    else
+        len = dwHeaderLength;
+    buffer = HeapAlloc( GetProcessHeap(), 0, sizeof(WCHAR)*(len+1) );
+    strncpyW( buffer, lpszHeader, len );
+    buffer[len]=0;
+
     lpszStart = buffer;
 
     do
@@ -1512,7 +1521,7 @@
         static const WCHAR szSetCookie[] = {'S','e','t','-','C','o','o','k','i','e',0 };
         static const WCHAR szColon[] = { ':',' ',0 };
         LPCWSTR *req;
-        LPWSTR p, szCookedHeaders = NULL;
+        LPWSTR p;
         DWORD len, n;
         char *ascii_req;
 
@@ -1536,17 +1545,10 @@
         }
 
         /* add the headers the caller supplied */
-        if( lpszHeaders )
+        if( lpszHeaders && dwHeaderLength )
         {
-            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;
+            HTTP_HttpAddRequestHeadersW(lpwhr, lpszHeaders, dwHeaderLength,
+                        HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REPLACE);
         }
 
         /* allocate space for an array of all the string pointers to be added */
@@ -1559,11 +1561,6 @@
         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++)
@@ -1609,7 +1606,6 @@
         req[n] = NULL;
         requestString = HTTP_build_req( req, 4 );
         HeapFree( GetProcessHeap(), 0, req );
-        HeapFree( GetProcessHeap(), 0, szCookedHeaders );
  
         /*
          * Set (header) termination string for request


More information about the wine-patches mailing list