[2/4] winhttp: Move handling of default request parameters back to WinHttpOpenRequest.

Hans Leidekker hans at codeweavers.com
Tue Sep 16 05:31:16 CDT 2008


Avoids special casing all over the place.

 -Hans

diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c
index b62a0e3..485ec73 100644
--- a/dlls/winhttp/request.c
+++ b/dlls/winhttp/request.c
@@ -480,28 +480,20 @@ static WCHAR *build_request_string( request_t *request )
     static const WCHAR crlf[]    = {'\r','\n',0};
     static const WCHAR colon[]   = {':',' ',0};
     static const WCHAR twocrlf[] = {'\r','\n','\r','\n',0};
-    static const WCHAR get[]     = {'G','E','T',0};
-    static const WCHAR slash[]   = {'/',0};
-    static const WCHAR http1_1[] = {'H','T','T','P','/','1','.','1',0};
 
     WCHAR *ret;
     const WCHAR **headers, **p;
-    const WCHAR *verb = get, *path = slash, *version = http1_1;
     unsigned int len, i = 0, j;
 
-    if (request->verb && request->verb[0]) verb = request->verb;
-    if (request->path && request->path[0]) path = request->path;
-    if (request->version && request->version[0]) version = request->version;
-
     /* allocate space for an array of all the string pointers to be added */
     len = request->num_headers * 4 + 7;
     if (!(headers = heap_alloc( len * sizeof(LPCWSTR) ))) return NULL;
 
-    headers[i++] = verb;
+    headers[i++] = request->verb;
     headers[i++] = space;
-    headers[i++] = path;
+    headers[i++] = request->path;
     headers[i++] = space;
-    headers[i++] = version;
+    headers[i++] = request->version;
 
     for (j = 0; j < request->num_headers; j++)
     {
@@ -797,7 +789,6 @@ static BOOL send_request( request_t *request, LPCWSTR headers, DWORD headers_len
     static const WCHAR keep_alive[] = {'K','e','e','p','-','A','l','i','v','e',0};
     static const WCHAR no_cache[]   = {'n','o','-','c','a','c','h','e',0};
     static const WCHAR length_fmt[] = {'%','l','d',0};
-    static const WCHAR post[]       = {'P','O','S','T',0};
 
     BOOL ret = FALSE;
     connect_t *connect = request->connect;
@@ -813,7 +804,7 @@ static BOOL send_request( request_t *request, LPCWSTR headers, DWORD headers_len
     if (connect->hostname)
         add_host_header( request, connect->hostname, connect->hostport, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW );
 
-    if (total_len || (request->verb && !strcmpW( request->verb, post )))
+    if (total_len || (request->verb && !strcmpW( request->verb, postW )))
     {
         WCHAR length[21]; /* decimal long int + null */
         sprintfW( length, length_fmt, total_len );
@@ -1114,6 +1105,7 @@ static BOOL handle_redirect( request_t *request )
             if (!(request->path = heap_alloc( (len + 1) * sizeof(WCHAR) ))) goto end;
             strcpyW( request->path, uc.lpszUrlPath );
         }
+        else request->path = strdupW( slashW );
     }
 
     /* remove content-type/length headers */
@@ -1122,7 +1114,7 @@ static BOOL handle_redirect( request_t *request )
 
     /* redirects are always GET requests */
     heap_free( request->verb );
-    request->verb = NULL;
+    request->verb = strdupW( getW );
     ret = TRUE;
 
 end:
diff --git a/dlls/winhttp/session.c b/dlls/winhttp/session.c
index 4bf9d43..35cac0c 100644
--- a/dlls/winhttp/session.c
+++ b/dlls/winhttp/session.c
@@ -480,9 +480,13 @@ HINTERNET WINAPI WinHttpOpenRequest( HINTERNET hconnect, LPCWSTR verb, LPCWSTR o
 
     if (!netconn_init( &request->netconn, request->hdr.flags & WINHTTP_FLAG_SECURE )) goto end;
 
-    if (verb && !(request->verb = strdupW( verb ))) goto end;
-    if (object && !(request->path = strdupW( object ))) goto end;
-    if (version && !(request->version = strdupW( version ))) goto end;
+    if (!verb || !verb[0]) verb = getW;
+    if (!object || !object[0]) object = slashW;
+    if (!version || !version[0]) version = http1_1;
+
+    if (!(request->verb = strdupW( verb ))) goto end;
+    if (!(request->path = strdupW( object ))) goto end;
+    if (!(request->version = strdupW( version ))) goto end;
 
     if (!(hrequest = alloc_handle( &request->hdr ))) goto end;
     request->hdr.handle = hrequest;
diff --git a/dlls/winhttp/winhttp_private.h b/dlls/winhttp/winhttp_private.h
index 6508b38..ee01f4d 100644
--- a/dlls/winhttp/winhttp_private.h
+++ b/dlls/winhttp/winhttp_private.h
@@ -36,6 +36,11 @@
 # include <ws2tcpip.h>
 #endif
 
+static const WCHAR getW[]    = {'G','E','T',0};
+static const WCHAR postW[]   = {'P','O','S','T',0};
+static const WCHAR slashW[]  = {'/',0};
+static const WCHAR http1_1[] = {'H','T','T','P','/','1','.','1',0};
+
 typedef struct _object_header_t object_header_t;
 
 typedef struct



More information about the wine-patches mailing list