[2/2] wininet: Add port number to Host HTTP header

Alexander Morozov amorozov at etersoft.ru
Fri Jul 4 03:21:14 CDT 2008


Add port number to Host HTTP header. Windows do not add port number if it is 
equal to 0, 80 or 443.
-------------- next part --------------
From 1767c43298e320cd851702db36fec09716bfa230 Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov at etersoft.ru>
Date: Thu, 3 Jul 2008 16:34:40 +0400
Subject: [PATCH] wininet: Add port number to Host HTTP header

---
 dlls/wininet/http.c       |   34 +++++++++++++++++++++++++++++++---
 dlls/wininet/tests/http.c |    4 ----
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index 813b963..9ea6868 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -1454,14 +1454,20 @@ static DWORD HTTPREQ_QueryOption(WININETHANDLEHEADER *hdr, DWORD option, void *b
         WCHAR url[INTERNET_MAX_URL_LENGTH];
         HTTPHEADERW *host;
         DWORD len;
+        WCHAR *pch;
 
-        static const WCHAR formatW[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
+        static const WCHAR httpW[] = {'h','t','t','p',':','/','/',0};
         static const WCHAR hostW[] = {'H','o','s','t',0};
 
         TRACE("INTERNET_OPTION_URL\n");
 
         host = HTTP_GetHeader(req, hostW);
-        sprintfW(url, formatW, host->lpszValue, req->lpszPath);
+        strcpyW(url, httpW);
+        strcatW(url, host->lpszValue);
+        if (NULL != (pch = strchrW(url + strlenW(httpW), ':')))
+            *pch = 0;
+        strcatW(url, req->lpszPath);
+
         TRACE("INTERNET_OPTION_URL: %s\n",debugstr_w(url));
 
         if(unicode) {
@@ -1886,9 +1892,11 @@ HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
     LPWININETHTTPREQW lpwhr;
     LPWSTR lpszCookies;
     LPWSTR lpszUrl = NULL;
+    LPWSTR lpszHostName = NULL;
     DWORD nCookieSize;
     HINTERNET handle = NULL;
     static const WCHAR szUrlForm[] = {'h','t','t','p',':','/','/','%','s',0};
+    static const WCHAR szHostForm[] = {'%','s',':','%','u',0};
     DWORD len;
     LPHTTPHEADERW Host;
 
@@ -1915,6 +1923,14 @@ HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
     lpwhr->lpHttpSession = lpwhs;
     list_add_head( &lpwhs->hdr.children, &lpwhr->hdr.entry );
 
+    lpszHostName = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) *
+            (strlenW(lpwhs->lpszHostName) + 7 /* length of ":65535" + 1 */));
+    if (NULL == lpszHostName)
+    {
+        INTERNET_SetLastError(ERROR_OUTOFMEMORY);
+        goto lend;
+    }
+
     handle = WININET_AllocHandle( &lpwhr->hdr );
     if (NULL == handle)
     {
@@ -1969,7 +1985,17 @@ HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
     else
         lpwhr->lpszVersion = WININET_strdupW(g_szHttp1_1);
 
-    HTTP_ProcessHeader(lpwhr, szHost, lpwhs->lpszHostName, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REQ);
+    if (lpwhs->nHostPort != INTERNET_INVALID_PORT_NUMBER &&
+        lpwhs->nHostPort != INTERNET_DEFAULT_HTTP_PORT &&
+        lpwhs->nHostPort != INTERNET_DEFAULT_HTTPS_PORT)
+    {
+        sprintfW(lpszHostName, szHostForm, lpwhs->lpszHostName, lpwhs->nHostPort);
+        HTTP_ProcessHeader(lpwhr, szHost, lpszHostName,
+                HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REQ);
+    }
+    else
+        HTTP_ProcessHeader(lpwhr, szHost, lpwhs->lpszHostName,
+                HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REQ);
 
     if (lpwhs->nServerPort == INTERNET_INVALID_PORT_NUMBER)
         lpwhs->nServerPort = (dwFlags & INTERNET_FLAG_SECURE ?
@@ -2015,6 +2041,8 @@ HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs,
                           sizeof(handle));
 
 lend:
+    if (lpszHostName)
+        HeapFree(GetProcessHeap(), 0, lpszHostName);
     if( lpwhr )
         WININET_Release( &lpwhr->hdr );
 
diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c
index d6da2ca..272e3e7 100644
--- a/dlls/wininet/tests/http.c
+++ b/dlls/wininet/tests/http.c
@@ -1734,7 +1734,6 @@ static void test_connection_header(int port)
     size = sizeof(status);
     ret = HttpQueryInfo(req, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL);
     ok(ret, "HttpQueryInfo failed\n");
-    todo_wine
     ok(status == 200, "request failed with status %u\n", status);
 
     InternetCloseHandle(req);
@@ -1749,7 +1748,6 @@ static void test_connection_header(int port)
     size = sizeof(status);
     ret = HttpQueryInfo(req, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL);
     ok(ret, "HttpQueryInfo failed\n");
-    todo_wine
     ok(status == 200, "request failed with status %u\n", status);
 
     InternetCloseHandle(req);
@@ -1764,7 +1762,6 @@ static void test_connection_header(int port)
     size = sizeof(status);
     ret = HttpQueryInfo(req, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL);
     ok(ret, "HttpQueryInfo failed\n");
-    todo_wine
     ok(status == 200, "request failed with status %u\n", status);
 
     InternetCloseHandle(req);
@@ -1779,7 +1776,6 @@ static void test_connection_header(int port)
     size = sizeof(status);
     ret = HttpQueryInfo(req, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL);
     ok(ret, "HttpQueryInfo failed\n");
-    todo_wine
     ok(status == 200, "request failed with status %u\n", status);
 
     InternetCloseHandle(req);
-- 
1.5.4.5.GIT



More information about the wine-patches mailing list