Module: wine Branch: master Commit: 667e48286e25c56bca98a135db62d723b74ef89e URL: http://source.winehq.org/git/wine.git/?a=commit;h=667e48286e25c56bca98a135db...
Author: Hans Leidekker hans@codeweavers.com Date: Thu Jan 15 16:41:53 2009 +0100
wininet: Calculate the header size if needed in HttpSendRequestW.
---
dlls/wininet/http.c | 9 +++++++-- dlls/wininet/tests/http.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index ea4e456..0dd68fa 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -2897,8 +2897,13 @@ BOOL WINAPI HttpSendRequestW(HINTERNET hHttpRequest, LPCWSTR lpszHeaders, req = &workRequest.u.HttpSendRequestW; if (lpszHeaders) { - req->lpszHeader = HeapAlloc(GetProcessHeap(), 0, dwHeaderLength * sizeof(WCHAR)); - memcpy(req->lpszHeader, lpszHeaders, dwHeaderLength * sizeof(WCHAR)); + DWORD size; + + if (dwHeaderLength == ~0u) size = (strlenW(lpszHeaders) + 1) * sizeof(WCHAR); + else size = dwHeaderLength * sizeof(WCHAR); + + req->lpszHeader = HeapAlloc(GetProcessHeap(), 0, size); + memcpy(req->lpszHeader, lpszHeaders, size); } else req->lpszHeader = 0; diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c index 19eb982..c5321b4 100644 --- a/dlls/wininet/tests/http.c +++ b/dlls/wininet/tests/http.c @@ -1814,6 +1814,33 @@ static void test_http1_1(int port) InternetCloseHandle(ses); }
+static void test_HttpSendRequestW(int port) +{ + static const WCHAR header[] = {'U','A','-','C','P','U',':',' ','x','8','6',0}; + HINTERNET ses, con, req; + DWORD error; + BOOL ret; + + ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC); + ok(ses != NULL, "InternetOpen failed\n"); + + con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); + ok(con != NULL, "InternetConnect failed\n"); + + req = HttpOpenRequest(con, NULL, "/test1", NULL, NULL, NULL, 0, 0); + ok(req != NULL, "HttpOpenRequest failed\n"); + + SetLastError(0xdeadbeef); + ret = HttpSendRequestW(req, header, ~0u, NULL, 0); + error = GetLastError(); + ok(!ret, "HttpSendRequestW succeeded\n"); + ok(error == ERROR_IO_PENDING, "got %u expected ERROR_IO_PENDING\n", error); + + InternetCloseHandle(req); + InternetCloseHandle(con); + InternetCloseHandle(ses); +} + static void test_cookie_header(int port) { HINTERNET ses, con, req; @@ -2023,6 +2050,7 @@ static void test_http_connection(void) test_cookie_header(si.port); test_basic_authentication(si.port); test_HttpQueryInfo(si.port); + test_HttpSendRequestW(si.port);
/* send the basic request again to shutdown the server thread */ test_basic_request(si.port, "GET", "/quit");