4 * Copyright 2002 Aric Stewart
5 * Copyright 2004 Mike McCormack
6 * Copyright 2005 Hans Leidekker
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/test.h"
35 #define TEST_URL "http://test.winehq.org/tests/hello.html"
37 static BOOL first_connection_to_test_url = TRUE;
39 /* Adapted from dlls/urlmon/tests/protocol.c */
41 #define SET_EXPECT2(status, num) \
44 #define SET_EXPECT(status) \
45 SET_EXPECT2(status, 1)
47 #define SET_OPTIONAL2(status, num) \
48 optional[status] = num
50 #define SET_OPTIONAL(status) \
51 SET_OPTIONAL2(status, 1)
53 /* SET_WINE_ALLOW's should be used with an appropriate
54 * todo_wine CHECK_NOTIFIED at a later point in the code */
55 #define SET_WINE_ALLOW2(status, num) \
56 wine_allow[status] = num
58 #define SET_WINE_ALLOW(status) \
59 SET_WINE_ALLOW2(status, 1)
61 #define CHECK_EXPECT(status) \
63 if (!expect[status] && !optional[status] && wine_allow[status]) \
65 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
66 status < MAX_INTERNET_STATUS && status_string[status] ? \
67 status_string[status] : "unknown"); \
68 wine_allow[status]--; \
72 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
73 status < MAX_INTERNET_STATUS && status_string[status] ? \
74 status_string[status] : "unknown"); \
75 if (expect[status]) expect[status]--; \
76 else optional[status]--; \
81 /* CLEAR_NOTIFIED used in cases when notification behavior
82 * differs between Windows versions */
83 #define CLEAR_NOTIFIED(status) \
84 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
86 #define CHECK_NOTIFIED2(status, num) \
88 ok(notified[status] + optional[status] == (num), \
89 "expected status %d (%s) %d times, received %d times\n", \
90 status, status < MAX_INTERNET_STATUS && status_string[status] ? \
91 status_string[status] : "unknown", (num), notified[status]); \
92 CLEAR_NOTIFIED(status); \
95 #define CHECK_NOTIFIED(status) \
96 CHECK_NOTIFIED2(status, 1)
98 #define CHECK_NOT_NOTIFIED(status) \
99 CHECK_NOTIFIED2(status, 0)
101 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
102 static int expect[MAX_INTERNET_STATUS], optional[MAX_INTERNET_STATUS],
103 wine_allow[MAX_INTERNET_STATUS], notified[MAX_INTERNET_STATUS];
104 static const char *status_string[MAX_INTERNET_STATUS];
106 static HANDLE hCompleteEvent, conn_close_event;
107 static DWORD req_error;
109 #define TESTF_REDIRECT 0x01
110 #define TESTF_COMPRESSED 0x02
111 #define TESTF_CHUNKED 0x04
115 const char *redirected_url;
120 const char *post_data;
124 static const test_data_t test_data[] = {
126 "http://test.winehq.org/tests/data.php",
127 "http://test.winehq.org/tests/data.php",
134 "http://test.winehq.org/tests/redirect",
135 "http://test.winehq.org/tests/hello.html",
142 "http://www.codeweavers.com/",
143 "http://www.codeweavers.com/",
144 "www.codeweavers.com",
146 "Accept-Encoding: gzip, deflate",
150 "http://test.winehq.org/tests/post.php",
151 "http://test.winehq.org/tests/post.php",
154 "Content-Type: application/x-www-form-urlencoded",
161 static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackA)(HINTERNET ,INTERNET_STATUS_CALLBACK);
162 static BOOL (WINAPI *pInternetGetSecurityInfoByURLA)(LPSTR,PCCERT_CHAIN_CONTEXT*,DWORD*);
164 static int strcmp_wa(LPCWSTR strw, const char *stra)
167 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
168 return lstrcmpW(strw, buf);
171 static BOOL proxy_active(void)
173 HKEY internet_settings;
177 if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
178 0, KEY_QUERY_VALUE, &internet_settings) != ERROR_SUCCESS)
181 size = sizeof(DWORD);
182 if (RegQueryValueExA(internet_settings, "ProxyEnable", NULL, NULL, (LPBYTE) &proxy_enable, &size) != ERROR_SUCCESS)
185 RegCloseKey(internet_settings);
187 return proxy_enable != 0;
190 #define test_status_code(a,b) _test_status_code(__LINE__,a,b)
191 static void _test_status_code(unsigned line, HINTERNET req, DWORD excode)
193 DWORD code, size, index;
194 char exbuf[10], bufa[10];
200 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, NULL);
201 ok_(__FILE__,line)(res, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
202 ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
203 ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
208 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index);
209 ok_(__FILE__,line)(res, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
210 ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
211 ok_(__FILE__,line)(!index, "index = %d, expected 0\n", code);
212 ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
214 sprintf(exbuf, "%u", excode);
217 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, bufa, &size, NULL);
218 ok_(__FILE__,line)(res, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
219 ok_(__FILE__,line)(!strcmp(bufa, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
220 ok_(__FILE__,line)(size == strlen(exbuf), "unexpected size %d for \"%s\"\n", size, exbuf);
223 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, NULL, &size, NULL);
224 ok_(__FILE__,line)(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
225 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
226 ok_(__FILE__,line)(size == strlen(exbuf)+1, "unexpected size %d for \"%s\"\n", size, exbuf);
229 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL);
230 ok_(__FILE__,line)(res, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
231 ok_(__FILE__,line)(!strcmp_wa(bufw, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
232 ok_(__FILE__,line)(size == strlen(exbuf)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
235 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL);
236 ok_(__FILE__,line)(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
237 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
238 ok_(__FILE__,line)(size == (strlen(exbuf)+1)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
242 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, NULL, &size, NULL);
243 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
244 ok(size == sizeof(bufw), "unexpected size %d\n", size);
250 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index);
251 ok_(__FILE__,line)(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
252 "[7] HttpQueryInfoA failed: %x(%d)\n", res, GetLastError());
256 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_REQUEST_HEADERS, &code, &size, NULL);
257 ok_(__FILE__,line)(!res && GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST,
258 "[8] HttpQueryInfoA failed: %x(%d)\n", res, GetLastError());
261 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
262 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
263 static void _test_request_flags(unsigned line, HINTERNET req, DWORD exflags, BOOL is_todo)
269 size = sizeof(flags);
270 res = InternetQueryOptionW(req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &size);
271 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
273 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
274 flags &= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED;
276 ok_(__FILE__,line)(flags == exflags, "flags = %x, expected %x\n", flags, exflags);
278 todo_wine ok_(__FILE__,line)(flags == exflags, "flags = %x, expected %x\n", flags, exflags);
281 #define test_http_version(a) _test_http_version(__LINE__,a)
282 static void _test_http_version(unsigned line, HINTERNET req)
284 HTTP_VERSION_INFO v = {0xdeadbeef, 0xdeadbeef};
289 res = InternetQueryOptionW(req, INTERNET_OPTION_HTTP_VERSION, &v, &size);
290 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
291 ok_(__FILE__,line)(v.dwMajorVersion == 1, "dwMajorVersion = %d\n", v.dwMajorVersion);
292 ok_(__FILE__,line)(v.dwMinorVersion == 1, "dwMinorVersion = %d\n", v.dwMinorVersion);
295 static int close_handle_cnt;
297 static VOID WINAPI callback(
300 DWORD dwInternetStatus,
301 LPVOID lpvStatusInformation,
302 DWORD dwStatusInformationLength
305 CHECK_EXPECT(dwInternetStatus);
306 switch (dwInternetStatus)
308 case INTERNET_STATUS_RESOLVING_NAME:
309 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
310 GetCurrentThreadId(), hInternet, dwContext,
311 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
312 *(LPSTR)lpvStatusInformation = '\0';
314 case INTERNET_STATUS_NAME_RESOLVED:
315 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
316 GetCurrentThreadId(), hInternet, dwContext,
317 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
318 *(LPSTR)lpvStatusInformation = '\0';
320 case INTERNET_STATUS_CONNECTING_TO_SERVER:
321 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
322 GetCurrentThreadId(), hInternet, dwContext,
323 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
324 *(LPSTR)lpvStatusInformation = '\0';
326 case INTERNET_STATUS_CONNECTED_TO_SERVER:
327 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
328 GetCurrentThreadId(), hInternet, dwContext,
329 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
330 *(LPSTR)lpvStatusInformation = '\0';
332 case INTERNET_STATUS_SENDING_REQUEST:
333 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
334 GetCurrentThreadId(), hInternet, dwContext,
335 lpvStatusInformation,dwStatusInformationLength);
337 case INTERNET_STATUS_REQUEST_SENT:
338 ok(dwStatusInformationLength == sizeof(DWORD),
339 "info length should be sizeof(DWORD) instead of %d\n",
340 dwStatusInformationLength);
341 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
342 GetCurrentThreadId(), hInternet, dwContext,
343 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
345 case INTERNET_STATUS_RECEIVING_RESPONSE:
346 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
347 GetCurrentThreadId(), hInternet, dwContext,
348 lpvStatusInformation,dwStatusInformationLength);
350 case INTERNET_STATUS_RESPONSE_RECEIVED:
351 ok(dwStatusInformationLength == sizeof(DWORD),
352 "info length should be sizeof(DWORD) instead of %d\n",
353 dwStatusInformationLength);
354 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
355 GetCurrentThreadId(), hInternet, dwContext,
356 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
358 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
359 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
360 GetCurrentThreadId(), hInternet,dwContext,
361 lpvStatusInformation,dwStatusInformationLength);
363 case INTERNET_STATUS_PREFETCH:
364 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
365 GetCurrentThreadId(), hInternet, dwContext,
366 lpvStatusInformation,dwStatusInformationLength);
368 case INTERNET_STATUS_CLOSING_CONNECTION:
369 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
370 GetCurrentThreadId(), hInternet, dwContext,
371 lpvStatusInformation,dwStatusInformationLength);
373 case INTERNET_STATUS_CONNECTION_CLOSED:
374 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
375 GetCurrentThreadId(), hInternet, dwContext,
376 lpvStatusInformation,dwStatusInformationLength);
378 case INTERNET_STATUS_HANDLE_CREATED:
379 ok(dwStatusInformationLength == sizeof(HINTERNET),
380 "info length should be sizeof(HINTERNET) instead of %d\n",
381 dwStatusInformationLength);
382 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
383 GetCurrentThreadId(), hInternet, dwContext,
384 *(HINTERNET *)lpvStatusInformation,dwStatusInformationLength);
385 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
386 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
388 case INTERNET_STATUS_HANDLE_CLOSING:
389 ok(dwStatusInformationLength == sizeof(HINTERNET),
390 "info length should be sizeof(HINTERNET) instead of %d\n",
391 dwStatusInformationLength);
392 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
393 GetCurrentThreadId(), hInternet, dwContext,
394 *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength);
395 if(!--close_handle_cnt)
396 SetEvent(hCompleteEvent);
398 case INTERNET_STATUS_REQUEST_COMPLETE:
400 INTERNET_ASYNC_RESULT *iar = (INTERNET_ASYNC_RESULT *)lpvStatusInformation;
401 ok(dwStatusInformationLength == sizeof(INTERNET_ASYNC_RESULT),
402 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
403 dwStatusInformationLength);
404 ok(iar->dwResult == 1 || iar->dwResult == 0, "iar->dwResult = %ld\n", iar->dwResult);
405 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
406 GetCurrentThreadId(), hInternet, dwContext,
407 iar->dwResult,iar->dwError,dwStatusInformationLength);
408 req_error = iar->dwError;
409 SetEvent(hCompleteEvent);
412 case INTERNET_STATUS_REDIRECT:
413 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
414 GetCurrentThreadId(), hInternet, dwContext,
415 (LPCSTR)lpvStatusInformation, dwStatusInformationLength);
416 *(LPSTR)lpvStatusInformation = '\0';
417 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
418 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
420 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
421 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
422 GetCurrentThreadId(), hInternet, dwContext,
423 lpvStatusInformation, dwStatusInformationLength);
426 trace("%04x:Callback %p 0x%lx %d %p %d\n",
427 GetCurrentThreadId(), hInternet, dwContext, dwInternetStatus,
428 lpvStatusInformation, dwStatusInformationLength);
432 static void close_async_handle(HINTERNET handle, HANDLE complete_event, int handle_cnt)
436 close_handle_cnt = handle_cnt;
438 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
439 res = InternetCloseHandle(handle);
440 ok(res, "InternetCloseHandle failed: %u\n", GetLastError());
441 WaitForSingleObject(hCompleteEvent, INFINITE);
442 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
443 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
446 static void InternetReadFile_test(int flags, const test_data_t *test)
448 char *post_data = NULL;
449 BOOL res, on_async = TRUE;
451 DWORD length, post_len = 0;
452 const char *types[2] = { "*", NULL };
453 HINTERNET hi, hic = 0, hor = 0;
455 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
457 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags,test->url);
459 trace("InternetOpenA <--\n");
460 hi = InternetOpenA((test->flags & TESTF_COMPRESSED) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
461 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
462 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
463 trace("InternetOpenA -->\n");
465 if (hi == 0x0) goto abort;
467 pInternetSetStatusCallbackA(hi,&callback);
469 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
471 trace("InternetConnectA <--\n");
472 hic=InternetConnectA(hi, test->host, INTERNET_INVALID_PORT_NUMBER,
473 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
474 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
475 trace("InternetConnectA -->\n");
477 if (hic == 0x0) goto abort;
479 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
480 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
482 trace("HttpOpenRequestA <--\n");
483 hor = HttpOpenRequestA(hic, test->post_data ? "POST" : "GET", test->path, NULL, NULL, types,
484 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
486 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
488 * If the internet name can't be resolved we are probably behind
489 * a firewall or in some other way not directly connected to the
490 * Internet. Not enough reason to fail the test. Just ignore and
494 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
496 trace("HttpOpenRequestA -->\n");
498 if (hor == 0x0) goto abort;
500 test_request_flags(hor, INTERNET_REQFLAG_NO_HEADERS);
502 length = sizeof(buffer);
503 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
504 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
505 ok(!strcmp(buffer, test->url), "Wrong URL %s, expected %s\n", buffer, test->url);
507 length = sizeof(buffer);
508 res = HttpQueryInfoA(hor, HTTP_QUERY_RAW_HEADERS, buffer, &length, 0x0);
509 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
510 ok(length == 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length);
511 ok(!strcmp(buffer, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer);
513 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
514 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
515 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
516 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT,2);
517 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED,2);
518 if (first_connection_to_test_url)
520 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
521 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
523 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
524 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
525 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, (test->flags & TESTF_REDIRECT) ? 2 : 1);
526 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, (test->flags & TESTF_REDIRECT) ? 2 : 1);
527 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, (test->flags & TESTF_REDIRECT) ? 2 : 1);
528 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, (test->flags & TESTF_REDIRECT) ? 2 : 1);
529 if(test->flags & TESTF_REDIRECT) {
530 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
531 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
533 SET_EXPECT(INTERNET_STATUS_REDIRECT);
534 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER);
535 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER);
536 if (flags & INTERNET_FLAG_ASYNC)
537 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
539 if(test->flags & TESTF_COMPRESSED) {
542 res = InternetSetOption(hor, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b));
543 ok(res || broken(!res && GetLastError() == ERROR_INTERNET_INVALID_OPTION),
544 "InternetSetOption failed: %u\n", GetLastError());
549 test_status_code(hor, 0);
551 trace("HttpSendRequestA -->\n");
552 if(test->post_data) {
553 post_len = strlen(test->post_data);
554 post_data = HeapAlloc(GetProcessHeap(), 0, post_len);
555 memcpy(post_data, test->post_data, post_len);
557 SetLastError(0xdeadbeef);
558 res = HttpSendRequestA(hor, test->headers, -1, post_data, post_len);
559 if (flags & INTERNET_FLAG_ASYNC)
560 ok(!res && (GetLastError() == ERROR_IO_PENDING),
561 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
563 ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED),
564 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
565 trace("HttpSendRequestA <--\n");
567 if (flags & INTERNET_FLAG_ASYNC) {
568 WaitForSingleObject(hCompleteEvent, INFINITE);
569 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
571 HeapFree(GetProcessHeap(), 0, post_data);
573 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
574 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED);
575 if (first_connection_to_test_url)
577 if (! proxy_active())
579 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
580 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
584 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
585 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
590 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
591 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
593 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, (test->flags & TESTF_REDIRECT) ? 2 : 1);
594 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, (test->flags & TESTF_REDIRECT) ? 2 : 1);
595 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, (test->flags & TESTF_REDIRECT) ? 2 : 1);
596 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, (test->flags & TESTF_REDIRECT) ? 2 : 1);
597 if(test->flags & TESTF_REDIRECT)
598 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
599 if (flags & INTERNET_FLAG_ASYNC)
600 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
601 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
602 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
603 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
605 test_request_flags(hor, 0);
608 res = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
609 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
611 length = sizeof(buffer);
612 res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0);
613 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
616 length = sizeof(buffer);
617 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
618 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
619 ok(!strcmp(buffer, test->redirected_url), "Wrong URL %s\n", buffer);
622 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
623 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res,buffer,GetLastError());
624 if(test->flags & TESTF_COMPRESSED)
625 ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
626 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res, GetLastError());
629 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
631 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res,buffer);
634 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_ENCODING,buffer,&length,0x0);
636 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res,buffer);
638 SetLastError(0xdeadbeef);
639 res = InternetReadFile(NULL, buffer, 100, &length);
640 ok(!res, "InternetReadFile should have failed\n");
641 ok(GetLastError() == ERROR_INVALID_HANDLE,
642 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
646 trace("Entering Query loop\n");
650 if (flags & INTERNET_FLAG_ASYNC)
651 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
652 res = InternetQueryDataAvailable(hor,&length,0x0,0x0);
653 if (flags & INTERNET_FLAG_ASYNC)
657 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
659 else if (GetLastError() == ERROR_IO_PENDING)
662 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
663 if(!(test->flags & TESTF_CHUNKED))
664 ok(!length, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length);
665 WaitForSingleObject(hCompleteEvent, INFINITE);
666 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
667 ok(req_error, "req_error = 0\n");
670 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
673 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
675 trace("LENGTH %d\n", length);
676 if(test->flags & TESTF_CHUNKED)
677 ok(length <= 8192, "length = %d, expected <= 8192\n", length);
681 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
683 res = InternetReadFile(hor,buffer,length,&length);
687 trace("ReadFile -> %s %i\n",res?"TRUE":"FALSE",length);
690 ok(!strcmp(buffer, test->content), "buffer = '%s', expected '%s'\n", buffer, test->content);
691 HeapFree(GetProcessHeap(),0,buffer);
693 ok(!on_async, "Returned zero size in response to request complete\n");
698 if(test->flags & TESTF_REDIRECT) {
699 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
700 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
704 close_async_handle(hi, hCompleteEvent, 2);
705 CloseHandle(hCompleteEvent);
706 first_connection_to_test_url = FALSE;
709 static void InternetReadFile_chunked_test(void)
714 const char *types[2] = { "*", NULL };
715 HINTERNET hi, hic = 0, hor = 0;
717 trace("Starting InternetReadFile chunked test\n");
719 trace("InternetOpenA <--\n");
720 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
721 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
722 trace("InternetOpenA -->\n");
724 if (hi == 0x0) goto abort;
726 trace("InternetConnectA <--\n");
727 hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER,
728 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
729 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
730 trace("InternetConnectA -->\n");
732 if (hic == 0x0) goto abort;
734 trace("HttpOpenRequestA <--\n");
735 hor = HttpOpenRequestA(hic, "GET", "/tests/chunked", NULL, NULL, types,
736 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
738 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
740 * If the internet name can't be resolved we are probably behind
741 * a firewall or in some other way not directly connected to the
742 * Internet. Not enough reason to fail the test. Just ignore and
746 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
748 trace("HttpOpenRequestA -->\n");
750 if (hor == 0x0) goto abort;
752 trace("HttpSendRequestA -->\n");
753 SetLastError(0xdeadbeef);
754 res = HttpSendRequestA(hor, "", -1, NULL, 0);
755 ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED),
756 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
757 trace("HttpSendRequestA <--\n");
759 test_request_flags(hor, 0);
762 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
764 trace("Option CONTENT_TYPE -> %i %s\n",res,buffer);
766 SetLastError( 0xdeadbeef );
768 res = HttpQueryInfoA(hor,HTTP_QUERY_TRANSFER_ENCODING,buffer,&length,0x0);
770 trace("Option TRANSFER_ENCODING -> %i %s\n",res,buffer);
771 ok( res || ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND ),
772 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
773 ok( !strcmp( buffer, "chunked" ) || ( ! res && proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND ),
774 "Wrong transfer encoding '%s'\n", buffer );
776 SetLastError( 0xdeadbeef );
778 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
779 ok( !res, "Found CONTENT_LENGTH option '%s'\n", buffer );
780 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "Wrong error %u\n", GetLastError() );
783 trace("Entering Query loop\n");
787 res = InternetQueryDataAvailable(hor,&length,0x0,0x0);
788 ok(!(!res && length != 0),"InternetQueryDataAvailable failed with non-zero length\n");
789 ok(res, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
790 trace("got %u available\n",length);
794 char *buffer = HeapAlloc(GetProcessHeap(),0,length+1);
796 res = InternetReadFile(hor,buffer,length,&got);
799 trace("ReadFile -> %i %i\n",res,got);
800 ok( length == got, "only got %u of %u available\n", got, length );
801 ok( buffer[got-1] == '\n', "received partial line '%s'\n", buffer );
803 HeapFree(GetProcessHeap(),0,buffer);
812 res = InternetCloseHandle(hor);
813 ok (res, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
816 res = InternetCloseHandle(hi);
817 ok (res, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
821 static void InternetReadFileExA_test(int flags)
825 const char *types[2] = { "*", NULL };
826 HINTERNET hi, hic = 0, hor = 0;
827 INTERNET_BUFFERS inetbuffers;
829 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
831 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags);
833 trace("InternetOpenA <--\n");
834 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
835 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
836 trace("InternetOpenA -->\n");
838 if (hi == 0x0) goto abort;
840 pInternetSetStatusCallbackA(hi,&callback);
842 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
844 trace("InternetConnectA <--\n");
845 hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER,
846 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
847 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
848 trace("InternetConnectA -->\n");
850 if (hic == 0x0) goto abort;
852 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
853 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
855 trace("HttpOpenRequestA <--\n");
856 hor = HttpOpenRequestA(hic, "GET", "/tests/redirect", NULL, NULL, types,
857 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
859 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
861 * If the internet name can't be resolved we are probably behind
862 * a firewall or in some other way not directly connected to the
863 * Internet. Not enough reason to fail the test. Just ignore and
867 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
869 trace("HttpOpenRequestA -->\n");
871 if (hor == 0x0) goto abort;
873 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
874 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
875 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
876 if (first_connection_to_test_url)
878 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
879 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
881 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT, 2);
882 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
883 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
884 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, 2);
885 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, 2);
886 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
887 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
888 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
889 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
890 SET_EXPECT(INTERNET_STATUS_REDIRECT);
891 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER);
892 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER);
893 if (flags & INTERNET_FLAG_ASYNC)
894 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
896 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
898 trace("HttpSendRequestA -->\n");
899 SetLastError(0xdeadbeef);
900 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
901 if (flags & INTERNET_FLAG_ASYNC)
902 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
903 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
905 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
906 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
907 trace("HttpSendRequestA <--\n");
909 if (!rc && (GetLastError() == ERROR_IO_PENDING)) {
910 WaitForSingleObject(hCompleteEvent, INFINITE);
911 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
914 if (first_connection_to_test_url)
916 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
917 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
921 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
922 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
924 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, 2);
925 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, 2);
926 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
927 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
928 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
929 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
930 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
931 if (flags & INTERNET_FLAG_ASYNC)
932 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
934 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
935 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
936 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
937 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
938 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
940 /* tests invalid dwStructSize */
941 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS)+1;
942 inetbuffers.lpcszHeader = NULL;
943 inetbuffers.dwHeadersLength = 0;
944 inetbuffers.dwBufferLength = 10;
945 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10);
946 inetbuffers.dwOffsetHigh = 1234;
947 inetbuffers.dwOffsetLow = 5678;
948 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
949 ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
950 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
951 rc ? "TRUE" : "FALSE", GetLastError());
952 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
954 test_request_flags(hor, 0);
956 /* tests to see whether lpcszHeader is used - it isn't */
957 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
958 inetbuffers.lpcszHeader = (LPCTSTR)0xdeadbeef;
959 inetbuffers.dwHeadersLength = 255;
960 inetbuffers.dwBufferLength = 0;
961 inetbuffers.lpvBuffer = NULL;
962 inetbuffers.dwOffsetHigh = 1234;
963 inetbuffers.dwOffsetLow = 5678;
964 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
965 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
966 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
967 ok(rc, "InternetReadFileEx failed with error %u\n", GetLastError());
968 trace("read %i bytes\n", inetbuffers.dwBufferLength);
971 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
972 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
975 rc = InternetReadFileEx(NULL, &inetbuffers, 0, 0xdeadcafe);
976 ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE),
977 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
978 rc ? "TRUE" : "FALSE", GetLastError());
981 trace("Entering Query loop\n");
985 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
986 inetbuffers.dwBufferLength = 1024;
987 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1);
988 inetbuffers.dwOffsetHigh = 1234;
989 inetbuffers.dwOffsetLow = 5678;
991 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE);
992 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED);
993 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
994 rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe);
997 if (GetLastError() == ERROR_IO_PENDING)
999 trace("InternetReadFileEx -> PENDING\n");
1000 ok(flags & INTERNET_FLAG_ASYNC,
1001 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1002 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1003 WaitForSingleObject(hCompleteEvent, INFINITE);
1004 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1005 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1006 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
1010 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1016 trace("InternetReadFileEx -> SUCCEEDED\n");
1017 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1018 if (inetbuffers.dwBufferLength)
1021 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1022 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1027 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1028 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1029 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1033 trace("read %i bytes\n", inetbuffers.dwBufferLength);
1034 ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
1036 ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678,
1037 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1038 inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
1040 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
1042 if (!inetbuffers.dwBufferLength)
1045 length += inetbuffers.dwBufferLength;
1047 ok(length > 0, "failed to read any of the document\n");
1048 trace("Finished. Read %d bytes\n", length);
1051 close_async_handle(hi, hCompleteEvent, 2);
1052 CloseHandle(hCompleteEvent);
1053 first_connection_to_test_url = FALSE;
1056 static void InternetOpenUrlA_test(void)
1058 HINTERNET myhinternet, myhttp;
1060 DWORD size, readbytes, totalbytes=0;
1063 myhinternet = InternetOpen("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
1064 ok((myhinternet != 0), "InternetOpen failed, error %u\n",GetLastError());
1066 ret = InternetCanonicalizeUrl(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
1067 ok( ret, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1070 myhttp = InternetOpenUrl(myhinternet, TEST_URL, 0, 0,
1071 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
1072 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1073 return; /* WinXP returns this when not connected to the net */
1074 ok((myhttp != 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1075 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
1076 ok( ret, "InternetReadFile failed, error %u\n",GetLastError());
1077 totalbytes += readbytes;
1078 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
1079 totalbytes += readbytes;
1080 trace("read 0x%08x bytes\n",totalbytes);
1082 InternetCloseHandle(myhttp);
1083 InternetCloseHandle(myhinternet);
1086 static void HttpSendRequestEx_test(void)
1092 INTERNET_BUFFERS BufferIn;
1093 DWORD dwBytesWritten, dwBytesRead, error;
1098 static char szPostData[] = "mode=Test";
1099 static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
1101 hSession = InternetOpen("Wine Regression Test",
1102 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1103 ok( hSession != NULL ,"Unable to open Internet session\n");
1104 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
1105 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1107 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
1108 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
1109 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1110 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1112 skip( "Network unreachable, skipping test\n" );
1115 ok( hRequest != NULL, "Failed to open request handle err %u\n", GetLastError());
1117 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1119 BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS);
1120 BufferIn.Next = (LPINTERNET_BUFFERS)0xdeadcab;
1121 BufferIn.lpcszHeader = szContentType;
1122 BufferIn.dwHeadersLength = sizeof(szContentType)-1;
1123 BufferIn.dwHeadersTotal = sizeof(szContentType)-1;
1124 BufferIn.lpvBuffer = szPostData;
1125 BufferIn.dwBufferLength = 3;
1126 BufferIn.dwBufferTotal = sizeof(szPostData)-1;
1127 BufferIn.dwOffsetLow = 0;
1128 BufferIn.dwOffsetHigh = 0;
1130 SetLastError(0xdeadbeef);
1131 ret = HttpSendRequestEx(hRequest, &BufferIn, NULL, 0 ,0);
1132 error = GetLastError();
1133 ok(ret, "HttpSendRequestEx Failed with error %u\n", error);
1134 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", error);
1136 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1138 for (i = 3; szPostData[i]; i++)
1139 ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten),
1140 "InternetWriteFile failed\n");
1142 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1144 ok(HttpEndRequest(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
1146 test_request_flags(hRequest, 0);
1148 ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead),
1149 "Unable to read response\n");
1150 szBuffer[dwBytesRead] = 0;
1152 ok(dwBytesRead == 13,"Read %u bytes instead of 13\n",dwBytesRead);
1153 ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0 || broken(proxy_active()),"Got string %s\n",szBuffer);
1155 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1157 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1158 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1161 static void InternetOpenRequest_test(void)
1163 HINTERNET session, connect, request;
1164 static const char *types[] = { "*", "", NULL };
1165 static const WCHAR slash[] = {'/', 0}, any[] = {'*', 0}, empty[] = {0};
1166 static const WCHAR *typesW[] = { any, empty, NULL };
1169 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1170 ok(session != NULL ,"Unable to open Internet session\n");
1172 connect = InternetConnectA(session, NULL, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1173 INTERNET_SERVICE_HTTP, 0, 0);
1174 ok(connect == NULL, "InternetConnectA should have failed\n");
1175 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1177 connect = InternetConnectA(session, "", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1178 INTERNET_SERVICE_HTTP, 0, 0);
1179 ok(connect == NULL, "InternetConnectA should have failed\n");
1180 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1182 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1183 INTERNET_SERVICE_HTTP, 0, 0);
1184 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1186 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1187 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1189 skip( "Network unreachable, skipping test\n" );
1192 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1194 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1195 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1196 ok(InternetCloseHandle(request), "Close request handle failed\n");
1198 request = HttpOpenRequestW(connect, NULL, slash, NULL, NULL, typesW, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1199 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1201 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1202 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1203 ok(InternetCloseHandle(request), "Close request handle failed\n");
1206 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1207 ok(InternetCloseHandle(session), "Close session handle failed\n");
1210 static void test_http_cache(void)
1212 HINTERNET session, connect, request;
1213 char file_name[MAX_PATH], url[INTERNET_MAX_URL_LENGTH];
1214 DWORD size, file_size;
1219 static const char *types[] = { "*", "", NULL };
1221 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1222 ok(session != NULL ,"Unable to open Internet session\n");
1224 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1225 INTERNET_SERVICE_HTTP, 0, 0);
1226 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1228 request = HttpOpenRequestA(connect, NULL, "/tests/hello.html", NULL, NULL, types, INTERNET_FLAG_NEED_FILE, 0);
1229 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1231 skip( "Network unreachable, skipping test\n" );
1233 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1234 ok(InternetCloseHandle(session), "Close session handle failed\n");
1238 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1241 ret = InternetQueryOptionA(request, INTERNET_OPTION_URL, url, &size);
1242 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1243 ok(!strcmp(url, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url);
1245 size = sizeof(file_name);
1246 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1247 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1248 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1249 ok(!size, "size = %d\n", size);
1251 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1252 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1254 size = sizeof(file_name);
1255 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1256 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1258 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
1259 FILE_ATTRIBUTE_NORMAL, NULL);
1260 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1261 file_size = GetFileSize(file, NULL);
1262 ok(file_size == 106, "file size = %u\n", file_size);
1265 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1266 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1267 ok(size == 100, "size = %u\n", size);
1269 file_size = GetFileSize(file, NULL);
1270 ok(file_size == 106, "file size = %u\n", file_size);
1273 ok(InternetCloseHandle(request), "Close request handle failed\n");
1275 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1276 FILE_ATTRIBUTE_NORMAL, NULL);
1277 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1280 /* Send the same request, requiring it to be retrieved from the cache */
1281 request = HttpOpenRequest(connect, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
1283 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1284 ok(ret, "HttpSendRequest failed\n");
1287 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1288 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1289 ok(size == 100, "size = %u\n", size);
1291 ok(InternetCloseHandle(request), "Close request handle failed\n");
1293 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1294 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1296 size = sizeof(file_name);
1297 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1298 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1299 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1300 ok(!size, "size = %d\n", size);
1302 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1303 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1305 size = sizeof(file_name);
1307 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1310 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1311 FILE_ATTRIBUTE_NORMAL, NULL);
1312 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1318 ok(file_name[0] == 0, "Didn't expect a file name\n");
1321 ok(InternetCloseHandle(request), "Close request handle failed\n");
1322 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1323 ok(InternetCloseHandle(session), "Close session handle failed\n");
1326 static void HttpHeaders_test(void)
1337 hSession = InternetOpen("Wine Regression Test",
1338 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1339 ok( hSession != NULL ,"Unable to open Internet session\n");
1340 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
1341 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1343 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
1344 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
1345 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1346 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1348 skip( "Network unreachable, skipping test\n" );
1351 ok( hRequest != NULL, "Failed to open request handle\n");
1354 len = sizeof(buffer);
1355 strcpy(buffer,"Warning");
1356 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1357 buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
1359 ok(HttpAddRequestHeaders(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
1360 "Failed to add new header\n");
1363 len = sizeof(buffer);
1364 strcpy(buffer,"Warning");
1365 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1366 buffer,&len,&index),"Unable to query header\n");
1367 ok(index == 1, "Index was not incremented\n");
1368 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1369 ok(len == 5, "Invalid length (exp. 5, got %d)\n", len);
1370 ok((len < sizeof(buffer)) && (buffer[len] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1371 len = sizeof(buffer);
1372 strcpy(buffer,"Warning");
1373 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1374 buffer,&len,&index)==0,"Second Index Should Not Exist\n");
1377 len = 5; /* could store the string but not the NULL terminator */
1378 strcpy(buffer,"Warning");
1379 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1380 buffer,&len,&index) == FALSE,"Query succeeded on a too small buffer\n");
1381 ok(strcmp(buffer,"Warning")==0, "incorrect string was returned(%s)\n",buffer); /* string not touched */
1382 ok(len == 6, "Invalid length (exp. 6, got %d)\n", len); /* unlike success, the length includes the NULL-terminator */
1384 /* a call with NULL will fail but will return the length */
1386 len = sizeof(buffer);
1387 SetLastError(0xdeadbeef);
1388 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1389 NULL,&len,&index) == FALSE,"Query worked\n");
1390 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1391 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1392 ok(index == 0, "Index was incremented\n");
1394 /* even for a len that is too small */
1397 SetLastError(0xdeadbeef);
1398 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1399 NULL,&len,&index) == FALSE,"Query worked\n");
1400 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1401 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1402 ok(index == 0, "Index was incremented\n");
1406 SetLastError(0xdeadbeef);
1407 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1408 NULL,&len,&index) == FALSE,"Query worked\n");
1409 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1410 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1411 ok(index == 0, "Index was incremented\n");
1412 oldlen = len; /* bytes; at least long enough to hold buffer & nul */
1415 /* a working query */
1417 len = sizeof(buffer);
1418 memset(buffer, 'x', sizeof(buffer));
1419 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1420 buffer,&len,&index),"Unable to query header\n");
1421 ok(len + sizeof(CHAR) <= oldlen, "Result longer than advertised\n");
1422 ok((len < sizeof(buffer)-sizeof(CHAR)) && (buffer[len/sizeof(CHAR)] == 0),"No NUL at end\n");
1423 ok(len == strlen(buffer) * sizeof(CHAR), "Length wrong\n");
1424 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1425 ok(strncmp(buffer, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1426 ok(strcmp(buffer + strlen(buffer) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1427 ok(index == 0, "Index was incremented\n");
1429 /* Like above two tests, but for W version */
1433 SetLastError(0xdeadbeef);
1434 ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1435 NULL,&len,&index) == FALSE,"Query worked\n");
1436 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1437 ok(len > 80, "Invalid length (exp. more than 80, got %d)\n", len);
1438 ok(index == 0, "Index was incremented\n");
1439 oldlen = len; /* bytes; at least long enough to hold buffer & nul */
1441 /* a working query */
1443 len = sizeof(wbuffer);
1444 memset(wbuffer, 'x', sizeof(wbuffer));
1445 ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1446 wbuffer,&len,&index),"Unable to query header\n");
1447 ok(len + sizeof(WCHAR) <= oldlen, "Result longer than advertised\n");
1448 ok(len == lstrlenW(wbuffer) * sizeof(WCHAR), "Length wrong\n");
1449 ok((len < sizeof(wbuffer)-sizeof(WCHAR)) && (wbuffer[len/sizeof(WCHAR)] == 0),"No NUL at end\n");
1450 ok(index == 0, "Index was incremented\n");
1452 /* end of W version tests */
1454 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1456 len = sizeof(buffer);
1457 memset(buffer, 'x', sizeof(buffer));
1458 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF,
1459 buffer,&len,&index) == TRUE,"Query failed\n");
1460 ok(len == 2, "Expected 2, got %d\n", len);
1461 ok(strcmp(buffer, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer);
1462 ok(index == 0, "Index was incremented\n");
1464 ok(HttpAddRequestHeaders(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
1465 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1468 len = sizeof(buffer);
1469 strcpy(buffer,"Warning");
1470 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1471 buffer,&len,&index),"Unable to query header\n");
1472 ok(index == 1, "Index was not incremented\n");
1473 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1474 len = sizeof(buffer);
1475 strcpy(buffer,"Warning");
1476 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1477 buffer,&len,&index),"Failed to get second header\n");
1478 ok(index == 2, "Index was not incremented\n");
1479 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1480 len = sizeof(buffer);
1481 strcpy(buffer,"Warning");
1482 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1483 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1485 ok(HttpAddRequestHeaders(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1488 len = sizeof(buffer);
1489 strcpy(buffer,"Warning");
1490 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1491 buffer,&len,&index),"Unable to query header\n");
1492 ok(index == 1, "Index was not incremented\n");
1493 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1494 len = sizeof(buffer);
1495 strcpy(buffer,"Warning");
1496 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1497 buffer,&len,&index),"Failed to get second header\n");
1498 ok(index == 2, "Index was not incremented\n");
1499 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1500 len = sizeof(buffer);
1501 strcpy(buffer,"Warning");
1502 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1503 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1505 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1508 len = sizeof(buffer);
1509 strcpy(buffer,"Warning");
1510 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1511 buffer,&len,&index),"Unable to query header\n");
1512 ok(index == 1, "Index was not incremented\n");
1513 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1514 len = sizeof(buffer);
1515 strcpy(buffer,"Warning");
1516 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1517 buffer,&len,&index),"Failed to get second header\n");
1518 ok(index == 2, "Index was not incremented\n");
1519 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1520 len = sizeof(buffer);
1521 strcpy(buffer,"Warning");
1522 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1523 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1525 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1528 len = sizeof(buffer);
1529 strcpy(buffer,"Warning");
1530 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1531 buffer,&len,&index),"Unable to query header\n");
1532 ok(index == 1, "Index was not incremented\n");
1533 ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer);
1534 len = sizeof(buffer);
1535 strcpy(buffer,"Warning");
1536 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1537 ok(index == 2, "Index was not incremented\n");
1538 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1539 len = sizeof(buffer);
1540 strcpy(buffer,"Warning");
1541 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1543 ok(HttpAddRequestHeaders(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1546 len = sizeof(buffer);
1547 strcpy(buffer,"Warning");
1548 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1549 ok(index == 1, "Index was not incremented\n");
1550 ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer);
1551 len = sizeof(buffer);
1552 strcpy(buffer,"Warning");
1553 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1554 ok(index == 2, "Index was not incremented\n");
1555 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1556 len = sizeof(buffer);
1557 strcpy(buffer,"Warning");
1558 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1560 ok(HttpAddRequestHeaders(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1563 len = sizeof(buffer);
1564 strcpy(buffer,"Warning");
1565 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1566 ok(index == 1, "Index was not incremented\n");
1567 ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer);
1568 len = sizeof(buffer);
1569 strcpy(buffer,"Warning");
1570 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1571 ok(index == 2, "Index was not incremented\n");
1572 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1573 len = sizeof(buffer);
1574 strcpy(buffer,"Warning");
1575 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1577 ok(HttpAddRequestHeaders(hRequest,"Warning:test7",-1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE), "HTTP_ADDREQ_FLAG_ADD with HTTP_ADDREQ_FLAG_REPALCE Did not work\n");
1580 len = sizeof(buffer);
1581 strcpy(buffer,"Warning");
1582 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1583 ok(index == 1, "Index was not incremented\n");
1584 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1585 len = sizeof(buffer);
1586 strcpy(buffer,"Warning");
1587 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1588 ok(index == 2, "Index was not incremented\n");
1589 ok(strcmp(buffer,"test7")==0, "incorrect string was returned(%s)\n",buffer);
1590 len = sizeof(buffer);
1591 strcpy(buffer,"Warning");
1592 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1594 /* Ensure that blank headers are ignored and don't cause a failure */
1595 ok(HttpAddRequestHeaders(hRequest,"\r\nBlankTest:value\r\n\r\n",-1, HTTP_ADDREQ_FLAG_ADD_IF_NEW), "Failed to add header with blank entries in list\n");
1598 len = sizeof(buffer);
1599 strcpy(buffer,"BlankTest");
1600 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1601 ok(index == 1, "Index was not incremented\n");
1602 ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
1604 /* Ensure that malformed header separators are ignored and don't cause a failure */
1605 ok(HttpAddRequestHeaders(hRequest,"\r\rMalformedTest:value\n\nMalformedTestTwo: value2\rMalformedTestThree: value3\n\n\r\r\n",-1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE),
1606 "Failed to add header with malformed entries in list\n");
1609 len = sizeof(buffer);
1610 strcpy(buffer,"MalformedTest");
1611 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1612 ok(index == 1, "Index was not incremented\n");
1613 ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
1615 len = sizeof(buffer);
1616 strcpy(buffer,"MalformedTestTwo");
1617 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1618 ok(index == 1, "Index was not incremented\n");
1619 ok(strcmp(buffer,"value2")==0, "incorrect string was returned(%s)\n",buffer);
1621 len = sizeof(buffer);
1622 strcpy(buffer,"MalformedTestThree");
1623 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1624 ok(index == 1, "Index was not incremented\n");
1625 ok(strcmp(buffer,"value3")==0, "incorrect string was returned(%s)\n",buffer);
1627 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1629 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1630 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1633 static const char garbagemsg[] =
1634 "Garbage: Header\r\n";
1636 static const char contmsg[] =
1637 "HTTP/1.1 100 Continue\r\n";
1639 static const char expandcontmsg[] =
1640 "HTTP/1.1 100 Continue\r\n"
1641 "Server: winecontinue\r\n"
1642 "Tag: something witty\r\n"
1645 static const char okmsg[] =
1646 "HTTP/1.1 200 OK\r\n"
1647 "Server: winetest\r\n"
1650 static const char okmsg2[] =
1651 "HTTP/1.1 200 OK\r\n"
1652 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1653 "Server: winetest\r\n"
1654 "Content-Length: 0\r\n"
1655 "Set-Cookie: one\r\n"
1656 "Set-Cookie: two\r\n"
1659 static const char notokmsg[] =
1660 "HTTP/1.1 400 Bad Request\r\n"
1661 "Server: winetest\r\n"
1664 static const char noauthmsg[] =
1665 "HTTP/1.1 401 Unauthorized\r\n"
1666 "Server: winetest\r\n"
1667 "Connection: close\r\n"
1668 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1671 static const char noauthmsg2[] =
1672 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
1673 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
1675 "Server: winetest\r\n";
1677 static const char proxymsg[] =
1678 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1679 "Server: winetest\r\n"
1680 "Proxy-Connection: close\r\n"
1681 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1684 static const char page1[] =
1686 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1687 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1690 struct server_info {
1693 int num_testH_retrievals;
1696 static DWORD CALLBACK server_thread(LPVOID param)
1698 struct server_info *si = param;
1701 struct sockaddr_in sa;
1704 int last_request = 0;
1705 char host_header[22];
1706 static int test_b = 0;
1708 WSAStartup(MAKEWORD(1,1), &wsaData);
1710 s = socket(AF_INET, SOCK_STREAM, 0);
1711 if (s == INVALID_SOCKET)
1715 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof on);
1717 memset(&sa, 0, sizeof sa);
1718 sa.sin_family = AF_INET;
1719 sa.sin_port = htons(si->port);
1720 sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
1722 r = bind(s, (struct sockaddr*) &sa, sizeof sa);
1728 SetEvent(si->hEvent);
1730 sprintf(host_header, "Host: localhost:%d", si->port);
1734 c = accept(s, NULL, NULL);
1736 memset(buffer, 0, sizeof buffer);
1737 for(i=0; i<(sizeof buffer-1); i++)
1739 r = recv(c, &buffer[i], 1, 0);
1743 if (buffer[i-2] == '\n' && buffer[i] == '\n' &&
1744 buffer[i-3] == '\r' && buffer[i-1] == '\r')
1747 if (strstr(buffer, "GET /test1"))
1749 if (!strstr(buffer, "Content-Length: 0"))
1751 send(c, okmsg, sizeof okmsg-1, 0);
1752 send(c, page1, sizeof page1-1, 0);
1755 send(c, notokmsg, sizeof notokmsg-1, 0);
1757 if (strstr(buffer, "/test2"))
1759 if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx"))
1761 send(c, okmsg, sizeof okmsg-1, 0);
1762 send(c, page1, sizeof page1-1, 0);
1765 send(c, proxymsg, sizeof proxymsg-1, 0);
1767 if (strstr(buffer, "/test3"))
1769 if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
1770 send(c, okmsg, sizeof okmsg-1, 0);
1772 send(c, noauthmsg, sizeof noauthmsg-1, 0);
1774 if (strstr(buffer, "/test4"))
1776 if (strstr(buffer, "Connection: Close"))
1777 send(c, okmsg, sizeof okmsg-1, 0);
1779 send(c, notokmsg, sizeof notokmsg-1, 0);
1781 if (strstr(buffer, "POST /test5") ||
1782 strstr(buffer, "RPC_IN_DATA /test5") ||
1783 strstr(buffer, "RPC_OUT_DATA /test5"))
1785 if (strstr(buffer, "Content-Length: 0"))
1787 send(c, okmsg, sizeof okmsg-1, 0);
1788 send(c, page1, sizeof page1-1, 0);
1791 send(c, notokmsg, sizeof notokmsg-1, 0);
1793 if (strstr(buffer, "GET /test6"))
1795 send(c, contmsg, sizeof contmsg-1, 0);
1796 send(c, contmsg, sizeof contmsg-1, 0);
1797 send(c, okmsg, sizeof okmsg-1, 0);
1798 send(c, page1, sizeof page1-1, 0);
1800 if (strstr(buffer, "POST /test7"))
1802 if (strstr(buffer, "Content-Length: 100"))
1804 send(c, okmsg, sizeof okmsg-1, 0);
1805 send(c, page1, sizeof page1-1, 0);
1808 send(c, notokmsg, sizeof notokmsg-1, 0);
1810 if (strstr(buffer, "/test8"))
1812 if (!strstr(buffer, "Connection: Close") &&
1813 strstr(buffer, "Connection: Keep-Alive") &&
1814 !strstr(buffer, "Cache-Control: no-cache") &&
1815 !strstr(buffer, "Pragma: no-cache") &&
1816 strstr(buffer, host_header))
1817 send(c, okmsg, sizeof okmsg-1, 0);
1819 send(c, notokmsg, sizeof notokmsg-1, 0);
1821 if (strstr(buffer, "/test9"))
1823 if (!strstr(buffer, "Connection: Close") &&
1824 !strstr(buffer, "Connection: Keep-Alive") &&
1825 !strstr(buffer, "Cache-Control: no-cache") &&
1826 !strstr(buffer, "Pragma: no-cache") &&
1827 strstr(buffer, host_header))
1828 send(c, okmsg, sizeof okmsg-1, 0);
1830 send(c, notokmsg, sizeof notokmsg-1, 0);
1832 if (strstr(buffer, "/testA"))
1834 if (!strstr(buffer, "Connection: Close") &&
1835 !strstr(buffer, "Connection: Keep-Alive") &&
1836 (strstr(buffer, "Cache-Control: no-cache") ||
1837 strstr(buffer, "Pragma: no-cache")) &&
1838 strstr(buffer, host_header))
1839 send(c, okmsg, sizeof okmsg-1, 0);
1841 send(c, notokmsg, sizeof notokmsg-1, 0);
1843 if (!test_b && strstr(buffer, "/testB HTTP/1.1"))
1846 send(c, okmsg, sizeof okmsg-1, 0);
1847 recvfrom(c, buffer, sizeof buffer, 0, NULL, NULL);
1848 send(c, okmsg, sizeof okmsg-1, 0);
1850 if (strstr(buffer, "/testC"))
1852 if (strstr(buffer, "Cookie: cookie=biscuit"))
1853 send(c, okmsg, sizeof okmsg-1, 0);
1855 send(c, notokmsg, sizeof notokmsg-1, 0);
1857 if (strstr(buffer, "/testD"))
1859 send(c, okmsg2, sizeof okmsg2-1, 0);
1861 if (strstr(buffer, "/testE"))
1863 send(c, noauthmsg2, sizeof noauthmsg2-1, 0);
1865 if (strstr(buffer, "GET /quit"))
1867 send(c, okmsg, sizeof okmsg-1, 0);
1868 send(c, page1, sizeof page1-1, 0);
1871 if (strstr(buffer, "GET /testF"))
1873 send(c, expandcontmsg, sizeof expandcontmsg-1, 0);
1874 send(c, garbagemsg, sizeof garbagemsg-1, 0);
1875 send(c, contmsg, sizeof contmsg-1, 0);
1876 send(c, garbagemsg, sizeof garbagemsg-1, 0);
1877 send(c, okmsg, sizeof okmsg-1, 0);
1878 send(c, page1, sizeof page1-1, 0);
1880 if (strstr(buffer, "GET /testG"))
1882 send(c, page1, sizeof page1-1, 0);
1884 if (strstr(buffer, "GET /testH"))
1886 si->num_testH_retrievals++;
1887 if (!strstr(buffer, "Content-Length: 0"))
1889 send(c, okmsg, sizeof okmsg-1, 0);
1890 send(c, page1, sizeof page1-1, 0);
1893 send(c, notokmsg, sizeof notokmsg-1, 0);
1895 if (strstr(buffer, "GET /test_no_content"))
1897 static const char nocontentmsg[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
1898 send(c, nocontentmsg, sizeof(nocontentmsg)-1, 0);
1900 if (strstr(buffer, "GET /test_conn_close"))
1902 static const char conn_close_response[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
1903 send(c, conn_close_response, sizeof(conn_close_response)-1, 0);
1904 WaitForSingleObject(conn_close_event, INFINITE);
1905 trace("closing connection\n");
1910 } while (!last_request);
1917 static void test_basic_request(int port, const char *verb, const char *url)
1919 HINTERNET hi, hc, hr;
1923 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1924 ok(hi != NULL, "open failed\n");
1926 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1927 ok(hc != NULL, "connect failed\n");
1929 hr = HttpOpenRequest(hc, verb, url, NULL, NULL, NULL, 0, 0);
1930 ok(hr != NULL, "HttpOpenRequest failed\n");
1932 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1933 ok(r, "HttpSendRequest failed\n");
1936 memset(buffer, 0, sizeof buffer);
1937 SetLastError(0xdeadbeef);
1938 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
1939 ok(r, "InternetReadFile failed %u\n", GetLastError());
1940 ok(count == sizeof page1 - 1, "count was wrong\n");
1941 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong, got: %s\n", buffer);
1943 InternetCloseHandle(hr);
1944 InternetCloseHandle(hc);
1945 InternetCloseHandle(hi);
1948 static void test_last_error(int port)
1950 HINTERNET hi, hc, hr;
1954 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1955 ok(hi != NULL, "open failed\n");
1957 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1958 ok(hc != NULL, "connect failed\n");
1960 hr = HttpOpenRequest(hc, NULL, "/test1", NULL, NULL, NULL, 0, 0);
1961 ok(hr != NULL, "HttpOpenRequest failed\n");
1963 SetLastError(0xdeadbeef);
1964 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1965 error = GetLastError();
1966 ok(r, "HttpSendRequest failed\n");
1967 ok(error == ERROR_SUCCESS || broken(error != ERROR_SUCCESS), "expected ERROR_SUCCESS, got %u\n", error);
1969 InternetCloseHandle(hr);
1970 InternetCloseHandle(hc);
1971 InternetCloseHandle(hi);
1974 static void test_proxy_indirect(int port)
1976 HINTERNET hi, hc, hr;
1980 hi = InternetOpen(NULL, 0, NULL, NULL, 0);
1981 ok(hi != NULL, "open failed\n");
1983 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1984 ok(hc != NULL, "connect failed\n");
1986 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
1987 ok(hr != NULL, "HttpOpenRequest failed\n");
1989 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1990 ok(r, "HttpSendRequest failed\n");
1993 r = HttpQueryInfo(hr, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL);
1994 ok(r || GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo failed: %d\n", GetLastError());
1997 skip("missing proxy header, not testing remaining proxy headers\n");
2000 ok(!strcmp(buffer, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2002 test_status_code(hr, 407);
2003 test_request_flags(hr, 0);
2006 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL);
2007 ok(r, "HttpQueryInfo failed\n");
2008 ok(!strcmp(buffer, "Proxy Authentication Required"), "proxy text wrong\n");
2011 r = HttpQueryInfo(hr, HTTP_QUERY_VERSION, buffer, &sz, NULL);
2012 ok(r, "HttpQueryInfo failed\n");
2013 ok(!strcmp(buffer, "HTTP/1.1"), "http version wrong\n");
2016 r = HttpQueryInfo(hr, HTTP_QUERY_SERVER, buffer, &sz, NULL);
2017 ok(r, "HttpQueryInfo failed\n");
2018 ok(!strcmp(buffer, "winetest"), "http server wrong\n");
2021 r = HttpQueryInfo(hr, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL);
2022 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo should fail\n");
2023 ok(r == FALSE, "HttpQueryInfo failed\n");
2026 InternetCloseHandle(hr);
2027 InternetCloseHandle(hc);
2028 InternetCloseHandle(hi);
2031 static void test_proxy_direct(int port)
2033 HINTERNET hi, hc, hr;
2036 static CHAR username[] = "mike",
2037 password[] = "1101";
2039 sprintf(buffer, "localhost:%d\n", port);
2040 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0);
2041 ok(hi != NULL, "open failed\n");
2043 /* try connect without authorization */
2044 hc = InternetConnect(hi, "test.winehq.org/", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2045 ok(hc != NULL, "connect failed\n");
2047 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
2048 ok(hr != NULL, "HttpOpenRequest failed\n");
2050 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
2051 ok(r, "HttpSendRequest failed\n");
2053 test_status_code(hr, 407);
2055 /* set the user + password then try again */
2057 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2058 ok(r, "failed to set user\n");
2060 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_PASSWORD, password, 4);
2061 ok(r, "failed to set password\n");
2064 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
2065 ok(r, "HttpSendRequest failed\n");
2067 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
2068 ok(r, "HttpQueryInfo failed\n");
2070 ok(!strcmp(buffer, "200"), "proxy code wrong\n");
2074 InternetCloseHandle(hr);
2075 InternetCloseHandle(hc);
2076 InternetCloseHandle(hi);
2079 static void test_header_handling_order(int port)
2081 static char authorization[] = "Authorization: Basic dXNlcjpwd2Q=";
2082 static char connection[] = "Connection: Close";
2084 static const char *types[2] = { "*", NULL };
2085 HINTERNET session, connect, request;
2089 session = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2090 ok(session != NULL, "InternetOpen failed\n");
2092 connect = InternetConnect(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2093 ok(connect != NULL, "InternetConnect failed\n");
2095 request = HttpOpenRequest(connect, NULL, "/test3", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2096 ok(request != NULL, "HttpOpenRequest failed\n");
2098 ret = HttpAddRequestHeaders(request, authorization, ~0u, HTTP_ADDREQ_FLAG_ADD);
2099 ok(ret, "HttpAddRequestHeaders failed\n");
2101 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
2102 ok(ret, "HttpSendRequest failed\n");
2104 test_status_code(request, 200);
2105 test_request_flags(request, 0);
2107 InternetCloseHandle(request);
2109 request = HttpOpenRequest(connect, NULL, "/test4", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2110 ok(request != NULL, "HttpOpenRequest failed\n");
2112 ret = HttpSendRequest(request, connection, ~0u, NULL, 0);
2113 ok(ret, "HttpSendRequest failed\n");
2116 size = sizeof(status);
2117 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2118 ok(ret, "HttpQueryInfo failed\n");
2119 ok(status == 200 || status == 400 /* IE6 */, "got status %u, expected 200 or 400\n", status);
2121 InternetCloseHandle(request);
2123 request = HttpOpenRequest(connect, "POST", "/test7", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2124 ok(request != NULL, "HttpOpenRequest failed\n");
2126 ret = HttpAddRequestHeaders(request, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
2127 ok(ret, "HttpAddRequestHeaders failed\n");
2129 ret = HttpSendRequest(request, connection, ~0u, NULL, 0);
2130 ok(ret, "HttpSendRequest failed\n");
2133 size = sizeof(status);
2134 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2135 ok(ret, "HttpQueryInfo failed\n");
2136 ok(status == 200 || status == 400 /* IE6 */, "got status %u, expected 200 or 400\n", status);
2138 InternetCloseHandle(request);
2139 InternetCloseHandle(connect);
2140 InternetCloseHandle(session);
2143 static void test_connection_header(int port)
2145 HINTERNET ses, con, req;
2148 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2149 ok(ses != NULL, "InternetOpen failed\n");
2151 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2152 ok(con != NULL, "InternetConnect failed\n");
2154 req = HttpOpenRequest(con, NULL, "/test8", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2155 ok(req != NULL, "HttpOpenRequest failed\n");
2157 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2158 ok(ret, "HttpSendRequest failed\n");
2160 test_status_code(req, 200);
2162 InternetCloseHandle(req);
2164 req = HttpOpenRequest(con, NULL, "/test9", NULL, NULL, NULL, 0, 0);
2165 ok(req != NULL, "HttpOpenRequest failed\n");
2167 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2168 ok(ret, "HttpSendRequest failed\n");
2170 test_status_code(req, 200);
2172 InternetCloseHandle(req);
2174 req = HttpOpenRequest(con, NULL, "/test9", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
2175 ok(req != NULL, "HttpOpenRequest failed\n");
2177 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2178 ok(ret, "HttpSendRequest failed\n");
2180 test_status_code(req, 200);
2182 InternetCloseHandle(req);
2184 req = HttpOpenRequest(con, "POST", "/testA", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
2185 ok(req != NULL, "HttpOpenRequest failed\n");
2187 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2188 ok(ret, "HttpSendRequest failed\n");
2190 test_status_code(req, 200);
2192 InternetCloseHandle(req);
2193 InternetCloseHandle(con);
2194 InternetCloseHandle(ses);
2197 static void test_http1_1(int port)
2199 HINTERNET ses, con, req;
2202 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2203 ok(ses != NULL, "InternetOpen failed\n");
2205 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2206 ok(con != NULL, "InternetConnect failed\n");
2208 req = HttpOpenRequest(con, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2209 ok(req != NULL, "HttpOpenRequest failed\n");
2211 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2214 InternetCloseHandle(req);
2216 req = HttpOpenRequest(con, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2217 ok(req != NULL, "HttpOpenRequest failed\n");
2219 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2220 ok(ret, "HttpSendRequest failed\n");
2223 InternetCloseHandle(req);
2224 InternetCloseHandle(con);
2225 InternetCloseHandle(ses);
2228 static void test_no_content(int port)
2230 HINTERNET session, connection, req;
2233 trace("Testing 204 no content response...\n");
2235 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
2237 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
2238 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
2240 pInternetSetStatusCallbackA(session, callback);
2242 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2243 connection = InternetConnectA(session, "localhost", port,
2244 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
2245 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
2246 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2248 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2249 req = HttpOpenRequestA(connection, "GET", "/test_no_content", NULL, NULL, NULL,
2250 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
2251 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
2252 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2254 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
2255 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
2256 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
2257 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
2258 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
2259 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
2260 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
2261 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
2262 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
2263 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2265 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
2266 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2267 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2268 WaitForSingleObject(hCompleteEvent, INFINITE);
2269 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2271 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
2272 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
2273 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
2274 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
2275 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
2276 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
2277 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
2278 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
2279 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
2280 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
2282 close_async_handle(session, hCompleteEvent, 2);
2283 CloseHandle(hCompleteEvent);
2286 static void test_conn_close(int port)
2288 HINTERNET session, connection, req;
2289 DWORD res, avail, size;
2292 trace("Testing connection close connection...\n");
2294 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
2295 conn_close_event = CreateEvent(NULL, FALSE, FALSE, NULL);
2297 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
2298 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
2300 pInternetSetStatusCallbackA(session, callback);
2302 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2303 connection = InternetConnectA(session, "localhost", port,
2304 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
2305 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
2306 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2308 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2309 req = HttpOpenRequestA(connection, "GET", "/test_conn_close", NULL, NULL, NULL,
2310 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
2311 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
2312 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2314 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
2315 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
2316 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
2317 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
2318 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
2319 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
2320 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
2321 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2323 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
2324 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2325 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2326 WaitForSingleObject(hCompleteEvent, INFINITE);
2327 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2329 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
2330 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
2331 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
2332 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
2333 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
2334 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
2335 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
2336 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
2339 res = InternetQueryDataAvailable(req, &avail, 0, 0);
2340 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
2341 ok(avail != 0, "avail = 0\n");
2344 res = InternetReadFile(req, buf, avail, &size);
2345 ok(res, "InternetReadFile failed: %u\n", GetLastError());
2347 res = InternetQueryDataAvailable(req, &avail, 0, 0);
2348 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2349 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2350 ok(!avail, "avail = %u, expected 0\n", avail);
2352 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
2353 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
2354 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2355 SetEvent(conn_close_event);
2356 WaitForSingleObject(hCompleteEvent, INFINITE);
2357 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2358 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
2359 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
2360 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
2362 close_async_handle(session, hCompleteEvent, 2);
2363 CloseHandle(hCompleteEvent);
2366 static void test_HttpSendRequestW(int port)
2368 static const WCHAR header[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
2369 HINTERNET ses, con, req;
2373 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
2374 ok(ses != NULL, "InternetOpen failed\n");
2376 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2377 ok(con != NULL, "InternetConnect failed\n");
2379 req = HttpOpenRequest(con, NULL, "/test1", NULL, NULL, NULL, 0, 0);
2380 ok(req != NULL, "HttpOpenRequest failed\n");
2382 SetLastError(0xdeadbeef);
2383 ret = HttpSendRequestW(req, header, ~0u, NULL, 0);
2384 error = GetLastError();
2385 ok(!ret, "HttpSendRequestW succeeded\n");
2386 ok(error == ERROR_IO_PENDING ||
2387 broken(error == ERROR_HTTP_HEADER_NOT_FOUND) || /* IE6 */
2388 broken(error == ERROR_INVALID_PARAMETER), /* IE5 */
2389 "got %u expected ERROR_IO_PENDING\n", error);
2391 InternetCloseHandle(req);
2392 InternetCloseHandle(con);
2393 InternetCloseHandle(ses);
2396 static void test_cookie_header(int port)
2398 HINTERNET ses, con, req;
2403 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2404 ok(ses != NULL, "InternetOpen failed\n");
2406 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2407 ok(con != NULL, "InternetConnect failed\n");
2409 InternetSetCookie("http://localhost", "cookie", "biscuit");
2411 req = HttpOpenRequest(con, NULL, "/testC", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2412 ok(req != NULL, "HttpOpenRequest failed\n");
2415 size = sizeof(buffer);
2416 SetLastError(0xdeadbeef);
2417 ret = HttpQueryInfo(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
2418 error = GetLastError();
2419 ok(!ret, "HttpQueryInfo succeeded\n");
2420 ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error);
2422 ret = HttpAddRequestHeaders(req, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD);
2423 ok(ret, "HttpAddRequestHeaders failed: %u\n", GetLastError());
2426 size = sizeof(buffer);
2427 ret = HttpQueryInfo(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
2428 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
2429 ok(!strcmp(buffer, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer);
2431 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2432 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
2434 test_status_code(req, 200);
2437 size = sizeof(buffer);
2438 ret = HttpQueryInfo(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
2439 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
2440 ok(!strcmp(buffer, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer);
2442 InternetCloseHandle(req);
2443 InternetCloseHandle(con);
2444 InternetCloseHandle(ses);
2447 static void test_basic_authentication(int port)
2449 HINTERNET session, connect, request;
2452 session = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2453 ok(session != NULL, "InternetOpen failed\n");
2455 connect = InternetConnect(session, "localhost", port, "user", "pwd", INTERNET_SERVICE_HTTP, 0, 0);
2456 ok(connect != NULL, "InternetConnect failed\n");
2458 request = HttpOpenRequest(connect, NULL, "/test3", NULL, NULL, NULL, 0, 0);
2459 ok(request != NULL, "HttpOpenRequest failed\n");
2461 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
2462 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
2464 test_status_code(request, 200);
2465 test_request_flags(request, 0);
2467 InternetCloseHandle(request);
2468 InternetCloseHandle(connect);
2469 InternetCloseHandle(session);
2472 static void test_invalid_response_headers(int port)
2474 HINTERNET session, connect, request;
2479 session = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2480 ok(session != NULL, "InternetOpen failed\n");
2482 connect = InternetConnect(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2483 ok(connect != NULL, "InternetConnect failed\n");
2485 request = HttpOpenRequest(connect, NULL, "/testE", NULL, NULL, NULL, 0, 0);
2486 ok(request != NULL, "HttpOpenRequest failed\n");
2488 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
2489 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
2491 test_status_code(request, 401);
2492 test_request_flags(request, 0);
2495 size = sizeof(buffer);
2496 ret = HttpQueryInfo( request, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
2497 ok(ret, "HttpQueryInfo failed\n");
2498 ok(!strcmp(buffer, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
2499 "headers wrong \"%s\"\n", buffer);
2502 size = sizeof(buffer);
2503 ret = HttpQueryInfo( request, HTTP_QUERY_SERVER, buffer, &size, NULL);
2504 ok(ret, "HttpQueryInfo failed\n");
2505 ok(!strcmp(buffer, "winetest"), "server wrong \"%s\"\n", buffer);
2507 InternetCloseHandle(request);
2508 InternetCloseHandle(connect);
2509 InternetCloseHandle(session);
2512 static void test_response_without_headers(int port)
2514 HINTERNET hi, hc, hr;
2515 DWORD r, count, size;
2518 SetLastError(0xdeadbeef);
2519 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2520 ok(hi != NULL, "open failed %u\n", GetLastError());
2522 SetLastError(0xdeadbeef);
2523 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2524 ok(hc != NULL, "connect failed %u\n", GetLastError());
2526 SetLastError(0xdeadbeef);
2527 hr = HttpOpenRequest(hc, NULL, "/testG", NULL, NULL, NULL, 0, 0);
2528 ok(hr != NULL, "HttpOpenRequest failed %u\n", GetLastError());
2530 test_request_flags(hr, INTERNET_REQFLAG_NO_HEADERS);
2532 SetLastError(0xdeadbeef);
2533 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
2534 ok(r, "HttpSendRequest failed %u\n", GetLastError());
2536 test_request_flags_todo(hr, INTERNET_REQFLAG_NO_HEADERS);
2539 memset(buffer, 0, sizeof buffer);
2540 SetLastError(0xdeadbeef);
2541 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
2542 ok(r, "InternetReadFile failed %u\n", GetLastError());
2543 todo_wine ok(count == sizeof page1 - 1, "count was wrong\n");
2544 todo_wine ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
2546 test_status_code(hr, 200);
2547 test_request_flags_todo(hr, INTERNET_REQFLAG_NO_HEADERS);
2550 size = sizeof(buffer);
2551 SetLastError(0xdeadbeef);
2552 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, NULL );
2553 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
2554 ok(!strcmp(buffer, "OK"), "expected OK got: \"%s\"\n", buffer);
2557 size = sizeof(buffer);
2558 SetLastError(0xdeadbeef);
2559 r = HttpQueryInfo(hr, HTTP_QUERY_VERSION, buffer, &size, NULL);
2560 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
2561 ok(!strcmp(buffer, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer);
2564 size = sizeof(buffer);
2565 SetLastError(0xdeadbeef);
2566 r = HttpQueryInfo(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
2567 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
2568 ok(!strcmp(buffer, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer);
2570 InternetCloseHandle(hr);
2571 InternetCloseHandle(hc);
2572 InternetCloseHandle(hi);
2575 static void test_HttpQueryInfo(int port)
2577 HINTERNET hi, hc, hr;
2582 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2583 ok(hi != NULL, "InternetOpen failed\n");
2585 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2586 ok(hc != NULL, "InternetConnect failed\n");
2588 hr = HttpOpenRequest(hc, NULL, "/testD", NULL, NULL, NULL, 0, 0);
2589 ok(hr != NULL, "HttpOpenRequest failed\n");
2591 ret = HttpSendRequest(hr, NULL, 0, NULL, 0);
2592 ok(ret, "HttpSendRequest failed\n");
2595 size = sizeof(buffer);
2596 ret = HttpQueryInfo(hr, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &index);
2597 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2598 ok(index == 1, "expected 1 got %u\n", index);
2601 size = sizeof(buffer);
2602 ret = HttpQueryInfo(hr, HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME, buffer, &size, &index);
2603 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2604 ok(index == 1, "expected 1 got %u\n", index);
2607 size = sizeof(buffer);
2608 ret = HttpQueryInfo(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
2609 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2610 ok(index == 0, "expected 0 got %u\n", index);
2612 size = sizeof(buffer);
2613 ret = HttpQueryInfo(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
2614 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2615 ok(index == 0, "expected 0 got %u\n", index);
2617 index = 0xdeadbeef; /* invalid start index */
2618 size = sizeof(buffer);
2619 ret = HttpQueryInfo(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
2620 todo_wine ok(!ret, "HttpQueryInfo should have failed\n");
2621 todo_wine ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
2622 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
2625 size = sizeof(buffer);
2626 ret = HttpQueryInfo(hr, HTTP_QUERY_RAW_HEADERS_CRLF, buffer, &size, &index);
2627 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2628 ok(index == 0, "expected 0 got %u\n", index);
2630 size = sizeof(buffer);
2631 ret = HttpQueryInfo(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
2632 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2633 ok(index == 0, "expected 0 got %u\n", index);
2635 size = sizeof(buffer);
2636 ret = HttpQueryInfo(hr, HTTP_QUERY_VERSION, buffer, &size, &index);
2637 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2638 ok(index == 0, "expected 0 got %u\n", index);
2640 test_status_code(hr, 200);
2643 size = sizeof(buffer);
2644 ret = HttpQueryInfo(hr, HTTP_QUERY_FORWARDED, buffer, &size, &index);
2645 ok(!ret, "HttpQueryInfo succeeded\n");
2646 ok(index == 0xdeadbeef, "expected 0xdeadbeef got %u\n", index);
2649 size = sizeof(buffer);
2650 ret = HttpQueryInfo(hr, HTTP_QUERY_SERVER, buffer, &size, &index);
2651 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2652 ok(index == 1, "expected 1 got %u\n", index);
2655 size = sizeof(buffer);
2656 strcpy(buffer, "Server");
2657 ret = HttpQueryInfo(hr, HTTP_QUERY_CUSTOM, buffer, &size, &index);
2658 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2659 ok(index == 1, "expected 1 got %u\n", index);
2662 size = sizeof(buffer);
2663 ret = HttpQueryInfo(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
2664 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2665 ok(index == 1, "expected 1 got %u\n", index);
2667 size = sizeof(buffer);
2668 ret = HttpQueryInfo(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
2669 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2670 ok(index == 2, "expected 2 got %u\n", index);
2672 InternetCloseHandle(hr);
2673 InternetCloseHandle(hc);
2674 InternetCloseHandle(hi);
2677 static void test_options(int port)
2679 HINTERNET ses, con, req;
2684 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2685 ok(ses != NULL, "InternetOpen failed\n");
2687 SetLastError(0xdeadbeef);
2688 ret = InternetSetOption(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, 0);
2689 error = GetLastError();
2690 ok(!ret, "InternetSetOption succeeded\n");
2691 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2693 SetLastError(0xdeadbeef);
2694 ret = InternetSetOption(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, sizeof(ctx));
2695 ok(!ret, "InternetSetOption succeeded\n");
2696 error = GetLastError();
2697 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2699 SetLastError(0xdeadbeef);
2700 ret = InternetSetOption(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, 0);
2701 ok(!ret, "InternetSetOption succeeded\n");
2702 error = GetLastError();
2703 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2706 ret = InternetSetOption(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
2707 ok(ret, "InternetSetOption failed %u\n", GetLastError());
2709 SetLastError(0xdeadbeef);
2710 ret = InternetQueryOption(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, NULL);
2711 error = GetLastError();
2712 ok(!ret, "InternetQueryOption succeeded\n");
2713 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2715 SetLastError(0xdeadbeef);
2716 ret = InternetQueryOption(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, NULL);
2717 error = GetLastError();
2718 ok(!ret, "InternetQueryOption succeeded\n");
2719 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2722 SetLastError(0xdeadbeef);
2723 ret = InternetQueryOption(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, &size);
2724 error = GetLastError();
2725 ok(!ret, "InternetQueryOption succeeded\n");
2726 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
2729 SetLastError(0xdeadbeef);
2730 ret = InternetQueryOption(NULL, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
2731 error = GetLastError();
2732 ok(!ret, "InternetQueryOption succeeded\n");
2733 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error);
2737 ret = InternetQueryOption(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
2738 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
2739 ok(ctx == 1, "expected 1 got %lu\n", ctx);
2741 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2742 ok(con != NULL, "InternetConnect failed\n");
2746 ret = InternetQueryOption(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
2747 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
2748 ok(ctx == 0, "expected 0 got %lu\n", ctx);
2751 ret = InternetSetOption(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
2752 ok(ret, "InternetSetOption failed %u\n", GetLastError());
2756 ret = InternetQueryOption(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
2757 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
2758 ok(ctx == 2, "expected 2 got %lu\n", ctx);
2760 req = HttpOpenRequest(con, NULL, "/test1", NULL, NULL, NULL, 0, 0);
2761 ok(req != NULL, "HttpOpenRequest failed\n");
2765 ret = InternetQueryOption(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
2766 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
2767 ok(ctx == 0, "expected 0 got %lu\n", ctx);
2770 ret = InternetSetOption(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
2771 ok(ret, "InternetSetOption failed %u\n", GetLastError());
2775 ret = InternetQueryOption(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
2776 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
2777 ok(ctx == 3, "expected 3 got %lu\n", ctx);
2779 /* INTERNET_OPTION_PROXY */
2780 SetLastError(0xdeadbeef);
2781 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, NULL);
2782 error = GetLastError();
2783 ok(!ret, "InternetQueryOption succeeded\n");
2784 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2786 SetLastError(0xdeadbeef);
2787 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, &ctx, NULL);
2788 error = GetLastError();
2789 ok(!ret, "InternetQueryOption succeeded\n");
2790 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2793 SetLastError(0xdeadbeef);
2794 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, &size);
2795 error = GetLastError();
2796 ok(!ret, "InternetQueryOption succeeded\n");
2797 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
2798 ok(size >= sizeof(INTERNET_PROXY_INFOA), "expected size to be greater or equal to the struct size\n");
2800 InternetCloseHandle(req);
2801 InternetCloseHandle(con);
2802 InternetCloseHandle(ses);
2805 static void test_url_caching(int port, int *num_retrievals)
2807 HINTERNET hi, hc, hr;
2811 ok(*num_retrievals == 0, "expected 0 retrievals prior to test\n");
2813 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2814 ok(hi != NULL, "open failed\n");
2816 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2817 ok(hc != NULL, "connect failed\n");
2819 /* Pre-load the cache: */
2820 hr = HttpOpenRequest(hc, "GET", "/testH", NULL, NULL, NULL, 0, 0);
2821 ok(hr != NULL, "HttpOpenRequest failed\n");
2823 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
2824 ok(r, "HttpSendRequest failed\n");
2826 ok(*num_retrievals == 1, "expected 1 retrievals, got %d\n", *num_retrievals);
2829 memset(buffer, 0, sizeof buffer);
2830 SetLastError(0xdeadbeef);
2831 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
2832 ok(r, "InternetReadFile failed %u\n", GetLastError());
2833 ok(count == sizeof page1 - 1, "count was wrong\n");
2834 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
2836 InternetCloseHandle(hr);
2838 /* Send the same request, requiring it to be retrieved from the cache */
2839 hr = HttpOpenRequest(hc, "GET", "/testH", NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
2840 ok(hr != NULL, "HttpOpenRequest failed\n");
2842 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
2843 /* Older Windows versions succeed with this request, newer ones fail with
2844 * ERROR_FILE_NOT_FOUND. Accept either, as the older version allows us
2845 * to verify that the server isn't contacted.
2848 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
2849 "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
2852 /* The server shouldn't be contacted for this request. */
2854 ok(*num_retrievals == 1, "expected 1 retrievals\n");
2857 memset(buffer, 0, sizeof buffer);
2858 SetLastError(0xdeadbeef);
2859 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
2860 ok(r, "InternetReadFile failed %u\n", GetLastError());
2861 ok(count == sizeof page1 - 1, "count was wrong\n");
2862 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
2865 InternetCloseHandle(hc);
2866 InternetCloseHandle(hi);
2869 static void test_http_connection(void)
2871 struct server_info si;
2875 si.hEvent = CreateEvent(NULL, 0, 0, NULL);
2877 si.num_testH_retrievals = 0;
2879 hThread = CreateThread(NULL, 0, server_thread, (LPVOID) &si, 0, &id);
2880 ok( hThread != NULL, "create thread failed\n");
2882 r = WaitForSingleObject(si.hEvent, 10000);
2883 ok (r == WAIT_OBJECT_0, "failed to start wininet test server\n");
2884 if (r != WAIT_OBJECT_0)
2887 test_basic_request(si.port, "GET", "/test1");
2888 test_proxy_indirect(si.port);
2889 test_proxy_direct(si.port);
2890 test_header_handling_order(si.port);
2891 test_basic_request(si.port, "POST", "/test5");
2892 test_basic_request(si.port, "RPC_IN_DATA", "/test5");
2893 test_basic_request(si.port, "RPC_OUT_DATA", "/test5");
2894 test_basic_request(si.port, "GET", "/test6");
2895 test_basic_request(si.port, "GET", "/testF");
2896 test_connection_header(si.port);
2897 test_http1_1(si.port);
2898 test_cookie_header(si.port);
2899 test_basic_authentication(si.port);
2900 test_invalid_response_headers(si.port);
2901 test_response_without_headers(si.port);
2902 test_HttpQueryInfo(si.port);
2903 test_HttpSendRequestW(si.port);
2904 test_last_error(si.port);
2905 test_options(si.port);
2906 test_url_caching(si.port, &si.num_testH_retrievals);
2907 test_no_content(si.port);
2908 test_conn_close(si.port);
2910 /* send the basic request again to shutdown the server thread */
2911 test_basic_request(si.port, "GET", "/quit");
2913 r = WaitForSingleObject(hThread, 3000);
2914 ok( r == WAIT_OBJECT_0, "thread wait failed\n");
2915 CloseHandle(hThread);
2918 static void release_cert_info(INTERNET_CERTIFICATE_INFOA *info)
2920 LocalFree(info->lpszSubjectInfo);
2921 LocalFree(info->lpszIssuerInfo);
2922 LocalFree(info->lpszProtocolName);
2923 LocalFree(info->lpszSignatureAlgName);
2924 LocalFree(info->lpszEncryptionAlgName);
2927 static void test_cert_struct(HINTERNET req)
2929 INTERNET_CERTIFICATE_INFOA info;
2933 static const char ex_subject[] =
2938 "test.winehq.org\r\n"
2939 "webmaster@winehq.org";
2941 static const char ex_issuer[] =
2945 "test.winehq.org\r\n"
2946 "webmaster@winehq.org";
2948 memset(&info, 0x5, sizeof(info));
2950 size = sizeof(info);
2951 res = InternetQueryOption(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, &info, &size);
2952 ok(res, "InternetQueryOption failed: %u\n", GetLastError());
2953 ok(size == sizeof(info), "size = %u\n", size);
2955 ok(!strcmp(info.lpszSubjectInfo, ex_subject), "lpszSubjectInfo = %s\n", info.lpszSubjectInfo);
2956 ok(!strcmp(info.lpszIssuerInfo, ex_issuer), "lpszIssuerInfo = %s\n", info.lpszIssuerInfo);
2957 ok(!info.lpszSignatureAlgName, "lpszSignatureAlgName = %s\n", info.lpszSignatureAlgName);
2958 ok(!info.lpszEncryptionAlgName, "lpszEncryptionAlgName = %s\n", info.lpszEncryptionAlgName);
2959 ok(!info.lpszProtocolName, "lpszProtocolName = %s\n", info.lpszProtocolName);
2961 ok(info.dwKeySize == 128, "dwKeySize = %u\n", info.dwKeySize);
2963 release_cert_info(&info);
2966 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
2967 static void _test_security_info(unsigned line, const char *urlc, DWORD error, DWORD ex_flags)
2969 char url[INTERNET_MAX_URL_LENGTH];
2970 const CERT_CHAIN_CONTEXT *chain;
2974 if(!pInternetGetSecurityInfoByURLA) {
2975 win_skip("pInternetGetSecurityInfoByURLA not available\n");
2980 chain = (void*)0xdeadbeef;
2982 res = pInternetGetSecurityInfoByURLA(url, &chain, &flags);
2983 if(error == ERROR_SUCCESS) {
2984 ok_(__FILE__,line)(res, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
2985 ok_(__FILE__,line)(chain != NULL, "chain = NULL\n");
2986 ok_(__FILE__,line)(flags == ex_flags, "flags = %x\n", flags);
2987 CertFreeCertificateChain(chain);
2989 ok_(__FILE__,line)(!res && GetLastError() == error,
2990 "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res, GetLastError(), error);
2994 #define test_secflags_option(a,b) _test_secflags_option(__LINE__,a,b)
2995 static void _test_secflags_option(unsigned line, HINTERNET req, DWORD ex_flags)
3001 size = sizeof(flags);
3002 res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
3003 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
3004 ok_(__FILE__,line)(flags == ex_flags, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n", flags, ex_flags);
3006 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
3008 size = sizeof(flags);
3009 res = InternetQueryOptionW(req, 98, &flags, &size);
3010 ok_(__FILE__,line)(res, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
3011 ok_(__FILE__,line)(flags == ex_flags, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n", flags, ex_flags);
3014 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
3015 static void _set_secflags(unsigned line, HINTERNET req, BOOL use_undoc, DWORD flags)
3019 res = InternetSetOptionW(req, use_undoc ? 99 : INTERNET_OPTION_SECURITY_FLAGS, &flags, sizeof(flags));
3020 ok_(__FILE__,line)(res, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
3023 static void test_security_flags(void)
3025 HINTERNET ses, conn, req;
3030 trace("Testing security flags...\n");
3032 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
3034 ses = InternetOpen("WineTest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
3035 ok(ses != NULL, "InternetOpen failed\n");
3037 pInternetSetStatusCallbackA(ses, &callback);
3039 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3040 conn = InternetConnectA(ses, "test.winehq.org", INTERNET_DEFAULT_HTTPS_PORT,
3041 NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0xdeadbeef);
3042 ok(conn != NULL, "InternetConnect failed with error %u\n", GetLastError());
3043 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3045 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3046 req = HttpOpenRequest(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
3047 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
3049 ok(req != NULL, "HttpOpenRequest failed\n");
3050 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3053 size = sizeof(flags);
3054 res = InternetQueryOptionW(req, 98, &flags, &size);
3055 if(!res && GetLastError() == ERROR_INVALID_PARAMETER) {
3056 win_skip("Incomplete security flags support, skipping\n");
3058 close_async_handle(ses, hCompleteEvent, 2);
3059 CloseHandle(hCompleteEvent);
3063 test_secflags_option(req, 0);
3064 test_security_info("https://test.winehq.org/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
3066 set_secflags(req, TRUE, SECURITY_FLAG_IGNORE_REVOCATION);
3067 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION);
3069 set_secflags(req, TRUE, SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
3070 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
3072 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
3073 test_secflags_option(req, SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
3075 flags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_SECURE;
3076 res = InternetSetOptionW(req, 99, &flags, sizeof(flags));
3077 ok(!res && GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE, "InternetSetOption(99) failed: %u\n", GetLastError());
3079 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
3080 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
3081 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3082 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3083 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3084 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3085 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3086 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3087 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3088 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3089 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3091 res = HttpSendRequest(req, NULL, 0, NULL, 0);
3092 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
3094 WaitForSingleObject(hCompleteEvent, INFINITE);
3095 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
3097 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
3098 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
3099 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3100 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3101 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3102 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3103 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3104 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3105 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3106 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3107 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3109 test_request_flags(req, 0);
3110 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA
3111 |SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_STRENGTH_STRONG);
3113 res = InternetReadFile(req, buf, sizeof(buf), &size);
3114 ok(res, "InternetReadFile failed: %u\n", GetLastError());
3115 ok(size, "size = 0\n");
3117 /* Collect all existing persistent connections */
3118 res = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
3119 ok(res, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
3121 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3122 req = HttpOpenRequest(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
3123 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
3125 ok(req != NULL, "HttpOpenRequest failed\n");
3126 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3128 flags = INTERNET_ERROR_MASK_COMBINED_SEC_CERT|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY;
3129 res = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&flags, sizeof(flags));
3130 ok(res, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
3132 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3133 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3134 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
3135 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
3136 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3137 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3138 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3140 res = HttpSendRequest(req, NULL, 0, NULL, 0);
3141 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
3143 WaitForSingleObject(hCompleteEvent, INFINITE);
3144 ok(req_error == ERROR_INTERNET_SEC_CERT_REV_FAILED || broken(req_error == ERROR_INTERNET_SEC_CERT_ERRORS),
3145 "req_error = %d\n", req_error);
3147 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3148 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3149 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3150 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3151 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3152 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3153 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3155 if(req_error != ERROR_INTERNET_SEC_CERT_REV_FAILED) {
3156 win_skip("Unexpected cert errors, skipping security flags tests\n");
3158 close_async_handle(ses, hCompleteEvent, 3);
3159 CloseHandle(hCompleteEvent);
3164 res = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
3165 ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
3167 test_request_flags(req, 8);
3168 test_secflags_option(req, 0x800000);
3170 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_REVOCATION);
3171 test_secflags_option(req, 0x800000|SECURITY_FLAG_IGNORE_REVOCATION);
3173 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3174 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3175 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
3176 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
3177 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3178 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3179 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3181 res = HttpSendRequest(req, NULL, 0, NULL, 0);
3182 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
3184 WaitForSingleObject(hCompleteEvent, INFINITE);
3185 ok(req_error == ERROR_INTERNET_SEC_CERT_ERRORS, "req_error = %d\n", req_error);
3187 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3188 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3189 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3190 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3191 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3192 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3193 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3195 test_request_flags(req, INTERNET_REQFLAG_NO_HEADERS);
3196 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION|0x1800000);
3197 test_security_info("https://test.winehq.org/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
3199 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
3200 test_secflags_option(req, 0x1800000|SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_UNKNOWN_CA
3201 |SECURITY_FLAG_IGNORE_REVOCATION);
3202 test_http_version(req);
3204 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3205 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3206 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3207 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3208 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3209 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3210 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3211 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3212 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3214 res = HttpSendRequest(req, NULL, 0, NULL, 0);
3215 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
3217 WaitForSingleObject(hCompleteEvent, INFINITE);
3218 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
3220 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3221 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3222 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3223 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3224 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3225 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3226 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3227 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3228 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3230 test_request_flags(req, 0);
3231 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION
3232 |SECURITY_FLAG_STRENGTH_STRONG|0x1800000);
3234 test_cert_struct(req);
3235 test_security_info("https://test.winehq.org/data/some_file.html?q", 0, 0x1800000);
3237 res = InternetReadFile(req, buf, sizeof(buf), &size);
3238 ok(res, "InternetReadFile failed: %u\n", GetLastError());
3239 ok(size, "size = 0\n");
3241 close_async_handle(ses, hCompleteEvent, 3);
3243 /* Collect all existing persistent connections */
3244 res = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
3245 ok(res, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
3247 /* Make another request, without setting security flags */
3249 ses = InternetOpen("WineTest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
3250 ok(ses != NULL, "InternetOpen failed\n");
3252 pInternetSetStatusCallbackA(ses, &callback);
3254 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3255 conn = InternetConnectA(ses, "test.winehq.org", INTERNET_DEFAULT_HTTPS_PORT,
3256 NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0xdeadbeef);
3257 ok(conn != NULL, "InternetConnect failed with error %u\n", GetLastError());
3258 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3260 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3261 req = HttpOpenRequest(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
3262 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
3264 ok(req != NULL, "HttpOpenRequest failed\n");
3265 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3267 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_STRENGTH_STRONG
3268 |SECURITY_FLAG_IGNORE_REVOCATION|0x1800000);
3269 test_http_version(req);
3271 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3272 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3273 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3274 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3275 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3276 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3277 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3278 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3280 res = HttpSendRequest(req, NULL, 0, NULL, 0);
3281 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
3283 WaitForSingleObject(hCompleteEvent, INFINITE);
3284 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
3286 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3287 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3288 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3289 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3290 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3291 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3292 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3293 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3295 test_request_flags(req, 0);
3296 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_STRENGTH_STRONG
3297 |SECURITY_FLAG_IGNORE_REVOCATION|0x1800000);
3299 res = InternetReadFile(req, buf, sizeof(buf), &size);
3300 ok(res, "InternetReadFile failed: %u\n", GetLastError());
3301 ok(size, "size = 0\n");
3303 close_async_handle(ses, hCompleteEvent, 2);
3305 CloseHandle(hCompleteEvent);
3307 test_security_info("http://test.winehq.org/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
3308 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
3309 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
3312 static void test_secure_connection(void)
3314 static const WCHAR gizmo5[] = {'G','i','z','m','o','5',0};
3315 static const WCHAR testbot[] = {'t','e','s','t','b','o','t','.','w','i','n','e','h','q','.','o','r','g',0};
3316 static const WCHAR get[] = {'G','E','T',0};
3317 static const WCHAR slash[] = {'/',0};
3318 HINTERNET ses, con, req;
3320 INTERNET_CERTIFICATE_INFOA *certificate_structA = NULL;
3321 INTERNET_CERTIFICATE_INFOW *certificate_structW = NULL;
3324 ses = InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
3325 ok(ses != NULL, "InternetOpen failed\n");
3327 con = InternetConnect(ses, "testbot.winehq.org",
3328 INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL,
3329 INTERNET_SERVICE_HTTP, 0, 0);
3330 ok(con != NULL, "InternetConnect failed\n");
3332 req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL,
3333 INTERNET_FLAG_SECURE, 0);
3334 ok(req != NULL, "HttpOpenRequest failed\n");
3336 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
3337 ok(ret, "HttpSendRequest failed: %d\n", GetLastError());
3339 size = sizeof(flags);
3340 ret = InternetQueryOption(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
3341 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
3342 ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set\n");
3344 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3346 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
3347 ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %d\n", size);
3348 certificate_structA = HeapAlloc(GetProcessHeap(), 0, size);
3349 ret = InternetQueryOption(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3350 certificate_structA, &size);
3351 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
3354 ok(certificate_structA->lpszSubjectInfo &&
3355 strlen(certificate_structA->lpszSubjectInfo) > 1,
3356 "expected a non-empty subject name\n");
3357 ok(certificate_structA->lpszIssuerInfo &&
3358 strlen(certificate_structA->lpszIssuerInfo) > 1,
3359 "expected a non-empty issuer name\n");
3360 ok(!certificate_structA->lpszSignatureAlgName,
3361 "unexpected signature algorithm name\n");
3362 ok(!certificate_structA->lpszEncryptionAlgName,
3363 "unexpected encryption algorithm name\n");
3364 ok(!certificate_structA->lpszProtocolName,
3365 "unexpected protocol name\n");
3366 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
3367 release_cert_info(certificate_structA);
3369 HeapFree(GetProcessHeap(), 0, certificate_structA);
3371 /* Querying the same option through InternetQueryOptionW still results in
3372 * ASCII strings being returned.
3375 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3377 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
3378 ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size);
3379 certificate_structW = HeapAlloc(GetProcessHeap(), 0, size);
3380 ret = InternetQueryOption(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3381 certificate_structW, &size);
3382 certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW;
3383 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
3386 ok(certificate_structA->lpszSubjectInfo &&
3387 strlen(certificate_structA->lpszSubjectInfo) > 1,
3388 "expected a non-empty subject name\n");
3389 ok(certificate_structA->lpszIssuerInfo &&
3390 strlen(certificate_structA->lpszIssuerInfo) > 1,
3391 "expected a non-empty issuer name\n");
3392 ok(!certificate_structA->lpszSignatureAlgName,
3393 "unexpected signature algorithm name\n");
3394 ok(!certificate_structA->lpszEncryptionAlgName,
3395 "unexpected encryption algorithm name\n");
3396 ok(!certificate_structA->lpszProtocolName,
3397 "unexpected protocol name\n");
3398 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
3399 release_cert_info(certificate_structA);
3401 HeapFree(GetProcessHeap(), 0, certificate_structW);
3403 InternetCloseHandle(req);
3404 InternetCloseHandle(con);
3405 InternetCloseHandle(ses);
3407 /* Repeating the tests with the W functions has the same result: */
3408 ses = InternetOpenW(gizmo5, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
3409 ok(ses != NULL, "InternetOpen failed\n");
3411 con = InternetConnectW(ses, testbot,
3412 INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL,
3413 INTERNET_SERVICE_HTTP, 0, 0);
3414 ok(con != NULL, "InternetConnect failed\n");
3416 req = HttpOpenRequestW(con, get, slash, NULL, NULL, NULL,
3417 INTERNET_FLAG_SECURE, 0);
3418 ok(req != NULL, "HttpOpenRequest failed\n");
3420 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
3421 ok(ret, "HttpSendRequest failed: %d\n", GetLastError());
3423 size = sizeof(flags);
3424 ret = InternetQueryOption(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
3425 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
3426 ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set\n");
3428 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3430 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
3431 ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %d\n", size);
3432 certificate_structA = HeapAlloc(GetProcessHeap(), 0, size);
3433 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3434 certificate_structA, &size);
3435 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
3438 ok(certificate_structA->lpszSubjectInfo &&
3439 strlen(certificate_structA->lpszSubjectInfo) > 1,
3440 "expected a non-empty subject name\n");
3441 ok(certificate_structA->lpszIssuerInfo &&
3442 strlen(certificate_structA->lpszIssuerInfo) > 1,
3443 "expected a non-empty issuer name\n");
3444 ok(!certificate_structA->lpszSignatureAlgName,
3445 "unexpected signature algorithm name\n");
3446 ok(!certificate_structA->lpszEncryptionAlgName,
3447 "unexpected encryption algorithm name\n");
3448 ok(!certificate_structA->lpszProtocolName,
3449 "unexpected protocol name\n");
3450 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
3451 release_cert_info(certificate_structA);
3453 HeapFree(GetProcessHeap(), 0, certificate_structA);
3455 /* Again, querying the same option through InternetQueryOptionW still
3456 * results in ASCII strings being returned.
3459 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3461 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
3462 ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size);
3463 certificate_structW = HeapAlloc(GetProcessHeap(), 0, size);
3464 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3465 certificate_structW, &size);
3466 certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW;
3467 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
3470 ok(certificate_structA->lpszSubjectInfo &&
3471 strlen(certificate_structA->lpszSubjectInfo) > 1,
3472 "expected a non-empty subject name\n");
3473 ok(certificate_structA->lpszIssuerInfo &&
3474 strlen(certificate_structA->lpszIssuerInfo) > 1,
3475 "expected a non-empty issuer name\n");
3476 ok(!certificate_structA->lpszSignatureAlgName,
3477 "unexpected signature algorithm name\n");
3478 ok(!certificate_structA->lpszEncryptionAlgName,
3479 "unexpected encryption algorithm name\n");
3480 ok(!certificate_structA->lpszProtocolName,
3481 "unexpected protocol name\n");
3482 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
3483 release_cert_info(certificate_structA);
3485 HeapFree(GetProcessHeap(), 0, certificate_structW);
3487 InternetCloseHandle(req);
3488 InternetCloseHandle(con);
3489 InternetCloseHandle(ses);
3492 static void test_user_agent_header(void)
3494 HINTERNET ses, con, req;
3499 ses = InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
3500 ok(ses != NULL, "InternetOpen failed\n");
3502 con = InternetConnect(ses, "test.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3503 ok(con != NULL, "InternetConnect failed\n");
3505 req = HttpOpenRequest(con, "GET", "/tests/hello.html", "HTTP/1.0", NULL, NULL, 0, 0);
3506 ok(req != NULL, "HttpOpenRequest failed\n");
3508 size = sizeof(buffer);
3509 ret = HttpQueryInfo(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3510 err = GetLastError();
3511 ok(!ret, "HttpQueryInfo succeeded\n");
3512 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
3514 ret = HttpAddRequestHeaders(req, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
3515 ok(ret, "HttpAddRequestHeaders succeeded\n");
3517 size = sizeof(buffer);
3518 ret = HttpQueryInfo(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3519 err = GetLastError();
3520 ok(ret, "HttpQueryInfo failed\n");
3521 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
3523 InternetCloseHandle(req);
3525 req = HttpOpenRequest(con, "GET", "/", "HTTP/1.0", NULL, NULL, 0, 0);
3526 ok(req != NULL, "HttpOpenRequest failed\n");
3528 size = sizeof(buffer);
3529 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3530 err = GetLastError();
3531 ok(!ret, "HttpQueryInfo succeeded\n");
3532 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
3534 ret = HttpAddRequestHeaders(req, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
3535 ok(ret, "HttpAddRequestHeaders failed\n");
3538 size = sizeof(buffer);
3539 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3540 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
3541 ok(!strcmp(buffer, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer);
3543 InternetCloseHandle(req);
3544 InternetCloseHandle(con);
3545 InternetCloseHandle(ses);
3548 static void test_bogus_accept_types_array(void)
3550 HINTERNET ses, con, req;
3551 static const char *types[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL };
3556 ses = InternetOpen("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT, "", "", 0);
3557 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3558 req = HttpOpenRequest(con, "POST", "/post/post_action.php", "HTTP/1.0", "", types, INTERNET_FLAG_FORMS_SUBMIT, 0);
3560 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
3563 size = sizeof(buffer);
3564 SetLastError(0xdeadbeef);
3565 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3566 error = GetLastError();
3567 ok(!ret || broken(ret), "HttpQueryInfo succeeded\n");
3568 if (!ret) ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error);
3569 ok(broken(!strcmp(buffer, ", */*, %p, , , */*")) /* IE6 */ ||
3570 broken(!strcmp(buffer, "*/*, %p, */*")) /* IE7/8 */ ||
3571 !strcmp(buffer, ""), "got '%s' expected ''\n", buffer);
3573 InternetCloseHandle(req);
3574 InternetCloseHandle(con);
3575 InternetCloseHandle(ses);
3584 static void WINAPI cb(HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID info, DWORD size)
3586 INTERNET_ASYNC_RESULT *result = info;
3587 struct context *ctx = (struct context *)context;
3589 trace("%p 0x%08lx %u %p 0x%08x\n", handle, context, status, info, size);
3591 if (status == INTERNET_STATUS_REQUEST_COMPLETE)
3593 trace("request handle: 0x%08lx\n", result->dwResult);
3594 ctx->req = (HINTERNET)result->dwResult;
3595 SetEvent(ctx->event);
3597 if (status == INTERNET_STATUS_HANDLE_CLOSING)
3599 DWORD type = INTERNET_HANDLE_TYPE_CONNECT_HTTP, size = sizeof(type);
3601 if (InternetQueryOption(handle, INTERNET_OPTION_HANDLE_TYPE, &type, &size))
3602 ok(type != INTERNET_HANDLE_TYPE_CONNECT_HTTP, "unexpected callback\n");
3603 SetEvent(ctx->event);
3607 static void test_open_url_async(void)
3616 ctx.event = CreateEvent(NULL, TRUE, FALSE, "Z:_home_hans_jaman-installer.exe_ev1");
3618 ses = InternetOpen("AdvancedInstaller", 0, NULL, NULL, INTERNET_FLAG_ASYNC);
3619 ok(ses != NULL, "InternetOpen failed\n");
3621 SetLastError(0xdeadbeef);
3622 ret = InternetSetOptionA(NULL, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR));
3623 error = GetLastError();
3624 ok(!ret, "InternetSetOptionA succeeded\n");
3625 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error);
3627 ret = InternetSetOptionA(ses, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR));
3628 error = GetLastError();
3629 ok(!ret, "InternetSetOptionA failed\n");
3630 ok(error == ERROR_INTERNET_OPTION_NOT_SETTABLE, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error);
3632 pInternetSetStatusCallbackA(ses, cb);
3633 ResetEvent(ctx.event);
3635 req = InternetOpenUrl(ses, "http://test.winehq.org", NULL, 0, 0, (DWORD_PTR)&ctx);
3636 ok(!req && GetLastError() == ERROR_IO_PENDING, "InternetOpenUrl failed\n");
3638 WaitForSingleObject(ctx.event, INFINITE);
3641 size = sizeof(type);
3642 ret = InternetQueryOption(ctx.req, INTERNET_OPTION_HANDLE_TYPE, &type, &size);
3643 ok(ret, "InternetQueryOption failed: %u\n", GetLastError());
3644 ok(type == INTERNET_HANDLE_TYPE_HTTP_REQUEST,
3645 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type);
3648 ret = HttpQueryInfo(ctx.req, HTTP_QUERY_RAW_HEADERS_CRLF, NULL, &size, NULL);
3649 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "HttpQueryInfo failed\n");
3650 ok(size > 0, "expected size > 0\n");
3652 ResetEvent(ctx.event);
3653 InternetCloseHandle(ctx.req);
3654 WaitForSingleObject(ctx.event, INFINITE);
3656 InternetCloseHandle(ses);
3657 CloseHandle(ctx.event);
3662 internet_connect = 1,
3664 http_send_request_ex,
3667 internet_close_handle
3672 enum api function; /* api responsible for notification */
3673 unsigned int status; /* status received */
3674 int async; /* delivered from another thread? */
3682 const struct notification *test;
3688 DWORD expect_result;
3692 static CRITICAL_SECTION notification_cs;
3694 static void CALLBACK check_notification( HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID buffer, DWORD buflen )
3696 BOOL status_ok, function_ok;
3697 struct info *info = (struct info *)context;
3700 EnterCriticalSection( ¬ification_cs );
3702 if(info->is_aborted) {
3703 LeaveCriticalSection(¬ification_cs);
3707 if (status == INTERNET_STATUS_HANDLE_CREATED)
3709 DWORD size = sizeof(struct info *);
3710 HttpQueryInfoA( handle, INTERNET_OPTION_CONTEXT_VALUE, &info, &size, 0 );
3711 }else if(status == INTERNET_STATUS_REQUEST_COMPLETE) {
3712 INTERNET_ASYNC_RESULT *ar = (INTERNET_ASYNC_RESULT*)buffer;
3714 ok(buflen == sizeof(*ar), "unexpected buflen = %d\n", buflen);
3715 if(info->expect_result == ERROR_SUCCESS) {
3716 ok(ar->dwResult == 1, "ar->dwResult = %ld, expected 1\n", ar->dwResult);
3718 ok(!ar->dwResult, "ar->dwResult = %ld, expected 1\n", ar->dwResult);
3719 ok(ar->dwError == info->expect_result, "ar->dwError = %d, expected %d\n", ar->dwError, info->expect_result);
3724 if (i >= info->count)
3726 LeaveCriticalSection( ¬ification_cs );
3730 while (info->test[i].status != status &&
3731 (info->test[i].optional || info->test[i].todo) &&
3732 i < info->count - 1 &&
3733 info->test[i].function == info->test[i + 1].function)
3738 status_ok = (info->test[i].status == status);
3739 function_ok = (info->test[i].function == info->function);
3741 if (!info->test[i].todo)
3743 ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status );
3744 ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
3746 if (info->test[i].async)
3747 ok(info->thread != GetCurrentThreadId(), "%u: expected thread %u got %u\n",
3748 info->line, info->thread, GetCurrentThreadId());
3752 todo_wine ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status );
3754 todo_wine ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
3756 if (i == info->count - 1 || info->test[i].function != info->test[i + 1].function) SetEvent( info->wait );
3759 LeaveCriticalSection( ¬ification_cs );
3762 static void setup_test( struct info *info, enum api function, unsigned int line, DWORD expect_result )
3764 info->function = function;
3766 info->expect_result = expect_result;
3769 struct notification_data
3771 const struct notification *test;
3772 const unsigned int count;
3777 BOOL expect_conn_failure;
3780 static const struct notification async_send_request_ex_test[] =
3782 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, 0 },
3783 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, 0 },
3784 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
3785 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, 1, 0, 1 },
3786 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, 1, 0, 1 },
3787 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, 1, 0, 1 },
3788 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, 1 },
3789 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, 1 },
3790 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, 1 },
3791 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, 1 },
3792 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
3793 { internet_writefile, INTERNET_STATUS_SENDING_REQUEST, 0 },
3794 { internet_writefile, INTERNET_STATUS_REQUEST_SENT, 0 },
3795 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, 1 },
3796 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, 1 },
3797 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
3798 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, 0, 0, 1 },
3799 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, 0, 0, 1 },
3800 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, },
3801 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, }
3804 static const struct notification async_send_request_ex_test2[] =
3806 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, 0 },
3807 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, 0 },
3808 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
3809 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, 1, 0, 1 },
3810 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, 1, 0, 1 },
3811 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, 1, 0, 1 },
3812 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, 1, 1 },
3813 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, 1, 1 },
3814 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, 1 },
3815 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, 1 },
3816 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
3817 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, 1 },
3818 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, 1 },
3819 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
3820 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, 0, 0, 1 },
3821 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, 0, 0, 1 },
3822 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, },
3823 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, }
3826 static const struct notification async_send_request_ex_resolve_failure_test[] =
3828 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, 0 },
3829 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, 0 },
3830 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
3831 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, 1 },
3832 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
3833 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
3834 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
3835 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, 0, 0, 1 },
3836 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, 0, 0, 1 },
3837 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, },
3838 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, }
3841 static const struct notification_data notification_data[] = {
3843 async_send_request_ex_test,
3844 sizeof(async_send_request_ex_test)/sizeof(async_send_request_ex_test[0]),
3847 "tests/posttest.php",
3848 "Public ID=codeweavers"
3851 async_send_request_ex_test2,
3852 sizeof(async_send_request_ex_test)/sizeof(async_send_request_ex_test[0]),
3855 "tests/posttest.php"
3858 async_send_request_ex_resolve_failure_test,
3859 sizeof(async_send_request_ex_resolve_failure_test)/sizeof(async_send_request_ex_resolve_failure_test[0]),
3868 static void test_async_HttpSendRequestEx(const struct notification_data *nd)
3871 HINTERNET ses, req, con;
3873 DWORD size, written, error;
3874 INTERNET_BUFFERSA b;
3875 static const char *accept[2] = {"*/*", NULL};
3878 trace("Async HttpSendRequestEx test (%s %s)\n", nd->method, nd->host);
3880 InitializeCriticalSection( ¬ification_cs );
3882 info.test = nd->test;
3883 info.count = nd->count;
3885 info.wait = CreateEvent( NULL, FALSE, FALSE, NULL );
3886 info.thread = GetCurrentThreadId();
3887 info.is_aborted = FALSE;
3889 ses = InternetOpen( "winetest", 0, NULL, NULL, INTERNET_FLAG_ASYNC );
3890 ok( ses != NULL, "InternetOpen failed\n" );
3892 pInternetSetStatusCallbackA( ses, check_notification );
3894 setup_test( &info, internet_connect, __LINE__, ERROR_SUCCESS );
3895 con = InternetConnect( ses, nd->host, 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, (DWORD_PTR)&info );
3896 ok( con != NULL, "InternetConnect failed %u\n", GetLastError() );
3898 WaitForSingleObject( info.wait, 10000 );
3900 setup_test( &info, http_open_request, __LINE__, ERROR_SUCCESS );
3901 req = HttpOpenRequest( con, nd->method, nd->path, NULL, NULL, accept, 0, (DWORD_PTR)&info );
3902 ok( req != NULL, "HttpOpenRequest failed %u\n", GetLastError() );
3904 WaitForSingleObject( info.wait, 10000 );
3907 memset( &b, 0, sizeof(INTERNET_BUFFERSA) );
3908 b.dwStructSize = sizeof(INTERNET_BUFFERSA);
3909 b.lpcszHeader = "Content-Type: application/x-www-form-urlencoded";
3910 b.dwHeadersLength = strlen( b.lpcszHeader );
3911 b.dwBufferTotal = nd->data ? strlen( nd->data ) : 0;
3914 setup_test( &info, http_send_request_ex, __LINE__,
3915 nd->expect_conn_failure ? ERROR_INTERNET_NAME_NOT_RESOLVED : ERROR_SUCCESS );
3916 ret = HttpSendRequestExA( req, nd->data ? &b : NULL, NULL, 0x28, 0 );
3917 ok( !ret && GetLastError() == ERROR_IO_PENDING, "HttpSendRequestExA failed %d %u\n", ret, GetLastError() );
3919 error = WaitForSingleObject( info.wait, 10000 );
3920 if(error != WAIT_OBJECT_0) {
3921 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error);
3922 info.is_aborted = TRUE;
3926 size = sizeof(buffer);
3927 SetLastError( 0xdeadbeef );
3928 ret = HttpQueryInfoA( req, HTTP_QUERY_CONTENT_ENCODING, buffer, &size, 0 );
3929 error = GetLastError();
3930 ok( !ret, "HttpQueryInfoA failed %u\n", GetLastError() );
3931 if(nd->expect_conn_failure) {
3932 ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error );
3935 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_STATE,
3936 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error );
3942 size = strlen( nd->data );
3943 setup_test( &info, internet_writefile, __LINE__, ERROR_SUCCESS );
3944 ret = InternetWriteFile( req, nd->data, size, &written );
3945 ok( ret, "InternetWriteFile failed %u\n", GetLastError() );
3946 ok( written == size, "expected %u got %u\n", written, size );
3948 WaitForSingleObject( info.wait, 10000 );
3950 SetLastError( 0xdeadbeef );
3951 ret = HttpEndRequestA( req, (void *)nd->data, 0x28, 0 );
3952 error = GetLastError();
3953 ok( !ret, "HttpEndRequestA succeeded\n" );
3954 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error );
3957 SetLastError( 0xdeadbeef );
3958 setup_test( &info, http_end_request, __LINE__,
3959 nd->expect_conn_failure ? ERROR_INTERNET_OPERATION_CANCELLED : ERROR_SUCCESS);
3960 ret = HttpEndRequestA( req, NULL, 0x28, 0 );
3961 error = GetLastError();
3962 ok( !ret, "HttpEndRequestA succeeded\n" );
3963 ok( error == ERROR_IO_PENDING, "expected ERROR_IO_PENDING got %u\n", error );
3965 WaitForSingleObject( info.wait, 10000 );
3967 setup_test( &info, internet_close_handle, __LINE__, ERROR_SUCCESS );
3969 InternetCloseHandle( req );
3970 InternetCloseHandle( con );
3971 InternetCloseHandle( ses );
3973 WaitForSingleObject( info.wait, 10000 );
3975 CloseHandle( info.wait );
3978 static HINTERNET closetest_session, closetest_req, closetest_conn;
3979 static BOOL closetest_closed;
3981 static void WINAPI closetest_callback(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus,
3982 LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
3987 trace("closetest_callback %p: %d\n", hInternet, dwInternetStatus);
3989 ok(hInternet == closetest_session || hInternet == closetest_conn || hInternet == closetest_req,
3990 "Unexpected hInternet %p\n", hInternet);
3991 if(!closetest_closed)
3995 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_HANDLE_TYPE, &type, &len);
3996 ok(!res && GetLastError() == ERROR_INVALID_HANDLE,
3997 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
3998 closetest_req, res, GetLastError());
4001 static void test_InternetCloseHandle(void)
4006 closetest_session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
4007 ok(closetest_session != NULL,"InternetOpen failed with error %u\n", GetLastError());
4009 pInternetSetStatusCallbackA(closetest_session, closetest_callback);
4011 closetest_conn = InternetConnectA(closetest_session, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER,
4012 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
4013 ok(closetest_conn != NULL,"InternetConnect failed with error %u\n", GetLastError());
4015 closetest_req = HttpOpenRequestA(closetest_conn, "GET", "winegecko.php", NULL, NULL, NULL,
4016 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
4018 res = HttpSendRequestA(closetest_req, NULL, -1, NULL, 0);
4019 ok(!res && (GetLastError() == ERROR_IO_PENDING),
4020 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
4022 test_request_flags(closetest_req, INTERNET_REQFLAG_NO_HEADERS);
4024 res = InternetCloseHandle(closetest_session);
4025 ok(res, "InternetCloseHandle failed: %u\n", GetLastError());
4026 closetest_closed = TRUE;
4027 trace("Closed session handle\n");
4029 res = InternetCloseHandle(closetest_conn);
4030 ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(conn) failed: %x %u\n",
4031 res, GetLastError());
4033 res = InternetCloseHandle(closetest_req);
4034 ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(req) failed: %x %u\n",
4035 res, GetLastError());
4037 len = sizeof(flags);
4038 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &len);
4039 ok(!res && GetLastError() == ERROR_INVALID_HANDLE,
4040 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
4041 closetest_req, res, GetLastError());
4044 static void init_status_tests(void)
4046 memset(expect, 0, sizeof(expect));
4047 memset(optional, 0, sizeof(optional));
4048 memset(wine_allow, 0, sizeof(wine_allow));
4049 memset(notified, 0, sizeof(notified));
4050 memset(status_string, 0, sizeof(status_string));
4052 #define STATUS_STRING(status) status_string[status] = #status
4053 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME);
4054 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED);
4055 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER);
4056 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER);
4057 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST);
4058 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT);
4059 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE);
4060 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED);
4061 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED);
4062 STATUS_STRING(INTERNET_STATUS_PREFETCH);
4063 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION);
4064 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED);
4065 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED);
4066 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING);
4067 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY);
4068 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE);
4069 STATUS_STRING(INTERNET_STATUS_REDIRECT);
4070 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE);
4071 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED);
4072 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE);
4073 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT);
4074 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED);
4075 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED);
4076 STATUS_STRING(INTERNET_STATUS_P3P_HEADER);
4077 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF);
4078 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY);
4079 #undef STATUS_STRING
4085 hdll = GetModuleHandleA("wininet.dll");
4087 if(!GetProcAddress(hdll, "InternetGetCookieExW")) {
4088 win_skip("Too old IE (older than 6.0)\n");
4092 pInternetSetStatusCallbackA = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackA");
4093 pInternetGetSecurityInfoByURLA = (void*)GetProcAddress(hdll, "InternetGetSecurityInfoByURLA");
4095 init_status_tests();
4096 test_InternetCloseHandle();
4097 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[0]);
4098 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[1]);
4099 InternetReadFile_test(0, &test_data[1]);
4100 first_connection_to_test_url = TRUE;
4101 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[2]);
4102 test_security_flags();
4103 InternetReadFile_test(0, &test_data[2]);
4104 InternetReadFileExA_test(INTERNET_FLAG_ASYNC);
4105 test_open_url_async();
4106 test_async_HttpSendRequestEx(¬ification_data[0]);
4107 test_async_HttpSendRequestEx(¬ification_data[1]);
4108 test_async_HttpSendRequestEx(¬ification_data[2]);
4109 InternetOpenRequest_test();
4111 InternetOpenUrlA_test();
4113 test_http_connection();
4114 test_secure_connection();
4115 test_user_agent_header();
4116 test_bogus_accept_types_array();
4117 InternetReadFile_chunked_test();
4118 HttpSendRequestEx_test();
4119 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[3]);