[WININET_WINETEST] Sync with Wine Staging 1.9.11. CORE-11368
authorAmine Khaldi <amine.khaldi@reactos.org>
Sat, 2 Jul 2016 15:23:55 +0000 (15:23 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Sat, 2 Jul 2016 15:23:55 +0000 (15:23 +0000)
svn path=/trunk/; revision=71752

rostests/winetests/wininet/http.c
rostests/winetests/wininet/internet.c
rostests/winetests/wininet/url.c

index 4e3fb8d..37918bc 100644 (file)
@@ -114,7 +114,7 @@ static int expect[MAX_INTERNET_STATUS], optional[MAX_INTERNET_STATUS],
     wine_allow[MAX_INTERNET_STATUS], notified[MAX_INTERNET_STATUS];
 static const char *status_string[MAX_INTERNET_STATUS];
 
-static HANDLE hCompleteEvent, conn_close_event;
+static HANDLE hCompleteEvent, conn_close_event, conn_wait_event, server_req_rec_event;
 static DWORD req_error;
 
 #define TESTF_REDIRECT      0x01
@@ -447,6 +447,51 @@ static VOID WINAPI callback(
     }
 }
 
+typedef struct {
+    HINTERNET session;
+    HINTERNET connection;
+    HINTERNET request;
+} test_request_t;
+
+#define open_simple_request(a,b,c,d,e) _open_simple_request(__LINE__,a,b,c,d,e)
+static void _open_simple_request(unsigned line, test_request_t *req, const char *host,
+        int port, const char *verb, const char *url)
+{
+    req->session = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
+    ok_(__FILE__,line)(req->session != NULL, "InternetOpenA failed: %u\n", GetLastError());
+
+    req->connection = InternetConnectA(req->session, host, port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
+    ok_(__FILE__,line)(req->connection != NULL, "InternetConnectA failed: %u\n", GetLastError());
+
+    req->request = HttpOpenRequestA(req->connection, verb, url, NULL, NULL, NULL, 0, 0);
+    ok_(__FILE__,line)(req->request != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
+}
+
+#define close_request(a) _close_request(__LINE__,a)
+static void _close_request(unsigned line, test_request_t *req)
+{
+    BOOL ret;
+
+    ret = InternetCloseHandle(req->request);
+    ok_(__FILE__,line)(ret, "InternetCloseHandle(request) failed: %u\n", GetLastError());
+    ret = InternetCloseHandle(req->connection);
+    ok_(__FILE__,line)(ret, "InternetCloseHandle(connection) failed: %u\n", GetLastError());
+    ret = InternetCloseHandle(req->session);
+    ok_(__FILE__,line)(ret, "InternetCloseHandle(session) failed: %u\n", GetLastError());
+}
+
+#define receive_simple_request(a,b,c) _receive_simple_request(__LINE__,a,b,c)
+static DWORD _receive_simple_request(unsigned line, HINTERNET req, char *buf, size_t buf_size)
+{
+    DWORD read = 0;
+    BOOL ret;
+
+    ret = InternetReadFile(req, buf, buf_size, &read);
+    ok_(__FILE__,line)(ret, "InternetReadFile failed: %u\n", GetLastError());
+
+    return read;
+}
+
 static void close_async_handle(HINTERNET handle, HANDLE complete_event, int handle_cnt)
 {
     BOOL res;
@@ -525,7 +570,7 @@ static void InternetReadFile_test(int flags, const test_data_t *test)
     length = sizeof(buffer);
     res = HttpQueryInfoA(hor, HTTP_QUERY_RAW_HEADERS, buffer, &length, 0x0);
     ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
-    ok(length == 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length);
+    ok(length == 0 || (length == 1 && !*buffer) /* win10 */, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length);
     ok(!strcmp(buffer, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer);
 
     CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
@@ -1039,6 +1084,11 @@ static void InternetReadFileExA_test(int flags)
     CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
     CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
 
+    rc = InternetReadFileExW(hor, NULL, 0, 0xdeadcafe);
+    ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
+        "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
+        rc ? "TRUE" : "FALSE", GetLastError());
+
     /* tests invalid dwStructSize */
     inetbuffers.dwStructSize = sizeof(inetbuffers)+1;
     inetbuffers.lpcszHeader = NULL;
@@ -1104,7 +1154,7 @@ static void InternetReadFileExA_test(int flags)
                 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
                 WaitForSingleObject(hCompleteEvent, INFINITE);
                 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
-                CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
+                CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
                 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
             }
             else
@@ -1557,55 +1607,36 @@ static void test_http_cache(void)
 
 static void InternetLockRequestFile_test(void)
 {
-    HINTERNET session, connect, request;
     char file_name[MAX_PATH];
+    test_request_t req;
     HANDLE lock, lock2;
     DWORD size;
     BOOL ret;
 
-    static const char *types[] = { "*", "", NULL };
-
-    session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
-    ok(session != NULL ,"Unable to open Internet session\n");
-
-    connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
-                              INTERNET_SERVICE_HTTP, 0, 0);
-    ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
-
-    request = HttpOpenRequestA(connect, NULL, "/tests/hello.html", NULL, NULL, types, INTERNET_FLAG_NEED_FILE|INTERNET_FLAG_RELOAD, 0);
-    if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
-    {
-        skip( "Network unreachable, skipping test\n" );
-
-        ok(InternetCloseHandle(connect), "Close connect handle failed\n");
-        ok(InternetCloseHandle(session), "Close session handle failed\n");
-
-        return;
-    }
-    ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
+    open_simple_request(&req, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, "/tests/hello.html");
 
     size = sizeof(file_name);
-    ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
+    ret = InternetQueryOptionA(req.request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
     ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
     ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
     ok(!size, "size = %d\n", size);
 
     lock = NULL;
-    ret = InternetLockRequestFile(request, &lock);
+    ret = InternetLockRequestFile(req.request, &lock);
     ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
 
-    ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
+    ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0);
     ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
 
     size = sizeof(file_name);
-    ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
+    ret = InternetQueryOptionA(req.request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
     ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
 
-    ret = InternetLockRequestFile(request, &lock);
+    ret = InternetLockRequestFile(req.request, &lock);
     ok(ret, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
     ok(lock != NULL, "lock == NULL\n");
 
-    ret = InternetLockRequestFile(request, &lock2);
+    ret = InternetLockRequestFile(req.request, &lock2);
     ok(ret, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
     ok(lock == lock2, "lock != lock2\n");
 
@@ -1615,7 +1646,7 @@ static void InternetLockRequestFile_test(void)
     ret = DeleteFileA(file_name);
     ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
 
-    ok(InternetCloseHandle(request), "Close request handle failed\n");
+    ok(InternetCloseHandle(req.request), "Close request handle failed\n");
 
     ret = DeleteFileA(file_name);
     ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
@@ -1764,8 +1795,8 @@ static void HttpHeaders_test(void)
     memset(buffer, 'x', sizeof(buffer));
     ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF,
                 buffer,&len,&index) == TRUE,"Query failed\n");
-    ok(len == 2, "Expected 2, got %d\n", len);
-    ok(strcmp(buffer, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer);
+    ok(len == 2 || len == 4 /* win10 */, "Expected 2 or 4, got %d\n", len);
+    ok(memcmp(buffer, "\r\n\r\n", len) == 0, "Expected CRLF, got '%s'\n", buffer);
     ok(index == 0, "Index was incremented\n");
 
     ok(HttpAddRequestHeadersA(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
@@ -1967,8 +1998,7 @@ static const char contmsg[] =
 static const char expandcontmsg[] =
 "HTTP/1.1 100 Continue\r\n"
 "Server: winecontinue\r\n"
-"Tag: something witty\r\n"
-"\r\n";
+"Tag: something witty\r\n";
 
 static const char okmsg[] =
 "HTTP/1.1 200 OK\r\n"
@@ -2050,6 +2080,7 @@ struct server_info {
 
 static int test_cache_gzip;
 static const char *send_buffer;
+static int server_socket;
 
 static DWORD CALLBACK server_thread(LPVOID param)
 {
@@ -2057,12 +2088,12 @@ static DWORD CALLBACK server_thread(LPVOID param)
     int r, c = -1, i, on, count = 0;
     SOCKET s;
     struct sockaddr_in sa;
-    char buffer[0x100];
+    char *buffer;
+    size_t buffer_size;
     WSADATA wsaData;
     int last_request = 0;
     char host_header[22];
     char host_header_override[30];
-    static BOOL test_b = FALSE;
     static int test_no_cache = 0;
 
     WSAStartup(MAKEWORD(1,1), &wsaData);
@@ -2089,16 +2120,20 @@ static DWORD CALLBACK server_thread(LPVOID param)
 
     sprintf(host_header, "Host: localhost:%d", si->port);
     sprintf(host_header_override, "Host: test.local:%d\r\n", si->port);
+    buffer = HeapAlloc(GetProcessHeap(), 0, buffer_size = 1000);
 
     do
     {
         if(c == -1)
             c = accept(s, NULL, NULL);
 
-        memset(buffer, 0, sizeof buffer);
-        for(i=0; i<(sizeof buffer-1); i++)
+        memset(buffer, 0, buffer_size);
+        for(i=0;; i++)
         {
-            r = recv(c, &buffer[i], 1, 0);
+            if(i == buffer_size)
+                buffer = HeapReAlloc(GetProcessHeap(), 0, buffer, buffer_size *= 2);
+
+            r = recv(c, buffer+i, 1, 0);
             if (r != 1)
                 break;
             if (i<4) continue;
@@ -2171,7 +2206,7 @@ static DWORD CALLBACK server_thread(LPVOID param)
             if (strstr(buffer, "Content-Length: 100"))
             {
                 if (strstr(buffer, "POST /test7b"))
-                    recvfrom(c, buffer, sizeof buffer, 0, NULL, NULL);
+                    recvfrom(c, buffer, buffer_size, 0, NULL, NULL);
                 send(c, okmsg, sizeof okmsg-1, 0);
                 send(c, page1, sizeof page1-1, 0);
             }
@@ -2211,13 +2246,6 @@ static DWORD CALLBACK server_thread(LPVOID param)
             else
                 send(c, notokmsg, sizeof notokmsg-1, 0);
         }
-        if (!test_b && strstr(buffer, "/testB HTTP/1.1"))
-        {
-            test_b = TRUE;
-            send(c, okmsg, sizeof okmsg-1, 0);
-            recvfrom(c, buffer, sizeof buffer, 0, NULL, NULL);
-            send(c, okmsg, sizeof okmsg-1, 0);
-        }
         if (strstr(buffer, "/testC"))
         {
             if (strstr(buffer, "cookie=biscuit"))
@@ -2269,7 +2297,7 @@ static DWORD CALLBACK server_thread(LPVOID param)
         if (strstr(buffer, "GET /testH"))
         {
             send(c, ok_with_length2, sizeof(ok_with_length2)-1, 0);
-            recvfrom(c, buffer, sizeof(buffer), 0, NULL, NULL);
+            recvfrom(c, buffer, buffer_size, 0, NULL, NULL);
             send(c, ok_with_length, sizeof(ok_with_length)-1, 0);
         }
 
@@ -2351,13 +2379,6 @@ 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);
-        }
         if (strstr(buffer, "HEAD /upload.txt"))
         {
             if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
@@ -2424,6 +2445,26 @@ static DWORD CALLBACK server_thread(LPVOID param)
             else
                 send(c, notokmsg, sizeof notokmsg-1, 0);
         }
+        if (strstr(buffer, "/async_read"))
+        {
+            const char *page1_mid = page1 + (sizeof page1 - 1)/2;
+            const char *page1_end = page1 + sizeof page1 - 1;
+            send(c, okmsg, sizeof okmsg-1, 0);
+            send(c, page1, page1_mid - page1, 0);
+            WaitForSingleObject(conn_wait_event, INFINITE);
+            send(c, page1_mid, page1_end - page1_mid, 0);
+        }
+        if (strstr(buffer, "/socket"))
+        {
+            server_socket = c;
+            SetEvent(server_req_rec_event);
+            WaitForSingleObject(conn_wait_event, INFINITE);
+        }
+        if (strstr(buffer, "/echo_request"))
+        {
+            send(c, okmsg, sizeof(okmsg)-1, 0);
+            send(c, buffer, strlen(buffer), 0);
+        }
         if (strstr(buffer, "HEAD /test_auth_host1"))
         {
             if (strstr(buffer, "Authorization: Basic dGVzdDE6cGFzcw=="))
@@ -2444,64 +2485,51 @@ static DWORD CALLBACK server_thread(LPVOID param)
     } while (!last_request);
 
     closesocket(s);
+    HeapFree(GetProcessHeap(), 0, buffer);
 
     return 0;
 }
 
 static void test_basic_request(int port, const char *verb, const char *url)
 {
-    HINTERNET hi, hc, hr;
+    test_request_t req;
     DWORD r, count, error;
     char buffer[0x100];
 
-    hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
-    ok(hi != NULL, "open failed\n");
-
-    hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
-    ok(hc != NULL, "connect failed\n");
+    trace("basic request %s %s\n", verb, url);
 
-    hr = HttpOpenRequestA(hc, verb, url, NULL, NULL, NULL, 0, 0);
-    ok(hr != NULL, "HttpOpenRequest failed\n");
+    open_simple_request(&req, "localhost", port, verb, url);
 
     SetLastError(0xdeadbeef);
-    r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
+    r = HttpSendRequestA(req.request, NULL, 0, NULL, 0);
     error = GetLastError();
     ok(error == ERROR_SUCCESS || broken(error != ERROR_SUCCESS), "expected ERROR_SUCCESS, got %u\n", error);
-    ok(r, "HttpSendRequest failed\n");
+    ok(r, "HttpSendRequest failed: %u\n", GetLastError());
 
     count = 0;
     memset(buffer, 0, sizeof buffer);
     SetLastError(0xdeadbeef);
-    r = InternetReadFile(hr, buffer, sizeof buffer, &count);
+    r = InternetReadFile(req.request, buffer, sizeof buffer, &count);
     ok(r, "InternetReadFile failed %u\n", GetLastError());
     ok(count == sizeof page1 - 1, "count was wrong\n");
     ok(!memcmp(buffer, page1, sizeof page1), "http data wrong, got: %s\n", buffer);
 
-    InternetCloseHandle(hr);
-    InternetCloseHandle(hc);
-    InternetCloseHandle(hi);
+    close_request(&req);
 }
 
 static void test_proxy_indirect(int port)
 {
-    HINTERNET hi, hc, hr;
+    test_request_t req;
     DWORD r, sz;
     char buffer[0x40];
 
-    hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
-    ok(hi != NULL, "open failed\n");
+    open_simple_request(&req, "localhost", port, NULL, "/test2");
 
-    hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
-    ok(hc != NULL, "connect failed\n");
-
-    hr = HttpOpenRequestA(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
-    ok(hr != NULL, "HttpOpenRequest failed\n");
-
-    r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
+    r = HttpSendRequestA(req.request, NULL, 0, NULL, 0);
     ok(r, "HttpSendRequest failed %u\n", GetLastError());
 
     sz = sizeof buffer;
-    r = HttpQueryInfoA(hr, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL);
+    r = HttpQueryInfoA(req.request, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL);
     ok(r || GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo failed: %d\n", GetLastError());
     if (!r)
     {
@@ -2510,33 +2538,31 @@ static void test_proxy_indirect(int port)
     }
     ok(!strcmp(buffer, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
 
-    test_status_code(hr, 407);
-    test_request_flags(hr, 0);
+    test_status_code(req.request, 407);
+    test_request_flags(req.request, 0);
 
     sz = sizeof buffer;
-    r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL);
+    r = HttpQueryInfoA(req.request, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL);
     ok(r, "HttpQueryInfo failed\n");
     ok(!strcmp(buffer, "Proxy Authentication Required"), "proxy text wrong\n");
 
     sz = sizeof buffer;
-    r = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &sz, NULL);
+    r = HttpQueryInfoA(req.request, HTTP_QUERY_VERSION, buffer, &sz, NULL);
     ok(r, "HttpQueryInfo failed\n");
     ok(!strcmp(buffer, "HTTP/1.1"), "http version wrong\n");
 
     sz = sizeof buffer;
-    r = HttpQueryInfoA(hr, HTTP_QUERY_SERVER, buffer, &sz, NULL);
+    r = HttpQueryInfoA(req.request, HTTP_QUERY_SERVER, buffer, &sz, NULL);
     ok(r, "HttpQueryInfo failed\n");
     ok(!strcmp(buffer, "winetest"), "http server wrong\n");
 
     sz = sizeof buffer;
-    r = HttpQueryInfoA(hr, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL);
+    r = HttpQueryInfoA(req.request, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL);
     ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo should fail\n");
     ok(r == FALSE, "HttpQueryInfo failed\n");
 
 out:
-    InternetCloseHandle(hr);
-    InternetCloseHandle(hc);
-    InternetCloseHandle(hi);
+    close_request(&req);
 }
 
 static void test_proxy_direct(int port)
@@ -3137,14 +3163,24 @@ static void test_header_override(int port)
     ok(req != NULL, "HttpOpenRequest failed\n");
 
     ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_REPLACE);
-    err = GetLastError();
-    ok(!ret, "HttpAddRequestHeaders succeeded\n");
-    ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err);
+    if(ret) { /* win10 returns success */
+        trace("replacing host header is supported.\n");
 
-    ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
-    ok(ret, "HttpSendRequest failed\n");
+        ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
+        ok(ret, "HttpSendRequest failed\n");
 
-    test_status_code(req, 400);
+        test_status_code(req, 200);
+    }else {
+        trace("replacing host header is not supported.\n");
+
+        err = GetLastError();
+        ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err);
+
+        ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
+        ok(ret, "HttpSendRequest failed\n");
+
+        test_status_code(req, 400);
+    }
 
     InternetCloseHandle(req);
     InternetSetCookieA("http://localhost", "cookie", "biscuit");
@@ -3297,37 +3333,6 @@ static void test_header_override(int port)
     InternetCloseHandle(ses);
 }
 
-static void test_http1_1(int port)
-{
-    HINTERNET ses, con, req;
-    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, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
-    ok(req != NULL, "HttpOpenRequest failed\n");
-
-    ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
-    if (ret)
-    {
-        InternetCloseHandle(req);
-
-        req = HttpOpenRequestA(con, NULL, "/testB", 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\n");
-    }
-
-    InternetCloseHandle(req);
-    InternetCloseHandle(con);
-    InternetCloseHandle(ses);
-}
-
 static void test_connection_closing(int port)
 {
     HINTERNET session, connection, req;
@@ -4041,278 +4046,225 @@ static void test_basic_authentication(int port)
 
 static void test_premature_disconnect(int port)
 {
-    HINTERNET session, connect, request;
+    test_request_t req;
     DWORD err;
     BOOL ret;
 
-    session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
-    ok(session != NULL, "InternetOpen failed\n");
-
-    connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
-    ok(connect != NULL, "InternetConnect failed\n");
-
-    request = HttpOpenRequestA(connect, NULL, "/premature_disconnect", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
-    ok(request != NULL, "HttpOpenRequest failed\n");
+    open_simple_request(&req, "localhost", port, NULL, "/premature_disconnect");
 
     SetLastError(0xdeadbeef);
-    ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
+    ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0);
     err = GetLastError();
     todo_wine ok(!ret, "HttpSendRequest succeeded\n");
     todo_wine ok(err == ERROR_HTTP_INVALID_SERVER_RESPONSE, "got %u\n", err);
 
-    InternetCloseHandle(request);
-    InternetCloseHandle(connect);
-    InternetCloseHandle(session);
+    close_request(&req);
 }
 
 static void test_invalid_response_headers(int port)
 {
-    HINTERNET session, connect, request;
+    test_request_t req;
     DWORD size;
     BOOL ret;
     char buffer[256];
 
-    session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
-    ok(session != NULL, "InternetOpen failed\n");
-
-    connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
-    ok(connect != NULL, "InternetConnect failed\n");
-
-    request = HttpOpenRequestA(connect, NULL, "/testE", NULL, NULL, NULL, 0, 0);
-    ok(request != NULL, "HttpOpenRequest failed\n");
+    open_simple_request(&req, "localhost", port, NULL, "/testE");
 
-    ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
+    ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0);
     ok(ret, "HttpSendRequest failed %u\n", GetLastError());
 
-    test_status_code(request, 401);
-    test_request_flags(request, 0);
+    test_status_code(req.request, 401);
+    test_request_flags(req.request, 0);
 
     buffer[0] = 0;
     size = sizeof(buffer);
-    ret = HttpQueryInfoA( request, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
     ok(ret, "HttpQueryInfo failed\n");
     ok(!strcmp(buffer, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
        "headers wrong \"%s\"\n", buffer);
 
     buffer[0] = 0;
     size = sizeof(buffer);
-    ret = HttpQueryInfoA( request, HTTP_QUERY_SERVER, buffer, &size, NULL);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_SERVER, buffer, &size, NULL);
     ok(ret, "HttpQueryInfo failed\n");
     ok(!strcmp(buffer, "winetest"), "server wrong \"%s\"\n", buffer);
 
-    InternetCloseHandle(request);
-    InternetCloseHandle(connect);
-    InternetCloseHandle(session);
+    close_request(&req);
 }
 
 static void test_response_without_headers(int port)
 {
-    HINTERNET hi, hc, hr;
+    test_request_t req;
     DWORD r, count, size;
     char buffer[1024];
 
-    SetLastError(0xdeadbeef);
-    hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
-    ok(hi != NULL, "open failed %u\n", GetLastError());
+    open_simple_request(&req, "localhost", port, NULL, "/testG");
 
-    SetLastError(0xdeadbeef);
-    hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
-    ok(hc != NULL, "connect failed %u\n", GetLastError());
-
-    SetLastError(0xdeadbeef);
-    hr = HttpOpenRequestA(hc, NULL, "/testG", NULL, NULL, NULL, 0, 0);
-    ok(hr != NULL, "HttpOpenRequest failed %u\n", GetLastError());
+    test_request_flags(req.request, INTERNET_REQFLAG_NO_HEADERS);
 
-    test_request_flags(hr, INTERNET_REQFLAG_NO_HEADERS);
-
-    SetLastError(0xdeadbeef);
-    r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
+    r = HttpSendRequestA(req.request, NULL, 0, NULL, 0);
     ok(r, "HttpSendRequest failed %u\n", GetLastError());
 
-    test_request_flags_todo(hr, INTERNET_REQFLAG_NO_HEADERS);
+    test_request_flags_todo(req.request, INTERNET_REQFLAG_NO_HEADERS);
 
     count = 0;
     memset(buffer, 0, sizeof buffer);
-    SetLastError(0xdeadbeef);
-    r = InternetReadFile(hr, buffer, sizeof buffer, &count);
+    r = InternetReadFile(req.request, buffer, sizeof buffer, &count);
     ok(r, "InternetReadFile failed %u\n", GetLastError());
     todo_wine ok(count == sizeof page1 - 1, "count was wrong\n");
     todo_wine ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
 
-    test_status_code(hr, 200);
-    test_request_flags_todo(hr, INTERNET_REQFLAG_NO_HEADERS);
+    test_status_code(req.request, 200);
+    test_request_flags_todo(req.request, INTERNET_REQFLAG_NO_HEADERS);
 
     buffer[0] = 0;
     size = sizeof(buffer);
-    SetLastError(0xdeadbeef);
-    r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, NULL );
+    r = HttpQueryInfoA(req.request, HTTP_QUERY_STATUS_TEXT, buffer, &size, NULL );
     ok(r, "HttpQueryInfo failed %u\n", GetLastError());
     ok(!strcmp(buffer, "OK"), "expected OK got: \"%s\"\n", buffer);
 
     buffer[0] = 0;
     size = sizeof(buffer);
-    SetLastError(0xdeadbeef);
-    r = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &size, NULL);
+    r = HttpQueryInfoA(req.request, HTTP_QUERY_VERSION, buffer, &size, NULL);
     ok(r, "HttpQueryInfo failed %u\n", GetLastError());
     ok(!strcmp(buffer, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer);
 
     buffer[0] = 0;
     size = sizeof(buffer);
-    SetLastError(0xdeadbeef);
-    r = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
+    r = HttpQueryInfoA(req.request, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
     ok(r, "HttpQueryInfo failed %u\n", GetLastError());
     ok(!strcmp(buffer, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer);
 
-    InternetCloseHandle(hr);
-    InternetCloseHandle(hc);
-    InternetCloseHandle(hi);
+    close_request(&req);
 }
 
 static void test_head_request(int port)
 {
     DWORD len, content_length;
-    HINTERNET ses, con, req;
+    test_request_t 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");
+    open_simple_request(&req, "localhost", port, "HEAD", "/test_head");
 
-    ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
+    ret = HttpSendRequestA(req.request, 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);
+    ret = HttpQueryInfoA(req.request, 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);
+    ret = InternetReadFile(req.request, buf, sizeof(buf), &len);
     ok(ret, "InternetReadFile failed: %u\n", GetLastError());
 
     len = -1;
-    ret = InternetReadFile(req, buf, sizeof(buf), &len);
+    ret = InternetReadFile(req.request, buf, sizeof(buf), &len);
     ok(ret, "InternetReadFile failed: %u\n", GetLastError());
 
-    InternetCloseHandle(req);
-    InternetCloseHandle(con);
-    InternetCloseHandle(ses);
+    close_request(&req);
 }
 
 static void test_HttpQueryInfo(int port)
 {
-    HINTERNET hi, hc, hr;
+    test_request_t req;
     DWORD size, index, error;
     char buffer[1024];
     BOOL ret;
 
-    hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
-    ok(hi != NULL, "InternetOpen failed\n");
-
-    hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
-    ok(hc != NULL, "InternetConnect failed\n");
-
-    hr = HttpOpenRequestA(hc, NULL, "/testD", NULL, NULL, NULL, 0, 0);
-    ok(hr != NULL, "HttpOpenRequest failed\n");
+    open_simple_request(&req, "localhost", port, NULL, "/testD");
 
     size = sizeof(buffer);
-    ret = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
     error = GetLastError();
     ok(!ret || broken(ret), "HttpQueryInfo succeeded\n");
     if (!ret) ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error);
 
-    ret = HttpSendRequestA(hr, NULL, 0, NULL, 0);
+    ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0);
     ok(ret, "HttpSendRequest failed\n");
 
     index = 0;
     size = sizeof(buffer);
-    ret = HttpQueryInfoA(hr, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &index);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &index);
     ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
     ok(index == 1, "expected 1 got %u\n", index);
 
     index = 0;
     size = sizeof(buffer);
-    ret = HttpQueryInfoA(hr, HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME, buffer, &size, &index);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME, buffer, &size, &index);
     ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
     ok(index == 1, "expected 1 got %u\n", index);
 
     index = 0;
     size = sizeof(buffer);
-    ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
     ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
     ok(index == 0, "expected 0 got %u\n", index);
 
     size = sizeof(buffer);
-    ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
     ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
     ok(index == 0, "expected 0 got %u\n", index);
 
     index = 0xdeadbeef; /* invalid start index */
     size = sizeof(buffer);
-    ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
     todo_wine ok(!ret, "HttpQueryInfo should have failed\n");
     todo_wine ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
        "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
 
     index = 0;
     size = sizeof(buffer);
-    ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS_CRLF, buffer, &size, &index);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_RAW_HEADERS_CRLF, buffer, &size, &index);
     ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
     ok(index == 0, "expected 0 got %u\n", index);
 
     size = sizeof(buffer);
-    ret = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
     ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
     ok(index == 0, "expected 0 got %u\n", index);
 
     size = sizeof(buffer);
-    ret = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &size, &index);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_VERSION, buffer, &size, &index);
     ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
     ok(index == 0, "expected 0 got %u\n", index);
 
-    test_status_code(hr, 200);
+    test_status_code(req.request, 200);
 
     index = 0xdeadbeef;
     size = sizeof(buffer);
-    ret = HttpQueryInfoA(hr, HTTP_QUERY_FORWARDED, buffer, &size, &index);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_FORWARDED, buffer, &size, &index);
     ok(!ret, "HttpQueryInfo succeeded\n");
     ok(index == 0xdeadbeef, "expected 0xdeadbeef got %u\n", index);
 
     index = 0;
     size = sizeof(buffer);
-    ret = HttpQueryInfoA(hr, HTTP_QUERY_SERVER, buffer, &size, &index);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_SERVER, buffer, &size, &index);
     ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
     ok(index == 1, "expected 1 got %u\n", index);
 
     index = 0;
     size = sizeof(buffer);
     strcpy(buffer, "Server");
-    ret = HttpQueryInfoA(hr, HTTP_QUERY_CUSTOM, buffer, &size, &index);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_CUSTOM, buffer, &size, &index);
     ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
     ok(index == 1, "expected 1 got %u\n", index);
 
     index = 0;
     size = sizeof(buffer);
-    ret = HttpQueryInfoA(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
     ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
     ok(index == 1, "expected 1 got %u\n", index);
 
     size = sizeof(buffer);
-    ret = HttpQueryInfoA(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
+    ret = HttpQueryInfoA(req.request, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
     ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
     ok(index == 2, "expected 2 got %u\n", index);
 
-    InternetCloseHandle(hr);
-    InternetCloseHandle(hc);
-    InternetCloseHandle(hi);
+    close_request(&req);
 }
 
 static void test_options(int port)
@@ -4495,7 +4447,7 @@ static const http_status_test_t http_status_tests[] = {
 
 static void test_http_status(int port)
 {
-    HINTERNET ses, con, req;
+    test_request_t req;
     char buf[1000];
     DWORD i, size;
     BOOL res;
@@ -4503,29 +4455,20 @@ static void test_http_status(int port)
     for(i=0; i < sizeof(http_status_tests)/sizeof(*http_status_tests); i++) {
         send_buffer = http_status_tests[i].response_text;
 
-        ses = InternetOpenA(NULL, 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, NULL, "/send_from_buffer", NULL, NULL, NULL, 0, 0);
-        ok(req != NULL, "HttpOpenRequest failed\n");
+        open_simple_request(&req, "localhost", port, NULL, "/send_from_buffer");
 
-        res = HttpSendRequestA(req, NULL, 0, NULL, 0);
+        res = HttpSendRequestA(req.request, NULL, 0, NULL, 0);
         ok(res, "HttpSendRequest failed\n");
 
-        test_status_code(req, http_status_tests[i].status_code);
+        test_status_code(req.request, http_status_tests[i].status_code);
 
         size = sizeof(buf);
-        res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_TEXT, buf, &size, NULL);
+        res = HttpQueryInfoA(req.request, HTTP_QUERY_STATUS_TEXT, buf, &size, NULL);
         ok(res, "HttpQueryInfo failed: %u\n", GetLastError());
         ok(!strcmp(buf, http_status_tests[i].status_text), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
            i, buf, http_status_tests[i].status_text);
 
-        InternetCloseHandle(req);
-        InternetCloseHandle(con);
-        InternetCloseHandle(ses);
+        close_request(&req);
     }
 }
 
@@ -4579,44 +4522,33 @@ static void test_cache_control_verb(int port)
 static void test_request_content_length(int port)
 {
     char data[] = {'t','e','s','t'};
-    HINTERNET ses, con, req;
+    test_request_t req;
     BOOL ret;
 
     hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
 
-    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");
+    open_simple_request(&req, "localhost", port, "POST", "/test_request_content_length");
 
-    /* On XP there is a weird bug that the following tests fail if certain cookies
-     * are set. We workaround this problem by passing INTERNET_FLAG_NO_COOKIES as flag. */
-    req = HttpOpenRequestA(con, "POST", "/test_request_content_length", NULL, NULL, NULL,
-                           INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_COOKIES, 0);
-    ok(req != NULL, "HttpOpenRequest failed\n");
-
-    ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
+    ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0);
     ok(ret, "HttpSendRequest failed %u\n", GetLastError());
-    test_status_code(req, 200);
+    test_status_code(req.request, 200);
 
     SetEvent(hCompleteEvent);
 
-    ret = HttpSendRequestA(req, NULL, 0, data, sizeof(data));
+    ret = HttpSendRequestA(req.request, NULL, 0, data, sizeof(data));
     ok(ret, "HttpSendRequest failed %u\n", GetLastError());
-    test_status_code(req, 200);
+    test_status_code(req.request, 200);
 
     SetEvent(hCompleteEvent);
 
-    InternetCloseHandle(req);
-    InternetCloseHandle(con);
-    InternetCloseHandle(ses);
+    close_request(&req);
     CloseHandle(hCompleteEvent);
 }
 
 static void test_accept_encoding(int port)
 {
     HINTERNET ses, con, req;
+    char buf[1000];
     BOOL ret;
 
     ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
@@ -4625,7 +4557,7 @@ static void test_accept_encoding(int port)
     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);
+    req = HttpOpenRequestA(con, "GET", "/echo_request", "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);
@@ -4635,16 +4567,20 @@ static void test_accept_encoding(int port)
     ok(ret, "HttpSendRequestA failed\n");
 
     test_status_code(req, 200);
+    receive_simple_request(req, buf, sizeof(buf));
+    ok(strstr(buf, "Accept-Encoding: gzip") != NULL, "Accept-Encoding header not found in %s\n", buf);
 
     InternetCloseHandle(req);
 
-    req = HttpOpenRequestA(con, "GET", "/test_accept_encoding_http10", "HTTP/1.0", NULL, NULL, 0, 0);
+    req = HttpOpenRequestA(con, "GET", "/echo_request", "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);
+    receive_simple_request(req, buf, sizeof(buf));
+    ok(strstr(buf, "Accept-Encoding: gzip") != NULL, "Accept-Encoding header not found in %s\n", buf);
 
     InternetCloseHandle(req);
     InternetCloseHandle(con);
@@ -4704,6 +4640,396 @@ static void test_basic_auth_credentials_reuse(int port)
     InternetCloseHandle( ses );
 }
 
+static void test_async_read(int port)
+{
+    HINTERNET ses, con, req;
+    INTERNET_BUFFERSA ib;
+    char buffer[0x100];
+    DWORD pending_reads;
+    DWORD res, count, bytes;
+    BOOL ret;
+
+    hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
+    conn_wait_event = CreateEventW(NULL, FALSE, FALSE, NULL);
+
+    /* test asynchronous InternetReadFileEx */
+    ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC );
+    ok( ses != NULL, "InternetOpenA failed\n" );
+    pInternetSetStatusCallbackA( ses, &callback );
+
+    SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED );
+    con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0xdeadbeef );
+    ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
+    CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED );
+
+    SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED );
+    req = HttpOpenRequestA( con, "GET", "/async_read", NULL, NULL, NULL, INTERNET_FLAG_RELOAD, 0xdeadbeef );
+    ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
+    CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED );
+
+    SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT );
+    SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY );
+    SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER );
+    SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER );
+    SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST );
+    SET_EXPECT( INTERNET_STATUS_REQUEST_SENT );
+    SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE );
+    SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED );
+    SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION );
+    SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED );
+    SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE );
+
+    SetLastError( 0xdeadbeef );
+    ret = HttpSendRequestA( req, NULL, 0, NULL, 0 );
+    ok( !ret, "HttpSendRequestA unexpectedly succeeded\n" );
+    ok( GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
+    WaitForSingleObject( hCompleteEvent, INFINITE );
+    ok( req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error );
+
+    CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT );
+    CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY );
+    CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER );
+    CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER );
+    CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST );
+    CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT );
+    CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE );
+    CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED );
+    CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION );
+    CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED );
+    CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE );
+
+    pending_reads = 0;
+    memset( &ib, 0, sizeof(ib) );
+    memset( buffer, 0, sizeof(buffer) );
+    ib.dwStructSize = sizeof(ib);
+    for (count = 0; count < sizeof(buffer); count += ib.dwBufferLength)
+    {
+        ib.lpvBuffer = buffer + count;
+        ib.dwBufferLength = min(16, sizeof(buffer) - count);
+
+        SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE );
+        SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED );
+
+        ret = InternetReadFileExA( req, &ib, 0, 0xdeadbeef );
+        if (!count) /* the first part should arrive immediately */
+            ok( ret, "InternetReadFileExA failed %u\n", GetLastError() );
+        if (!ret)
+        {
+            ok( GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
+            CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE );
+            SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE );
+            if (!pending_reads++)
+            {
+                res = WaitForSingleObject( hCompleteEvent, 0 );
+                ok( res == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %u\n", res );
+                SetEvent( conn_wait_event );
+            }
+            res = WaitForSingleObject( hCompleteEvent, INFINITE );
+            ok( res == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", res );
+            ok( req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error );
+            todo_wine_if( pending_reads > 1 )
+            ok( ib.dwBufferLength != 0, "expected ib.dwBufferLength != 0\n" );
+            CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED );
+            CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE );
+        }
+
+        CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE );
+        CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED );
+        if (!ib.dwBufferLength) break;
+    }
+
+    todo_wine
+    ok( pending_reads == 1, "expected 1 pending read, got %u\n", pending_reads );
+    ok( !strcmp(buffer, page1), "unexpected buffer content\n" );
+    close_async_handle( ses, hCompleteEvent, 2 );
+    ResetEvent( conn_wait_event );
+
+    /* test asynchronous InternetReadFile */
+    ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC );
+    ok( ses != NULL, "InternetOpenA failed\n" );
+    pInternetSetStatusCallbackA( ses, &callback );
+
+    SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED );
+    con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0xdeadbeef );
+    ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
+    CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED );
+
+    SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED );
+    req = HttpOpenRequestA( con, "GET", "/async_read", NULL, NULL, NULL, INTERNET_FLAG_RELOAD, 0xdeadbeef );
+    ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
+    CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED );
+
+    SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT );
+    SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY );
+    SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER );
+    SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER );
+    SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST );
+    SET_EXPECT( INTERNET_STATUS_REQUEST_SENT );
+    SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE );
+    SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED );
+    SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION );
+    SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED );
+    SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE );
+
+    SetLastError( 0xdeadbeef );
+    ret = HttpSendRequestA( req, NULL, 0, NULL, 0 );
+    ok( !ret, "HttpSendRequestA unexpectedly succeeded\n" );
+    ok( GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
+    WaitForSingleObject( hCompleteEvent, INFINITE );
+    ok( req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error );
+
+    CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT );
+    CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY );
+    CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER );
+    CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER );
+    CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST );
+    CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT );
+    CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE );
+    CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED );
+    CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION );
+    CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED );
+    CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE );
+
+    pending_reads = 0;
+    memset( buffer, 0, sizeof(buffer) );
+    for (count = 0; count < sizeof(buffer); count += bytes)
+    {
+        SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE );
+        SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED );
+
+        bytes = 0xdeadbeef;
+        ret = InternetReadFile( req, buffer + count, min(16, sizeof(buffer) - count), &bytes );
+        if (!count) /* the first part should arrive immediately */
+            ok( ret, "InternetReadFile failed %u\n", GetLastError() );
+        if (!ret)
+        {
+            ok( GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
+            ok( bytes == 0, "expected 0, got %u\n", bytes );
+            todo_wine
+            CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE );
+            SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE );
+            if (!pending_reads++)
+            {
+                res = WaitForSingleObject( hCompleteEvent, 0 );
+                ok( res == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %u\n", res );
+                SetEvent( conn_wait_event );
+            }
+            res = WaitForSingleObject( hCompleteEvent, INFINITE );
+            ok( res == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", res );
+            ok( req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error );
+            todo_wine_if( pending_reads > 1 )
+            ok( bytes != 0, "expected bytes != 0\n" );
+            CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED );
+            CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE );
+        }
+
+        CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE );
+        CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED );
+        if (!bytes) break;
+    }
+
+    todo_wine
+    ok( pending_reads == 1, "expected 1 pending read, got %u\n", pending_reads );
+    ok( !strcmp(buffer, page1), "unexpected buffer content\n" );
+    close_async_handle( ses, hCompleteEvent, 2 );
+
+    CloseHandle( hCompleteEvent );
+    CloseHandle( conn_wait_event );
+}
+
+static void server_send_string(const char *msg)
+{
+    send(server_socket, msg, strlen(msg), 0);
+}
+
+static void WINAPI readex_callback(HINTERNET handle, DWORD_PTR context, DWORD status, void *info, DWORD info_size)
+{
+    switch(status) {
+    case INTERNET_STATUS_RECEIVING_RESPONSE:
+    case INTERNET_STATUS_RESPONSE_RECEIVED:
+        break;
+    default:
+        callback(handle, context, status, info, info_size);
+    }
+}
+
+static void open_read_test_request(int port, test_request_t *req, const char *response)
+{
+    BOOL ret;
+
+    req->session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
+    ok(req->session != NULL, "InternetOpenA failed\n");
+    pInternetSetStatusCallbackA(req->session, readex_callback);
+
+    SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
+    req->connection = InternetConnectA(req->session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0xdeadbeef);
+    ok(req->connection != NULL, "InternetConnectA failed %u\n", GetLastError());
+    CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED );
+
+    SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
+    req->request = HttpOpenRequestA(req->connection, "GET", "/socket", NULL, NULL, NULL, INTERNET_FLAG_RELOAD, 0xdeadbeef);
+    ok(req->request != NULL, "HttpOpenRequestA failed %u\n", GetLastError());
+    CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED );
+
+    SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
+    SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
+    SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
+    SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
+    SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
+    SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
+
+    SetLastError(0xdeadbeef);
+    ret = HttpSendRequestA(req->request, NULL, 0, NULL, 0);
+    ok(!ret, "HttpSendRequestA unexpectedly succeeded\n");
+    ok(GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %u\n", GetLastError());
+    ok(req_error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", req_error);
+
+    WaitForSingleObject(server_req_rec_event, INFINITE);
+
+    CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
+    CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
+    CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
+    CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
+    CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
+
+    SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
+
+    server_send_string(response);
+    WaitForSingleObject(hCompleteEvent, INFINITE);
+
+    CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
+    CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
+}
+
+#define readex_expect_sync_data(a,b,c,d,e) _readex_expect_sync_data(__LINE__,a,b,c,d,e)
+static void _readex_expect_sync_data(unsigned line, HINTERNET req, DWORD flags, INTERNET_BUFFERSW *buf,
+        DWORD buf_size, const char *exdata)
+{
+    DWORD len = strlen(exdata);
+    BOOL ret;
+
+    SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
+
+    memset(buf->lpvBuffer, 0xff, buf_size);
+    buf->dwBufferLength = buf_size;
+    ret = InternetReadFileExW(req, buf, flags, 0xdeadbeef);
+    ok_(__FILE__,line)(ret, "InternetReadFileExW failed: %u\n", GetLastError());
+    ok_(__FILE__,line)(buf->dwBufferLength == len, "dwBufferLength = %u, expected %u\n", buf->dwBufferLength, len);
+    if(len)
+        ok_(__FILE__,line)(!memcmp(buf->lpvBuffer, exdata, len), "Unexpected data\n");
+
+    CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
+}
+
+static void send_response_and_wait(const char *response, BOOL close_connection, INTERNET_BUFFERSW *buf)
+{
+    DWORD orig_size = buf->dwBufferLength;
+
+    SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
+
+    if(response)
+        server_send_string(response);
+
+    if(close_connection) {
+        char c;
+        SetEvent(conn_wait_event);
+        recv(server_socket, &c, 1, 0);
+    }
+
+    WaitForSingleObject(hCompleteEvent, INFINITE);
+
+    CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
+
+    /* If IRF_NO_WAIT is used, buffer is not changed. */
+    ok(buf->dwBufferLength == orig_size, "dwBufferLength = %u\n", buf->dwBufferLength);
+    ok(!*(int*)buf->lpvBuffer, "buffer data changed\n");
+}
+
+static void readex_expect_async(HINTERNET req, DWORD flags, INTERNET_BUFFERSW *buf, DWORD buf_size)
+{
+    BOOL ret;
+
+    memset(buf->lpvBuffer, 0, buf_size);
+    buf->dwBufferLength = buf_size;
+    ret = InternetReadFileExW(req, buf, flags, 0xdeadbeef);
+    ok(!ret && GetLastError() == ERROR_IO_PENDING, "InternetReadFileExW returned %x (%u)\n", ret, GetLastError());
+    ok(buf->dwBufferLength == buf_size, "dwBufferLength = %u, expected %u\n", buf->dwBufferLength, buf_size);
+    ok(!*(int*)buf->lpvBuffer, "buffer data changed\n");
+}
+
+static void test_http_read(int port)
+{
+    INTERNET_BUFFERSW ib;
+    test_request_t req;
+    char buf[4096];
+
+    hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
+    conn_wait_event = CreateEventW(NULL, FALSE, FALSE, NULL);
+    server_req_rec_event = CreateEventW(NULL, FALSE, FALSE, NULL);
+
+    trace("Testing InternetReadFileExW with IRF_NO_WAIT flag...\n");
+
+    open_read_test_request(port, &req,
+                           "HTTP/1.1 200 OK\r\n"
+                           "Server: winetest\r\n"
+                           "\r\n"
+                           "xx");
+
+    memset(&ib, 0, sizeof(ib));
+    ib.dwStructSize = sizeof(ib);
+    ib.lpvBuffer = buf;
+
+    readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "xx");
+
+    readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf));
+    send_response_and_wait("1234567890", FALSE, &ib);
+    readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, 5, "12345");
+    readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "67890");
+
+    readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf));
+    send_response_and_wait("12345", TRUE, &ib);
+
+    readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "12345");
+    readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "");
+
+    close_async_handle(req.session, hCompleteEvent, 2);
+
+    CloseHandle(hCompleteEvent);
+    CloseHandle(conn_wait_event);
+    CloseHandle(server_req_rec_event);
+}
+
+static void test_long_url(int port)
+{
+    char long_path[INTERNET_MAX_PATH_LENGTH*2] = "/echo_request?";
+    char buf[sizeof(long_path)*2], url[sizeof(buf)];
+    test_request_t req;
+    DWORD size, len;
+    BOOL ret;
+
+    memset(long_path+strlen(long_path), 'x', sizeof(long_path)-strlen(long_path));
+    long_path[sizeof(long_path)-1] = 0;
+    open_simple_request(&req, "localhost", port, NULL, long_path);
+
+    ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0);
+    ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
+    test_status_code(req.request, 200);
+
+    receive_simple_request(req.request, buf, sizeof(buf));
+    ok(strstr(buf, long_path) != NULL, "long pathnot found in %s\n", buf);
+
+    sprintf(url, "http://localhost:%u%s", port, long_path);
+
+    size = sizeof(buf);
+    ret = InternetQueryOptionA(req.request, INTERNET_OPTION_URL, buf, &size);
+    ok(ret, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
+    len = strlen(url);
+    ok(size == len, "size = %u, expected %u\n", size, len);
+    ok(!strcmp(buf, url), "Wrong URL %s, expected %s\n", buf, url);
+
+    close_request(&req);
+}
+
 static void test_http_connection(void)
 {
     struct server_info si;
@@ -4732,7 +5058,6 @@ static void test_http_connection(void)
     test_basic_request(si.port, "GET", "/testF");
     test_connection_header(si.port);
     test_header_override(si.port);
-    test_http1_1(si.port);
     test_cookie_header(si.port);
     test_basic_authentication(si.port);
     test_invalid_response_headers(si.port);
@@ -4753,6 +5078,9 @@ static void test_http_connection(void)
     test_request_content_length(si.port);
     test_accept_encoding(si.port);
     test_basic_auth_credentials_reuse(si.port);
+    test_async_read(si.port);
+    test_http_read(si.port);
+    test_long_url(si.port);
 
     /* send the basic request again to shutdown the server thread */
     test_basic_request(si.port, "GET", "/quit");
@@ -4777,14 +5105,11 @@ typedef struct {
 } cert_struct_test_t;
 
 static const cert_struct_test_t test_winehq_org_cert = {
-    "GT98380011\r\n"
-    "See www.rapidssl.com/resources/cps (c)14\r\n"
-    "Domain Control Validated - RapidSSL(R)\r\n"
     "*.winehq.org",
 
     "US\r\n"
     "GeoTrust Inc.\r\n"
-    "RapidSSL SHA256 CA - G3"
+    "RapidSSL SHA256 CA"
 };
 
 static const cert_struct_test_t test_winehq_com_cert = {
@@ -5990,34 +6315,26 @@ static void test_InternetCloseHandle(void)
 
 static void test_connection_failure(void)
 {
-    HINTERNET session, connect, request;
+    test_request_t req;
     DWORD error;
     BOOL ret;
 
-    session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
-    ok(session != NULL, "failed to get session handle\n");
-
-    connect = InternetConnectA(session, "localhost", 1, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
-    ok(connect != NULL, "failed to get connection handle\n");
-
-    request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, 0, 0);
-    ok(request != NULL, "failed to get request handle\n");
+    open_simple_request(&req, "localhost", 1, NULL, "/");
 
     SetLastError(0xdeadbeef);
-    ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
+    ret = HttpSendRequestA(req.request, NULL, 0, NULL, 0);
     error = GetLastError();
     ok(!ret, "unexpected success\n");
     ok(error == ERROR_INTERNET_CANNOT_CONNECT, "wrong error %u\n", error);
 
-    InternetCloseHandle(request);
-    InternetCloseHandle(connect);
-    InternetCloseHandle(session);
+    close_request(&req);
 }
 
 static void test_default_service_port(void)
 {
     HINTERNET session, connect, request;
-    DWORD error;
+    DWORD size, error;
+    char buffer[128];
     BOOL ret;
 
     session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
@@ -6037,6 +6354,50 @@ static void test_default_service_port(void)
     ok(error == ERROR_INTERNET_SECURITY_CHANNEL_ERROR || error == ERROR_INTERNET_CANNOT_CONNECT,
        "got %u\n", error);
 
+    size = sizeof(buffer);
+    memset(buffer, 0, sizeof(buffer));
+    ret = HttpQueryInfoA(request, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
+    ok(ret, "HttpQueryInfo failed with error %u\n", GetLastError());
+    ok(!strcmp(buffer, "test.winehq.org:80"), "Expected test.winehg.org:80, got '%s'\n", buffer);
+
+    InternetCloseHandle(request);
+    InternetCloseHandle(connect);
+
+    connect = InternetConnectA(session, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL,
+                               INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0);
+    ok(connect != NULL, "InternetConnect failed\n");
+
+    request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0);
+    ok(request != NULL, "HttpOpenRequest failed\n");
+
+    ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
+    ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
+
+    size = sizeof(buffer);
+    memset(buffer, 0, sizeof(buffer));
+    ret = HttpQueryInfoA(request, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
+    ok(ret, "HttpQueryInfo failed with error %u\n", GetLastError());
+    ok(!strcmp(buffer, "test.winehq.org"), "Expected test.winehg.org, got '%s'\n", buffer);
+
+    InternetCloseHandle(request);
+    InternetCloseHandle(connect);
+
+    connect = InternetConnectA(session, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL,
+                               INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0);
+    ok(connect != NULL, "InternetConnect failed\n");
+
+    request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, 0, 0);
+    ok(request != NULL, "HttpOpenRequest failed\n");
+
+    ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
+    ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
+
+    size = sizeof(buffer);
+    memset(buffer, 0, sizeof(buffer));
+    ret = HttpQueryInfoA(request, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
+    ok(ret, "HttpQueryInfo failed with error %u\n", GetLastError());
+    ok(!strcmp(buffer, "test.winehq.org:443"), "Expected test.winehg.org:443, got '%s'\n", buffer);
+
     InternetCloseHandle(request);
     InternetCloseHandle(connect);
     InternetCloseHandle(session);
index fe6e2ae..d0ca8ee 100644 (file)
@@ -615,6 +615,7 @@ static void test_cookie_attrs(void)
 
 static void test_cookie_url(void)
 {
+    char long_url[5000] = "http://long.url.test.com/", *p;
     WCHAR bufw[512];
     char buf[512];
     DWORD len;
@@ -641,6 +642,23 @@ static void test_cookie_url(void)
     res = pInternetGetCookieExW(about_blankW, NULL, bufw, &len, 0, NULL);
     ok(!res && GetLastError() == ERROR_INVALID_PARAMETER,
        "InternetGetCookeExW failed: %u, expected ERROR_INVALID_PARAMETER\n", GetLastError());
+
+    p = long_url + strlen(long_url);
+    memset(p, 'x', long_url+sizeof(long_url)-p);
+    p += (long_url+sizeof(long_url)-p) - 3;
+    p[0] = '/';
+    p[2] = 0;
+    res = InternetSetCookieA(long_url, NULL, "A=B");
+    ok(res, "InternetSetCookieA failed: %u\n", GetLastError());
+
+    len = sizeof(buf);
+    res = InternetGetCookieA(long_url, NULL, buf, &len);
+    ok(res, "InternetGetCookieA failed: %u\n", GetLastError());
+    ok(!strcmp(buf, "A=B"), "buf = %s\n", buf);
+
+    len = sizeof(buf);
+    res = InternetGetCookieA("http://long.url.test.com/", NULL, buf, &len);
+    ok(!res && GetLastError() == ERROR_NO_MORE_ITEMS, "InternetGetCookieA failed: %u\n", GetLastError());
 }
 
 static void test_null(void)
@@ -1515,6 +1533,10 @@ static void test_InternetErrorDlg(void)
                 continue;
             }
             break;
+        case ERROR_INTERNET_CHG_POST_IS_NON_SECURE:
+            if(res == ERROR_SUCCESS) /* win10 returns ERROR_SUCCESS */
+                expected = ERROR_SUCCESS;
+            break;
         default: break;
         }
 
index adb6eb1..7c032cb 100644 (file)
@@ -130,6 +130,9 @@ static const crack_url_test_t crack_url_tests[] = {
     {"HtTp://www.winehq.org/scheme",
         0, 4, INTERNET_SCHEME_HTTP, 7, 14, 23, 80, -1, 0, -1, 0, 21, 7, -1, 0,
         "HtTp", "www.winehq.org", "", "", "/scheme", ""},
+    {"http://www.winehq.org",
+        0, 4, INTERNET_SCHEME_HTTP, 7, 14, 23, 80, -1, 0, -1, 0, 21, 0, -1, 0,
+        "http", "www.winehq.org", "", "", "", ""},
     {"file:///C:/Program%20Files/Atmel/AVR%20Tools/STK500/STK500.xml",
         0, 4, INTERNET_SCHEME_FILE, -1, 0, -1, 0, -1, 0, -1, 0, 7, 55, -1, 0,
         "file", "", "", "", "C:\\Program Files\\Atmel\\AVR Tools\\STK500\\STK500.xml", ""},
@@ -168,20 +171,35 @@ static const crack_url_test_t crack_url_tests[] = {
         "C", "", "", "", "\\file.txt", ""}
 };
 
-static const WCHAR *w_str_of(const char *str)
+static WCHAR *a2w(const char *str)
 {
-    static WCHAR buf[512];
-    MultiByteToWideChar(CP_ACP, 0, str, -1, buf, sizeof(buf)/sizeof(buf[0]));
-    return buf;
+    WCHAR *ret;
+    int len;
+
+    len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
+    ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
+    MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
+    return ret;
+}
+
+static int strcmp_wa(const WCHAR *str1, const char *str2)
+{
+    WCHAR *str2w = a2w(str2);
+    int ret = lstrcmpW(str1, str2w);
+    HeapFree(GetProcessHeap(), 0, str2w);
+    return ret;
 }
 
 static void test_crack_url(const crack_url_test_t *test)
 {
-    WCHAR buf[INTERNET_MAX_URL_LENGTH];
     URL_COMPONENTSW urlw;
     URL_COMPONENTSA url;
-    char scheme[32], hostname[1024], username[1024];
-    char password[1024], extrainfo[1024], urlpath[1024];
+    char *scheme_a, *hostname_a, *username_a;
+    char *password_a, *extrainfo_a, *urlpath_a;
+    WCHAR *scheme_w, *hostname_w, *username_w;
+    WCHAR *password_w, *extrainfo_w, *urlpath_w;
+    size_t buf_len = strlen(test->url);
+    WCHAR *buf;
     BOOL b;
 
     /* test InternetCrackUrlA with NULL buffers */
@@ -231,9 +249,9 @@ static void test_crack_url(const crack_url_test_t *test)
        test->url, url.dwPasswordLength, test->pass_len);
 
     if(test->path_off == -1)
-        ok(!url.lpszUrlPath, "[%s] url.lpszPath = %p, expected NULL\n", test->url, url.lpszUrlPath);
+        ok(!url.lpszUrlPath, "[%s] url.lpszUrlPath = %p, expected NULL\n", test->url, url.lpszUrlPath);
     else
-        ok(url.lpszUrlPath == test->url+test->path_off, "[%s] url.lpszPath = %p, expected %p\n",
+        ok(url.lpszUrlPath == test->url+test->path_off, "[%s] url.lpszUrlPath = %p, expected %p\n",
            test->url, url.lpszUrlPath, test->url+test->path_off);
     ok(url.dwUrlPathLength == test->path_len, "[%s] url.lpszUrlPathLength = %d, expected %d\n",
        test->url, url.dwUrlPathLength, test->path_len);
@@ -256,10 +274,11 @@ static void test_crack_url(const crack_url_test_t *test)
     urlw.dwUrlPathLength = 1;
     urlw.dwExtraInfoLength = 1;
 
-    MultiByteToWideChar(CP_ACP, 0, test->url, -1, buf, sizeof(buf)/sizeof(buf[0]));
+    buf = a2w(test->url);
     b = InternetCrackUrlW(buf, lstrlenW(buf), 0, &urlw);
     if(!b && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
         win_skip("InternetCrackUrlW is not implemented\n");
+        HeapFree(GetProcessHeap(), 0, buf);
         return;
     }
     ok(b, "InternetCrackUrl failed with error %d\n", GetLastError());
@@ -310,9 +329,9 @@ static void test_crack_url(const crack_url_test_t *test)
     }
 
     if(test->path_off == -1)
-        ok(!urlw.lpszUrlPath, "[%s] urlw.lpszPath = %p, expected NULL\n", test->url, urlw.lpszUrlPath);
+        ok(!urlw.lpszUrlPath, "[%s] urlw.lpszUrlPath = %p, expected NULL\n", test->url, urlw.lpszUrlPath);
     else
-        ok(urlw.lpszUrlPath == buf+test->path_off, "[%s] urlw.lpszPath = %p, expected %p\n",
+        ok(urlw.lpszUrlPath == buf+test->path_off, "[%s] urlw.lpszUrlPath = %p, expected %p\n",
            test->url, urlw.lpszUrlPath, buf+test->path_off);
     ok(urlw.dwUrlPathLength == test->path_len, "[%s] urlw.lpszUrlPathLength = %d, expected %d\n",
        test->url, urlw.dwUrlPathLength, test->path_len);
@@ -329,114 +348,165 @@ static void test_crack_url(const crack_url_test_t *test)
     }
 
     /* test InternetCrackUrlA with valid buffers */
+    scheme_a = (char*)(scheme_w = HeapAlloc(GetProcessHeap(), 0, buf_len*sizeof(WCHAR)));
+    hostname_a = (char*)(hostname_w = HeapAlloc(GetProcessHeap(), 0, buf_len*sizeof(WCHAR)));
+    username_a = (char*)(username_w = HeapAlloc(GetProcessHeap(), 0, buf_len*sizeof(WCHAR)));
+    password_a = (char*)(password_w = HeapAlloc(GetProcessHeap(), 0, buf_len*sizeof(WCHAR)));
+    urlpath_a = (char*)(urlpath_w = HeapAlloc(GetProcessHeap(), 0, buf_len*sizeof(WCHAR)));
+    extrainfo_a = (char*)(extrainfo_w = HeapAlloc(GetProcessHeap(), 0, buf_len*sizeof(WCHAR)));
     memset(&url, 0, sizeof(URL_COMPONENTSA));
     url.dwStructSize = sizeof(URL_COMPONENTSA);
-    url.lpszScheme = scheme;
-    url.dwSchemeLength = sizeof(scheme);
-    url.lpszHostName = hostname;
-    url.dwHostNameLength = sizeof(hostname);
-    url.lpszUserName = username;
-    url.dwUserNameLength = sizeof(username);
-    url.lpszPassword = password;
-    url.dwPasswordLength = sizeof(password);
-    url.lpszUrlPath = urlpath;
-    url.dwUrlPathLength = sizeof(urlpath);
-    url.lpszExtraInfo = extrainfo;
-    url.dwExtraInfoLength = sizeof(extrainfo);
+    url.lpszScheme = scheme_a;
+    url.dwSchemeLength = buf_len;
+    url.lpszHostName = hostname_a;
+    url.dwHostNameLength = buf_len;
+    url.lpszUserName = username_a;
+    url.dwUserNameLength = buf_len;
+    url.lpszPassword = password_a;
+    url.dwPasswordLength = buf_len;
+    url.lpszUrlPath = urlpath_a;
+    url.dwUrlPathLength = buf_len;
+    url.lpszExtraInfo = extrainfo_a;
+    url.dwExtraInfoLength = buf_len;
 
     b = InternetCrackUrlA(test->url, strlen(test->url), 0, &url);
     ok(b, "InternetCrackUrlA failed with error %d\n", GetLastError());
 
     ok(url.dwSchemeLength == strlen(test->exp_scheme), "[%s] Got wrong scheme length: %d\n",
-            test->url, url.dwSchemeLength);
-    ok(!strcmp(scheme, test->exp_scheme), "[%s] Got wrong scheme, expected: %s, got: %s\n",
-            test->url, test->exp_scheme, scheme);
+       test->url, url.dwSchemeLength);
+    ok(!strcmp(scheme_a, test->exp_scheme), "[%s] Got wrong scheme, expected: %s, got: %s\n",
+       test->url, test->exp_scheme, scheme_a);
 
     ok(url.nScheme == test->scheme, "[%s] Got wrong nScheme, expected: %d, got: %d\n",
-            test->url, test->scheme, url.nScheme);
+       test->url, test->scheme, url.nScheme);
 
     ok(url.dwHostNameLength == strlen(test->exp_hostname), "[%s] Got wrong hostname length: %d\n",
-            test->url, url.dwHostNameLength);
-    ok(!strcmp(hostname, test->exp_hostname), "[%s] Got wrong hostname, expected: %s, got: %s\n",
-            test->url, test->exp_hostname, hostname);
+       test->url, url.dwHostNameLength);
+    ok(!strcmp(hostname_a, test->exp_hostname), "[%s] Got wrong hostname, expected: %s, got: %s\n",
+       test->url, test->exp_hostname, hostname_a);
 
     ok(url.nPort == test->port, "[%s] Got wrong port, expected: %d, got: %d\n",
-            test->url, test->port, url.nPort);
+       test->url, test->port, url.nPort);
 
     ok(url.dwUserNameLength == strlen(test->exp_username), "[%s] Got wrong username length: %d\n",
-            test->url, url.dwUserNameLength);
-    ok(!strcmp(username, test->exp_username), "[%s] Got wrong username, expected: %s, got: %s\n",
-            test->url, test->exp_username, username);
+       test->url, url.dwUserNameLength);
+    ok(!strcmp(username_a, test->exp_username), "[%s] Got wrong username, expected: %s, got: %s\n",
+       test->url, test->exp_username, username_a);
 
     ok(url.dwPasswordLength == strlen(test->exp_password), "[%s] Got wrong password length: %d\n",
-            test->url, url.dwPasswordLength);
-    ok(!strcmp(password, test->exp_password), "[%s] Got wrong password, expected: %s, got: %s\n",
-            test->url, test->exp_password, password);
+       test->url, url.dwPasswordLength);
+    ok(!strcmp(password_a, test->exp_password), "[%s] Got wrong password, expected: %s, got: %s\n",
+       test->url, test->exp_password, password_a);
 
     ok(url.dwUrlPathLength == strlen(test->exp_urlpath), "[%s] Got wrong urlpath length: %d\n",
-            test->url, url.dwUrlPathLength);
-    ok(!strcmp(urlpath, test->exp_urlpath), "[%s] Got wrong urlpath, expected: %s, got: %s\n",
-            test->url, test->exp_urlpath, urlpath);
+       test->url, url.dwUrlPathLength);
+    ok(!strcmp(urlpath_a, test->exp_urlpath), "[%s] Got wrong urlpath, expected: %s, got: %s\n",
+       test->url, test->exp_urlpath, urlpath_a);
 
     ok(url.dwExtraInfoLength == strlen(test->exp_extrainfo), "[%s] Got wrong extrainfo length: %d\n",
-            test->url, url.dwExtraInfoLength);
-    ok(!strcmp(extrainfo, test->exp_extrainfo), "[%s] Got wrong extrainfo, expected: %s, got: %s\n",
-            test->url, test->exp_extrainfo, extrainfo);
+       test->url, url.dwExtraInfoLength);
+    ok(!strcmp(extrainfo_a, test->exp_extrainfo), "[%s] Got wrong extrainfo, expected: %s, got: %s\n",
+       test->url, test->exp_extrainfo, extrainfo_a);
 
     /* test InternetCrackUrlW with valid buffers */
     memset(&urlw, 0, sizeof(URL_COMPONENTSW));
     urlw.dwStructSize = sizeof(URL_COMPONENTSW);
-    urlw.lpszScheme = (WCHAR*)scheme;
-    urlw.dwSchemeLength = sizeof(scheme) / sizeof(WCHAR);
-    urlw.lpszHostName = (WCHAR*)hostname;
-    urlw.dwHostNameLength = sizeof(hostname) / sizeof(WCHAR);
-    urlw.lpszUserName = (WCHAR*)username;
-    urlw.dwUserNameLength = sizeof(username) / sizeof(WCHAR);
-    urlw.lpszPassword = (WCHAR*)password;
-    urlw.dwPasswordLength = sizeof(password) / sizeof(WCHAR);
-    urlw.lpszUrlPath = (WCHAR*)urlpath;
-    urlw.dwUrlPathLength = sizeof(urlpath) / sizeof(WCHAR);
-    urlw.lpszExtraInfo = (WCHAR*)extrainfo;
-    urlw.dwExtraInfoLength = sizeof(extrainfo) / sizeof(WCHAR);
+    urlw.lpszScheme = scheme_w;
+    urlw.dwSchemeLength = buf_len;
+    urlw.lpszHostName = hostname_w;
+    urlw.dwHostNameLength = buf_len;
+    urlw.lpszUserName = username_w;
+    urlw.dwUserNameLength = buf_len;
+    urlw.lpszPassword = password_w;
+    urlw.dwPasswordLength = buf_len;
+    urlw.lpszUrlPath = urlpath_w;
+    urlw.dwUrlPathLength = buf_len;
+    urlw.lpszExtraInfo = extrainfo_w;
+    urlw.dwExtraInfoLength = buf_len;
 
     b = InternetCrackUrlW(buf, lstrlenW(buf), 0, &urlw);
     ok(b, "InternetCrackUrlW failed with error %d\n", GetLastError());
 
     ok(urlw.dwSchemeLength == strlen(test->exp_scheme), "[%s] Got wrong scheme length: %d\n",
-            test->url, urlw.dwSchemeLength);
-    ok(!lstrcmpW((WCHAR*)scheme, w_str_of(test->exp_scheme)), "[%s] Got wrong scheme, expected: %s, got: %s\n",
-            test->url, test->exp_scheme, wine_dbgstr_w((WCHAR*)scheme));
+       test->url, urlw.dwSchemeLength);
+    ok(!strcmp_wa(scheme_w, test->exp_scheme), "[%s] Got wrong scheme, expected: %s, got: %s\n",
+       test->url, test->exp_scheme, wine_dbgstr_w(scheme_w));
 
     ok(urlw.nScheme == test->scheme, "[%s] Got wrong nScheme, expected: %d, got: %d\n",
-            test->url, test->scheme, urlw.nScheme);
+       test->url, test->scheme, urlw.nScheme);
 
     ok(urlw.dwHostNameLength == strlen(test->exp_hostname), "[%s] Got wrong hostname length: %d\n",
-            test->url, urlw.dwHostNameLength);
-    ok(!lstrcmpW((WCHAR*)hostname, w_str_of(test->exp_hostname)), "[%s] Got wrong hostname, expected: %s, got: %s\n",
-            test->url, test->exp_hostname, wine_dbgstr_w((WCHAR*)hostname));
+       test->url, urlw.dwHostNameLength);
+    ok(!strcmp_wa(hostname_w, test->exp_hostname), "[%s] Got wrong hostname, expected: %s, got: %s\n",
+       test->url, test->exp_hostname, wine_dbgstr_w(hostname_w));
 
     ok(urlw.nPort == test->port, "[%s] Got wrong port, expected: %d, got: %d\n",
-            test->url, test->port, urlw.nPort);
+       test->url, test->port, urlw.nPort);
 
     ok(urlw.dwUserNameLength == strlen(test->exp_username), "[%s] Got wrong username length: %d\n",
-            test->url, urlw.dwUserNameLength);
-    ok(!lstrcmpW((WCHAR*)username, w_str_of(test->exp_username)), "[%s] Got wrong username, expected: %s, got: %s\n",
-            test->url, test->exp_username, wine_dbgstr_w((WCHAR*)username));
+       test->url, urlw.dwUserNameLength);
+    ok(!strcmp_wa(username_w, test->exp_username), "[%s] Got wrong username, expected: %s, got: %s\n",
+       test->url, test->exp_username, wine_dbgstr_w(username_w));
 
     ok(urlw.dwPasswordLength == strlen(test->exp_password), "[%s] Got wrong password length: %d\n",
-            test->url, urlw.dwPasswordLength);
-    ok(!lstrcmpW((WCHAR*)password, w_str_of(test->exp_password)), "[%s] Got wrong password, expected: %s, got: %s\n",
-            test->url, test->exp_password, wine_dbgstr_w((WCHAR*)password));
+       test->url, urlw.dwPasswordLength);
+    ok(!strcmp_wa(password_w, test->exp_password), "[%s] Got wrong password, expected: %s, got: %s\n",
+       test->url, test->exp_password, wine_dbgstr_w(password_w));
 
     ok(urlw.dwUrlPathLength == strlen(test->exp_urlpath), "[%s] Got wrong urlpath length: %d\n",
-            test->url, urlw.dwUrlPathLength);
-    ok(!lstrcmpW((WCHAR*)urlpath, w_str_of(test->exp_urlpath)), "[%s] Got wrong urlpath, expected: %s, got: %s\n",
-            test->url, test->exp_urlpath, wine_dbgstr_w((WCHAR*)urlpath));
+       test->url, urlw.dwUrlPathLength);
+    ok(!strcmp_wa(urlpath_w, test->exp_urlpath), "[%s] Got wrong urlpath, expected: %s, got: %s\n",
+       test->url, test->exp_urlpath, wine_dbgstr_w(urlpath_w));
 
     ok(urlw.dwExtraInfoLength == strlen(test->exp_extrainfo), "[%s] Got wrong extrainfo length: %d\n",
-            test->url, urlw.dwExtraInfoLength);
-    ok(!lstrcmpW((WCHAR*)extrainfo, w_str_of(test->exp_extrainfo)), "[%s] Got wrong extrainfo, expected: %s, got: %s\n",
-            test->url, test->exp_extrainfo, wine_dbgstr_w((WCHAR*)extrainfo));
+       test->url, urlw.dwExtraInfoLength);
+    ok(!strcmp_wa(extrainfo_w, test->exp_extrainfo), "[%s] Got wrong extrainfo, expected: %s, got: %s\n",
+       test->url, test->exp_extrainfo, wine_dbgstr_w(extrainfo_w));
+
+    HeapFree(GetProcessHeap(), 0, scheme_w);
+    HeapFree(GetProcessHeap(), 0, hostname_w);
+    HeapFree(GetProcessHeap(), 0, username_w);
+    HeapFree(GetProcessHeap(), 0, password_w);
+    HeapFree(GetProcessHeap(), 0, urlpath_w);
+    HeapFree(GetProcessHeap(), 0, extrainfo_w);
+    HeapFree(GetProcessHeap(), 0, buf);
+}
+
+static void test_long_url(void)
+{
+    char long_buf[6000];
+    char long_url[sizeof(long_buf) + 1000];
+    crack_url_test_t test_long_path =
+        {long_url, 0, 4, INTERNET_SCHEME_HTTP, 7, 14, -1, 80, -1, 0, -1, 0, 21, sizeof(long_buf)-1, -1, 0,
+         "http", "www.winehq.org", "", "", long_buf, ""};
+    crack_url_test_t test_long_extra =
+        {long_url, 0, 4, INTERNET_SCHEME_HTTP, 7, 14, -1, 80, -1, 0, -1, 0, 21, 6, 27, sizeof(long_buf)-1,
+         "http", "www.winehq.org", "", "", "/path/", long_buf};
+    URL_COMPONENTSA url_comp;
+    BOOL b;
+
+    memset(long_buf, 'x', sizeof(long_buf));
+    long_buf[0] = '/';
+    long_buf[sizeof(long_buf)-1] = 0;
+
+    strcpy(long_url, "http://www.winehq.org");
+    strcat(long_url, long_buf);
+    test_crack_url(&test_long_path);
+
+    strcpy(long_url, "http://www.winehq.org/path/");
+    long_buf[0] = '#';
+    strcat(long_url, long_buf);
+    test_crack_url(&test_long_extra);
+
+    zero_compsA(&url_comp, 0, 0, 0, 0, 0, 100);
+    url_comp.lpszExtraInfo = long_buf;
+    b = InternetCrackUrlA(long_url, strlen(long_url), 0, &url_comp);
+    ok(!b && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetCrackUrlA returned %x with error %d\n", b, GetLastError());
+
+    zero_compsA(&url_comp, 4, 0, 0, 0, 0, 0);
+    url_comp.lpszScheme = long_buf;
+    b = InternetCrackUrlA(long_url, strlen(long_url), 0, &url_comp);
+    ok(!b && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetCrackUrlA returned %x with error %d\n", b, GetLastError());
 }
 
 static void InternetCrackUrl_test(void)
@@ -1152,6 +1222,8 @@ START_TEST(url)
     for(i=0; i < sizeof(crack_url_tests)/sizeof(*crack_url_tests); i++)
         test_crack_url(crack_url_tests+i);
 
+    test_long_url();
+
     InternetCrackUrl_test();
     InternetCrackUrlW_test();
     InternetCreateUrlA_test();