HTTP Host Header Fix

Robert Shearman rob at codeweavers.com
Mon Sep 13 07:56:05 CDT 2004


Hi,

The "Host: " header is better stored in the same way as the other 
headers as it reduces the amount of special cases for it and it helps 
when applications decide to provide their own "Host: " in a call to 
HttpAddRequestHeaders.

Rob

Changelog:
Store HTTP host header in the same way as most other headers.
-------------- next part --------------
diff -u -N -r -x '*~' -x '.#*' -x CVS -x Makefile -x '*.o' -x '*.orig' -x '*.diff' -x '*.rej' -x '*.spec.c' wine/dlls/wininet_1/http.c wine/dlls/wininet/http.c
--- wine/dlls/wininet_1/http.c	2004-09-13 13:50:15.967845400 +0100
+++ wine/dlls/wininet/http.c	2004-09-13 13:50:24.324574984 +0100
@@ -58,14 +58,13 @@
 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
 
 static const WCHAR g_szHttp[] = {' ','H','T','T','P','/','1','.','0',0 };
-static const WCHAR g_szHost[] = {'\r','\n','H','o','s','t',':',' ',0 };
 static const WCHAR g_szReferer[] = {'R','e','f','e','r','e','r',0};
 static const WCHAR g_szAccept[] = {'A','c','c','e','p','t',0};
 static const WCHAR g_szUserAgent[] = {'U','s','e','r','-','A','g','e','n','t',0};
+static const WCHAR g_szHost[] = {'H','o','s','t',0};
 
 
 #define HTTPHEADER g_szHttp
-#define HTTPHOSTHEADER g_szHost
 #define MAXHOSTNAME 100
 #define MAX_FIELD_VALUE_LEN 256
 #define MAX_FIELD_LEN 256
@@ -746,10 +745,11 @@
 
         InternetCrackUrlW(lpszReferrer, 0, 0, &UrlComponents);
         if (strlenW(UrlComponents.lpszHostName))
-            lpwhr->lpszHostName = WININET_strdupW(UrlComponents.lpszHostName);
-    } else {
-        lpwhr->lpszHostName = WININET_strdupW(lpwhs->lpszServerName);
+            HTTP_ProcessHeader(lpwhr, g_szHost, UrlComponents.lpszHostName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REQ);
     }
+    else
+        HTTP_ProcessHeader(lpwhr, g_szHost, lpwhs->lpszServerName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REQ);
+
     if (NULL != hIC->lpszProxy && hIC->lpszProxy[0] != 0)
         HTTP_DealWithProxy( hIC, lpwhs, lpwhr );
 
@@ -767,9 +767,9 @@
         HeapFree(GetProcessHeap(), 0, agent_header);
     }
 
-    len = strlenW(lpwhr->lpszHostName) + strlenW(szUrlForm);
+    len = strlenW(lpwhr->StdHeaders[HTTP_QUERY_HOST].lpszValue) + strlenW(szUrlForm);
     lpszUrl = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
-    sprintfW( lpszUrl, szUrlForm, lpwhr->lpszHostName );
+    sprintfW( lpszUrl, szUrlForm, lpwhr->StdHeaders[HTTP_QUERY_HOST].lpszValue );
 
     if (!(lpwhr->hdr.dwFlags & INTERNET_FLAG_NO_COOKIES) &&
         InternetGetCookieW(lpszUrl, NULL, NULL, &nCookieSize))
@@ -1379,9 +1379,7 @@
         lpwhs->lpszUserName = WININET_strdupW(userName);
         lpwhs->nServerPort = urlComponents.nPort;
 
-        if (NULL != lpwhr->lpszHostName)
-            HeapFree(GetProcessHeap(), 0, lpwhr->lpszHostName);
-        lpwhr->lpszHostName=WININET_strdupW(hostName);
+        HTTP_ProcessHeader(lpwhr, g_szHost, hostName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REQ);
 
         SendAsyncCallback(hIC, &lpwhs->hdr, lpwhr->hdr.dwContext,
                       INTERNET_STATUS_RESOLVING_NAME,
@@ -1524,7 +1522,7 @@
         DWORD len, n;
         char *ascii_req;
 
-        TRACE("Going to url %s %s\n", debugstr_w(lpwhr->lpszHostName), debugstr_w(lpwhr->lpszPath));
+        TRACE("Going to url %s %s\n", debugstr_w(lpwhr->StdHeaders[HTTP_QUERY_HOST].lpszValue), debugstr_w(lpwhr->lpszPath));
         loop_next = FALSE;
 
         /* If we don't have a path we set it to root */
@@ -1593,12 +1591,6 @@
             }
         }
 
-        if (lpwhr->lpszHostName)
-        {
-            req[n++] = HTTPHOSTHEADER;
-            req[n++] = lpwhr->lpszHostName;
-        }
-
         if( n >= len )
             ERR("oops. buffer overrun\n");
 
@@ -1722,9 +1714,10 @@
                 cookie_data = &buf_cookie[nEqualPos + 1];
 
 
-                len = strlenW((domain ? domain : lpwhr->lpszHostName)) + strlenW(lpwhr->lpszPath) + 9;
+                len = strlenW((domain ? domain : lpwhr->StdHeaders[HTTP_QUERY_HOST].lpszValue)) + 
+                    strlenW(lpwhr->lpszPath) + 9;
                 buf_url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
-                sprintfW(buf_url, szFmt, (domain ? domain : lpwhr->lpszHostName)); /* FIXME PATH!!! */
+                sprintfW(buf_url, szFmt, (domain ? domain : lpwhr->StdHeaders[HTTP_QUERY_HOST].lpszValue)); /* FIXME PATH!!! */
                 InternetSetCookieW(buf_url, cookie_name, cookie_data);
 
                 HeapFree(GetProcessHeap(), 0, buf_url);
@@ -2251,6 +2244,8 @@
         index = HTTP_QUERY_VARY;
     else if (!strcmpiW(lpszField,szVia))
         index = HTTP_QUERY_VIA;
+    else if (!strcmpiW(lpszField,g_szHost))
+        index = HTTP_QUERY_HOST;
     else
     {
         TRACE("Couldn't find %s in standard header table\n", debugstr_w(lpszField));
@@ -2463,8 +2458,6 @@
         HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath);
     if (lpwhr->lpszVerb)
         HeapFree(GetProcessHeap(), 0, lpwhr->lpszVerb);
-    if (lpwhr->lpszHostName)
-        HeapFree(GetProcessHeap(), 0, lpwhr->lpszHostName);
     if (lpwhr->lpszRawHeaders)
         HeapFree(GetProcessHeap(), 0, lpwhr->lpszRawHeaders);
 
diff -u -N -r -x '*~' -x '.#*' -x CVS -x Makefile -x '*.o' -x '*.orig' -x '*.diff' -x '*.rej' -x '*.spec.c' wine/dlls/wininet_1/internet.c wine/dlls/wininet/internet.c
--- wine/dlls/wininet_1/internet.c	2004-09-13 13:50:15.967845400 +0100
+++ wine/dlls/wininet/internet.c	2004-09-13 13:50:24.327574528 +0100
@@ -1783,7 +1783,7 @@
                 WCHAR url[1023];
                 static const WCHAR szFmt[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
 
-                sprintfW(url,szFmt,lpreq->lpszHostName,lpreq->lpszPath);
+                sprintfW(url,szFmt,lpreq->StdHeaders[HTTP_QUERY_HOST].lpszValue,lpreq->lpszPath);
                 TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
                 if (*lpdwBufferLength < strlenW(url)+1)
                     INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
diff -u -N -r -x '*~' -x '.#*' -x CVS -x Makefile -x '*.o' -x '*.orig' -x '*.diff' -x '*.rej' -x '*.spec.c' wine/dlls/wininet_1/internet.h wine/dlls/wininet/internet.h
--- wine/dlls/wininet_1/internet.h	2004-09-13 13:50:15.977843880 +0100
+++ wine/dlls/wininet/internet.h	2004-09-13 13:50:24.328574376 +0100
@@ -185,7 +185,6 @@
     WININETHANDLEHEADER hdr;
     LPWSTR lpszPath;
     LPWSTR lpszVerb;
-    LPWSTR lpszHostName;
     LPWSTR lpszRawHeaders;
     WININET_NETCONNECTION netConnection;
     HTTPHEADERW StdHeaders[HTTP_QUERY_MAX+1];


More information about the wine-patches mailing list