Commit d050343c authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

wininet: Set Content-Length header to zero if the verb is CONNECT.

parent a4281607
...@@ -4877,6 +4877,16 @@ static char *build_ascii_request( const WCHAR *str, void *data, DWORD data_len, ...@@ -4877,6 +4877,16 @@ static char *build_ascii_request( const WCHAR *str, void *data, DWORD data_len,
return ret; return ret;
} }
static void set_content_length_header( http_request_t *request, DWORD len, DWORD flags )
{
static const WCHAR fmtW[] =
{'C','o','n','t','e','n','t','-','L','e','n','g','t','h',':',' ','%','u','\r','\n',0};
WCHAR buf[sizeof(fmtW)/sizeof(fmtW[0]) + 10];
sprintfW( buf, fmtW, len );
HTTP_HttpAddRequestHeadersW( request, buf, ~0u, flags );
}
/*********************************************************************** /***********************************************************************
* HTTP_HttpSendRequestW (internal) * HTTP_HttpSendRequestW (internal)
* *
...@@ -4891,12 +4901,9 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, ...@@ -4891,12 +4901,9 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders,
DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength, DWORD dwHeaderLength, LPVOID lpOptional, DWORD dwOptionalLength,
DWORD dwContentLength, BOOL bEndRequest) DWORD dwContentLength, BOOL bEndRequest)
{ {
static const WCHAR szContentLength[] =
{ 'C','o','n','t','e','n','t','-','L','e','n','g','t','h',':',' ','%','l','i','\r','\n',0 };
BOOL redirected = FALSE, secure_proxy_connect = FALSE, loop_next; BOOL redirected = FALSE, secure_proxy_connect = FALSE, loop_next;
LPWSTR requestString = NULL; LPWSTR requestString = NULL;
INT responseLen, cnt; INT responseLen, cnt;
WCHAR contentLengthStr[sizeof szContentLength/2 /* includes \r\n */ + 20 /* int */ ];
DWORD res; DWORD res;
TRACE("--> %p\n", request); TRACE("--> %p\n", request);
...@@ -4912,8 +4919,7 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, ...@@ -4912,8 +4919,7 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders,
if (dwContentLength || strcmpW(request->verb, szGET)) if (dwContentLength || strcmpW(request->verb, szGET))
{ {
sprintfW(contentLengthStr, szContentLength, dwContentLength); set_content_length_header(request, dwContentLength, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
HTTP_HttpAddRequestHeadersW(request, contentLengthStr, -1L, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
request->bytesToWrite = dwContentLength; request->bytesToWrite = dwContentLength;
} }
if (request->session->appInfo->agent) if (request->session->appInfo->agent)
...@@ -5002,6 +5008,10 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, ...@@ -5002,6 +5008,10 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders,
{ {
static const WCHAR connectW[] = {'C','O','N','N','E','C','T',0}; static const WCHAR connectW[] = {'C','O','N','N','E','C','T',0};
const WCHAR *target = request->server->host_port; const WCHAR *target = request->server->host_port;
if (HTTP_GetCustomHeaderIndex(request, szContent_Length, 0, TRUE) >= 0)
set_content_length_header(request, 0, HTTP_ADDREQ_FLAG_REPLACE);
requestString = build_request_header(request, connectW, target, g_szHttp1_1, TRUE); requestString = build_request_header(request, connectW, target, g_szHttp1_1, TRUE);
} }
else if (request->proxy && !(request->hdr.dwFlags & INTERNET_FLAG_SECURE)) else if (request->proxy && !(request->hdr.dwFlags & INTERNET_FLAG_SECURE))
...@@ -5011,7 +5021,12 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, ...@@ -5011,7 +5021,12 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders,
heap_free(url); heap_free(url);
} }
else else
{
if (request->proxy && HTTP_GetCustomHeaderIndex(request, szContent_Length, 0, TRUE) >= 0)
set_content_length_header(request, dwContentLength, HTTP_ADDREQ_FLAG_REPLACE);
requestString = build_request_header(request, request->verb, request->path, request->version, TRUE); requestString = build_request_header(request, request->verb, request->path, request->version, TRUE);
}
TRACE("Request header -> %s\n", debugstr_w(requestString) ); TRACE("Request header -> %s\n", debugstr_w(requestString) );
......
...@@ -2106,6 +2106,13 @@ static DWORD CALLBACK server_thread(LPVOID param) ...@@ -2106,6 +2106,13 @@ static DWORD CALLBACK server_thread(LPVOID param)
else else
send(c, notokmsg, sizeof notokmsg-1, 0); send(c, notokmsg, sizeof notokmsg-1, 0);
} }
if (strstr(buffer, "CONNECT "))
{
if (!strstr(buffer, "Content-Length: 0"))
send(c, notokmsg, sizeof notokmsg-1, 0);
else
send(c, proxymsg, sizeof proxymsg-1, 0);
}
if (strstr(buffer, "/test2")) if (strstr(buffer, "/test2"))
{ {
if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx")) if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx"))
...@@ -2806,6 +2813,25 @@ static void test_proxy_direct(int port) ...@@ -2806,6 +2813,25 @@ static void test_proxy_direct(int port)
ok(r, "HttpQueryInfo failed\n"); ok(r, "HttpQueryInfo failed\n");
ok(!strcmp(buffer, "200"), "proxy code wrong\n"); ok(!strcmp(buffer, "200"), "proxy code wrong\n");
InternetCloseHandle(hr);
InternetCloseHandle(hc);
InternetCloseHandle(hi);
sprintf(buffer, "localhost:%d\n", port);
hi = InternetOpenA("winetest", INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0);
ok(hi != NULL, "InternetOpen failed\n");
hc = InternetConnectA(hi, "test.winehq.org", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
ok(hc != NULL, "InternetConnect failed\n");
hr = HttpOpenRequestA(hc, "POST", "/test2", NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0);
ok(hr != NULL, "HttpOpenRequest failed\n");
r = HttpSendRequestA(hr, NULL, 0, (char *)"data", sizeof("data"));
ok(r, "HttpSendRequest failed %u\n", GetLastError());
test_status_code(hr, 407);
done: done:
InternetCloseHandle(hr); InternetCloseHandle(hr);
InternetCloseHandle(hc); InternetCloseHandle(hc);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment