From d6a59f755eff0a6f05dc7b4b375ea96c21e7a0b1 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Mon, 26 May 2014 14:09:10 +0200 Subject: [PATCH] wininet: Only set the content length header if it's not explicitly set by the user. --- dlls/wininet/http.c | 2 +- dlls/wininet/tests/http.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index 97becd4f6e4..c7e3474b9a5 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -4851,7 +4851,7 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, if (dwContentLength || strcmpW(request->verb, szGET)) { sprintfW(contentLengthStr, szContentLength, dwContentLength); - HTTP_HttpAddRequestHeadersW(request, contentLengthStr, -1L, HTTP_ADDREQ_FLAG_REPLACE); + HTTP_HttpAddRequestHeadersW(request, contentLengthStr, -1L, HTTP_ADDREQ_FLAG_ADD_IF_NEW); request->bytesToWrite = dwContentLength; } if (request->session->appInfo->agent) diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c index 70e82db09be..41f4c5be0ae 100644 --- a/dlls/wininet/tests/http.c +++ b/dlls/wininet/tests/http.c @@ -2654,10 +2654,10 @@ static void test_header_handling_order(int port) { static const char authorization[] = "Authorization: Basic dXNlcjpwd2Q="; static const char connection[] = "Connection: Close"; - static const char *types[2] = { "*", NULL }; + char data[32]; HINTERNET session, connect, request; - DWORD size, status; + DWORD size, status, data_len; BOOL ret; session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); @@ -2693,6 +2693,10 @@ static void test_header_handling_order(int port) ok(status == 200 || status == 400 /* IE6 */, "got status %u, expected 200 or 400\n", status); InternetCloseHandle(request); + InternetCloseHandle(connect); + + connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); + ok(connect != NULL, "InternetConnect failed\n"); request = HttpOpenRequestA(connect, "POST", "/test7", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0); ok(request != NULL, "HttpOpenRequest failed\n"); @@ -2707,7 +2711,30 @@ static void test_header_handling_order(int port) size = sizeof(status); ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); ok(ret, "HttpQueryInfo failed\n"); - ok(status == 200 || status == 400 /* IE6 */, "got status %u, expected 200 or 400\n", status); + ok(status == 200, "got status %u, expected 200\n", status); + + InternetCloseHandle(request); + InternetCloseHandle(connect); + + connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); + ok(connect != NULL, "InternetConnect failed\n"); + + request = HttpOpenRequestA(connect, "POST", "/test7b", NULL, NULL, types, 0, 0); + ok(request != NULL, "HttpOpenRequest failed\n"); + + ret = HttpAddRequestHeadersA(request, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW); + ok(ret, "HttpAddRequestHeaders failed\n"); + + data_len = sizeof(data); + memset(data, 'a', sizeof(data)); + ret = HttpSendRequestA(request, connection, ~0u, data, data_len); + ok(ret, "HttpSendRequest failed\n"); + + status = 0; + size = sizeof(status); + ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL ); + ok(ret, "HttpQueryInfo failed\n"); + ok(status == 200, "got status %u, expected 200\n", status); InternetCloseHandle(request); InternetCloseHandle(connect);