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;
+static BOOL is_ie7plus = TRUE;
#define TESTF_REDIRECT 0x01
#define TESTF_COMPRESSED 0x02
static void _test_status_code(unsigned line, HINTERNET req, DWORD excode, BOOL is_todo)
{
DWORD code, size, index;
- char exbuf[10], bufa[10];
+ char exbuf[12], bufa[10];
WCHAR bufw[10];
BOOL res;
size = sizeof(code);
res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, NULL);
ok_(__FILE__,line)(res, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
- if (is_todo)
- todo_wine ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
- else
+ todo_wine_if (is_todo)
ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
size = sizeof(code);
res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index);
ok_(__FILE__,line)(res, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
- if (is_todo)
- todo_wine ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
- else
- ok_(__FILE__,line)(!index, "index = %d, expected 0\n", code);
+ ok_(__FILE__,line)(!index, "index = %d, expected 0\n", index);
ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
sprintf(exbuf, "%u", excode);
size = sizeof(bufa);
res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, bufa, &size, NULL);
ok_(__FILE__,line)(res, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
- if (is_todo)
- todo_wine ok_(__FILE__,line)(!strcmp(bufa, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
- else
+ todo_wine_if (is_todo)
ok_(__FILE__,line)(!strcmp(bufa, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
ok_(__FILE__,line)(size == strlen(exbuf), "unexpected size %d for \"%s\"\n", size, exbuf);
size = sizeof(bufw);
res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL);
ok_(__FILE__,line)(res, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
- if (is_todo)
- todo_wine ok_(__FILE__,line)(!strcmp_wa(bufw, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
- else
+ todo_wine_if (is_todo)
ok_(__FILE__,line)(!strcmp_wa(bufw, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
ok_(__FILE__,line)(size == strlen(exbuf)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
/* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
flags &= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED;
- if(!is_todo)
+ todo_wine_if (is_todo)
ok_(__FILE__,line)(flags == exflags, "flags = %x, expected %x\n", flags, exflags);
- else
- todo_wine ok_(__FILE__,line)(flags == exflags, "flags = %x, expected %x\n", flags, exflags);
}
#define test_http_version(a) _test_http_version(__LINE__,a)
}
}
+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;
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);
CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
+ if(is_ie7plus) {
+ 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;
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
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");
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());
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),
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"
static int test_cache_gzip;
static const char *send_buffer;
+static int server_socket;
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);
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;
else
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, "Proxy-Authorization: Basic bWlrZToxMTAx"))
{
if (strstr(buffer, "Content-Length: 100"))
{
+ if (strstr(buffer, "POST /test7b"))
+ recvfrom(c, buffer, buffer_size, 0, NULL, NULL);
send(c, okmsg, sizeof okmsg-1, 0);
send(c, page1, sizeof page1-1, 0);
}
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"))
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);
}
}
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="))
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=="))
} 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, 0, 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");
+ open_simple_request(&req, "localhost", port, NULL, "/test2");
- 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)
{
}
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)
ok(r, "HttpQueryInfo failed\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:
InternetCloseHandle(hr);
InternetCloseHandle(hc);
connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
ok(connect != NULL, "InternetConnect failed\n");
- request = HttpOpenRequestA(connect, "POST", "/test7b", NULL, NULL, types, 0, 0);
+ request = HttpOpenRequestA(connect, "POST", "/test7b", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
ok(request != NULL, "HttpOpenRequest failed\n");
ret = HttpAddRequestHeadersA(request, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
data_len = sizeof(data);
memset(data, 'a', sizeof(data));
- ret = HttpSendRequestA(request, connection, ~0u, data, data_len);
- ok(ret, "HttpSendRequest failed\n");
+ ret = HttpSendRequestA(request, NULL, 0, data, data_len);
+ ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
status = 0;
size = sizeof(status);
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");
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;
hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
- session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
+ session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
pInternetSetStatusCallbackA(session, callback);
hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
conn_close_event = CreateEventW(NULL, FALSE, FALSE, NULL);
- session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
+ session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
pInternetSetStatusCallbackA(session, callback);
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");
+ open_simple_request(&req, "localhost", port, NULL, "/testE");
- 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");
-
- 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());
-
- 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());
+ open_simple_request(&req, "localhost", port, NULL, "/testG");
- test_request_flags(hr, INTERNET_REQFLAG_NO_HEADERS);
+ test_request_flags(req.request, 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");
+ open_simple_request(&req, "localhost", port, "HEAD", "/test_head");
- 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);
+ 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)
static void test_http_status(int port)
{
- HINTERNET ses, con, req;
+ test_request_t req;
char buf[1000];
DWORD i, size;
BOOL res;
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");
+ open_simple_request(&req, "localhost", port, NULL, "/send_from_buffer");
- 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");
-
- 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);
}
}
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_PRECONFIG, NULL, NULL, 0);
+ 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, "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);
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);
DWORD status, size;
BOOL ret;
- ses = InternetOpenA( "winetest", 0, NULL, NULL, 0 );
+ ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 );
ok( ses != NULL, "InternetOpenA failed\n" );
con = InternetConnectA( ses, "localhost", port, "user", "pwd",
InternetCloseHandle( con );
InternetCloseHandle( ses );
- ses = InternetOpenA( "winetest", 0, NULL, NULL, 0 );
+ ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 );
ok( ses != NULL, "InternetOpenA failed\n" );
con = InternetConnectA( ses, "localhost", port, NULL, NULL,
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_len(a,b,c,d,e,f) _readex_expect_sync_data_len(__LINE__,a,b,c,d,e,f)
+static void _readex_expect_sync_data_len(unsigned line, HINTERNET req, DWORD flags, INTERNET_BUFFERSW *buf,
+ DWORD buf_size, const char *exdata, DWORD len)
+{
+ 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 && exdata)
+ ok_(__FILE__,line)(!memcmp(buf->lpvBuffer, exdata, len), "Unexpected data\n");
+
+ CLEAR_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)
+{
+ _readex_expect_sync_data_len(line, req, flags, buf, buf_size, exdata, strlen(exdata));
+}
+
+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 send_response_len_and_wait(unsigned len, BOOL close_connection, INTERNET_BUFFERSW *buf)
+{
+ char *response;
+
+ response = HeapAlloc(GetProcessHeap(), 0, len+1);
+ memset(response, 'x', len);
+ response[len] = 0;
+ send_response_and_wait(response, close_connection, buf);
+ HeapFree(GetProcessHeap(), 0, response);
+}
+
+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");
+}
+
+#define expect_data_available(a,b) _expect_data_available(__LINE__,a,b)
+static DWORD _expect_data_available(unsigned line, HINTERNET req, int exsize)
+{
+ DWORD size = 0;
+ BOOL res;
+
+ res = InternetQueryDataAvailable(req, &size, 0, 0);
+ ok_(__FILE__,line)(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
+ if(exsize != -1)
+ ok_(__FILE__,line)(size == exsize, "size = %u, expected %u\n", size, exsize);
+
+ return size;
+}
+
+static void test_http_read(int port)
+{
+ INTERNET_BUFFERSW ib;
+ test_request_t req;
+ char buf[24000];
+ DWORD avail;
+
+ if(!is_ie7plus)
+ return;
+
+ 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);
+
+ open_read_test_request(port, &req,
+ "HTTP/1.1 200 OK\r\n"
+ "Server: winetest\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n"
+ "9\r\n123456789");
+ readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "123456789");
+ readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf));
+
+ send_response_and_wait("\r\n1\r\na\r\n1\r\nb\r", FALSE, &ib);
+ readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "ab");
+ readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf));
+
+ send_response_and_wait("\n3\r\nab", FALSE, &ib);
+ readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "ab");
+ readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf));
+
+ send_response_and_wait("c", FALSE, &ib);
+ readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "c");
+ readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf));
+
+ send_response_and_wait("\r\n1\r\nx\r\n0\r\n\r\n", TRUE, &ib);
+ readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "x");
+ readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "");
+
+ close_async_handle(req.session, hCompleteEvent, 2);
+
+ open_read_test_request(port, &req,
+ "HTTP/1.1 200 OK\r\n"
+ "Server: winetest\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n"
+ "3\r\n123\r\n");
+ readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "123");
+ readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf));
+
+ send_response_and_wait("0\r\n\r\n", TRUE, &ib);
+ readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "");
+
+ close_async_handle(req.session, hCompleteEvent, 2);
+
+ trace("Testing InternetQueryDataAvailable...\n");
+
+ open_read_test_request(port, &req,
+ "HTTP/1.1 200 OK\r\n"
+ "Server: winetest\r\n"
+ "\r\n"
+ "123");
+ expect_data_available(req.request, 3);
+ readex_expect_sync_data(req.request, IRF_NO_WAIT, &ib, sizeof(buf), "123");
+ readex_expect_async(req.request, IRF_NO_WAIT, &ib, sizeof(buf));
+
+ send_response_len_and_wait(20000, TRUE, &ib);
+ avail = expect_data_available(req.request, -1);
+ ok(avail < 17000, "avail = %u\n", avail);
+
+ SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION);
+ SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED);
+ close_async_handle(req.session, hCompleteEvent, 2);
+ todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
+ todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
+
+ 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;
+
+ if(!is_ie7plus)
+ return;
+
+ 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;
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);
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");
} 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 = {
CertFreeCertificateChain(chain);
}else {
ok_(__FILE__,line)(!res && GetLastError() == error,
- "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res, GetLastError(), error);
+ "InternetGetSecurityInfoByURLA returned: %x(%u), expected %u\n", res, GetLastError(), error);
}
}
* other versions never do. They also hang of following tests. We disable it for everything older
* than IE7.
*/
- if(!pInternetGetSecurityInfoByURLA) {
- win_skip("Skipping async open on too old wininet version.\n");
+ if(!is_ie7plus)
return;
- }
ctx.req = NULL;
ctx.event = CreateEventA(NULL, TRUE, FALSE, "Z:_home_hans_jaman-installer.exe_ev1");
WaitForSingleObject( info.wait, 10000 );
Sleep(100);
CloseHandle( info.wait );
+ DeleteCriticalSection( ¬ification_cs );
}
static HINTERNET closetest_session, closetest_req, closetest_conn;
static void test_connection_failure(void)
{
- HINTERNET session, connect, request;
+ test_request_t req;
DWORD error;
BOOL ret;
- session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG, 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;
+ if(!is_ie7plus)
+ return;
+
session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
ok(session != NULL, "InternetOpen failed\n");
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);
static void WINAPI header_cb( HINTERNET handle, DWORD_PTR ctx, DWORD status, LPVOID info, DWORD len )
{
- if (status == INTERNET_STATUS_REQUEST_COMPLETE) SetEvent( (HANDLE)ctx );
+ BOOL ret;
+ DWORD index, size;
+ char buf[256];
+
+ if (status == INTERNET_STATUS_SENDING_REQUEST)
+ {
+ ret = HttpAddRequestHeadersA( handle, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD );
+ ok( ret, "HttpAddRequestHeadersA failed %u\n", GetLastError() );
+ SetEvent( (HANDLE)ctx );
+ }
+ else if (status == INTERNET_STATUS_REQUEST_SENT)
+ {
+ index = 0;
+ size = sizeof(buf);
+ ret = HttpQueryInfoA( handle, HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
+ buf, &size, &index );
+ ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() );
+ ok( strstr( buf, "winetest: winetest" ) != NULL, "header missing\n" );
+ SetEvent( (HANDLE)ctx );
+ }
}
static void test_concurrent_header_access(void)
{
HINTERNET ses, con, req;
- DWORD index, len, err;
+ DWORD err;
BOOL ret;
- char buf[128];
HANDLE wait = CreateEventW( NULL, FALSE, FALSE, NULL );
ses = InternetOpenA( "winetest", 0, NULL, NULL, INTERNET_FLAG_ASYNC );
ok( !ret, "HttpSendRequestA succeeded\n" );
ok( err == ERROR_IO_PENDING, "got %u\n", ERROR_IO_PENDING );
- ret = HttpAddRequestHeadersA( req, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD );
- ok( ret, "HttpAddRequestHeadersA failed %u\n", GetLastError() );
-
- index = 0;
- len = sizeof(buf);
- ret = HttpQueryInfoA( req, HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
- buf, &len, &index );
- ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() );
- ok( strstr( buf, "winetest: winetest" ) != NULL, "header missing\n" );
-
+ WaitForSingleObject( wait, 5000 );
WaitForSingleObject( wait, 5000 );
InternetCloseHandle( req );
pInternetSetStatusCallbackW = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackW");
pInternetGetSecurityInfoByURLA = (void*)GetProcAddress(hdll, "InternetGetSecurityInfoByURLA");
+ if(!pInternetGetSecurityInfoByURLA) {
+ is_ie7plus = FALSE;
+ win_skip("IE6 found. It's too old for some tests.\n");
+ }
+
init_status_tests();
test_InternetCloseHandle();
InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[0]);