Commit 4e53f0ca authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

wininet: Don't try to read content in response to HEAD request.

parent 2ba9ee01
...@@ -2881,10 +2881,11 @@ static const data_stream_vtbl_t chunked_stream_vtbl = { ...@@ -2881,10 +2881,11 @@ static const data_stream_vtbl_t chunked_stream_vtbl = {
static DWORD set_content_length(http_request_t *request) static DWORD set_content_length(http_request_t *request)
{ {
static const WCHAR szChunked[] = {'c','h','u','n','k','e','d',0}; static const WCHAR szChunked[] = {'c','h','u','n','k','e','d',0};
static const WCHAR headW[] = {'H','E','A','D',0};
WCHAR encoding[20]; WCHAR encoding[20];
DWORD size; DWORD size;
if(request->status_code == HTTP_STATUS_NO_CONTENT) { if(request->status_code == HTTP_STATUS_NO_CONTENT || !strcmpW(request->verb, headW)) {
request->contentLength = request->netconn_stream.content_length = 0; request->contentLength = request->netconn_stream.content_length = 0;
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
......
...@@ -1979,7 +1979,7 @@ static const char *send_buffer; ...@@ -1979,7 +1979,7 @@ static const char *send_buffer;
static DWORD CALLBACK server_thread(LPVOID param) static DWORD CALLBACK server_thread(LPVOID param)
{ {
struct server_info *si = param; struct server_info *si = param;
int r, c, i, on, count = 0; int r, c = -1, i, on, count = 0;
SOCKET s; SOCKET s;
struct sockaddr_in sa; struct sockaddr_in sa;
char buffer[0x100]; char buffer[0x100];
...@@ -2015,7 +2015,8 @@ static DWORD CALLBACK server_thread(LPVOID param) ...@@ -2015,7 +2015,8 @@ static DWORD CALLBACK server_thread(LPVOID param)
do do
{ {
c = accept(s, NULL, NULL); if(c == -1)
c = accept(s, NULL, NULL);
memset(buffer, 0, sizeof buffer); memset(buffer, 0, sizeof buffer);
for(i=0; i<(sizeof buffer-1); i++) for(i=0; i<(sizeof buffer-1); i++)
...@@ -2221,6 +2222,16 @@ static DWORD CALLBACK server_thread(LPVOID param) ...@@ -2221,6 +2222,16 @@ 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, "HEAD /test_head")) {
static const char head_response[] =
"HTTP/1.1 200 OK\r\n"
"Connection: Keep-Alive\r\n"
"Content-Length: 100\r\n"
"\r\n";
send(c, head_response, sizeof(head_response), 0);
continue;
}
if (strstr(buffer, "GET /send_from_buffer")) if (strstr(buffer, "GET /send_from_buffer"))
send(c, send_buffer, strlen(send_buffer), 0); send(c, send_buffer, strlen(send_buffer), 0);
if (strstr(buffer, "/test_cache_control_verb")) if (strstr(buffer, "/test_cache_control_verb"))
...@@ -2235,6 +2246,7 @@ static DWORD CALLBACK server_thread(LPVOID param) ...@@ -2235,6 +2246,7 @@ static DWORD CALLBACK server_thread(LPVOID param)
shutdown(c, 2); shutdown(c, 2);
closesocket(c); closesocket(c);
c = -1;
} while (!last_request); } while (!last_request);
closesocket(s); closesocket(s);
...@@ -3635,6 +3647,45 @@ static void test_response_without_headers(int port) ...@@ -3635,6 +3647,45 @@ static void test_response_without_headers(int port)
InternetCloseHandle(hi); InternetCloseHandle(hi);
} }
static void test_head_request(int port)
{
DWORD len, content_length;
HINTERNET ses, con, req;
BYTE buf[100];
BOOL ret;
ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, 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, "HEAD", "/test_head", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
ok(req != NULL, "HttpOpenRequest failed\n");
ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
len = sizeof(content_length);
content_length = -1;
ret = HttpQueryInfoA(req, HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_CONTENT_LENGTH, &content_length, &len, 0);
ok(ret, "HttpQueryInfo dailed: %u\n", GetLastError());
ok(len == sizeof(DWORD), "len = %u\n", len);
ok(content_length == 100, "content_length = %u\n", content_length);
len = -1;
ret = InternetReadFile(req, buf, sizeof(buf), &len);
ok(ret, "InternetReadFile failed: %u\n", GetLastError());
len = -1;
ret = InternetReadFile(req, buf, sizeof(buf), &len);
ok(ret, "InternetReadFile failed: %u\n", GetLastError());
InternetCloseHandle(req);
InternetCloseHandle(con);
InternetCloseHandle(ses);
}
static void test_HttpQueryInfo(int port) static void test_HttpQueryInfo(int port)
{ {
HINTERNET hi, hc, hr; HINTERNET hi, hc, hr;
...@@ -4048,6 +4099,7 @@ static void test_http_connection(void) ...@@ -4048,6 +4099,7 @@ static void test_http_connection(void)
test_connection_closing(si.port); test_connection_closing(si.port);
test_cache_control_verb(si.port); test_cache_control_verb(si.port);
test_successive_HttpSendRequest(si.port); test_successive_HttpSendRequest(si.port);
test_head_request(si.port);
/* send the basic request again to shutdown the server thread */ /* send the basic request again to shutdown the server thread */
test_basic_request(si.port, "GET", "/quit"); test_basic_request(si.port, "GET", "/quit");
......
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