From: Michael Müller Subject: wininet: Allow Accept-Encoding for HTTP/1.0 requests. Message-Id: <549EBE2C.1010502@fds-team.de> Date: Sat, 27 Dec 2014 15:11:56 +0100 Wininet allows to include an Accept-Encoding header for HTTP 1.0 requets. The patch fixes this problem and includes tests to check this behaviour. --- dlls/wininet/http.c | 22 ++-------------------- dlls/wininet/tests/http.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 21 deletions(-) From 9944fecef8ce9c9bfeab1870b009022a24f9dc1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Mon, 8 Dec 2014 02:51:30 +0100 Subject: wininet: Allow Accept-Encoding for HTTP/1.0 requests. --- dlls/wininet/http.c | 22 ++-------------------- dlls/wininet/tests/http.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index 532b65a..ee89061 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -217,7 +217,6 @@ static LPWSTR HTTP_build_req( LPCWSTR *list, int len ); static DWORD HTTP_HttpQueryInfoW(http_request_t*, DWORD, LPVOID, LPDWORD, LPDWORD); static LPWSTR HTTP_GetRedirectURL(http_request_t *req, LPCWSTR lpszUrl); static UINT HTTP_DecodeBase64(LPCWSTR base64, LPSTR bin); -static BOOL HTTP_VerifyValidHeader(http_request_t *req, LPCWSTR field); static BOOL drain_content(http_request_t*,BOOL); static CRITICAL_SECTION connection_pool_cs; @@ -1324,10 +1323,8 @@ static DWORD HTTP_HttpAddRequestHeadersW(http_request_t *request, pFieldAndValue = HTTP_InterpretHttpHeader(lpszStart); if (pFieldAndValue) { - res = HTTP_VerifyValidHeader(request, pFieldAndValue[0]); - if (res == ERROR_SUCCESS) - res = HTTP_ProcessHeader(request, pFieldAndValue[0], - pFieldAndValue[1], dwModifier | HTTP_ADDHDR_FLAG_REQ); + res = HTTP_ProcessHeader(request, pFieldAndValue[0], + pFieldAndValue[1], dwModifier | HTTP_ADDHDR_FLAG_REQ); HTTP_FreeTokens(pFieldAndValue); } @@ -6335,21 +6332,6 @@ static BOOL HTTP_DeleteCustomHeader(http_request_t *request, DWORD index) /*********************************************************************** - * HTTP_VerifyValidHeader (internal) - * - * Verify the given header is not invalid for the given http request - * - */ -static BOOL HTTP_VerifyValidHeader(http_request_t *request, LPCWSTR field) -{ - /* Accept-Encoding is stripped from HTTP/1.0 requests. It is invalid */ - if (!strcmpW(request->version, g_szHttp1_0) && !strcmpiW(field, szAccept_Encoding)) - return ERROR_HTTP_INVALID_HEADER; - - return ERROR_SUCCESS; -} - -/*********************************************************************** * IsHostInProxyBypassList (@) * * Undocumented diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c index 92a6b8d..3e66a27 100644 --- a/dlls/wininet/tests/http.c +++ b/dlls/wininet/tests/http.c @@ -2314,7 +2314,13 @@ static DWORD CALLBACK server_thread(LPVOID param) } if (strstr(buffer, "GET /test_premature_disconnect")) trace("closing connection\n"); - + if (strstr(buffer, "/test_accept_encoding_http10")) + { + if (strstr(buffer, "Accept-Encoding: gzip")) + send(c, okmsg, sizeof okmsg-1, 0); + else + send(c, notokmsg, sizeof notokmsg-1, 0); + } shutdown(c, 2); closesocket(c); c = -1; @@ -4169,6 +4175,43 @@ static void test_request_content_length(int port) CloseHandle(hCompleteEvent); } +static void test_accept_encoding(int port) +{ + HINTERNET ses, con, req; + BOOL ret; + + ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); + ok(ses != NULL, "InternetOpen failed\n"); + + con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); + ok(con != NULL, "InternetConnect failed\n"); + + req = HttpOpenRequestA(con, "GET", "/test_accept_encoding_http10", "HTTP/1.0", NULL, NULL, 0, 0); + ok(req != NULL, "HttpOpenRequest failed\n"); + + ret = HttpAddRequestHeadersA(req, "Accept-Encoding: gzip\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD); + ok(ret, "HttpAddRequestHeaders failed\n"); + + ret = HttpSendRequestA(req, NULL, 0, NULL, 0); + ok(ret, "HttpSendRequestA failed\n"); + + test_status_code(req, 200); + + InternetCloseHandle(req); + + req = HttpOpenRequestA(con, "GET", "/test_accept_encoding_http10", "HTTP/1.0", NULL, NULL, 0, 0); + ok(req != NULL, "HttpOpenRequest failed\n"); + + ret = HttpSendRequestA(req, "Accept-Encoding: gzip", ~0u, NULL, 0); + ok(ret, "HttpSendRequestA failed\n"); + + test_status_code(req, 200); + + InternetCloseHandle(req); + InternetCloseHandle(con); + InternetCloseHandle(ses); +} + static void test_http_connection(void) { struct server_info si; @@ -4215,6 +4258,7 @@ static void test_http_connection(void) test_successive_HttpSendRequest(si.port); test_head_request(si.port); test_request_content_length(si.port); + test_accept_encoding(si.port); /* send the basic request again to shutdown the server thread */ test_basic_request(si.port, "GET", "/quit"); -- 2.1.3