Hans Leidekker : winhttp: A non-standard port must be included in the host header.

Alexandre Julliard julliard at winehq.org
Wed Sep 3 07:44:06 CDT 2008


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

Author: Hans Leidekker <hans at codeweavers.com>
Date:   Wed Sep  3 12:33:44 2008 +0200

winhttp: A non-standard port must be included in the host header.

---

 dlls/winhttp/request.c |   27 +++++++++++++++++++++++----
 1 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c
index 0c954b6..6bcfb87 100644
--- a/dlls/winhttp/request.c
+++ b/dlls/winhttp/request.c
@@ -721,6 +721,25 @@ void close_connection( request_t *request )
     send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED, 0, 0 );
 }
 
+static BOOL add_host_header( request_t *request, WCHAR *hostname, INTERNET_PORT port, DWORD modifier )
+{
+    BOOL ret;
+    DWORD len;
+    WCHAR *host;
+    static const WCHAR fmt[] = {'%','s',':','%','u',0};
+
+    if (port == INTERNET_DEFAULT_HTTP_PORT || port == INTERNET_DEFAULT_HTTPS_PORT)
+    {
+        return process_header( request, attr_host, hostname, modifier, TRUE );
+    }
+    len = strlenW( hostname ) + 7; /* sizeof(":65335") */
+    if (!(host = heap_alloc( len * sizeof(WCHAR) ))) return FALSE;
+    sprintfW( host, fmt, hostname, port );
+    ret = process_header( request, attr_host, host, modifier, TRUE );
+    heap_free( host );
+    return ret;
+}
+
 static BOOL send_request( request_t *request, LPCWSTR headers, DWORD headers_len, LPVOID optional,
                           DWORD optional_len, DWORD total_len, DWORD_PTR context )
 {
@@ -741,9 +760,9 @@ static BOOL send_request( request_t *request, LPCWSTR headers, DWORD headers_len
         process_header( request, attr_user_agent, session->agent, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW, TRUE );
 
     if (connect->hostname)
-        process_header( request, attr_host, connect->hostname, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW, TRUE );
+        add_host_header( request, connect->hostname, connect->hostport, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW );
 
-    if (total_len || !strcmpW( request->verb, post ))
+    if (total_len || (request->verb && !strcmpW( request->verb, post )))
     {
         WCHAR length[21]; /* decimal long int + null */
         sprintfW( length, length_fmt, total_len );
@@ -980,12 +999,12 @@ static BOOL handle_redirect( request_t *request )
     {
         heap_free( connect->servername );
         connect->servername = hostname;
-        connect->serverport = port;
+        connect->serverport = connect->hostport = port;
 
         netconn_close( &request->netconn );
         if (!(ret = netconn_init( &request->netconn, request->hdr.flags & WINHTTP_FLAG_SECURE ))) goto end;
     }
-    if (!(ret = process_header( request, attr_host, hostname, WINHTTP_ADDREQ_FLAG_REPLACE, TRUE ))) goto end;
+    if (!(ret = add_host_header( request, hostname, port, WINHTTP_ADDREQ_FLAG_REPLACE ))) goto end;
     if (!(ret = open_connection( request ))) goto end;
 
     heap_free( request->path );




More information about the wine-cvs mailing list