[1/2] wininet: add test showing that HTTP request doesn't have User-Agent set upon creation
Rok Mandeljc
rok.mandeljc at email.si
Sat Apr 12 11:00:55 CDT 2008
Neverwinter Nights 2 updater fails to "detect" internet connection because it calls HttpAddRequestHeaders(), providing the User-Agent string and using HTTP_ADDREQ_FLAG_ADD_IF_NEW flag. Since builtin wininet currently sets User-Agent to app's name that was provided with InternetOpen(), the call fails and updater stops. Native version sets User-Agent to app's name when HttpSendRequest() is called, provided that user hasn't already set it.
---
dlls/wininet/tests/http.c | 58 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c
index d87fb5e..321f422 100644
--- a/dlls/wininet/tests/http.c
+++ b/dlls/wininet/tests/http.c
@@ -1686,6 +1686,63 @@ static void test_http_connection(void)
CloseHandle(hThread);
}
+static void test_http_req_user_agent(void)
+{
+ static char default_user_agent[] = "Default";
+
+ HINTERNET hSession;
+ HINTERNET hConnect;
+ HINTERNET hRequest;
+
+ CHAR buffer[256];
+ DWORD len = 256;
+ DWORD index = 0;
+
+
+ InternetOpen(default_user_agent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
+
+ hSession = InternetOpen(default_user_agent,
+ INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
+ ok( hSession != NULL ,"Unable to open Internet session\n");
+ hConnect = InternetConnect(hSession, "localhost",
+ INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
+ 0);
+ ok( hConnect != NULL, "Unable to connect to localhost\n");
+ hRequest = HttpOpenRequest(hConnect, "GET", "/file.txt",
+ NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
+ if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
+ {
+ trace( "Network unreachable, skipping test\n" );
+ goto done;
+ }
+ ok( hRequest != NULL, "Failed to open request handle\n");
+
+ /* check if User-Agent exists */
+ index = 0;
+ len = sizeof(buffer);
+ memset(buffer, 0, sizeof(buffer));
+ ok(HttpQueryInfo(hRequest,HTTP_QUERY_USER_AGENT|HTTP_QUERY_FLAG_REQUEST_HEADERS,
+ buffer,&len,&index)==0,"User-Agent reported as Existing\n");
+
+ /* send request (it should fail, but it doesn't really matter) */
+ HttpSendRequest(hRequest, NULL, 0, NULL, 0);
+
+ /* check if User-Agent exists */
+ index = 0;
+ len = sizeof(buffer);
+ memset(buffer, 0, sizeof(buffer));
+ ok(HttpQueryInfo(hRequest,HTTP_QUERY_USER_AGENT|HTTP_QUERY_FLAG_REQUEST_HEADERS,
+ buffer,&len,&index),"User-Agent missing\n");
+ ok(strcmp(buffer, default_user_agent) == 0,
+ "incorrect User-Agent returned (%s)", buffer);
+
+
+ ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
+done:
+ ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
+ ok(InternetCloseHandle(hSession), "Close session handle failed\n");
+}
+
#define STATUS_STRING(status) \
memcpy(status_string[status], #status, sizeof(CHAR) * \
(strlen(#status) < MAX_STATUS_NAME ? \
@@ -1759,4 +1816,5 @@ START_TEST(http)
HttpSendRequestEx_test();
HttpHeaders_test();
test_http_connection();
+ test_http_req_user_agent();
}
--
1.5.4.1
More information about the wine-patches
mailing list