Module: wine Branch: master Commit: e2f690a0acf90c335c098e427fc5c2a58ba41c51 URL: http://source.winehq.org/git/wine.git/?a=commit;h=e2f690a0acf90c335c098e427f...
Author: Hans Leidekker hans@it.vu.nl Date: Fri May 2 21:59:24 2008 +0200
wininet: Don't add the user agent header until HttpSendRequest is called.
---
dlls/wininet/http.c | 27 ++++++++++----------- dlls/wininet/tests/http.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 14 deletions(-)
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index 0f7df63..3155ac1 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -1965,20 +1965,6 @@ HINTERNET WINAPI HTTP_HttpOpenRequestW(LPWININETHTTPSESSIONW lpwhs, if (NULL != hIC->lpszProxy && hIC->lpszProxy[0] != 0) HTTP_DealWithProxy( hIC, lpwhs, lpwhr );
- if (hIC->lpszAgent) - { - WCHAR *agent_header; - static const WCHAR user_agent[] = {'U','s','e','r','-','A','g','e','n','t',':',' ','%','s','\r','\n',0 }; - - len = strlenW(hIC->lpszAgent) + strlenW(user_agent); - agent_header = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) ); - sprintfW(agent_header, user_agent, hIC->lpszAgent ); - - HTTP_HttpAddRequestHeadersW(lpwhr, agent_header, strlenW(agent_header), - HTTP_ADDREQ_FLAG_ADD); - HeapFree(GetProcessHeap(), 0, agent_header); - } - Host = HTTP_GetHeader(lpwhr,szHost);
len = lstrlenW(Host->lpszValue) + strlenW(szUrlForm); @@ -3175,6 +3161,19 @@ BOOL WINAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders, sprintfW(contentLengthStr, szContentLength, dwContentLength); HTTP_HttpAddRequestHeadersW(lpwhr, contentLengthStr, -1L, HTTP_ADDREQ_FLAG_ADD | HTTP_ADDHDR_FLAG_REPLACE); } + if (lpwhr->lpHttpSession->lpAppInfo->lpszAgent) + { + WCHAR *agent_header; + static const WCHAR user_agent[] = {'U','s','e','r','-','A','g','e','n','t',':',' ','%','s','\r','\n',0}; + int len; + + len = strlenW(lpwhr->lpHttpSession->lpAppInfo->lpszAgent) + strlenW(user_agent); + agent_header = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); + sprintfW(agent_header, user_agent, lpwhr->lpHttpSession->lpAppInfo->lpszAgent); + + HTTP_HttpAddRequestHeadersW(lpwhr, agent_header, strlenW(agent_header), HTTP_ADDREQ_FLAG_ADD_IF_NEW); + HeapFree(GetProcessHeap(), 0, agent_header); + }
do { diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c index d87fb5e..8e29dac 100644 --- a/dlls/wininet/tests/http.c +++ b/dlls/wininet/tests/http.c @@ -1686,6 +1686,62 @@ static void test_http_connection(void) CloseHandle(hThread); }
+static void test_user_agent_header(void) +{ + HINTERNET ses, con, req; + DWORD size, err; + char buffer[64]; + BOOL ret; + + ses = InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); + ok(ses != NULL, "InternetOpen failed\n"); + + con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); + ok(con != NULL, "InternetConnect failed\n"); + + req = HttpOpenRequest(con, "GET", "/", "HTTP/1.0", NULL, NULL, 0, 0); + ok(req != NULL, "HttpOpenRequest failed\n"); + + size = sizeof(buffer); + ret = HttpQueryInfo(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); + err = GetLastError(); + ok(!ret, "HttpQueryInfo succeeded\n"); + ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err); + + ret = HttpAddRequestHeaders(req, "User-Agent: Gizmo Project\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW); + ok(ret, "HttpAddRequestHeaders succeeded\n"); + + size = sizeof(buffer); + ret = HttpQueryInfo(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); + err = GetLastError(); + ok(ret, "HttpQueryInfo failed\n"); + ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err); + + InternetCloseHandle(req); + + req = HttpOpenRequest(con, "GET", "/", "HTTP/1.0", NULL, NULL, 0, 0); + ok(req != NULL, "HttpOpenRequest failed\n"); + + size = sizeof(buffer); + ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); + err = GetLastError(); + ok(!ret, "HttpQueryInfo succeeded\n"); + ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err); + + ret = HttpAddRequestHeaders(req, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW); + ok(ret, "HttpAddRequestHeaders failed\n"); + + buffer[0] = 0; + size = sizeof(buffer); + ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL); + ok(ret, "HttpQueryInfo failed: %u\n", GetLastError()); + ok(!strcmp(buffer, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer); + + InternetCloseHandle(req); + InternetCloseHandle(con); + InternetCloseHandle(ses); +} + #define STATUS_STRING(status) \ memcpy(status_string[status], #status, sizeof(CHAR) * \ (strlen(#status) < MAX_STATUS_NAME ? \ @@ -1759,4 +1815,5 @@ START_TEST(http) HttpSendRequestEx_test(); HttpHeaders_test(); test_http_connection(); + test_user_agent_header(); }