wininet: Don't add the user agent header until HttpSendRequest is called.
This commit is contained in:
parent
c6da2a0b9d
commit
e2f690a0ac
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue