+static void test_head_request(int port)
+{
+ static const WCHAR verbW[] = {'H','E','A','D',0};
+ static const WCHAR headW[] = {'/','h','e','a','d',0};
+ HINTERNET ses, con, req;
+ char buf[128];
+ DWORD size, len, count, status;
+ BOOL ret;
+
+ ses = WinHttpOpen(test_useragent, 0, NULL, NULL, 0);
+ ok(ses != NULL, "failed to open session %u\n", GetLastError());
+
+ con = WinHttpConnect(ses, localhostW, port, 0);
+ ok(con != NULL, "failed to open a connection %u\n", GetLastError());
+
+ req = WinHttpOpenRequest(con, verbW, headW, NULL, NULL, NULL, 0);
+ ok(req != NULL, "failed to open a request %u\n", GetLastError());
+
+ ret = WinHttpSendRequest(req, NULL, 0, NULL, 0, 0, 0);
+ ok(ret, "failed to send request %u\n", GetLastError());
+
+ ret = WinHttpReceiveResponse(req, NULL);
+ ok(ret, "failed to receive response %u\n", GetLastError());
+
+ status = 0xdeadbeef;
+ size = sizeof(status);
+ ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
+ NULL, &status, &size, NULL);
+ ok(ret, "failed to get status code %u\n", GetLastError());
+ ok(status == 200, "got %u\n", status);
+
+ len = 0xdeadbeef;
+ size = sizeof(len);
+ ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_CONTENT_LENGTH | WINHTTP_QUERY_FLAG_NUMBER,
+ NULL, &len, &size, 0);
+ ok(ret, "failed to get content-length header %u\n", GetLastError());
+ ok(len == 100, "got %u\n", len);
+
+ count = 0xdeadbeef;
+ ret = WinHttpQueryDataAvailable(req, &count);
+ ok(ret, "failed to query data available %u\n", GetLastError());
+ ok(!count, "got %u\n", count);
+
+ len = sizeof(buf);
+ count = 0xdeadbeef;
+ ret = WinHttpReadData(req, buf, len, &count);
+ ok(ret, "failed to read data %u\n", GetLastError());
+ ok(!count, "got %u\n", count);
+
+ count = 0xdeadbeef;
+ ret = WinHttpQueryDataAvailable(req, &count);
+ ok(ret, "failed to query data available %u\n", GetLastError());
+ ok(!count, "got %u\n", count);
+
+ WinHttpCloseHandle(req);
+ WinHttpCloseHandle(con);
+ WinHttpCloseHandle(ses);
+}
+
+static void test_not_modified(int port)
+{
+ static const WCHAR pathW[] = {'/','n','o','t','_','m','o','d','i','f','i','e','d',0};
+ static const WCHAR ifmodifiedW[] = {'I','f','-','M','o','d','i','f','i','e','d','-','S','i','n','c','e',':',' '};
+ BOOL ret;
+ HINTERNET session, request, connection;
+ DWORD status, size, start = GetTickCount();
+ SYSTEMTIME st;
+ WCHAR today[(sizeof(ifmodifiedW) + WINHTTP_TIME_FORMAT_BUFSIZE)/sizeof(WCHAR) + 3];
+
+ memcpy(today, ifmodifiedW, sizeof(ifmodifiedW));
+ GetSystemTime(&st);
+ WinHttpTimeFromSystemTime(&st, &today[sizeof(ifmodifiedW)/sizeof(WCHAR)]);
+
+ session = WinHttpOpen(test_useragent, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
+ WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
+ ok(session != NULL, "WinHttpOpen failed: %u\n", GetLastError());
+
+ connection = WinHttpConnect(session, localhostW, port, 0);
+ ok(connection != NULL, "WinHttpConnect failed: %u\n", GetLastError());
+
+ request = WinHttpOpenRequest(connection, NULL, pathW, NULL, WINHTTP_NO_REFERER,
+ WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_BYPASS_PROXY_CACHE);
+ ok(request != NULL, "WinHttpOpenrequest failed: %u\n", GetLastError());
+
+ ret = WinHttpSendRequest(request, today, ~0u, NULL, 0, 0, 0);
+ ok(ret, "WinHttpSendRequest failed: %u\n", GetLastError());
+
+ ret = WinHttpReceiveResponse(request, NULL);
+ ok(ret, "WinHttpReceiveResponse failed: %u\n", GetLastError());
+
+ size = sizeof(status);
+ ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_STATUS_CODE|WINHTTP_QUERY_FLAG_NUMBER,
+ NULL, &status, &size, NULL);
+ ok(ret, "WinHttpQueryHeaders failed: %u\n", GetLastError());
+ ok(status == HTTP_STATUS_NOT_MODIFIED, "got %u\n", status);
+
+ size = 0xdeadbeef;
+ ret = WinHttpQueryDataAvailable(request, &size);
+ ok(ret, "WinHttpQueryDataAvailable failed: %u\n", GetLastError());
+ ok(!size, "got %u\n", size);
+
+ WinHttpCloseHandle(request);
+ WinHttpCloseHandle(connection);
+ WinHttpCloseHandle(session);
+ start = GetTickCount() - start;
+ ok(start <= 2000, "Expected less than 2 seconds for the test, got %u ms\n", start);
+}
+