wininet/tests: Add more tests for INTERNET_INVALID_PORT_NUMBER.
[wine.git] / dlls / wininet / tests / http.c
blob66ba526f2fcf2aa61df47915085127236e75542a
1 /*
2 * Wininet - HTTP tests
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
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wininet.h"
30 #include "winineti.h"
31 #include "winsock2.h"
33 #include "wine/test.h"
35 /* Undocumented security flags */
36 #define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
37 #define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
38 #define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
39 #define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
41 #define TEST_URL "http://test.winehq.org/tests/hello.html"
43 static BOOL first_connection_to_test_url = TRUE;
45 /* Adapted from dlls/urlmon/tests/protocol.c */
47 #define SET_EXPECT2(status, num) \
48 expect[status] = num
50 #define SET_EXPECT(status) \
51 SET_EXPECT2(status, 1)
53 #define SET_OPTIONAL2(status, num) \
54 optional[status] = num
56 #define SET_OPTIONAL(status) \
57 SET_OPTIONAL2(status, 1)
59 /* SET_WINE_ALLOW's should be used with an appropriate
60 * todo_wine CHECK_NOTIFIED at a later point in the code */
61 #define SET_WINE_ALLOW2(status, num) \
62 wine_allow[status] = num
64 #define SET_WINE_ALLOW(status) \
65 SET_WINE_ALLOW2(status, 1)
67 #define CHECK_EXPECT(status) \
68 do { \
69 if (!expect[status] && !optional[status] && wine_allow[status]) \
70 { \
71 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
72 status < MAX_INTERNET_STATUS && status_string[status] ? \
73 status_string[status] : "unknown"); \
74 wine_allow[status]--; \
75 } \
76 else \
77 { \
78 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
79 status < MAX_INTERNET_STATUS && status_string[status] ? \
80 status_string[status] : "unknown"); \
81 if (expect[status]) expect[status]--; \
82 else if(optional[status]) optional[status]--; \
83 } \
84 notified[status]++; \
85 }while(0)
87 /* CLEAR_NOTIFIED used in cases when notification behavior
88 * differs between Windows versions */
89 #define CLEAR_NOTIFIED(status) \
90 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
92 #define CHECK_NOTIFIED2(status, num) \
93 do { \
94 ok(notified[status] + optional[status] == (num), \
95 "expected status %d (%s) %d times, received %d times\n", \
96 status, status < MAX_INTERNET_STATUS && status_string[status] ? \
97 status_string[status] : "unknown", (num), notified[status]); \
98 CLEAR_NOTIFIED(status); \
99 }while(0)
101 #define CHECK_NOTIFIED(status) \
102 CHECK_NOTIFIED2(status, 1)
104 #define CHECK_NOT_NOTIFIED(status) \
105 CHECK_NOTIFIED2(status, 0)
107 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
108 static int expect[MAX_INTERNET_STATUS], optional[MAX_INTERNET_STATUS],
109 wine_allow[MAX_INTERNET_STATUS], notified[MAX_INTERNET_STATUS];
110 static const char *status_string[MAX_INTERNET_STATUS];
112 static HANDLE hCompleteEvent, conn_close_event;
113 static DWORD req_error;
115 #define TESTF_REDIRECT 0x01
116 #define TESTF_COMPRESSED 0x02
117 #define TESTF_CHUNKED 0x04
119 typedef struct {
120 const char *url;
121 const char *redirected_url;
122 const char *host;
123 const char *path;
124 const char *headers;
125 DWORD flags;
126 const char *post_data;
127 const char *content;
128 } test_data_t;
130 static const test_data_t test_data[] = {
132 "http://test.winehq.org/tests/data.php",
133 "http://test.winehq.org/tests/data.php",
134 "test.winehq.org",
135 "/tests/data.php",
137 TESTF_CHUNKED
140 "http://test.winehq.org/tests/redirect",
141 "http://test.winehq.org/tests/hello.html",
142 "test.winehq.org",
143 "/tests/redirect",
145 TESTF_REDIRECT
148 "http://test.winehq.org/tests/gzip.php",
149 "http://test.winehq.org/tests/gzip.php",
150 "test.winehq.org",
151 "/tests/gzip.php",
152 "Accept-Encoding: gzip, deflate",
153 TESTF_COMPRESSED
156 "http://test.winehq.org/tests/post.php",
157 "http://test.winehq.org/tests/post.php",
158 "test.winehq.org",
159 "/tests/post.php",
160 "Content-Type: application/x-www-form-urlencoded",
162 "mode=Test",
163 "mode => Test\n"
167 static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackA)(HINTERNET ,INTERNET_STATUS_CALLBACK);
168 static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackW)(HINTERNET ,INTERNET_STATUS_CALLBACK);
169 static BOOL (WINAPI *pInternetGetSecurityInfoByURLA)(LPSTR,PCCERT_CHAIN_CONTEXT*,DWORD*);
171 static int strcmp_wa(LPCWSTR strw, const char *stra)
173 WCHAR buf[512];
174 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
175 return lstrcmpW(strw, buf);
178 static BOOL proxy_active(void)
180 HKEY internet_settings;
181 DWORD proxy_enable;
182 DWORD size;
184 if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
185 0, KEY_QUERY_VALUE, &internet_settings) != ERROR_SUCCESS)
186 return FALSE;
188 size = sizeof(DWORD);
189 if (RegQueryValueExA(internet_settings, "ProxyEnable", NULL, NULL, (LPBYTE) &proxy_enable, &size) != ERROR_SUCCESS)
190 proxy_enable = 0;
192 RegCloseKey(internet_settings);
194 return proxy_enable != 0;
197 #define test_status_code(a,b) _test_status_code(__LINE__,a,b, FALSE)
198 #define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)
199 static void _test_status_code(unsigned line, HINTERNET req, DWORD excode, BOOL is_todo)
201 DWORD code, size, index;
202 char exbuf[10], bufa[10];
203 WCHAR bufw[10];
204 BOOL res;
206 code = 0xdeadbeef;
207 size = sizeof(code);
208 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, NULL);
209 ok_(__FILE__,line)(res, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
210 todo_wine_if (is_todo)
211 ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
212 ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
214 code = 0xdeadbeef;
215 index = 0;
216 size = sizeof(code);
217 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index);
218 ok_(__FILE__,line)(res, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
219 ok_(__FILE__,line)(!index, "index = %d, expected 0\n", index);
220 ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
222 sprintf(exbuf, "%u", excode);
224 size = sizeof(bufa);
225 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, bufa, &size, NULL);
226 ok_(__FILE__,line)(res, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
227 todo_wine_if (is_todo)
228 ok_(__FILE__,line)(!strcmp(bufa, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
229 ok_(__FILE__,line)(size == strlen(exbuf), "unexpected size %d for \"%s\"\n", size, exbuf);
231 size = 0;
232 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, NULL, &size, NULL);
233 ok_(__FILE__,line)(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
234 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
235 ok_(__FILE__,line)(size == strlen(exbuf)+1, "unexpected size %d for \"%s\"\n", size, exbuf);
237 size = sizeof(bufw);
238 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL);
239 ok_(__FILE__,line)(res, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
240 todo_wine_if (is_todo)
241 ok_(__FILE__,line)(!strcmp_wa(bufw, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
242 ok_(__FILE__,line)(size == strlen(exbuf)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
244 size = 0;
245 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL);
246 ok_(__FILE__,line)(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
247 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
248 ok_(__FILE__,line)(size == (strlen(exbuf)+1)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
250 if(0) {
251 size = sizeof(bufw);
252 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, NULL, &size, NULL);
253 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
254 ok(size == sizeof(bufw), "unexpected size %d\n", size);
257 code = 0xdeadbeef;
258 index = 1;
259 size = sizeof(code);
260 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index);
261 ok_(__FILE__,line)(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
262 "[7] HttpQueryInfoA failed: %x(%d)\n", res, GetLastError());
264 code = 0xdeadbeef;
265 size = sizeof(code);
266 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_REQUEST_HEADERS, &code, &size, NULL);
267 ok_(__FILE__,line)(!res && GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST,
268 "[8] HttpQueryInfoA failed: %x(%d)\n", res, GetLastError());
271 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
272 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
273 static void _test_request_flags(unsigned line, HINTERNET req, DWORD exflags, BOOL is_todo)
275 DWORD flags, size;
276 BOOL res;
278 flags = 0xdeadbeef;
279 size = sizeof(flags);
280 res = InternetQueryOptionW(req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &size);
281 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
283 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
284 flags &= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED;
285 todo_wine_if (is_todo)
286 ok_(__FILE__,line)(flags == exflags, "flags = %x, expected %x\n", flags, exflags);
289 #define test_http_version(a) _test_http_version(__LINE__,a)
290 static void _test_http_version(unsigned line, HINTERNET req)
292 HTTP_VERSION_INFO v = {0xdeadbeef, 0xdeadbeef};
293 DWORD size;
294 BOOL res;
296 size = sizeof(v);
297 res = InternetQueryOptionW(req, INTERNET_OPTION_HTTP_VERSION, &v, &size);
298 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
299 ok_(__FILE__,line)(v.dwMajorVersion == 1, "dwMajorVersion = %d\n", v.dwMajorVersion);
300 ok_(__FILE__,line)(v.dwMinorVersion == 1, "dwMinorVersion = %d\n", v.dwMinorVersion);
303 static int close_handle_cnt;
305 static VOID WINAPI callback(
306 HINTERNET hInternet,
307 DWORD_PTR dwContext,
308 DWORD dwInternetStatus,
309 LPVOID lpvStatusInformation,
310 DWORD dwStatusInformationLength
313 CHECK_EXPECT(dwInternetStatus);
314 switch (dwInternetStatus)
316 case INTERNET_STATUS_RESOLVING_NAME:
317 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
318 GetCurrentThreadId(), hInternet, dwContext,
319 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
320 *(LPSTR)lpvStatusInformation = '\0';
321 break;
322 case INTERNET_STATUS_NAME_RESOLVED:
323 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
324 GetCurrentThreadId(), hInternet, dwContext,
325 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
326 *(LPSTR)lpvStatusInformation = '\0';
327 break;
328 case INTERNET_STATUS_CONNECTING_TO_SERVER:
329 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
330 GetCurrentThreadId(), hInternet, dwContext,
331 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
332 ok(dwStatusInformationLength == strlen(lpvStatusInformation)+1, "unexpected size %u\n",
333 dwStatusInformationLength);
334 *(LPSTR)lpvStatusInformation = '\0';
335 break;
336 case INTERNET_STATUS_CONNECTED_TO_SERVER:
337 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
338 GetCurrentThreadId(), hInternet, dwContext,
339 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
340 ok(dwStatusInformationLength == strlen(lpvStatusInformation)+1, "unexpected size %u\n",
341 dwStatusInformationLength);
342 *(LPSTR)lpvStatusInformation = '\0';
343 break;
344 case INTERNET_STATUS_SENDING_REQUEST:
345 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
346 GetCurrentThreadId(), hInternet, dwContext,
347 lpvStatusInformation,dwStatusInformationLength);
348 break;
349 case INTERNET_STATUS_REQUEST_SENT:
350 ok(dwStatusInformationLength == sizeof(DWORD),
351 "info length should be sizeof(DWORD) instead of %d\n",
352 dwStatusInformationLength);
353 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
354 GetCurrentThreadId(), hInternet, dwContext,
355 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
356 break;
357 case INTERNET_STATUS_RECEIVING_RESPONSE:
358 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
359 GetCurrentThreadId(), hInternet, dwContext,
360 lpvStatusInformation,dwStatusInformationLength);
361 break;
362 case INTERNET_STATUS_RESPONSE_RECEIVED:
363 ok(dwStatusInformationLength == sizeof(DWORD),
364 "info length should be sizeof(DWORD) instead of %d\n",
365 dwStatusInformationLength);
366 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
367 GetCurrentThreadId(), hInternet, dwContext,
368 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
369 break;
370 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
371 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
372 GetCurrentThreadId(), hInternet,dwContext,
373 lpvStatusInformation,dwStatusInformationLength);
374 break;
375 case INTERNET_STATUS_PREFETCH:
376 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
377 GetCurrentThreadId(), hInternet, dwContext,
378 lpvStatusInformation,dwStatusInformationLength);
379 break;
380 case INTERNET_STATUS_CLOSING_CONNECTION:
381 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
382 GetCurrentThreadId(), hInternet, dwContext,
383 lpvStatusInformation,dwStatusInformationLength);
384 break;
385 case INTERNET_STATUS_CONNECTION_CLOSED:
386 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
387 GetCurrentThreadId(), hInternet, dwContext,
388 lpvStatusInformation,dwStatusInformationLength);
389 break;
390 case INTERNET_STATUS_HANDLE_CREATED:
391 ok(dwStatusInformationLength == sizeof(HINTERNET),
392 "info length should be sizeof(HINTERNET) instead of %d\n",
393 dwStatusInformationLength);
394 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
395 GetCurrentThreadId(), hInternet, dwContext,
396 *(HINTERNET *)lpvStatusInformation,dwStatusInformationLength);
397 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
398 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
399 break;
400 case INTERNET_STATUS_HANDLE_CLOSING:
401 ok(dwStatusInformationLength == sizeof(HINTERNET),
402 "info length should be sizeof(HINTERNET) instead of %d\n",
403 dwStatusInformationLength);
404 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
405 GetCurrentThreadId(), hInternet, dwContext,
406 *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength);
407 if(!InterlockedDecrement(&close_handle_cnt))
408 SetEvent(hCompleteEvent);
409 break;
410 case INTERNET_STATUS_REQUEST_COMPLETE:
412 INTERNET_ASYNC_RESULT *iar = (INTERNET_ASYNC_RESULT *)lpvStatusInformation;
413 ok(dwStatusInformationLength == sizeof(INTERNET_ASYNC_RESULT),
414 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
415 dwStatusInformationLength);
416 ok(iar->dwResult == 1 || iar->dwResult == 0, "iar->dwResult = %ld\n", iar->dwResult);
417 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
418 GetCurrentThreadId(), hInternet, dwContext,
419 iar->dwResult,iar->dwError,dwStatusInformationLength);
420 req_error = iar->dwError;
421 if(!close_handle_cnt)
422 SetEvent(hCompleteEvent);
423 break;
425 case INTERNET_STATUS_REDIRECT:
426 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
427 GetCurrentThreadId(), hInternet, dwContext,
428 (LPCSTR)lpvStatusInformation, dwStatusInformationLength);
429 *(LPSTR)lpvStatusInformation = '\0';
430 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
431 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
432 break;
433 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
434 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
435 GetCurrentThreadId(), hInternet, dwContext,
436 lpvStatusInformation, dwStatusInformationLength);
437 break;
438 default:
439 trace("%04x:Callback %p 0x%lx %d %p %d\n",
440 GetCurrentThreadId(), hInternet, dwContext, dwInternetStatus,
441 lpvStatusInformation, dwStatusInformationLength);
445 static void close_async_handle(HINTERNET handle, HANDLE complete_event, int handle_cnt)
447 BOOL res;
449 close_handle_cnt = handle_cnt;
451 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
452 res = InternetCloseHandle(handle);
453 ok(res, "InternetCloseHandle failed: %u\n", GetLastError());
454 WaitForSingleObject(hCompleteEvent, INFINITE);
455 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
458 static void InternetReadFile_test(int flags, const test_data_t *test)
460 char *post_data = NULL;
461 BOOL res, on_async = TRUE;
462 CHAR buffer[4000];
463 WCHAR wbuffer[4000];
464 DWORD length, length2, index, exlen = 0, post_len = 0;
465 const char *types[2] = { "*", NULL };
466 HINTERNET hi, hic = 0, hor = 0;
468 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
470 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags,test->url);
472 trace("InternetOpenA <--\n");
473 hi = InternetOpenA((test->flags & TESTF_COMPRESSED) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
474 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
475 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
476 trace("InternetOpenA -->\n");
478 if (hi == 0x0) goto abort;
480 pInternetSetStatusCallbackA(hi,&callback);
482 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
484 trace("InternetConnectA <--\n");
485 hic=InternetConnectA(hi, test->host, INTERNET_INVALID_PORT_NUMBER,
486 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
487 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
488 trace("InternetConnectA -->\n");
490 if (hic == 0x0) goto abort;
492 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
493 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
495 trace("HttpOpenRequestA <--\n");
496 hor = HttpOpenRequestA(hic, test->post_data ? "POST" : "GET", test->path, NULL, NULL, types,
497 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
498 0xdeadbead);
499 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
501 * If the internet name can't be resolved we are probably behind
502 * a firewall or in some other way not directly connected to the
503 * Internet. Not enough reason to fail the test. Just ignore and
504 * abort.
506 } else {
507 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
509 trace("HttpOpenRequestA -->\n");
511 if (hor == 0x0) goto abort;
513 test_request_flags(hor, INTERNET_REQFLAG_NO_HEADERS);
515 length = sizeof(buffer);
516 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
517 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
518 ok(!strcmp(buffer, test->url), "Wrong URL %s, expected %s\n", buffer, test->url);
520 length = sizeof(buffer);
521 res = HttpQueryInfoA(hor, HTTP_QUERY_RAW_HEADERS, buffer, &length, 0x0);
522 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
523 ok(length == 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length);
524 ok(!strcmp(buffer, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer);
526 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
527 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
528 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
529 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT,2);
530 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED,2);
531 if (first_connection_to_test_url)
533 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
534 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
536 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
537 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
538 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, (test->flags & TESTF_REDIRECT) ? 2 : 1);
539 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, (test->flags & TESTF_REDIRECT) ? 2 : 1);
540 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, (test->flags & TESTF_REDIRECT) ? 2 : 1);
541 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, (test->flags & TESTF_REDIRECT) ? 2 : 1);
542 if(test->flags & TESTF_REDIRECT) {
543 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
544 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
546 SET_EXPECT(INTERNET_STATUS_REDIRECT);
547 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER);
548 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER);
549 if (flags & INTERNET_FLAG_ASYNC)
550 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
552 if(test->flags & TESTF_COMPRESSED) {
553 BOOL b = TRUE;
555 res = InternetSetOptionA(hor, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b));
556 ok(res || broken(!res && GetLastError() == ERROR_INTERNET_INVALID_OPTION),
557 "InternetSetOption failed: %u\n", GetLastError());
558 if(!res)
559 goto abort;
562 test_status_code(hor, 0);
564 trace("HttpSendRequestA -->\n");
565 if(test->post_data) {
566 post_len = strlen(test->post_data);
567 post_data = HeapAlloc(GetProcessHeap(), 0, post_len);
568 memcpy(post_data, test->post_data, post_len);
570 SetLastError(0xdeadbeef);
571 res = HttpSendRequestA(hor, test->headers, -1, post_data, post_len);
572 if (flags & INTERNET_FLAG_ASYNC)
573 ok(!res && (GetLastError() == ERROR_IO_PENDING),
574 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
575 else
576 ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED),
577 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
578 trace("HttpSendRequestA <--\n");
580 if (flags & INTERNET_FLAG_ASYNC) {
581 WaitForSingleObject(hCompleteEvent, INFINITE);
582 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
584 HeapFree(GetProcessHeap(), 0, post_data);
586 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
587 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED);
588 if (first_connection_to_test_url)
590 if (! proxy_active())
592 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
593 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
595 else
597 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
598 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
601 else
603 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
604 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
606 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, (test->flags & TESTF_REDIRECT) ? 2 : 1);
607 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, (test->flags & TESTF_REDIRECT) ? 2 : 1);
608 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, (test->flags & TESTF_REDIRECT) ? 2 : 1);
609 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, (test->flags & TESTF_REDIRECT) ? 2 : 1);
610 if(test->flags & TESTF_REDIRECT)
611 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
612 if (flags & INTERNET_FLAG_ASYNC)
613 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
614 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
615 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
616 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
618 test_request_flags(hor, 0);
620 length = 100;
621 res = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
622 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
624 length = sizeof(buffer)-1;
625 memset(buffer, 0x77, sizeof(buffer));
626 res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0);
627 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
628 /* show that the function writes data past the length returned */
629 ok(buffer[length-2], "Expected any header character, got 0x00\n");
630 ok(!buffer[length-1], "Expected 0x00, got %02X\n", buffer[length-1]);
631 ok(!buffer[length], "Expected 0x00, got %02X\n", buffer[length]);
632 ok(buffer[length+1] == 0x77, "Expected 0x77, got %02X\n", buffer[length+1]);
634 length2 = length;
635 res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length2,0x0);
636 ok(!res, "Expected 0x00, got %d\n", res);
637 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
638 ok(length2 == length+1, "Expected %d, got %d\n", length+1, length2);
639 /* the in length of the buffer must be +1 but the length returned does not count this */
640 length2 = length+1;
641 memset(buffer, 0x77, sizeof(buffer));
642 res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length2,0x0);
643 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
644 ok(buffer[length2] == 0x00, "Expected 0x00, got %02X\n", buffer[length2]);
645 ok(buffer[length2+1] == 0x77, "Expected 0x77, got %02X\n", buffer[length2+1]);
646 ok(length2 == length, "Value should not have changed: %d != %d\n", length2, length);
648 length = sizeof(wbuffer)-sizeof(WCHAR);
649 memset(wbuffer, 0x77, sizeof(wbuffer));
650 res = HttpQueryInfoW(hor, HTTP_QUERY_RAW_HEADERS, wbuffer, &length, 0x0);
651 ok(res, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
652 ok(length % sizeof(WCHAR) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length);
653 length /= sizeof(WCHAR);
654 /* show that the function writes data past the length returned */
655 ok(wbuffer[length-2], "Expected any header character, got 0x0000\n");
656 ok(!wbuffer[length-1], "Expected 0x0000, got %04X\n", wbuffer[length-1]);
657 ok(!wbuffer[length], "Expected 0x0000, got %04X\n", wbuffer[length]);
658 ok(wbuffer[length+1] == 0x7777 || broken(wbuffer[length+1] != 0x7777),
659 "Expected 0x7777, got %04X\n", wbuffer[length+1]);
661 length2 = length*sizeof(WCHAR);
662 res = HttpQueryInfoW(hor,HTTP_QUERY_RAW_HEADERS,wbuffer,&length2,0x0);
663 ok(!res, "Expected 0x00, got %d\n", res);
664 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
665 ok(length2 % sizeof(WCHAR) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2);
666 length2 /= sizeof(WCHAR);
667 ok(length2 == length+1, "Expected %d, got %d\n", length+1, length2);
668 /* the in length of the buffer must be +1 but the length returned does not count this */
669 length2 = (length+1)*sizeof(WCHAR);
670 memset(wbuffer, 0x77, sizeof(wbuffer));
671 res = HttpQueryInfoW(hor,HTTP_QUERY_RAW_HEADERS,wbuffer,&length2,0x0);
672 ok(res, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
673 ok(length2 % sizeof(WCHAR) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2);
674 length2 /= sizeof(WCHAR);
675 ok(!wbuffer[length2], "Expected 0x0000, got %04X\n", wbuffer[length2]);
676 ok(wbuffer[length2+1] == 0x7777, "Expected 0x7777, got %04X\n", wbuffer[length2+1]);
677 ok(length2 == length, "Value should not have changed: %d != %d\n", length2, length);
679 length = sizeof(buffer);
680 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
681 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
682 ok(!strcmp(buffer, test->redirected_url), "Wrong URL %s\n", buffer);
684 index = 0;
685 length = 0;
686 SetLastError(0xdeadbeef);
687 ok(HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,NULL,&length,&index) == FALSE,"Query worked\n");
688 if(test->flags & TESTF_COMPRESSED)
689 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
690 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
691 ok(index == 0, "Index was incremented\n");
693 index = 0;
694 length = 16;
695 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,&index);
696 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res,buffer,GetLastError());
697 if(test->flags & TESTF_COMPRESSED)
698 ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
699 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res, GetLastError());
700 ok(!res || index == 1, "Index was not incremented although result is %x (index = %u)\n", res, index);
702 length = 100;
703 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
704 buffer[length]=0;
705 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res,buffer);
707 length = 100;
708 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_ENCODING,buffer,&length,0x0);
709 buffer[length]=0;
710 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res,buffer);
712 SetLastError(0xdeadbeef);
713 res = InternetReadFile(NULL, buffer, 100, &length);
714 ok(!res, "InternetReadFile should have failed\n");
715 ok(GetLastError() == ERROR_INVALID_HANDLE,
716 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
717 GetLastError());
719 length = 100;
720 trace("Entering Query loop\n");
722 while (TRUE)
724 if (flags & INTERNET_FLAG_ASYNC)
725 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
727 /* IE11 calls those in InternetQueryDataAvailable call. */
728 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE);
729 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED);
731 length = 0;
732 res = InternetQueryDataAvailable(hor,&length,0x0,0x0);
734 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
736 if (flags & INTERNET_FLAG_ASYNC)
738 if (res)
740 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
741 if(exlen) {
742 ok(length >= exlen, "length %u < exlen %u\n", length, exlen);
743 exlen = 0;
746 else if (GetLastError() == ERROR_IO_PENDING)
748 trace("PENDING\n");
749 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
750 if(!(test->flags & TESTF_CHUNKED))
751 ok(!length, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length);
752 WaitForSingleObject(hCompleteEvent, INFINITE);
753 exlen = length;
754 ok(exlen, "length = 0\n");
755 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
756 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
757 ok(req_error, "req_error = 0\n");
758 continue;
759 }else {
760 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
762 }else {
763 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
765 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
767 trace("LENGTH %d\n", length);
768 if(test->flags & TESTF_CHUNKED)
769 ok(length <= 8192, "length = %d, expected <= 8192\n", length);
770 if (length)
772 char *buffer;
773 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
775 res = InternetReadFile(hor,buffer,length,&length);
777 buffer[length]=0;
779 trace("ReadFile -> %s %i\n",res?"TRUE":"FALSE",length);
781 if(test->content)
782 ok(!strcmp(buffer, test->content), "buffer = '%s', expected '%s'\n", buffer, test->content);
783 HeapFree(GetProcessHeap(),0,buffer);
784 }else {
785 ok(!on_async, "Returned zero size in response to request complete\n");
786 break;
788 on_async = FALSE;
790 if(test->flags & TESTF_REDIRECT) {
791 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
792 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
794 abort:
795 trace("aborting\n");
796 close_async_handle(hi, hCompleteEvent, 2);
797 CloseHandle(hCompleteEvent);
798 first_connection_to_test_url = FALSE;
801 static void InternetReadFile_chunked_test(void)
803 BOOL res;
804 CHAR buffer[4000];
805 DWORD length, got;
806 const char *types[2] = { "*", NULL };
807 HINTERNET hi, hic = 0, hor = 0;
809 trace("Starting InternetReadFile chunked test\n");
811 trace("InternetOpenA <--\n");
812 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
813 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
814 trace("InternetOpenA -->\n");
816 if (hi == 0x0) goto abort;
818 trace("InternetConnectA <--\n");
819 hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER,
820 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
821 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
822 trace("InternetConnectA -->\n");
824 if (hic == 0x0) goto abort;
826 trace("HttpOpenRequestA <--\n");
827 hor = HttpOpenRequestA(hic, "GET", "/tests/chunked", NULL, NULL, types,
828 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
829 0xdeadbead);
830 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
832 * If the internet name can't be resolved we are probably behind
833 * a firewall or in some other way not directly connected to the
834 * Internet. Not enough reason to fail the test. Just ignore and
835 * abort.
837 } else {
838 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
840 trace("HttpOpenRequestA -->\n");
842 if (hor == 0x0) goto abort;
844 trace("HttpSendRequestA -->\n");
845 SetLastError(0xdeadbeef);
846 res = HttpSendRequestA(hor, "", -1, NULL, 0);
847 ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED),
848 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
849 trace("HttpSendRequestA <--\n");
851 test_request_flags(hor, 0);
853 length = 100;
854 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
855 buffer[length]=0;
856 trace("Option CONTENT_TYPE -> %i %s\n",res,buffer);
858 SetLastError( 0xdeadbeef );
859 length = 100;
860 res = HttpQueryInfoA(hor,HTTP_QUERY_TRANSFER_ENCODING,buffer,&length,0x0);
861 buffer[length]=0;
862 trace("Option TRANSFER_ENCODING -> %i %s\n",res,buffer);
863 ok( res || ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND ),
864 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
865 ok( !strcmp( buffer, "chunked" ) || ( ! res && proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND ),
866 "Wrong transfer encoding '%s'\n", buffer );
868 SetLastError( 0xdeadbeef );
869 length = 16;
870 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
871 ok( !res, "Found CONTENT_LENGTH option '%s'\n", buffer );
872 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "Wrong error %u\n", GetLastError() );
874 length = 100;
875 trace("Entering Query loop\n");
877 while (TRUE)
879 res = InternetQueryDataAvailable(hor,&length,0x0,0x0);
880 ok(!(!res && length != 0),"InternetQueryDataAvailable failed with non-zero length\n");
881 ok(res, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
882 trace("got %u available\n",length);
883 if (length)
885 char *buffer = HeapAlloc(GetProcessHeap(),0,length+1);
887 res = InternetReadFile(hor,buffer,length,&got);
889 buffer[got]=0;
890 trace("ReadFile -> %i %i\n",res,got);
891 ok( length == got, "only got %u of %u available\n", got, length );
892 ok( buffer[got-1] == '\n', "received partial line '%s'\n", buffer );
894 HeapFree(GetProcessHeap(),0,buffer);
895 if (!got) break;
897 if (length == 0)
899 got = 0xdeadbeef;
900 res = InternetReadFile( hor, buffer, 1, &got );
901 ok( res, "InternetReadFile failed: %u\n", GetLastError() );
902 ok( !got, "got %u\n", got );
903 break;
906 abort:
907 trace("aborting\n");
908 if (hor != 0x0) {
909 res = InternetCloseHandle(hor);
910 ok (res, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
912 if (hi != 0x0) {
913 res = InternetCloseHandle(hi);
914 ok (res, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
918 static void InternetReadFileExA_test(int flags)
920 DWORD rc;
921 DWORD length;
922 const char *types[2] = { "*", NULL };
923 HINTERNET hi, hic = 0, hor = 0;
924 INTERNET_BUFFERSA inetbuffers;
926 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
928 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags);
930 trace("InternetOpenA <--\n");
931 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
932 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
933 trace("InternetOpenA -->\n");
935 if (hi == 0x0) goto abort;
937 pInternetSetStatusCallbackA(hi,&callback);
939 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
941 trace("InternetConnectA <--\n");
942 hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER,
943 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
944 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
945 trace("InternetConnectA -->\n");
947 if (hic == 0x0) goto abort;
949 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
950 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
952 trace("HttpOpenRequestA <--\n");
953 hor = HttpOpenRequestA(hic, "GET", "/tests/redirect", NULL, NULL, types,
954 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
955 0xdeadbead);
956 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
958 * If the internet name can't be resolved we are probably behind
959 * a firewall or in some other way not directly connected to the
960 * Internet. Not enough reason to fail the test. Just ignore and
961 * abort.
963 } else {
964 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
966 trace("HttpOpenRequestA -->\n");
968 if (hor == 0x0) goto abort;
970 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
971 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
972 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
973 if (first_connection_to_test_url)
975 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
976 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
978 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT, 2);
979 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
980 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
981 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, 2);
982 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, 2);
983 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
984 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
985 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
986 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
987 SET_EXPECT(INTERNET_STATUS_REDIRECT);
988 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER);
989 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER);
990 if (flags & INTERNET_FLAG_ASYNC)
991 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
992 else
993 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
995 trace("HttpSendRequestA -->\n");
996 SetLastError(0xdeadbeef);
997 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
998 if (flags & INTERNET_FLAG_ASYNC)
999 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
1000 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
1001 else
1002 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
1003 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
1004 trace("HttpSendRequestA <--\n");
1006 if (!rc && (GetLastError() == ERROR_IO_PENDING)) {
1007 WaitForSingleObject(hCompleteEvent, INFINITE);
1008 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
1011 if (first_connection_to_test_url)
1013 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
1014 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
1016 else
1018 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
1019 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
1021 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, 2);
1022 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, 2);
1023 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
1024 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
1025 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
1026 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
1027 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
1028 if (flags & INTERNET_FLAG_ASYNC)
1029 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1030 else
1031 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1032 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
1033 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
1034 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
1035 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
1037 /* tests invalid dwStructSize */
1038 inetbuffers.dwStructSize = sizeof(inetbuffers)+1;
1039 inetbuffers.lpcszHeader = NULL;
1040 inetbuffers.dwHeadersLength = 0;
1041 inetbuffers.dwBufferLength = 10;
1042 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10);
1043 inetbuffers.dwOffsetHigh = 1234;
1044 inetbuffers.dwOffsetLow = 5678;
1045 rc = InternetReadFileExA(hor, &inetbuffers, 0, 0xdeadcafe);
1046 ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
1047 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1048 rc ? "TRUE" : "FALSE", GetLastError());
1049 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
1051 test_request_flags(hor, 0);
1053 /* tests to see whether lpcszHeader is used - it isn't */
1054 inetbuffers.dwStructSize = sizeof(inetbuffers);
1055 inetbuffers.lpcszHeader = (LPCSTR)0xdeadbeef;
1056 inetbuffers.dwHeadersLength = 255;
1057 inetbuffers.dwBufferLength = 0;
1058 inetbuffers.lpvBuffer = NULL;
1059 inetbuffers.dwOffsetHigh = 1234;
1060 inetbuffers.dwOffsetLow = 5678;
1061 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
1062 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
1063 rc = InternetReadFileExA(hor, &inetbuffers, 0, 0xdeadcafe);
1064 ok(rc, "InternetReadFileEx failed with error %u\n", GetLastError());
1065 trace("read %i bytes\n", inetbuffers.dwBufferLength);
1066 todo_wine
1068 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1069 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1072 rc = InternetReadFileExA(NULL, &inetbuffers, 0, 0xdeadcafe);
1073 ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE),
1074 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1075 rc ? "TRUE" : "FALSE", GetLastError());
1077 length = 0;
1078 trace("Entering Query loop\n");
1080 while (TRUE)
1082 inetbuffers.dwStructSize = sizeof(inetbuffers);
1083 inetbuffers.dwBufferLength = 1024;
1084 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1);
1085 inetbuffers.dwOffsetHigh = 1234;
1086 inetbuffers.dwOffsetLow = 5678;
1088 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE);
1089 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED);
1090 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
1091 rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe);
1092 if (!rc)
1094 if (GetLastError() == ERROR_IO_PENDING)
1096 trace("InternetReadFileEx -> PENDING\n");
1097 ok(flags & INTERNET_FLAG_ASYNC,
1098 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1099 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1100 WaitForSingleObject(hCompleteEvent, INFINITE);
1101 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1102 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1103 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
1105 else
1107 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1108 break;
1111 else
1113 trace("InternetReadFileEx -> SUCCEEDED\n");
1114 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1115 if (inetbuffers.dwBufferLength)
1117 todo_wine {
1118 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1119 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1122 else
1124 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1125 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1126 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1130 trace("read %i bytes\n", inetbuffers.dwBufferLength);
1131 ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
1133 ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678,
1134 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1135 inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
1137 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
1139 if (!inetbuffers.dwBufferLength)
1140 break;
1142 length += inetbuffers.dwBufferLength;
1144 ok(length > 0, "failed to read any of the document\n");
1145 trace("Finished. Read %d bytes\n", length);
1147 abort:
1148 close_async_handle(hi, hCompleteEvent, 2);
1149 CloseHandle(hCompleteEvent);
1150 first_connection_to_test_url = FALSE;
1153 static void InternetOpenUrlA_test(void)
1155 HINTERNET myhinternet, myhttp;
1156 char buffer[0x400];
1157 DWORD size, readbytes, totalbytes=0;
1158 BOOL ret;
1160 ret = DeleteUrlCacheEntryA(TEST_URL);
1161 ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND,
1162 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret, GetLastError());
1164 myhinternet = InternetOpenA("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
1165 ok((myhinternet != 0), "InternetOpen failed, error %u\n",GetLastError());
1166 size = 0x400;
1167 ret = InternetCanonicalizeUrlA(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
1168 ok( ret, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1170 SetLastError(0);
1171 myhttp = InternetOpenUrlA(myhinternet, TEST_URL, 0, 0,
1172 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
1173 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1174 return; /* WinXP returns this when not connected to the net */
1175 ok((myhttp != 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1176 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
1177 ok( ret, "InternetReadFile failed, error %u\n",GetLastError());
1178 totalbytes += readbytes;
1179 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
1180 totalbytes += readbytes;
1181 trace("read 0x%08x bytes\n",totalbytes);
1183 InternetCloseHandle(myhttp);
1184 InternetCloseHandle(myhinternet);
1186 ret = DeleteUrlCacheEntryA(TEST_URL);
1187 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1190 static void HttpSendRequestEx_test(void)
1192 HINTERNET hSession;
1193 HINTERNET hConnect;
1194 HINTERNET hRequest;
1196 INTERNET_BUFFERSA BufferIn;
1197 DWORD dwBytesWritten, dwBytesRead, error;
1198 CHAR szBuffer[256];
1199 int i;
1200 BOOL ret;
1202 static char szPostData[] = "mode=Test";
1203 static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
1205 hSession = InternetOpenA("Wine Regression Test",
1206 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1207 ok( hSession != NULL ,"Unable to open Internet session\n");
1208 hConnect = InternetConnectA(hSession, "test.winehq.org",
1209 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1211 ok( hConnect != NULL, "Unable to connect to http://test.winehq.org\n");
1212 hRequest = HttpOpenRequestA(hConnect, "POST", "/tests/post.php",
1213 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1214 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1216 skip( "Network unreachable, skipping test\n" );
1217 goto done;
1219 ok( hRequest != NULL, "Failed to open request handle err %u\n", GetLastError());
1221 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1223 BufferIn.dwStructSize = sizeof(BufferIn);
1224 BufferIn.Next = (INTERNET_BUFFERSA*)0xdeadcab;
1225 BufferIn.lpcszHeader = szContentType;
1226 BufferIn.dwHeadersLength = sizeof(szContentType)-1;
1227 BufferIn.dwHeadersTotal = sizeof(szContentType)-1;
1228 BufferIn.lpvBuffer = szPostData;
1229 BufferIn.dwBufferLength = 3;
1230 BufferIn.dwBufferTotal = sizeof(szPostData)-1;
1231 BufferIn.dwOffsetLow = 0;
1232 BufferIn.dwOffsetHigh = 0;
1234 SetLastError(0xdeadbeef);
1235 ret = HttpSendRequestExA(hRequest, &BufferIn, NULL, 0 ,0);
1236 error = GetLastError();
1237 ok(ret, "HttpSendRequestEx Failed with error %u\n", error);
1238 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", error);
1240 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1242 for (i = 3; szPostData[i]; i++)
1243 ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten),
1244 "InternetWriteFile failed\n");
1246 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1248 ok(HttpEndRequestA(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
1250 test_request_flags(hRequest, 0);
1252 ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead),
1253 "Unable to read response\n");
1254 szBuffer[dwBytesRead] = 0;
1256 ok(dwBytesRead == 13,"Read %u bytes instead of 13\n",dwBytesRead);
1257 ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0 || broken(proxy_active()),"Got string %s\n",szBuffer);
1259 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1260 done:
1261 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1262 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1265 static void InternetOpenRequest_test(void)
1267 HINTERNET session, connect, request;
1268 static const char *types[] = { "*", "", NULL };
1269 static const WCHAR slash[] = {'/', 0}, any[] = {'*', 0}, empty[] = {0};
1270 static const WCHAR *typesW[] = { any, empty, NULL };
1271 BOOL ret;
1273 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1274 ok(session != NULL ,"Unable to open Internet session\n");
1276 connect = InternetConnectA(session, NULL, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1277 INTERNET_SERVICE_HTTP, 0, 0);
1278 ok(connect == NULL, "InternetConnectA should have failed\n");
1279 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1281 connect = InternetConnectA(session, "", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1282 INTERNET_SERVICE_HTTP, 0, 0);
1283 ok(connect == NULL, "InternetConnectA should have failed\n");
1284 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1286 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1287 INTERNET_SERVICE_HTTP, 0, 0);
1288 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1290 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1291 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1293 skip( "Network unreachable, skipping test\n" );
1294 goto done;
1296 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1298 ret = HttpSendRequestW(request, NULL, 0, NULL, 0);
1299 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1300 ok(InternetCloseHandle(request), "Close request handle failed\n");
1302 request = HttpOpenRequestW(connect, NULL, slash, NULL, NULL, typesW, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1303 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1305 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1306 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1307 ok(InternetCloseHandle(request), "Close request handle failed\n");
1309 done:
1310 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1311 ok(InternetCloseHandle(session), "Close session handle failed\n");
1314 static void test_cache_read(void)
1316 HINTERNET session, connection, req;
1317 FILETIME now, tomorrow, yesterday;
1318 BYTE content[1000], buf[2000];
1319 char file_path[MAX_PATH];
1320 ULARGE_INTEGER li;
1321 HANDLE file;
1322 DWORD size;
1323 unsigned i;
1324 BOOL res;
1326 static const char cache_only_url[] = "http://test.winehq.org/tests/cache-only";
1327 BYTE cache_headers[] = "HTTP/1.1 200 OK\r\n\r\n";
1329 trace("Testing cache read...\n");
1331 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
1333 for(i = 0; i < sizeof(content); i++)
1334 content[i] = '0' + (i%10);
1336 GetSystemTimeAsFileTime(&now);
1337 li.u.HighPart = now.dwHighDateTime;
1338 li.u.LowPart = now.dwLowDateTime;
1339 li.QuadPart += (LONGLONG)10000000 * 3600 * 24;
1340 tomorrow.dwHighDateTime = li.u.HighPart;
1341 tomorrow.dwLowDateTime = li.u.LowPart;
1342 li.QuadPart -= (LONGLONG)10000000 * 3600 * 24 * 2;
1343 yesterday.dwHighDateTime = li.u.HighPart;
1344 yesterday.dwLowDateTime = li.u.LowPart;
1346 res = CreateUrlCacheEntryA(cache_only_url, sizeof(content), "", file_path, 0);
1347 ok(res, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1349 file = CreateFileA(file_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1350 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
1352 WriteFile(file, content, sizeof(content), &size, NULL);
1353 CloseHandle(file);
1355 res = CommitUrlCacheEntryA(cache_only_url, file_path, tomorrow, yesterday, NORMAL_CACHE_ENTRY,
1356 cache_headers, sizeof(cache_headers)-1, "", 0);
1357 ok(res, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1359 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
1360 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
1362 pInternetSetStatusCallbackA(session, callback);
1364 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
1365 connection = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT,
1366 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
1367 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
1368 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
1370 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
1371 req = HttpOpenRequestA(connection, "GET", "/tests/cache-only", NULL, NULL, NULL, 0, 0xdeadbead);
1372 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
1373 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
1375 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER);
1376 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER);
1377 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST);
1378 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT);
1379 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE);
1380 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED);
1381 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
1383 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
1384 todo_wine
1385 ok(res, "HttpSendRequest failed: %u\n", GetLastError());
1387 if(res) {
1388 size = 0;
1389 res = InternetQueryDataAvailable(req, &size, 0, 0);
1390 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1391 ok(size == sizeof(content), "size = %u\n", size);
1393 size = sizeof(buf);
1394 res = InternetReadFile(req, buf, sizeof(buf), &size);
1395 ok(res, "InternetReadFile failed: %u\n", GetLastError());
1396 ok(size == sizeof(content), "size = %u\n", size);
1397 ok(!memcmp(content, buf, sizeof(content)), "unexpected content\n");
1400 close_async_handle(session, hCompleteEvent, 2);
1402 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
1403 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
1404 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
1405 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
1406 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1407 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1408 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1410 res = DeleteUrlCacheEntryA(cache_only_url);
1411 ok(res, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1413 CloseHandle(hCompleteEvent);
1416 static void test_http_cache(void)
1418 HINTERNET session, connect, request;
1419 char file_name[MAX_PATH], url[INTERNET_MAX_URL_LENGTH];
1420 DWORD size, file_size;
1421 BYTE buf[100];
1422 HANDLE file;
1423 BOOL ret;
1424 FILETIME filetime_zero = {0};
1426 static const char cached_content[] = "data read from cache";
1427 static const char *types[] = { "*", "", NULL };
1429 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1430 ok(session != NULL ,"Unable to open Internet session\n");
1432 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1433 INTERNET_SERVICE_HTTP, 0, 0);
1434 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1436 request = HttpOpenRequestA(connect, NULL, "/tests/hello.html", NULL, NULL, types, INTERNET_FLAG_NEED_FILE, 0);
1437 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1439 skip( "Network unreachable, skipping test\n" );
1441 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1442 ok(InternetCloseHandle(session), "Close session handle failed\n");
1444 return;
1446 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1448 size = sizeof(url);
1449 ret = InternetQueryOptionA(request, INTERNET_OPTION_URL, url, &size);
1450 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1451 ok(!strcmp(url, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url);
1453 size = sizeof(file_name);
1454 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1455 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1456 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1457 ok(!size, "size = %d\n", size);
1459 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1460 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1462 size = sizeof(file_name);
1463 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1464 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1466 file = CreateFileA(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
1467 FILE_ATTRIBUTE_NORMAL, NULL);
1468 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1469 file_size = GetFileSize(file, NULL);
1470 ok(file_size == 106, "file size = %u\n", file_size);
1472 size = sizeof(buf);
1473 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1474 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1475 ok(size == 100, "size = %u\n", size);
1477 file_size = GetFileSize(file, NULL);
1478 ok(file_size == 106, "file size = %u\n", file_size);
1479 CloseHandle(file);
1481 ret = DeleteFileA(file_name);
1482 ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
1484 ok(InternetCloseHandle(request), "Close request handle failed\n");
1486 file = CreateFileA(file_name, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1487 FILE_ATTRIBUTE_NORMAL, NULL);
1488 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1489 ret = WriteFile(file, cached_content, sizeof(cached_content), &size, NULL);
1490 ok(ret && size, "WriteFile failed: %d, %d\n", ret, size);
1491 ret = CommitUrlCacheEntryA(url, file_name, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY, NULL, 0, NULL, 0);
1492 ok(ret, "CommitUrlCacheEntry failed: %d\n", GetLastError());
1493 CloseHandle(file);
1495 /* Send the same request, requiring it to be retrieved from the cache */
1496 request = HttpOpenRequestA(connect, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
1498 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1499 ok(ret, "HttpSendRequest failed\n");
1501 size = sizeof(buf);
1502 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1503 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1504 ok(size == 100, "size = %u\n", size);
1505 buf[99] = 0;
1506 todo_wine ok(!strcmp((char*)buf, cached_content), "incorrect page data: %s\n", (char*)buf);
1508 ok(InternetCloseHandle(request), "Close request handle failed\n");
1510 DeleteUrlCacheEntryA(url);
1511 request = HttpOpenRequestA(connect, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
1512 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1513 todo_wine ok(!ret, "HttpSendRequest succeeded\n");
1514 if(!ret)
1515 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError() = %d\n", GetLastError());
1516 ok(InternetCloseHandle(request), "Close request handle failed\n");
1518 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1519 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1521 size = sizeof(file_name);
1522 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1523 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1524 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1525 ok(!size, "size = %d\n", size);
1527 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1528 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1530 size = sizeof(file_name);
1531 file_name[0] = 0;
1532 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1533 if (ret)
1535 file = CreateFileA(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1536 FILE_ATTRIBUTE_NORMAL, NULL);
1537 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1538 CloseHandle(file);
1540 else
1542 /* < IE8 */
1543 ok(file_name[0] == 0, "Didn't expect a file name\n");
1546 ok(InternetCloseHandle(request), "Close request handle failed\n");
1547 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1548 ok(InternetCloseHandle(session), "Close session handle failed\n");
1550 test_cache_read();
1553 static void InternetLockRequestFile_test(void)
1555 HINTERNET session, connect, request;
1556 char file_name[MAX_PATH];
1557 HANDLE lock, lock2;
1558 DWORD size;
1559 BOOL ret;
1561 static const char *types[] = { "*", "", NULL };
1563 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1564 ok(session != NULL ,"Unable to open Internet session\n");
1566 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1567 INTERNET_SERVICE_HTTP, 0, 0);
1568 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1570 request = HttpOpenRequestA(connect, NULL, "/tests/hello.html", NULL, NULL, types, INTERNET_FLAG_NEED_FILE|INTERNET_FLAG_RELOAD, 0);
1571 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1573 skip( "Network unreachable, skipping test\n" );
1575 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1576 ok(InternetCloseHandle(session), "Close session handle failed\n");
1578 return;
1580 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1582 size = sizeof(file_name);
1583 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1584 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1585 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1586 ok(!size, "size = %d\n", size);
1588 lock = NULL;
1589 ret = InternetLockRequestFile(request, &lock);
1590 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
1592 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1593 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1595 size = sizeof(file_name);
1596 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1597 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1599 ret = InternetLockRequestFile(request, &lock);
1600 ok(ret, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
1601 ok(lock != NULL, "lock == NULL\n");
1603 ret = InternetLockRequestFile(request, &lock2);
1604 ok(ret, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
1605 ok(lock == lock2, "lock != lock2\n");
1607 ret = InternetUnlockRequestFile(lock2);
1608 ok(ret, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1610 ret = DeleteFileA(file_name);
1611 ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
1613 ok(InternetCloseHandle(request), "Close request handle failed\n");
1615 ret = DeleteFileA(file_name);
1616 ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
1618 ret = InternetUnlockRequestFile(lock);
1619 ok(ret, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1621 ret = DeleteFileA(file_name);
1622 ok(ret, "Deleting file returned %x(%u)\n", ret, GetLastError());
1625 static void HttpHeaders_test(void)
1627 HINTERNET hSession;
1628 HINTERNET hConnect;
1629 HINTERNET hRequest;
1630 CHAR buffer[256];
1631 WCHAR wbuffer[256];
1632 DWORD len = 256;
1633 DWORD oldlen;
1634 DWORD index = 0;
1635 BOOL ret;
1637 hSession = InternetOpenA("Wine Regression Test",
1638 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1639 ok( hSession != NULL ,"Unable to open Internet session\n");
1640 hConnect = InternetConnectA(hSession, "test.winehq.org",
1641 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1643 ok( hConnect != NULL, "Unable to connect to http://test.winehq.org\n");
1644 hRequest = HttpOpenRequestA(hConnect, "POST", "/tests/post.php",
1645 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1646 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1648 skip( "Network unreachable, skipping test\n" );
1649 goto done;
1651 ok( hRequest != NULL, "Failed to open request handle\n");
1653 index = 0;
1654 len = sizeof(buffer);
1655 strcpy(buffer,"Warning");
1656 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1657 buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
1659 ok(HttpAddRequestHeadersA(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
1660 "Failed to add new header\n");
1662 index = 0;
1663 len = sizeof(buffer);
1664 strcpy(buffer,"Warning");
1665 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1666 buffer,&len,&index),"Unable to query header\n");
1667 ok(index == 1, "Index was not incremented\n");
1668 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1669 ok(len == 5, "Invalid length (exp. 5, got %d)\n", len);
1670 ok((len < sizeof(buffer)) && (buffer[len] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1671 len = sizeof(buffer);
1672 strcpy(buffer,"Warning");
1673 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1674 buffer,&len,&index)==0,"Second Index Should Not Exist\n");
1676 index = 0;
1677 len = 5; /* could store the string but not the NULL terminator */
1678 strcpy(buffer,"Warning");
1679 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1680 buffer,&len,&index) == FALSE,"Query succeeded on a too small buffer\n");
1681 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1682 ok(index == 0, "Index was incremented\n");
1683 ok(strcmp(buffer,"Warning")==0, "incorrect string was returned(%s)\n",buffer); /* string not touched */
1684 ok(len == 6, "Invalid length (exp. 6, got %d)\n", len); /* unlike success, the length includes the NULL-terminator */
1686 /* a call with NULL will fail but will return the length */
1687 index = 0;
1688 len = sizeof(buffer);
1689 SetLastError(0xdeadbeef);
1690 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1691 NULL,&len,&index) == FALSE,"Query worked\n");
1692 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1693 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1694 ok(index == 0, "Index was incremented\n");
1696 /* even for a len that is too small */
1697 index = 0;
1698 len = 15;
1699 SetLastError(0xdeadbeef);
1700 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1701 NULL,&len,&index) == FALSE,"Query worked\n");
1702 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1703 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1704 ok(index == 0, "Index was incremented\n");
1706 index = 0;
1707 len = 0;
1708 SetLastError(0xdeadbeef);
1709 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1710 NULL,&len,&index) == FALSE,"Query worked\n");
1711 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1712 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1713 ok(index == 0, "Index was incremented\n");
1714 oldlen = len; /* bytes; at least long enough to hold buffer & nul */
1717 /* a working query */
1718 index = 0;
1719 len = sizeof(buffer);
1720 memset(buffer, 'x', sizeof(buffer));
1721 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1722 buffer,&len,&index),"Unable to query header\n");
1723 ok(len + sizeof(CHAR) <= oldlen, "Result longer than advertised\n");
1724 ok((len < sizeof(buffer)-sizeof(CHAR)) && (buffer[len/sizeof(CHAR)] == 0),"No NUL at end\n");
1725 ok(len == strlen(buffer) * sizeof(CHAR), "Length wrong\n");
1726 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1727 ok(strncmp(buffer, "POST /tests/post.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1728 ok(strcmp(buffer + strlen(buffer) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1729 ok(index == 0, "Index was incremented\n");
1731 /* Like above two tests, but for W version */
1733 index = 0;
1734 len = 0;
1735 SetLastError(0xdeadbeef);
1736 ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1737 NULL,&len,&index) == FALSE,"Query worked\n");
1738 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1739 ok(len > 80, "Invalid length (exp. more than 80, got %d)\n", len);
1740 ok(index == 0, "Index was incremented\n");
1741 oldlen = len; /* bytes; at least long enough to hold buffer & nul */
1743 /* a working query */
1744 index = 0;
1745 len = sizeof(wbuffer);
1746 memset(wbuffer, 'x', sizeof(wbuffer));
1747 ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1748 wbuffer,&len,&index),"Unable to query header\n");
1749 ok(len + sizeof(WCHAR) <= oldlen, "Result longer than advertised\n");
1750 ok(len == lstrlenW(wbuffer) * sizeof(WCHAR), "Length wrong\n");
1751 ok((len < sizeof(wbuffer)-sizeof(WCHAR)) && (wbuffer[len/sizeof(WCHAR)] == 0),"No NUL at end\n");
1752 ok(index == 0, "Index was incremented\n");
1754 /* end of W version tests */
1756 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1757 index = 0;
1758 len = sizeof(buffer);
1759 memset(buffer, 'x', sizeof(buffer));
1760 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF,
1761 buffer,&len,&index) == TRUE,"Query failed\n");
1762 ok(len == 2, "Expected 2, got %d\n", len);
1763 ok(strcmp(buffer, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer);
1764 ok(index == 0, "Index was incremented\n");
1766 ok(HttpAddRequestHeadersA(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
1767 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1769 index = 0;
1770 len = sizeof(buffer);
1771 strcpy(buffer,"Warning");
1772 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1773 buffer,&len,&index),"Unable to query header\n");
1774 ok(index == 1, "Index was not incremented\n");
1775 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1776 len = sizeof(buffer);
1777 strcpy(buffer,"Warning");
1778 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1779 buffer,&len,&index),"Failed to get second header\n");
1780 ok(index == 2, "Index was not incremented\n");
1781 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1782 len = sizeof(buffer);
1783 strcpy(buffer,"Warning");
1784 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1785 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1787 ok(HttpAddRequestHeadersA(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1789 index = 0;
1790 len = sizeof(buffer);
1791 strcpy(buffer,"Warning");
1792 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1793 buffer,&len,&index),"Unable to query header\n");
1794 ok(index == 1, "Index was not incremented\n");
1795 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1796 len = sizeof(buffer);
1797 strcpy(buffer,"Warning");
1798 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1799 buffer,&len,&index),"Failed to get second header\n");
1800 ok(index == 2, "Index was not incremented\n");
1801 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1802 len = sizeof(buffer);
1803 strcpy(buffer,"Warning");
1804 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1805 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1807 ok(HttpAddRequestHeadersA(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1809 index = 0;
1810 len = sizeof(buffer);
1811 strcpy(buffer,"Warning");
1812 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1813 buffer,&len,&index),"Unable to query header\n");
1814 ok(index == 1, "Index was not incremented\n");
1815 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1816 len = sizeof(buffer);
1817 strcpy(buffer,"Warning");
1818 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1819 buffer,&len,&index),"Failed to get second header\n");
1820 ok(index == 2, "Index was not incremented\n");
1821 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1822 len = sizeof(buffer);
1823 strcpy(buffer,"Warning");
1824 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1825 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1827 ok(HttpAddRequestHeadersA(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1829 index = 0;
1830 len = sizeof(buffer);
1831 strcpy(buffer,"Warning");
1832 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1833 buffer,&len,&index),"Unable to query header\n");
1834 ok(index == 1, "Index was not incremented\n");
1835 ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer);
1836 len = sizeof(buffer);
1837 strcpy(buffer,"Warning");
1838 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1839 ok(index == 2, "Index was not incremented\n");
1840 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1841 len = sizeof(buffer);
1842 strcpy(buffer,"Warning");
1843 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1845 ok(HttpAddRequestHeadersA(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1847 index = 0;
1848 len = sizeof(buffer);
1849 strcpy(buffer,"Warning");
1850 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1851 ok(index == 1, "Index was not incremented\n");
1852 ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer);
1853 len = sizeof(buffer);
1854 strcpy(buffer,"Warning");
1855 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1856 ok(index == 2, "Index was not incremented\n");
1857 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1858 len = sizeof(buffer);
1859 strcpy(buffer,"Warning");
1860 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1862 ok(HttpAddRequestHeadersA(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1864 index = 0;
1865 len = sizeof(buffer);
1866 strcpy(buffer,"Warning");
1867 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1868 ok(index == 1, "Index was not incremented\n");
1869 ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer);
1870 len = sizeof(buffer);
1871 strcpy(buffer,"Warning");
1872 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1873 ok(index == 2, "Index was not incremented\n");
1874 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1875 len = sizeof(buffer);
1876 strcpy(buffer,"Warning");
1877 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1879 ok(HttpAddRequestHeadersA(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");
1881 index = 0;
1882 len = sizeof(buffer);
1883 strcpy(buffer,"Warning");
1884 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1885 ok(index == 1, "Index was not incremented\n");
1886 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1887 len = sizeof(buffer);
1888 strcpy(buffer,"Warning");
1889 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1890 ok(index == 2, "Index was not incremented\n");
1891 ok(strcmp(buffer,"test7")==0, "incorrect string was returned(%s)\n",buffer);
1892 len = sizeof(buffer);
1893 strcpy(buffer,"Warning");
1894 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1896 /* Ensure that blank headers are ignored and don't cause a failure */
1897 ok(HttpAddRequestHeadersA(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");
1899 index = 0;
1900 len = sizeof(buffer);
1901 strcpy(buffer,"BlankTest");
1902 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1903 ok(index == 1, "Index was not incremented\n");
1904 ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
1906 /* Ensure that malformed header separators are ignored and don't cause a failure */
1907 ok(HttpAddRequestHeadersA(hRequest,"\r\rMalformedTest:value\n\nMalformedTestTwo: value2\rMalformedTestThree: value3\n\n\r\r\n",-1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE),
1908 "Failed to add header with malformed entries in list\n");
1910 index = 0;
1911 len = sizeof(buffer);
1912 strcpy(buffer,"MalformedTest");
1913 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1914 ok(index == 1, "Index was not incremented\n");
1915 ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
1916 index = 0;
1917 len = sizeof(buffer);
1918 strcpy(buffer,"MalformedTestTwo");
1919 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1920 ok(index == 1, "Index was not incremented\n");
1921 ok(strcmp(buffer,"value2")==0, "incorrect string was returned(%s)\n",buffer);
1922 index = 0;
1923 len = sizeof(buffer);
1924 strcpy(buffer,"MalformedTestThree");
1925 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1926 ok(index == 1, "Index was not incremented\n");
1927 ok(strcmp(buffer,"value3")==0, "incorrect string was returned(%s)\n",buffer);
1929 ret = HttpAddRequestHeadersA(hRequest, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD);
1930 ok(ret, "unable to add header %u\n", GetLastError());
1932 index = 0;
1933 buffer[0] = 0;
1934 len = sizeof(buffer);
1935 ret = HttpQueryInfoA(hRequest, HTTP_QUERY_AUTHORIZATION|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &len, &index);
1936 ok(ret, "unable to query header %u\n", GetLastError());
1937 ok(index == 1, "index was not incremented\n");
1938 ok(!strcmp(buffer, "Basic"), "incorrect string was returned (%s)\n", buffer);
1940 ret = HttpAddRequestHeadersA(hRequest, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE);
1941 ok(ret, "unable to remove header %u\n", GetLastError());
1943 index = 0;
1944 len = sizeof(buffer);
1945 SetLastError(0xdeadbeef);
1946 ok(!HttpQueryInfoA(hRequest, HTTP_QUERY_AUTHORIZATION|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &len, &index),
1947 "header still present\n");
1948 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "got %u\n", GetLastError());
1950 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1951 done:
1952 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1953 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1956 static const char garbagemsg[] =
1957 "Garbage: Header\r\n";
1959 static const char contmsg[] =
1960 "HTTP/1.1 100 Continue\r\n";
1962 static const char expandcontmsg[] =
1963 "HTTP/1.1 100 Continue\r\n"
1964 "Server: winecontinue\r\n"
1965 "Tag: something witty\r\n"
1966 "\r\n";
1968 static const char okmsg[] =
1969 "HTTP/1.1 200 OK\r\n"
1970 "Server: winetest\r\n"
1971 "\r\n";
1973 static const char okmsg2[] =
1974 "HTTP/1.1 200 OK\r\n"
1975 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1976 "Server: winetest\r\n"
1977 "Content-Length: 0\r\n"
1978 "Set-Cookie: one\r\n"
1979 "Set-Cookie: two\r\n"
1980 "\r\n";
1982 static const char notokmsg[] =
1983 "HTTP/1.1 400 Bad Request\r\n"
1984 "Server: winetest\r\n"
1985 "\r\n";
1987 static const char noauthmsg[] =
1988 "HTTP/1.1 401 Unauthorized\r\n"
1989 "Server: winetest\r\n"
1990 "Connection: close\r\n"
1991 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1992 "\r\n";
1994 static const char noauthmsg2[] =
1995 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
1996 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
1997 "\0d`0|6\n"
1998 "Server: winetest\r\n";
2000 static const char proxymsg[] =
2001 "HTTP/1.1 407 Proxy Authentication Required\r\n"
2002 "Server: winetest\r\n"
2003 "Proxy-Connection: close\r\n"
2004 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
2005 "\r\n";
2007 static const char page1[] =
2008 "<HTML>\r\n"
2009 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
2010 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
2011 "</HTML>\r\n\r\n";
2013 static const char ok_with_length[] =
2014 "HTTP/1.1 200 OK\r\n"
2015 "Connection: Keep-Alive\r\n"
2016 "Content-Length: 18\r\n\r\n"
2017 "HTTP/1.1 211 OK\r\n\r\n";
2019 static const char ok_with_length2[] =
2020 "HTTP/1.1 210 OK\r\n"
2021 "Connection: Keep-Alive\r\n"
2022 "Content-Length: 19\r\n\r\n"
2023 "HTTP/1.1 211 OK\r\n\r\n";
2025 struct server_info {
2026 HANDLE hEvent;
2027 int port;
2030 static int test_cache_gzip;
2031 static const char *send_buffer;
2033 static DWORD CALLBACK server_thread(LPVOID param)
2035 struct server_info *si = param;
2036 int r, c = -1, i, on, count = 0;
2037 SOCKET s;
2038 struct sockaddr_in sa;
2039 char buffer[0x100];
2040 WSADATA wsaData;
2041 int last_request = 0;
2042 char host_header[22];
2043 char host_header_override[30];
2044 static BOOL test_b = FALSE;
2045 static int test_no_cache = 0;
2047 WSAStartup(MAKEWORD(1,1), &wsaData);
2049 s = socket(AF_INET, SOCK_STREAM, 0);
2050 if (s == INVALID_SOCKET)
2051 return 1;
2053 on = 1;
2054 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof on);
2056 memset(&sa, 0, sizeof sa);
2057 sa.sin_family = AF_INET;
2058 sa.sin_port = htons(si->port);
2059 sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
2061 r = bind(s, (struct sockaddr*) &sa, sizeof sa);
2062 if (r<0)
2063 return 1;
2065 listen(s, 0);
2067 SetEvent(si->hEvent);
2069 sprintf(host_header, "Host: localhost:%d", si->port);
2070 sprintf(host_header_override, "Host: test.local:%d\r\n", si->port);
2074 if(c == -1)
2075 c = accept(s, NULL, NULL);
2077 memset(buffer, 0, sizeof buffer);
2078 for(i=0; i<(sizeof buffer-1); i++)
2080 r = recv(c, &buffer[i], 1, 0);
2081 if (r != 1)
2082 break;
2083 if (i<4) continue;
2084 if (buffer[i-2] == '\n' && buffer[i] == '\n' &&
2085 buffer[i-3] == '\r' && buffer[i-1] == '\r')
2086 break;
2088 if (strstr(buffer, "GET /test1"))
2090 if (!strstr(buffer, "Content-Length: 0"))
2092 send(c, okmsg, sizeof okmsg-1, 0);
2093 send(c, page1, sizeof page1-1, 0);
2095 else
2096 send(c, notokmsg, sizeof notokmsg-1, 0);
2098 if (strstr(buffer, "CONNECT "))
2100 if (!strstr(buffer, "Content-Length: 0"))
2101 send(c, notokmsg, sizeof notokmsg-1, 0);
2102 else
2103 send(c, proxymsg, sizeof proxymsg-1, 0);
2105 if (strstr(buffer, "/test2"))
2107 if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2109 send(c, okmsg, sizeof okmsg-1, 0);
2110 send(c, page1, sizeof page1-1, 0);
2112 else
2113 send(c, proxymsg, sizeof proxymsg-1, 0);
2115 if (strstr(buffer, "/test3"))
2117 if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
2118 send(c, okmsg, sizeof okmsg-1, 0);
2119 else
2120 send(c, noauthmsg, sizeof noauthmsg-1, 0);
2122 if (strstr(buffer, "/test4"))
2124 if (strstr(buffer, "Connection: Close"))
2125 send(c, okmsg, sizeof okmsg-1, 0);
2126 else
2127 send(c, notokmsg, sizeof notokmsg-1, 0);
2129 if (strstr(buffer, "POST /test5") ||
2130 strstr(buffer, "RPC_IN_DATA /test5") ||
2131 strstr(buffer, "RPC_OUT_DATA /test5"))
2133 if (strstr(buffer, "Content-Length: 0"))
2135 send(c, okmsg, sizeof okmsg-1, 0);
2136 send(c, page1, sizeof page1-1, 0);
2138 else
2139 send(c, notokmsg, sizeof notokmsg-1, 0);
2141 if (strstr(buffer, "GET /test6"))
2143 send(c, contmsg, sizeof contmsg-1, 0);
2144 send(c, contmsg, sizeof contmsg-1, 0);
2145 send(c, okmsg, sizeof okmsg-1, 0);
2146 send(c, page1, sizeof page1-1, 0);
2148 if (strstr(buffer, "POST /test7"))
2150 if (strstr(buffer, "Content-Length: 100"))
2152 if (strstr(buffer, "POST /test7b"))
2153 recvfrom(c, buffer, sizeof buffer, 0, NULL, NULL);
2154 send(c, okmsg, sizeof okmsg-1, 0);
2155 send(c, page1, sizeof page1-1, 0);
2157 else
2158 send(c, notokmsg, sizeof notokmsg-1, 0);
2160 if (strstr(buffer, "/test8"))
2162 if (!strstr(buffer, "Connection: Close") &&
2163 strstr(buffer, "Connection: Keep-Alive") &&
2164 !strstr(buffer, "Cache-Control: no-cache") &&
2165 !strstr(buffer, "Pragma: no-cache") &&
2166 strstr(buffer, host_header))
2167 send(c, okmsg, sizeof okmsg-1, 0);
2168 else
2169 send(c, notokmsg, sizeof notokmsg-1, 0);
2171 if (strstr(buffer, "/test9"))
2173 if (!strstr(buffer, "Connection: Close") &&
2174 !strstr(buffer, "Connection: Keep-Alive") &&
2175 !strstr(buffer, "Cache-Control: no-cache") &&
2176 !strstr(buffer, "Pragma: no-cache") &&
2177 strstr(buffer, host_header))
2178 send(c, okmsg, sizeof okmsg-1, 0);
2179 else
2180 send(c, notokmsg, sizeof notokmsg-1, 0);
2182 if (strstr(buffer, "/testA"))
2184 if (!strstr(buffer, "Connection: Close") &&
2185 !strstr(buffer, "Connection: Keep-Alive") &&
2186 (strstr(buffer, "Cache-Control: no-cache") ||
2187 strstr(buffer, "Pragma: no-cache")) &&
2188 strstr(buffer, host_header))
2189 send(c, okmsg, sizeof okmsg-1, 0);
2190 else
2191 send(c, notokmsg, sizeof notokmsg-1, 0);
2193 if (!test_b && strstr(buffer, "/testB HTTP/1.1"))
2195 test_b = TRUE;
2196 send(c, okmsg, sizeof okmsg-1, 0);
2197 recvfrom(c, buffer, sizeof buffer, 0, NULL, NULL);
2198 send(c, okmsg, sizeof okmsg-1, 0);
2200 if (strstr(buffer, "/testC"))
2202 if (strstr(buffer, "Cookie: cookie=biscuit"))
2203 send(c, okmsg, sizeof okmsg-1, 0);
2204 else
2205 send(c, notokmsg, sizeof notokmsg-1, 0);
2207 if (strstr(buffer, "/testD"))
2209 send(c, okmsg2, sizeof okmsg2-1, 0);
2211 if (strstr(buffer, "/testE"))
2213 send(c, noauthmsg2, sizeof noauthmsg2-1, 0);
2215 if (strstr(buffer, "GET /quit"))
2217 send(c, okmsg, sizeof okmsg-1, 0);
2218 send(c, page1, sizeof page1-1, 0);
2219 last_request = 1;
2221 if (strstr(buffer, "GET /testF"))
2223 send(c, expandcontmsg, sizeof expandcontmsg-1, 0);
2224 send(c, garbagemsg, sizeof garbagemsg-1, 0);
2225 send(c, contmsg, sizeof contmsg-1, 0);
2226 send(c, garbagemsg, sizeof garbagemsg-1, 0);
2227 send(c, okmsg, sizeof okmsg-1, 0);
2228 send(c, page1, sizeof page1-1, 0);
2230 if (strstr(buffer, "GET /testG"))
2232 send(c, page1, sizeof page1-1, 0);
2235 if (strstr(buffer, "GET /testJ"))
2237 if (count == 0)
2239 count++;
2240 send(c, ok_with_length, sizeof(ok_with_length)-1, 0);
2242 else
2244 send(c, ok_with_length2, sizeof(ok_with_length2)-1, 0);
2245 count = 0;
2248 if (strstr(buffer, "GET /testH"))
2250 send(c, ok_with_length2, sizeof(ok_with_length2)-1, 0);
2251 recvfrom(c, buffer, sizeof(buffer), 0, NULL, NULL);
2252 send(c, ok_with_length, sizeof(ok_with_length)-1, 0);
2255 if (strstr(buffer, "GET /test_no_content"))
2257 static const char nocontentmsg[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2258 send(c, nocontentmsg, sizeof(nocontentmsg)-1, 0);
2260 if (strstr(buffer, "GET /test_conn_close"))
2262 static const char conn_close_response[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2263 send(c, conn_close_response, sizeof(conn_close_response)-1, 0);
2264 WaitForSingleObject(conn_close_event, INFINITE);
2265 trace("closing connection\n");
2267 if (strstr(buffer, "GET /test_cache_control_no_cache"))
2269 static const char no_cache_response[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2270 if(!test_no_cache++)
2271 send(c, no_cache_response, sizeof(no_cache_response)-1, 0);
2272 else
2273 send(c, okmsg, sizeof(okmsg)-1, 0);
2275 if (strstr(buffer, "GET /test_cache_control_no_store"))
2277 static const char no_cache_response[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2278 send(c, no_cache_response, sizeof(no_cache_response)-1, 0);
2280 if (strstr(buffer, "GET /test_cache_gzip"))
2282 static const char gzip_response[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2283 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2284 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2285 if(!test_cache_gzip++)
2286 send(c, gzip_response, sizeof(gzip_response), 0);
2287 else
2288 send(c, notokmsg, sizeof(notokmsg)-1, 0);
2290 if (strstr(buffer, "HEAD /test_head")) {
2291 static const char head_response[] =
2292 "HTTP/1.1 200 OK\r\n"
2293 "Connection: Keep-Alive\r\n"
2294 "Content-Length: 100\r\n"
2295 "\r\n";
2297 send(c, head_response, sizeof(head_response), 0);
2298 continue;
2300 if (strstr(buffer, "GET /send_from_buffer"))
2301 send(c, send_buffer, strlen(send_buffer), 0);
2302 if (strstr(buffer, "/test_cache_control_verb"))
2304 if (!memcmp(buffer, "GET ", sizeof("GET ")-1) &&
2305 !strstr(buffer, "Cache-Control: no-cache\r\n")) send(c, okmsg, sizeof(okmsg)-1, 0);
2306 else if (strstr(buffer, "Cache-Control: no-cache\r\n")) send(c, okmsg, sizeof(okmsg)-1, 0);
2307 else send(c, notokmsg, sizeof(notokmsg)-1, 0);
2309 if (strstr(buffer, "/test_request_content_length"))
2311 static char msg[] = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\n\r\n";
2312 static int seen_content_length;
2314 if (!seen_content_length)
2316 if (strstr(buffer, "Content-Length: 0"))
2318 seen_content_length = 1;
2319 send(c, msg, sizeof msg-1, 0);
2321 else send(c, notokmsg, sizeof notokmsg-1, 0);
2322 WaitForSingleObject(hCompleteEvent, 5000);
2324 else
2326 if (strstr(buffer, "Content-Length: 0")) send(c, msg, sizeof msg-1, 0);
2327 else send(c, notokmsg, sizeof notokmsg-1, 0);
2328 WaitForSingleObject(hCompleteEvent, 5000);
2331 if (strstr(buffer, "GET /test_premature_disconnect"))
2332 trace("closing connection\n");
2333 if (strstr(buffer, "/test_accept_encoding_http10"))
2335 if (strstr(buffer, "Accept-Encoding: gzip"))
2336 send(c, okmsg, sizeof okmsg-1, 0);
2337 else
2338 send(c, notokmsg, sizeof notokmsg-1, 0);
2340 if (strstr(buffer, "HEAD /upload.txt"))
2342 if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
2343 send(c, okmsg, sizeof okmsg-1, 0);
2344 else
2345 send(c, noauthmsg, sizeof noauthmsg-1, 0);
2347 if (strstr(buffer, "PUT /upload2.txt"))
2349 if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
2350 send(c, okmsg, sizeof okmsg-1, 0);
2351 else
2352 send(c, notokmsg, sizeof notokmsg-1, 0);
2354 if (strstr(buffer, "/test_host_override"))
2356 if (strstr(buffer, host_header_override))
2357 send(c, okmsg, sizeof okmsg-1, 0);
2358 else
2359 send(c, notokmsg, sizeof notokmsg-1, 0);
2361 shutdown(c, 2);
2362 closesocket(c);
2363 c = -1;
2364 } while (!last_request);
2366 closesocket(s);
2368 return 0;
2371 static void test_basic_request(int port, const char *verb, const char *url)
2373 HINTERNET hi, hc, hr;
2374 DWORD r, count, error;
2375 char buffer[0x100];
2377 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2378 ok(hi != NULL, "open failed\n");
2380 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2381 ok(hc != NULL, "connect failed\n");
2383 hr = HttpOpenRequestA(hc, verb, url, NULL, NULL, NULL, 0, 0);
2384 ok(hr != NULL, "HttpOpenRequest failed\n");
2386 SetLastError(0xdeadbeef);
2387 r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
2388 error = GetLastError();
2389 ok(error == ERROR_SUCCESS || broken(error != ERROR_SUCCESS), "expected ERROR_SUCCESS, got %u\n", error);
2390 ok(r, "HttpSendRequest failed\n");
2392 count = 0;
2393 memset(buffer, 0, sizeof buffer);
2394 SetLastError(0xdeadbeef);
2395 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
2396 ok(r, "InternetReadFile failed %u\n", GetLastError());
2397 ok(count == sizeof page1 - 1, "count was wrong\n");
2398 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong, got: %s\n", buffer);
2400 InternetCloseHandle(hr);
2401 InternetCloseHandle(hc);
2402 InternetCloseHandle(hi);
2405 static void test_proxy_indirect(int port)
2407 HINTERNET hi, hc, hr;
2408 DWORD r, sz;
2409 char buffer[0x40];
2411 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2412 ok(hi != NULL, "open failed\n");
2414 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2415 ok(hc != NULL, "connect failed\n");
2417 hr = HttpOpenRequestA(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
2418 ok(hr != NULL, "HttpOpenRequest failed\n");
2420 r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
2421 ok(r, "HttpSendRequest failed %u\n", GetLastError());
2423 sz = sizeof buffer;
2424 r = HttpQueryInfoA(hr, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL);
2425 ok(r || GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo failed: %d\n", GetLastError());
2426 if (!r)
2428 skip("missing proxy header, not testing remaining proxy headers\n");
2429 goto out;
2431 ok(!strcmp(buffer, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2433 test_status_code(hr, 407);
2434 test_request_flags(hr, 0);
2436 sz = sizeof buffer;
2437 r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL);
2438 ok(r, "HttpQueryInfo failed\n");
2439 ok(!strcmp(buffer, "Proxy Authentication Required"), "proxy text wrong\n");
2441 sz = sizeof buffer;
2442 r = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &sz, NULL);
2443 ok(r, "HttpQueryInfo failed\n");
2444 ok(!strcmp(buffer, "HTTP/1.1"), "http version wrong\n");
2446 sz = sizeof buffer;
2447 r = HttpQueryInfoA(hr, HTTP_QUERY_SERVER, buffer, &sz, NULL);
2448 ok(r, "HttpQueryInfo failed\n");
2449 ok(!strcmp(buffer, "winetest"), "http server wrong\n");
2451 sz = sizeof buffer;
2452 r = HttpQueryInfoA(hr, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL);
2453 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo should fail\n");
2454 ok(r == FALSE, "HttpQueryInfo failed\n");
2456 out:
2457 InternetCloseHandle(hr);
2458 InternetCloseHandle(hc);
2459 InternetCloseHandle(hi);
2462 static void test_proxy_direct(int port)
2464 HINTERNET hi, hc, hr;
2465 DWORD r, sz, error;
2466 char buffer[0x40], *url;
2467 WCHAR bufferW[0x40];
2468 static const char url_fmt[] = "http://test.winehq.org:%u/test2";
2469 static CHAR username[] = "mike",
2470 password[] = "1101",
2471 useragent[] = "winetest";
2472 static const WCHAR usernameW[] = {'m','i','k','e',0},
2473 passwordW[] = {'1','1','0','1',0},
2474 useragentW[] = {'w','i','n','e','t','e','s','t',0};
2476 /* specify proxy type without the proxy and bypass */
2477 SetLastError(0xdeadbeef);
2478 hi = InternetOpenW(NULL, INTERNET_OPEN_TYPE_PROXY, NULL, NULL, 0);
2479 error = GetLastError();
2480 ok(error == ERROR_INVALID_PARAMETER ||
2481 broken(error == ERROR_SUCCESS) /* WinXPProSP2 */, "got %u\n", error);
2482 ok(hi == NULL || broken(!!hi) /* WinXPProSP2 */, "open should have failed\n");
2484 sprintf(buffer, "localhost:%d\n", port);
2485 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0);
2486 ok(hi != NULL, "open failed\n");
2488 /* try connect without authorization */
2489 hc = InternetConnectA(hi, "test.winehq.org", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2490 ok(hc != NULL, "connect failed\n");
2492 hr = HttpOpenRequestA(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
2493 ok(hr != NULL, "HttpOpenRequest failed\n");
2495 sz = 0;
2496 SetLastError(0xdeadbeef);
2497 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, NULL, &sz);
2498 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2499 ok(!r, "unexpected success\n");
2500 ok(sz == 1, "got %u\n", sz);
2502 sz = 0;
2503 SetLastError(0xdeadbeef);
2504 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, NULL, &sz);
2505 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2506 ok(!r, "unexpected success\n");
2507 ok(sz == 1, "got %u\n", sz);
2509 sz = sizeof(buffer);
2510 SetLastError(0xdeadbeef);
2511 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz);
2512 ok(r, "unexpected failure %u\n", GetLastError());
2513 ok(!sz, "got %u\n", sz);
2515 sz = sizeof(buffer);
2516 SetLastError(0xdeadbeef);
2517 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2518 ok(r, "unexpected failure %u\n", GetLastError());
2519 ok(!sz, "got %u\n", sz);
2521 sz = 0;
2522 SetLastError(0xdeadbeef);
2523 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, NULL, &sz);
2524 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2525 ok(!r, "unexpected success\n");
2526 ok(sz == 1, "got %u\n", sz);
2528 sz = 0;
2529 SetLastError(0xdeadbeef);
2530 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, NULL, &sz);
2531 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2532 ok(!r, "unexpected success\n");
2533 ok(sz == 1, "got %u\n", sz);
2535 sz = sizeof(buffer);
2536 SetLastError(0xdeadbeef);
2537 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz);
2538 ok(r, "unexpected failure %u\n", GetLastError());
2539 ok(!sz, "got %u\n", sz);
2541 sz = sizeof(buffer);
2542 SetLastError(0xdeadbeef);
2543 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz);
2544 ok(r, "unexpected failure %u\n", GetLastError());
2545 ok(!sz, "got %u\n", sz);
2547 sz = 0;
2548 SetLastError(0xdeadbeef);
2549 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, NULL, &sz);
2550 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2551 ok(!r, "unexpected success\n");
2552 ok(sz == 34, "got %u\n", sz);
2554 sz = sizeof(buffer);
2555 SetLastError(0xdeadbeef);
2556 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz);
2557 ok(r, "unexpected failure %u\n", GetLastError());
2558 ok(sz == 33, "got %u\n", sz);
2560 r = HttpSendRequestW(hr, NULL, 0, NULL, 0);
2561 ok(r || broken(!r), "HttpSendRequest failed %u\n", GetLastError());
2562 if (!r)
2564 win_skip("skipping proxy tests on broken wininet\n");
2565 goto done;
2568 test_status_code(hr, 407);
2570 /* set the user + password then try again */
2571 r = InternetSetOptionA(hi, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2572 ok(!r, "unexpected success\n");
2574 r = InternetSetOptionA(hc, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2575 ok(r, "failed to set user\n");
2577 r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2578 ok(r, "failed to set user\n");
2580 buffer[0] = 0;
2581 sz = 3;
2582 SetLastError(0xdeadbeef);
2583 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2584 ok(!r, "unexpected failure %u\n", GetLastError());
2585 ok(!buffer[0], "got %s\n", buffer);
2586 ok(sz == strlen(username) + 1, "got %u\n", sz);
2588 buffer[0] = 0;
2589 sz = 0;
2590 SetLastError(0xdeadbeef);
2591 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2592 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2593 ok(!r, "unexpected success\n");
2594 ok(sz == strlen(username) + 1, "got %u\n", sz);
2596 bufferW[0] = 0;
2597 sz = 0;
2598 SetLastError(0xdeadbeef);
2599 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_USERNAME, bufferW, &sz);
2600 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2601 ok(!r, "unexpected success\n");
2602 ok(sz == (lstrlenW(usernameW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2604 buffer[0] = 0;
2605 sz = sizeof(buffer);
2606 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2607 ok(r, "failed to get username\n");
2608 ok(!strcmp(buffer, username), "got %s\n", buffer);
2609 ok(sz == strlen(username), "got %u\n", sz);
2611 buffer[0] = 0;
2612 sz = sizeof(bufferW);
2613 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_USERNAME, bufferW, &sz);
2614 ok(r, "failed to get username\n");
2615 ok(!lstrcmpW(bufferW, usernameW), "wrong username\n");
2616 ok(sz == lstrlenW(usernameW), "got %u\n", sz);
2618 r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, username, 1);
2619 ok(r, "failed to set user\n");
2621 buffer[0] = 0;
2622 sz = sizeof(buffer);
2623 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2624 ok(r, "failed to get username\n");
2625 ok(!strcmp(buffer, username), "got %s\n", buffer);
2626 ok(sz == strlen(username), "got %u\n", sz);
2628 r = InternetSetOptionA(hi, INTERNET_OPTION_USER_AGENT, useragent, 1);
2629 ok(r, "failed to set useragent\n");
2631 buffer[0] = 0;
2632 sz = 0;
2633 SetLastError(0xdeadbeef);
2634 r = InternetQueryOptionA(hi, INTERNET_OPTION_USER_AGENT, buffer, &sz);
2635 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2636 ok(!r, "unexpected success\n");
2637 ok(sz == strlen(useragent) + 1, "got %u\n", sz);
2639 buffer[0] = 0;
2640 sz = sizeof(buffer);
2641 r = InternetQueryOptionA(hi, INTERNET_OPTION_USER_AGENT, buffer, &sz);
2642 ok(r, "failed to get user agent\n");
2643 ok(!strcmp(buffer, useragent), "got %s\n", buffer);
2644 ok(sz == strlen(useragent), "got %u\n", sz);
2646 bufferW[0] = 0;
2647 sz = 0;
2648 SetLastError(0xdeadbeef);
2649 r = InternetQueryOptionW(hi, INTERNET_OPTION_USER_AGENT, bufferW, &sz);
2650 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2651 ok(!r, "unexpected success\n");
2652 ok(sz == (lstrlenW(useragentW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2654 bufferW[0] = 0;
2655 sz = sizeof(bufferW);
2656 r = InternetQueryOptionW(hi, INTERNET_OPTION_USER_AGENT, bufferW, &sz);
2657 ok(r, "failed to get user agent\n");
2658 ok(!lstrcmpW(bufferW, useragentW), "wrong user agent\n");
2659 ok(sz == lstrlenW(useragentW), "got %u\n", sz);
2661 r = InternetSetOptionA(hr, INTERNET_OPTION_USERNAME, username, 1);
2662 ok(r, "failed to set user\n");
2664 buffer[0] = 0;
2665 sz = 0;
2666 SetLastError(0xdeadbeef);
2667 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz);
2668 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2669 ok(!r, "unexpected success\n");
2670 ok(sz == strlen(username) + 1, "got %u\n", sz);
2672 buffer[0] = 0;
2673 sz = sizeof(buffer);
2674 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz);
2675 ok(r, "failed to get user\n");
2676 ok(!strcmp(buffer, username), "got %s\n", buffer);
2677 ok(sz == strlen(username), "got %u\n", sz);
2679 bufferW[0] = 0;
2680 sz = 0;
2681 SetLastError(0xdeadbeef);
2682 r = InternetQueryOptionW(hr, INTERNET_OPTION_USERNAME, bufferW, &sz);
2683 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2684 ok(!r, "unexpected success\n");
2685 ok(sz == (lstrlenW(usernameW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2687 bufferW[0] = 0;
2688 sz = sizeof(bufferW);
2689 r = InternetQueryOptionW(hr, INTERNET_OPTION_USERNAME, bufferW, &sz);
2690 ok(r, "failed to get user\n");
2691 ok(!lstrcmpW(bufferW, usernameW), "wrong user\n");
2692 ok(sz == lstrlenW(usernameW), "got %u\n", sz);
2694 r = InternetSetOptionA(hr, INTERNET_OPTION_PASSWORD, password, 1);
2695 ok(r, "failed to set password\n");
2697 buffer[0] = 0;
2698 sz = 0;
2699 SetLastError(0xdeadbeef);
2700 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz);
2701 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2702 ok(!r, "unexpected success\n");
2703 ok(sz == strlen(password) + 1, "got %u\n", sz);
2705 buffer[0] = 0;
2706 sz = sizeof(buffer);
2707 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz);
2708 ok(r, "failed to get password\n");
2709 ok(!strcmp(buffer, password), "got %s\n", buffer);
2710 ok(sz == strlen(password), "got %u\n", sz);
2712 bufferW[0] = 0;
2713 sz = 0;
2714 SetLastError(0xdeadbeef);
2715 r = InternetQueryOptionW(hr, INTERNET_OPTION_PASSWORD, bufferW, &sz);
2716 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2717 ok(!r, "unexpected success\n");
2718 ok(sz == (lstrlenW(passwordW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2720 bufferW[0] = 0;
2721 sz = sizeof(bufferW);
2722 r = InternetQueryOptionW(hr, INTERNET_OPTION_PASSWORD, bufferW, &sz);
2723 ok(r, "failed to get password\n");
2724 ok(!lstrcmpW(bufferW, passwordW), "wrong password\n");
2725 ok(sz == lstrlenW(passwordW), "got %u\n", sz);
2727 url = HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt) + 11);
2728 sprintf(url, url_fmt, port);
2729 buffer[0] = 0;
2730 sz = 0;
2731 SetLastError(0xdeadbeef);
2732 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz);
2733 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2734 ok(!r, "unexpected success\n");
2735 ok(sz == strlen(url) + 1, "got %u\n", sz);
2737 buffer[0] = 0;
2738 sz = sizeof(buffer);
2739 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz);
2740 ok(r, "failed to get url\n");
2741 ok(!strcmp(buffer, url), "got %s\n", buffer);
2742 ok(sz == strlen(url), "got %u\n", sz);
2744 bufferW[0] = 0;
2745 sz = 0;
2746 SetLastError(0xdeadbeef);
2747 r = InternetQueryOptionW(hr, INTERNET_OPTION_URL, bufferW, &sz);
2748 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2749 ok(!r, "unexpected success\n");
2750 ok(sz == (strlen(url) + 1) * sizeof(WCHAR), "got %u\n", sz);
2752 bufferW[0] = 0;
2753 sz = sizeof(bufferW);
2754 r = InternetQueryOptionW(hr, INTERNET_OPTION_URL, bufferW, &sz);
2755 ok(r, "failed to get url\n");
2756 ok(!strcmp_wa(bufferW, url), "wrong url\n");
2757 ok(sz == strlen(url), "got %u\n", sz);
2758 HeapFree(GetProcessHeap(), 0, url);
2760 r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, password, 4);
2761 ok(r, "failed to set password\n");
2763 buffer[0] = 0;
2764 sz = 0;
2765 SetLastError(0xdeadbeef);
2766 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz);
2767 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2768 ok(!r, "unexpected success\n");
2769 ok(sz == strlen(password) + 1, "got %u\n", sz);
2771 buffer[0] = 0;
2772 sz = sizeof(buffer);
2773 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz);
2774 ok(r, "failed to get password\n");
2775 ok(!strcmp(buffer, password), "got %s\n", buffer);
2776 ok(sz == strlen(password), "got %u\n", sz);
2778 bufferW[0] = 0;
2779 sz = 0;
2780 SetLastError(0xdeadbeef);
2781 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_PASSWORD, bufferW, &sz);
2782 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2783 ok(!r, "unexpected success\n");
2784 ok(sz == (lstrlenW(passwordW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2786 bufferW[0] = 0;
2787 sz = sizeof(bufferW);
2788 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_PASSWORD, bufferW, &sz);
2789 ok(r, "failed to get password\n");
2790 ok(!lstrcmpW(bufferW, passwordW), "wrong password\n");
2791 ok(sz == lstrlenW(passwordW), "got %u\n", sz);
2793 r = HttpSendRequestW(hr, NULL, 0, NULL, 0);
2794 if (!r)
2796 win_skip("skipping proxy tests on broken wininet\n");
2797 goto done;
2799 ok(r, "HttpSendRequest failed %u\n", GetLastError());
2800 sz = sizeof buffer;
2801 r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
2802 ok(r, "HttpQueryInfo failed\n");
2803 ok(!strcmp(buffer, "200"), "proxy code wrong\n");
2805 InternetCloseHandle(hr);
2806 InternetCloseHandle(hc);
2807 InternetCloseHandle(hi);
2809 sprintf(buffer, "localhost:%d\n", port);
2810 hi = InternetOpenA("winetest", INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0);
2811 ok(hi != NULL, "InternetOpen failed\n");
2813 hc = InternetConnectA(hi, "test.winehq.org", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2814 ok(hc != NULL, "InternetConnect failed\n");
2816 hr = HttpOpenRequestA(hc, "POST", "/test2", NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0);
2817 ok(hr != NULL, "HttpOpenRequest failed\n");
2819 r = HttpSendRequestA(hr, NULL, 0, (char *)"data", sizeof("data"));
2820 ok(r, "HttpSendRequest failed %u\n", GetLastError());
2822 test_status_code(hr, 407);
2824 done:
2825 InternetCloseHandle(hr);
2826 InternetCloseHandle(hc);
2827 InternetCloseHandle(hi);
2830 static void test_header_handling_order(int port)
2832 static const char authorization[] = "Authorization: Basic dXNlcjpwd2Q=";
2833 static const char connection[] = "Connection: Close";
2834 static const char *types[2] = { "*", NULL };
2835 char data[32];
2836 HINTERNET session, connect, request;
2837 DWORD size, status, data_len;
2838 BOOL ret;
2840 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2841 ok(session != NULL, "InternetOpen failed\n");
2843 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2844 ok(connect != NULL, "InternetConnect failed\n");
2846 request = HttpOpenRequestA(connect, NULL, "/test3", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2847 ok(request != NULL, "HttpOpenRequest failed\n");
2849 ret = HttpAddRequestHeadersA(request, authorization, ~0u, HTTP_ADDREQ_FLAG_ADD);
2850 ok(ret, "HttpAddRequestHeaders failed\n");
2852 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
2853 ok(ret, "HttpSendRequest failed\n");
2855 test_status_code(request, 200);
2856 test_request_flags(request, 0);
2858 InternetCloseHandle(request);
2860 request = HttpOpenRequestA(connect, NULL, "/test4", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2861 ok(request != NULL, "HttpOpenRequest failed\n");
2863 ret = HttpSendRequestA(request, connection, ~0u, NULL, 0);
2864 ok(ret, "HttpSendRequest failed\n");
2866 status = 0;
2867 size = sizeof(status);
2868 ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2869 ok(ret, "HttpQueryInfo failed\n");
2870 ok(status == 200 || status == 400 /* IE6 */, "got status %u, expected 200 or 400\n", status);
2872 InternetCloseHandle(request);
2873 InternetCloseHandle(connect);
2875 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2876 ok(connect != NULL, "InternetConnect failed\n");
2878 request = HttpOpenRequestA(connect, "POST", "/test7", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2879 ok(request != NULL, "HttpOpenRequest failed\n");
2881 ret = HttpAddRequestHeadersA(request, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
2882 ok(ret, "HttpAddRequestHeaders failed\n");
2884 ret = HttpSendRequestA(request, connection, ~0u, NULL, 0);
2885 ok(ret, "HttpSendRequest failed\n");
2887 status = 0;
2888 size = sizeof(status);
2889 ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2890 ok(ret, "HttpQueryInfo failed\n");
2891 ok(status == 200, "got status %u, expected 200\n", status);
2893 InternetCloseHandle(request);
2894 InternetCloseHandle(connect);
2896 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2897 ok(connect != NULL, "InternetConnect failed\n");
2899 request = HttpOpenRequestA(connect, "POST", "/test7b", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2900 ok(request != NULL, "HttpOpenRequest failed\n");
2902 ret = HttpAddRequestHeadersA(request, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
2903 ok(ret, "HttpAddRequestHeaders failed\n");
2905 data_len = sizeof(data);
2906 memset(data, 'a', sizeof(data));
2907 ret = HttpSendRequestA(request, NULL, 0, data, data_len);
2908 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
2910 status = 0;
2911 size = sizeof(status);
2912 ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2913 ok(ret, "HttpQueryInfo failed\n");
2914 ok(status == 200, "got status %u, expected 200\n", status);
2916 InternetCloseHandle(request);
2917 InternetCloseHandle(connect);
2918 InternetCloseHandle(session);
2921 static void test_connection_header(int port)
2923 HINTERNET ses, con, req;
2924 BOOL ret;
2926 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2927 ok(ses != NULL, "InternetOpen failed\n");
2929 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2930 ok(con != NULL, "InternetConnect failed\n");
2932 req = HttpOpenRequestA(con, NULL, "/test8", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2933 ok(req != NULL, "HttpOpenRequest failed\n");
2935 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2936 ok(ret, "HttpSendRequest failed\n");
2938 test_status_code(req, 200);
2940 InternetCloseHandle(req);
2942 req = HttpOpenRequestA(con, NULL, "/test9", NULL, NULL, NULL, 0, 0);
2943 ok(req != NULL, "HttpOpenRequest failed\n");
2945 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2946 ok(ret, "HttpSendRequest failed\n");
2948 test_status_code(req, 200);
2950 InternetCloseHandle(req);
2952 req = HttpOpenRequestA(con, NULL, "/test9", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
2953 ok(req != NULL, "HttpOpenRequest failed\n");
2955 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2956 ok(ret, "HttpSendRequest failed\n");
2958 test_status_code(req, 200);
2960 InternetCloseHandle(req);
2962 req = HttpOpenRequestA(con, "POST", "/testA", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
2963 ok(req != NULL, "HttpOpenRequest failed\n");
2965 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2966 ok(ret, "HttpSendRequest failed\n");
2968 test_status_code(req, 200);
2970 InternetCloseHandle(req);
2971 InternetCloseHandle(con);
2972 InternetCloseHandle(ses);
2975 static void test_header_override(int port)
2977 char buffer[128], host_header_override[30], full_url[128];
2978 HINTERNET ses, con, req;
2979 DWORD size, count, err;
2980 BOOL ret;
2982 sprintf(host_header_override, "Host: test.local:%d\r\n", port);
2983 sprintf(full_url, "http://localhost:%d/test_host_override", port);
2985 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2986 ok(ses != NULL, "InternetOpen failed\n");
2988 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2989 ok(con != NULL, "InternetConnect failed\n");
2991 req = HttpOpenRequestA(con, NULL, "/test_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2992 ok(req != NULL, "HttpOpenRequest failed\n");
2994 size = sizeof(buffer) - 1;
2995 count = 0;
2996 memset(buffer, 0, sizeof(buffer));
2997 ret = HttpQueryInfoA(req, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &count);
2998 err = GetLastError();
2999 ok(!ret, "HttpQueryInfo succeeded\n");
3000 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err);
3002 size = sizeof(buffer) - 1;
3003 memset(buffer, 0, sizeof(buffer));
3004 ret = InternetQueryOptionA(req, INTERNET_OPTION_URL, buffer, &size);
3005 ok(ret, "InternetQueryOption failed\n");
3006 ok(!strcmp(full_url, buffer), "Expected %s, got %s\n", full_url, buffer);
3008 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_COALESCE);
3009 ok(ret, "HttpAddRequestHeaders failed\n");
3011 size = sizeof(buffer) - 1;
3012 count = 0;
3013 memset(buffer, 0, sizeof(buffer));
3014 ret = HttpQueryInfoA(req, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &count);
3015 ok(ret, "HttpQueryInfo failed\n");
3017 size = sizeof(buffer) - 1;
3018 memset(buffer, 0, sizeof(buffer));
3019 ret = InternetQueryOptionA(req, INTERNET_OPTION_URL, buffer, &size);
3020 ok(ret, "InternetQueryOption failed\n");
3021 ok(!strcmp(full_url, buffer), "Expected %s, got %s\n", full_url, buffer);
3023 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3024 ok(ret, "HttpSendRequest failed\n");
3026 test_status_code(req, 200);
3028 InternetCloseHandle(req);
3029 req = HttpOpenRequestA(con, NULL, "/test_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3030 ok(req != NULL, "HttpOpenRequest failed\n");
3032 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_COALESCE);
3033 ok(ret, "HttpAddRequestHeaders failed\n");
3035 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_COALESCE);
3036 ok(ret, "HttpAddRequestHeaders failed\n");
3038 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3039 ok(ret, "HttpSendRequest failed\n");
3041 test_status_code(req, 400);
3043 InternetCloseHandle(req);
3044 req = HttpOpenRequestA(con, NULL, "/test_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3045 ok(req != NULL, "HttpOpenRequest failed\n");
3047 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD);
3048 ok(ret, "HttpAddRequestHeaders failed\n");
3050 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3051 ok(ret, "HttpSendRequest failed\n");
3053 test_status_code(req, 200);
3055 InternetCloseHandle(req);
3056 req = HttpOpenRequestA(con, NULL, "/test_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3057 ok(req != NULL, "HttpOpenRequest failed\n");
3059 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_REPLACE);
3060 err = GetLastError();
3061 todo_wine ok(!ret, "HttpAddRequestHeaders succeeded\n");
3062 todo_wine ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err);
3064 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3065 ok(ret, "HttpSendRequest failed\n");
3067 test_status_code_todo(req, 400);
3069 InternetCloseHandle(req);
3070 InternetCloseHandle(con);
3071 InternetCloseHandle(ses);
3074 static void test_http1_1(int port)
3076 HINTERNET ses, con, req;
3077 BOOL ret;
3079 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3080 ok(ses != NULL, "InternetOpen failed\n");
3082 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3083 ok(con != NULL, "InternetConnect failed\n");
3085 req = HttpOpenRequestA(con, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3086 ok(req != NULL, "HttpOpenRequest failed\n");
3088 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3089 if (ret)
3091 InternetCloseHandle(req);
3093 req = HttpOpenRequestA(con, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3094 ok(req != NULL, "HttpOpenRequest failed\n");
3096 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3097 ok(ret, "HttpSendRequest failed\n");
3100 InternetCloseHandle(req);
3101 InternetCloseHandle(con);
3102 InternetCloseHandle(ses);
3105 static void test_connection_closing(int port)
3107 HINTERNET session, connection, req;
3108 DWORD res;
3110 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
3112 session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
3113 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
3115 pInternetSetStatusCallbackA(session, callback);
3117 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3118 connection = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
3119 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
3120 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3122 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3123 req = HttpOpenRequestA(connection, "GET", "/testJ", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0xdeadbeaf);
3124 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
3125 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3127 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3128 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3129 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3130 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3131 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3132 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3133 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3134 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3135 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION);
3136 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED);
3137 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3139 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
3140 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3141 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3142 WaitForSingleObject(hCompleteEvent, INFINITE);
3143 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3145 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3146 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3147 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3148 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3149 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3150 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3151 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3152 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3153 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3154 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3155 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3157 test_status_code(req, 200);
3159 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3160 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3161 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3162 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3163 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3164 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3165 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3166 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3167 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3169 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
3170 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3171 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3172 WaitForSingleObject(hCompleteEvent, INFINITE);
3173 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3175 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3176 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3177 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3178 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3179 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3180 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3181 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3182 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3183 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3185 test_status_code(req, 210);
3187 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3188 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3189 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3190 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3191 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3192 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3193 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3194 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3195 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION);
3196 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED);
3197 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3199 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
3200 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3201 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3202 WaitForSingleObject(hCompleteEvent, INFINITE);
3203 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3205 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3206 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3207 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3208 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3209 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3210 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3211 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3212 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3213 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3214 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3215 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3217 test_status_code(req, 200);
3219 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION);
3220 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED);
3222 close_async_handle(session, hCompleteEvent, 2);
3223 CloseHandle(hCompleteEvent);
3226 static void test_successive_HttpSendRequest(int port)
3228 HINTERNET session, connection, req;
3229 DWORD res;
3231 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
3233 session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
3234 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
3236 pInternetSetStatusCallbackA(session, callback);
3238 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3239 connection = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
3240 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
3241 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3243 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3244 req = HttpOpenRequestA(connection, "GET", "/testH", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0xdeadbeaf);
3245 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
3246 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3248 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3249 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3250 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3251 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3252 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3253 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3254 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3255 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3256 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3258 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
3259 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3260 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3261 WaitForSingleObject(hCompleteEvent, INFINITE);
3262 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3264 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3265 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3266 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3267 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3268 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3269 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3270 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3271 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3272 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3274 test_status_code(req, 210);
3276 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3277 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3278 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3279 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3280 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3281 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3282 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION);
3283 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED);
3284 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3286 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
3287 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3288 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3289 WaitForSingleObject(hCompleteEvent, INFINITE);
3290 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3292 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3293 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3294 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3295 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3296 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3297 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3298 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3299 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3300 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3302 test_status_code(req, 200);
3304 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION);
3305 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED);
3307 close_async_handle(session, hCompleteEvent, 2);
3308 CloseHandle(hCompleteEvent);
3311 static void test_no_content(int port)
3313 HINTERNET session, connection, req;
3314 DWORD res;
3316 trace("Testing 204 no content response...\n");
3318 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
3320 session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
3321 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
3323 pInternetSetStatusCallbackA(session, callback);
3325 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3326 connection = InternetConnectA(session, "localhost", port,
3327 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
3328 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
3329 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3331 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3332 req = HttpOpenRequestA(connection, "GET", "/test_no_content", NULL, NULL, NULL,
3333 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
3334 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
3335 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3337 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3338 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3339 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3340 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3341 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3342 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3343 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3344 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
3345 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
3346 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3348 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
3349 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3350 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3351 WaitForSingleObject(hCompleteEvent, INFINITE);
3352 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3354 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3355 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3356 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3357 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3358 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3359 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3360 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3361 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3363 close_async_handle(session, hCompleteEvent, 2);
3364 CloseHandle(hCompleteEvent);
3367 * The connection should be closed before closing handle. This is true for most
3368 * wininet versions (including Wine), but some old win2k versions fail to do that.
3370 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3371 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3374 static void test_conn_close(int port)
3376 HINTERNET session, connection, req;
3377 DWORD res, avail, size;
3378 BYTE buf[1024];
3380 trace("Testing connection close connection...\n");
3382 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
3383 conn_close_event = CreateEventW(NULL, FALSE, FALSE, NULL);
3385 session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
3386 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
3388 pInternetSetStatusCallbackA(session, callback);
3390 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3391 connection = InternetConnectA(session, "localhost", port,
3392 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
3393 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
3394 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3396 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3397 req = HttpOpenRequestA(connection, "GET", "/test_conn_close", NULL, NULL, NULL,
3398 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
3399 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
3400 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3402 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3403 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3404 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3405 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3406 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3407 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3408 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3409 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3411 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
3412 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3413 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3414 WaitForSingleObject(hCompleteEvent, INFINITE);
3415 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3417 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3418 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3419 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3420 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3421 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3422 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3423 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3424 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3426 avail = 0;
3427 res = InternetQueryDataAvailable(req, &avail, 0, 0);
3428 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3429 ok(avail != 0, "avail = 0\n");
3431 size = 0;
3432 res = InternetReadFile(req, buf, avail, &size);
3433 ok(res, "InternetReadFile failed: %u\n", GetLastError());
3435 /* IE11 calls those in InternetQueryDataAvailable call. */
3436 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE);
3437 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED);
3439 res = InternetQueryDataAvailable(req, &avail, 0, 0);
3440 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3441 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3442 ok(!avail, "avail = %u, expected 0\n", avail);
3444 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3446 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
3447 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
3448 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3449 SetEvent(conn_close_event);
3450 WaitForSingleObject(hCompleteEvent, INFINITE);
3451 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3452 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3453 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3454 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3455 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3457 close_async_handle(session, hCompleteEvent, 2);
3458 CloseHandle(hCompleteEvent);
3461 static void test_no_cache(int port)
3463 static const char cache_control_no_cache[] = "/test_cache_control_no_cache";
3464 static const char cache_control_no_store[] = "/test_cache_control_no_store";
3465 static const char cache_url_fmt[] = "http://localhost:%d%s";
3467 char cache_url[256], buf[256];
3468 HINTERNET ses, con, req;
3469 DWORD read, size;
3470 BOOL ret;
3472 trace("Testing no-cache header\n");
3474 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3475 ok(ses != NULL,"InternetOpen failed with error %u\n", GetLastError());
3477 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3478 ok(con != NULL, "InternetConnect failed with error %u\n", GetLastError());
3480 req = HttpOpenRequestA(con, NULL, cache_control_no_cache, NULL, NULL, NULL, 0, 0);
3481 ok(req != NULL, "HttpOpenRequest failed\n");
3483 sprintf(cache_url, cache_url_fmt, port, cache_control_no_cache);
3484 DeleteUrlCacheEntryA(cache_url);
3486 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3487 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3488 size = 0;
3489 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
3490 size += read;
3491 ok(size == 12, "read %d bytes of data\n", size);
3492 InternetCloseHandle(req);
3494 req = HttpOpenRequestA(con, NULL, cache_control_no_cache, NULL, NULL, NULL, 0, 0);
3495 ok(req != NULL, "HttpOpenRequest failed\n");
3497 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3498 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3499 size = 0;
3500 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
3501 size += read;
3502 ok(size == 0, "read %d bytes of data\n", size);
3503 InternetCloseHandle(req);
3504 DeleteUrlCacheEntryA(cache_url);
3506 req = HttpOpenRequestA(con, NULL, cache_control_no_store, NULL, NULL, NULL, 0, 0);
3507 ok(req != NULL, "HttpOpenRequest failed\n");
3509 sprintf(cache_url, cache_url_fmt, port, cache_control_no_store);
3510 DeleteUrlCacheEntryA(cache_url);
3512 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3513 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3514 size = 0;
3515 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
3516 size += read;
3517 ok(size == 12, "read %d bytes of data\n", size);
3518 InternetCloseHandle(req);
3520 ret = DeleteUrlCacheEntryA(cache_url);
3521 ok(!ret && GetLastError()==ERROR_FILE_NOT_FOUND, "cache entry should not exist\n");
3523 InternetCloseHandle(con);
3524 InternetCloseHandle(ses);
3527 static void test_cache_read_gzipped(int port)
3529 static const char cache_url_fmt[] = "http://localhost:%d%s";
3530 static const char get_gzip[] = "/test_cache_gzip";
3531 static const char content[] = "gzip test\n";
3532 static const char text_html[] = "text/html";
3533 static const char raw_header[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3535 HINTERNET ses, con, req;
3536 DWORD read, size;
3537 char cache_url[256], buf[256];
3538 BOOL ret;
3540 trace("Testing reading compressed content from cache\n");
3542 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3543 ok(ses != NULL,"InternetOpen failed with error %u\n", GetLastError());
3545 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3546 ok(con != NULL, "InternetConnect failed with error %u\n", GetLastError());
3548 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, 0, 0);
3549 ok(req != NULL, "HttpOpenRequest failed\n");
3551 ret = TRUE;
3552 ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
3553 if(!ret && GetLastError()==ERROR_INTERNET_INVALID_OPTION) {
3554 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3555 InternetCloseHandle(req);
3556 InternetCloseHandle(con);
3557 InternetCloseHandle(ses);
3558 return;
3560 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3562 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3563 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3564 size = 0;
3565 while(InternetReadFile(req, buf+size, sizeof(buf)-size, &read) && read)
3566 size += read;
3567 ok(size == 10, "read %d bytes of data\n", size);
3568 buf[size] = 0;
3569 ok(!strncmp(buf, content, size), "incorrect page content: %s\n", buf);
3571 size = sizeof(buf)-1;
3572 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_TYPE, buf, &size, 0);
3573 ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3574 buf[size] = 0;
3575 ok(!strncmp(text_html, buf, size), "buf = %s\n", buf);
3577 size = sizeof(buf)-1;
3578 ret = HttpQueryInfoA(req, HTTP_QUERY_RAW_HEADERS_CRLF, buf, &size, 0);
3579 ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3580 buf[size] = 0;
3581 ok(!strncmp(raw_header, buf, size), "buf = %s\n", buf);
3582 InternetCloseHandle(req);
3584 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
3585 ok(req != NULL, "HttpOpenRequest failed\n");
3587 ret = TRUE;
3588 ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
3589 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3591 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3592 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3593 size = 0;
3594 while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read)
3595 size += read;
3596 todo_wine ok(size == 10, "read %d bytes of data\n", size);
3597 buf[size] = 0;
3598 ok(!strncmp(buf, content, size), "incorrect page content: %s\n", buf);
3600 size = sizeof(buf);
3601 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
3602 ok(!ret && GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND,
3603 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3604 ret, GetLastError());
3606 size = sizeof(buf)-1;
3607 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_TYPE, buf, &size, 0);
3608 todo_wine ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3609 buf[size] = 0;
3610 todo_wine ok(!strncmp(text_html, buf, size), "buf = %s\n", buf);
3611 InternetCloseHandle(req);
3613 /* Decompression doesn't work while reading from cache */
3614 test_cache_gzip = 0;
3615 sprintf(cache_url, cache_url_fmt, port, get_gzip);
3616 DeleteUrlCacheEntryA(cache_url);
3618 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, 0, 0);
3619 ok(req != NULL, "HttpOpenRequest failed\n");
3621 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3622 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3623 size = 0;
3624 while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read)
3625 size += read;
3626 ok(size == 31, "read %d bytes of data\n", size);
3627 InternetCloseHandle(req);
3629 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
3630 ok(req != NULL, "HttpOpenRequest failed\n");
3632 ret = TRUE;
3633 ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
3634 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3636 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3637 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3638 size = 0;
3639 while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read)
3640 size += read;
3641 todo_wine ok(size == 31, "read %d bytes of data\n", size);
3643 size = sizeof(buf);
3644 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
3645 todo_wine ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3646 InternetCloseHandle(req);
3648 InternetCloseHandle(con);
3649 InternetCloseHandle(ses);
3651 DeleteUrlCacheEntryA(cache_url);
3654 static void test_HttpSendRequestW(int port)
3656 static const WCHAR header[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3657 HINTERNET ses, con, req;
3658 DWORD error;
3659 BOOL ret;
3661 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
3662 ok(ses != NULL, "InternetOpen failed\n");
3664 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3665 ok(con != NULL, "InternetConnect failed\n");
3667 req = HttpOpenRequestA(con, NULL, "/test1", NULL, NULL, NULL, 0, 0);
3668 ok(req != NULL, "HttpOpenRequest failed\n");
3670 SetLastError(0xdeadbeef);
3671 ret = HttpSendRequestW(req, header, ~0u, NULL, 0);
3672 error = GetLastError();
3673 ok(!ret, "HttpSendRequestW succeeded\n");
3674 ok(error == ERROR_IO_PENDING ||
3675 broken(error == ERROR_HTTP_HEADER_NOT_FOUND) || /* IE6 */
3676 broken(error == ERROR_INVALID_PARAMETER), /* IE5 */
3677 "got %u expected ERROR_IO_PENDING\n", error);
3679 InternetCloseHandle(req);
3680 InternetCloseHandle(con);
3681 InternetCloseHandle(ses);
3684 static void test_cookie_header(int port)
3686 HINTERNET ses, con, req;
3687 DWORD size, error;
3688 BOOL ret;
3689 char buffer[64];
3691 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3692 ok(ses != NULL, "InternetOpen failed\n");
3694 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3695 ok(con != NULL, "InternetConnect failed\n");
3697 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3699 req = HttpOpenRequestA(con, NULL, "/testC", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3700 ok(req != NULL, "HttpOpenRequest failed\n");
3702 buffer[0] = 0;
3703 size = sizeof(buffer);
3704 SetLastError(0xdeadbeef);
3705 ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3706 error = GetLastError();
3707 ok(!ret, "HttpQueryInfo succeeded\n");
3708 ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error);
3710 ret = HttpAddRequestHeadersA(req, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD);
3711 ok(ret, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3713 buffer[0] = 0;
3714 size = sizeof(buffer);
3715 ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3716 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
3717 ok(!strcmp(buffer, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer);
3719 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3720 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
3722 test_status_code(req, 200);
3724 buffer[0] = 0;
3725 size = sizeof(buffer);
3726 ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3727 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
3728 ok(!strcmp(buffer, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer);
3730 InternetCloseHandle(req);
3731 InternetCloseHandle(con);
3732 InternetCloseHandle(ses);
3735 static void test_basic_authentication(int port)
3737 HINTERNET session, connect, request;
3738 BOOL ret;
3740 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3741 ok(session != NULL, "InternetOpen failed\n");
3743 connect = InternetConnectA(session, "localhost", port, "user", "pwd", INTERNET_SERVICE_HTTP, 0, 0);
3744 ok(connect != NULL, "InternetConnect failed\n");
3746 request = HttpOpenRequestA(connect, NULL, "/test3", NULL, NULL, NULL, 0, 0);
3747 ok(request != NULL, "HttpOpenRequest failed\n");
3749 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
3750 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
3752 test_status_code(request, 200);
3753 test_request_flags(request, 0);
3755 InternetCloseHandle(request);
3756 InternetCloseHandle(connect);
3757 InternetCloseHandle(session);
3760 static void test_premature_disconnect(int port)
3762 HINTERNET session, connect, request;
3763 DWORD err;
3764 BOOL ret;
3766 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3767 ok(session != NULL, "InternetOpen failed\n");
3769 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3770 ok(connect != NULL, "InternetConnect failed\n");
3772 request = HttpOpenRequestA(connect, NULL, "/premature_disconnect", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3773 ok(request != NULL, "HttpOpenRequest failed\n");
3775 SetLastError(0xdeadbeef);
3776 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
3777 err = GetLastError();
3778 todo_wine ok(!ret, "HttpSendRequest succeeded\n");
3779 todo_wine ok(err == ERROR_HTTP_INVALID_SERVER_RESPONSE, "got %u\n", err);
3781 InternetCloseHandle(request);
3782 InternetCloseHandle(connect);
3783 InternetCloseHandle(session);
3786 static void test_invalid_response_headers(int port)
3788 HINTERNET session, connect, request;
3789 DWORD size;
3790 BOOL ret;
3791 char buffer[256];
3793 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3794 ok(session != NULL, "InternetOpen failed\n");
3796 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3797 ok(connect != NULL, "InternetConnect failed\n");
3799 request = HttpOpenRequestA(connect, NULL, "/testE", NULL, NULL, NULL, 0, 0);
3800 ok(request != NULL, "HttpOpenRequest failed\n");
3802 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
3803 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
3805 test_status_code(request, 401);
3806 test_request_flags(request, 0);
3808 buffer[0] = 0;
3809 size = sizeof(buffer);
3810 ret = HttpQueryInfoA( request, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
3811 ok(ret, "HttpQueryInfo failed\n");
3812 ok(!strcmp(buffer, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
3813 "headers wrong \"%s\"\n", buffer);
3815 buffer[0] = 0;
3816 size = sizeof(buffer);
3817 ret = HttpQueryInfoA( request, HTTP_QUERY_SERVER, buffer, &size, NULL);
3818 ok(ret, "HttpQueryInfo failed\n");
3819 ok(!strcmp(buffer, "winetest"), "server wrong \"%s\"\n", buffer);
3821 InternetCloseHandle(request);
3822 InternetCloseHandle(connect);
3823 InternetCloseHandle(session);
3826 static void test_response_without_headers(int port)
3828 HINTERNET hi, hc, hr;
3829 DWORD r, count, size;
3830 char buffer[1024];
3832 SetLastError(0xdeadbeef);
3833 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3834 ok(hi != NULL, "open failed %u\n", GetLastError());
3836 SetLastError(0xdeadbeef);
3837 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3838 ok(hc != NULL, "connect failed %u\n", GetLastError());
3840 SetLastError(0xdeadbeef);
3841 hr = HttpOpenRequestA(hc, NULL, "/testG", NULL, NULL, NULL, 0, 0);
3842 ok(hr != NULL, "HttpOpenRequest failed %u\n", GetLastError());
3844 test_request_flags(hr, INTERNET_REQFLAG_NO_HEADERS);
3846 SetLastError(0xdeadbeef);
3847 r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
3848 ok(r, "HttpSendRequest failed %u\n", GetLastError());
3850 test_request_flags_todo(hr, INTERNET_REQFLAG_NO_HEADERS);
3852 count = 0;
3853 memset(buffer, 0, sizeof buffer);
3854 SetLastError(0xdeadbeef);
3855 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
3856 ok(r, "InternetReadFile failed %u\n", GetLastError());
3857 todo_wine ok(count == sizeof page1 - 1, "count was wrong\n");
3858 todo_wine ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
3860 test_status_code(hr, 200);
3861 test_request_flags_todo(hr, INTERNET_REQFLAG_NO_HEADERS);
3863 buffer[0] = 0;
3864 size = sizeof(buffer);
3865 SetLastError(0xdeadbeef);
3866 r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, NULL );
3867 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
3868 ok(!strcmp(buffer, "OK"), "expected OK got: \"%s\"\n", buffer);
3870 buffer[0] = 0;
3871 size = sizeof(buffer);
3872 SetLastError(0xdeadbeef);
3873 r = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &size, NULL);
3874 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
3875 ok(!strcmp(buffer, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer);
3877 buffer[0] = 0;
3878 size = sizeof(buffer);
3879 SetLastError(0xdeadbeef);
3880 r = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
3881 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
3882 ok(!strcmp(buffer, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer);
3884 InternetCloseHandle(hr);
3885 InternetCloseHandle(hc);
3886 InternetCloseHandle(hi);
3889 static void test_head_request(int port)
3891 DWORD len, content_length;
3892 HINTERNET ses, con, req;
3893 BYTE buf[100];
3894 BOOL ret;
3896 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3897 ok(ses != NULL, "InternetOpen failed\n");
3899 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3900 ok(con != NULL, "InternetConnect failed\n");
3902 req = HttpOpenRequestA(con, "HEAD", "/test_head", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3903 ok(req != NULL, "HttpOpenRequest failed\n");
3905 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3906 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
3908 len = sizeof(content_length);
3909 content_length = -1;
3910 ret = HttpQueryInfoA(req, HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_CONTENT_LENGTH, &content_length, &len, 0);
3911 ok(ret, "HttpQueryInfo dailed: %u\n", GetLastError());
3912 ok(len == sizeof(DWORD), "len = %u\n", len);
3913 ok(content_length == 100, "content_length = %u\n", content_length);
3915 len = -1;
3916 ret = InternetReadFile(req, buf, sizeof(buf), &len);
3917 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
3919 len = -1;
3920 ret = InternetReadFile(req, buf, sizeof(buf), &len);
3921 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
3923 InternetCloseHandle(req);
3924 InternetCloseHandle(con);
3925 InternetCloseHandle(ses);
3928 static void test_HttpQueryInfo(int port)
3930 HINTERNET hi, hc, hr;
3931 DWORD size, index, error;
3932 char buffer[1024];
3933 BOOL ret;
3935 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3936 ok(hi != NULL, "InternetOpen failed\n");
3938 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3939 ok(hc != NULL, "InternetConnect failed\n");
3941 hr = HttpOpenRequestA(hc, NULL, "/testD", NULL, NULL, NULL, 0, 0);
3942 ok(hr != NULL, "HttpOpenRequest failed\n");
3944 size = sizeof(buffer);
3945 ret = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
3946 error = GetLastError();
3947 ok(!ret || broken(ret), "HttpQueryInfo succeeded\n");
3948 if (!ret) ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error);
3950 ret = HttpSendRequestA(hr, NULL, 0, NULL, 0);
3951 ok(ret, "HttpSendRequest failed\n");
3953 index = 0;
3954 size = sizeof(buffer);
3955 ret = HttpQueryInfoA(hr, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &index);
3956 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3957 ok(index == 1, "expected 1 got %u\n", index);
3959 index = 0;
3960 size = sizeof(buffer);
3961 ret = HttpQueryInfoA(hr, HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME, buffer, &size, &index);
3962 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3963 ok(index == 1, "expected 1 got %u\n", index);
3965 index = 0;
3966 size = sizeof(buffer);
3967 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
3968 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3969 ok(index == 0, "expected 0 got %u\n", index);
3971 size = sizeof(buffer);
3972 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
3973 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3974 ok(index == 0, "expected 0 got %u\n", index);
3976 index = 0xdeadbeef; /* invalid start index */
3977 size = sizeof(buffer);
3978 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
3979 todo_wine ok(!ret, "HttpQueryInfo should have failed\n");
3980 todo_wine ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
3981 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
3983 index = 0;
3984 size = sizeof(buffer);
3985 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS_CRLF, buffer, &size, &index);
3986 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3987 ok(index == 0, "expected 0 got %u\n", index);
3989 size = sizeof(buffer);
3990 ret = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
3991 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3992 ok(index == 0, "expected 0 got %u\n", index);
3994 size = sizeof(buffer);
3995 ret = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &size, &index);
3996 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3997 ok(index == 0, "expected 0 got %u\n", index);
3999 test_status_code(hr, 200);
4001 index = 0xdeadbeef;
4002 size = sizeof(buffer);
4003 ret = HttpQueryInfoA(hr, HTTP_QUERY_FORWARDED, buffer, &size, &index);
4004 ok(!ret, "HttpQueryInfo succeeded\n");
4005 ok(index == 0xdeadbeef, "expected 0xdeadbeef got %u\n", index);
4007 index = 0;
4008 size = sizeof(buffer);
4009 ret = HttpQueryInfoA(hr, HTTP_QUERY_SERVER, buffer, &size, &index);
4010 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4011 ok(index == 1, "expected 1 got %u\n", index);
4013 index = 0;
4014 size = sizeof(buffer);
4015 strcpy(buffer, "Server");
4016 ret = HttpQueryInfoA(hr, HTTP_QUERY_CUSTOM, buffer, &size, &index);
4017 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4018 ok(index == 1, "expected 1 got %u\n", index);
4020 index = 0;
4021 size = sizeof(buffer);
4022 ret = HttpQueryInfoA(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
4023 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4024 ok(index == 1, "expected 1 got %u\n", index);
4026 size = sizeof(buffer);
4027 ret = HttpQueryInfoA(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
4028 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4029 ok(index == 2, "expected 2 got %u\n", index);
4031 InternetCloseHandle(hr);
4032 InternetCloseHandle(hc);
4033 InternetCloseHandle(hi);
4036 static void test_options(int port)
4038 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi;
4039 HINTERNET ses, con, req;
4040 DWORD size, error;
4041 DWORD_PTR ctx;
4042 BOOL ret;
4044 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4045 ok(ses != NULL, "InternetOpen failed\n");
4047 SetLastError(0xdeadbeef);
4048 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, 0);
4049 error = GetLastError();
4050 ok(!ret, "InternetSetOption succeeded\n");
4051 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
4053 SetLastError(0xdeadbeef);
4054 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, sizeof(ctx));
4055 ok(!ret, "InternetSetOption succeeded\n");
4056 error = GetLastError();
4057 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
4059 SetLastError(0xdeadbeef);
4060 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, 0);
4061 ok(!ret, "InternetSetOption succeeded\n");
4062 error = GetLastError();
4063 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
4065 ctx = 1;
4066 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
4067 ok(ret, "InternetSetOption failed %u\n", GetLastError());
4069 SetLastError(0xdeadbeef);
4070 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, NULL);
4071 error = GetLastError();
4072 ok(!ret, "InternetQueryOption succeeded\n");
4073 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
4075 SetLastError(0xdeadbeef);
4076 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, NULL);
4077 error = GetLastError();
4078 ok(!ret, "InternetQueryOption succeeded\n");
4079 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
4081 size = 0;
4082 SetLastError(0xdeadbeef);
4083 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, &size);
4084 error = GetLastError();
4085 ok(!ret, "InternetQueryOption succeeded\n");
4086 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
4088 size = sizeof(ctx);
4089 SetLastError(0xdeadbeef);
4090 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
4091 error = GetLastError();
4092 ok(!ret, "InternetQueryOption succeeded\n");
4093 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error);
4095 ctx = 0xdeadbeef;
4096 size = sizeof(ctx);
4097 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
4098 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
4099 ok(ctx == 1, "expected 1 got %lu\n", ctx);
4101 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4102 ok(con != NULL, "InternetConnect failed\n");
4104 ctx = 0xdeadbeef;
4105 size = sizeof(ctx);
4106 ret = InternetQueryOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
4107 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
4108 ok(ctx == 0, "expected 0 got %lu\n", ctx);
4110 ctx = 2;
4111 ret = InternetSetOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
4112 ok(ret, "InternetSetOption failed %u\n", GetLastError());
4114 ctx = 0xdeadbeef;
4115 size = sizeof(ctx);
4116 ret = InternetQueryOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
4117 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
4118 ok(ctx == 2, "expected 2 got %lu\n", ctx);
4120 req = HttpOpenRequestA(con, NULL, "/test1", NULL, NULL, NULL, 0, 0);
4121 ok(req != NULL, "HttpOpenRequest failed\n");
4123 ctx = 0xdeadbeef;
4124 size = sizeof(ctx);
4125 ret = InternetQueryOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
4126 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
4127 ok(ctx == 0, "expected 0 got %lu\n", ctx);
4129 ctx = 3;
4130 ret = InternetSetOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
4131 ok(ret, "InternetSetOption failed %u\n", GetLastError());
4133 ctx = 0xdeadbeef;
4134 size = sizeof(ctx);
4135 ret = InternetQueryOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
4136 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
4137 ok(ctx == 3, "expected 3 got %lu\n", ctx);
4139 size = sizeof(idsi);
4140 ret = InternetQueryOptionA(req, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO, &idsi, &size);
4141 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
4143 size = 0;
4144 SetLastError(0xdeadbeef);
4145 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, NULL, &size);
4146 error = GetLastError();
4147 ok(!ret, "InternetQueryOption succeeded\n");
4148 ok(error == ERROR_INTERNET_INVALID_OPERATION, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error);
4150 /* INTERNET_OPTION_PROXY */
4151 SetLastError(0xdeadbeef);
4152 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, NULL);
4153 error = GetLastError();
4154 ok(!ret, "InternetQueryOption succeeded\n");
4155 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
4157 SetLastError(0xdeadbeef);
4158 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, &ctx, NULL);
4159 error = GetLastError();
4160 ok(!ret, "InternetQueryOption succeeded\n");
4161 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
4163 size = 0;
4164 SetLastError(0xdeadbeef);
4165 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, &size);
4166 error = GetLastError();
4167 ok(!ret, "InternetQueryOption succeeded\n");
4168 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
4169 ok(size >= sizeof(INTERNET_PROXY_INFOA), "expected size to be greater or equal to the struct size\n");
4171 InternetCloseHandle(req);
4172 InternetCloseHandle(con);
4173 InternetCloseHandle(ses);
4176 typedef struct {
4177 const char *response_text;
4178 int status_code;
4179 const char *status_text;
4180 const char *raw_headers;
4181 } http_status_test_t;
4183 static const http_status_test_t http_status_tests[] = {
4185 "HTTP/1.1 200 OK\r\n"
4186 "Content-Length: 1\r\n"
4187 "\r\nx",
4188 200,
4189 "OK"
4192 "HTTP/1.1 404 Fail\r\n"
4193 "Content-Length: 1\r\n"
4194 "\r\nx",
4195 404,
4196 "Fail"
4199 "HTTP/1.1 200\r\n"
4200 "Content-Length: 1\r\n"
4201 "\r\nx",
4202 200,
4206 "HTTP/1.1 410 \r\n"
4207 "Content-Length: 1\r\n"
4208 "\r\nx",
4209 410,
4214 static void test_http_status(int port)
4216 HINTERNET ses, con, req;
4217 char buf[1000];
4218 DWORD i, size;
4219 BOOL res;
4221 for(i=0; i < sizeof(http_status_tests)/sizeof(*http_status_tests); i++) {
4222 send_buffer = http_status_tests[i].response_text;
4224 ses = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4225 ok(ses != NULL, "InternetOpen failed\n");
4227 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4228 ok(con != NULL, "InternetConnect failed\n");
4230 req = HttpOpenRequestA(con, NULL, "/send_from_buffer", NULL, NULL, NULL, 0, 0);
4231 ok(req != NULL, "HttpOpenRequest failed\n");
4233 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4234 ok(res, "HttpSendRequest failed\n");
4236 test_status_code(req, http_status_tests[i].status_code);
4238 size = sizeof(buf);
4239 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_TEXT, buf, &size, NULL);
4240 ok(res, "HttpQueryInfo failed: %u\n", GetLastError());
4241 ok(!strcmp(buf, http_status_tests[i].status_text), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
4242 i, buf, http_status_tests[i].status_text);
4244 InternetCloseHandle(req);
4245 InternetCloseHandle(con);
4246 InternetCloseHandle(ses);
4250 static void test_cache_control_verb(int port)
4252 HINTERNET session, connect, request;
4253 BOOL ret;
4255 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4256 ok(session != NULL, "InternetOpen failed\n");
4258 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4259 ok(connect != NULL, "InternetConnect failed\n");
4261 request = HttpOpenRequestA(connect, "RPC_OUT_DATA", "/test_cache_control_verb", NULL, NULL, NULL,
4262 INTERNET_FLAG_NO_CACHE_WRITE, 0);
4263 ok(request != NULL, "HttpOpenRequest failed\n");
4264 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4265 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4266 test_status_code(request, 200);
4267 InternetCloseHandle(request);
4269 request = HttpOpenRequestA(connect, "POST", "/test_cache_control_verb", NULL, NULL, NULL,
4270 INTERNET_FLAG_NO_CACHE_WRITE, 0);
4271 ok(request != NULL, "HttpOpenRequest failed\n");
4272 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4273 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4274 test_status_code(request, 200);
4275 InternetCloseHandle(request);
4277 request = HttpOpenRequestA(connect, "HEAD", "/test_cache_control_verb", NULL, NULL, NULL,
4278 INTERNET_FLAG_NO_CACHE_WRITE, 0);
4279 ok(request != NULL, "HttpOpenRequest failed\n");
4280 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4281 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4282 test_status_code(request, 200);
4283 InternetCloseHandle(request);
4285 request = HttpOpenRequestA(connect, "GET", "/test_cache_control_verb", NULL, NULL, NULL,
4286 INTERNET_FLAG_NO_CACHE_WRITE, 0);
4287 ok(request != NULL, "HttpOpenRequest failed\n");
4288 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4289 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4290 test_status_code(request, 200);
4291 InternetCloseHandle(request);
4293 InternetCloseHandle(connect);
4294 InternetCloseHandle(session);
4297 static void test_request_content_length(int port)
4299 char data[] = {'t','e','s','t'};
4300 HINTERNET ses, con, req;
4301 BOOL ret;
4303 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
4305 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4306 ok(ses != NULL, "InternetOpen failed\n");
4308 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4309 ok(con != NULL, "InternetConnect failed\n");
4311 req = HttpOpenRequestA(con, "POST", "/test_request_content_length", NULL, NULL, NULL,
4312 INTERNET_FLAG_KEEP_CONNECTION, 0);
4313 ok(req != NULL, "HttpOpenRequest failed\n");
4315 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
4316 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4317 test_status_code(req, 200);
4319 SetEvent(hCompleteEvent);
4321 ret = HttpSendRequestA(req, NULL, 0, data, sizeof(data));
4322 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4323 test_status_code(req, 200);
4325 SetEvent(hCompleteEvent);
4327 InternetCloseHandle(req);
4328 InternetCloseHandle(con);
4329 InternetCloseHandle(ses);
4330 CloseHandle(hCompleteEvent);
4333 static void test_accept_encoding(int port)
4335 HINTERNET ses, con, req;
4336 BOOL ret;
4338 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4339 ok(ses != NULL, "InternetOpen failed\n");
4341 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4342 ok(con != NULL, "InternetConnect failed\n");
4344 req = HttpOpenRequestA(con, "GET", "/test_accept_encoding_http10", "HTTP/1.0", NULL, NULL, 0, 0);
4345 ok(req != NULL, "HttpOpenRequest failed\n");
4347 ret = HttpAddRequestHeadersA(req, "Accept-Encoding: gzip\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
4348 ok(ret, "HttpAddRequestHeaders failed\n");
4350 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
4351 ok(ret, "HttpSendRequestA failed\n");
4353 test_status_code(req, 200);
4355 InternetCloseHandle(req);
4357 req = HttpOpenRequestA(con, "GET", "/test_accept_encoding_http10", "HTTP/1.0", NULL, NULL, 0, 0);
4358 ok(req != NULL, "HttpOpenRequest failed\n");
4360 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", ~0u, NULL, 0);
4361 ok(ret, "HttpSendRequestA failed\n");
4363 test_status_code(req, 200);
4365 InternetCloseHandle(req);
4366 InternetCloseHandle(con);
4367 InternetCloseHandle(ses);
4370 static void test_basic_auth_credentials_reuse(int port)
4372 HINTERNET ses, con, req;
4373 DWORD status, size;
4374 BOOL ret;
4376 ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 );
4377 ok( ses != NULL, "InternetOpenA failed\n" );
4379 con = InternetConnectA( ses, "localhost", port, "user", "pwd",
4380 INTERNET_SERVICE_HTTP, 0, 0 );
4381 ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
4383 req = HttpOpenRequestA( con, "HEAD", "/upload.txt", NULL, NULL, NULL, 0, 0 );
4384 ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
4386 ret = HttpSendRequestA( req, NULL, 0, NULL, 0 );
4387 ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
4389 status = 0xdeadbeef;
4390 size = sizeof(status);
4391 ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
4392 ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() );
4393 ok( status == 200, "got %u\n", status );
4395 InternetCloseHandle( req );
4396 InternetCloseHandle( con );
4397 InternetCloseHandle( ses );
4399 ses = InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 );
4400 ok( ses != NULL, "InternetOpenA failed\n" );
4402 con = InternetConnectA( ses, "localhost", port, NULL, NULL,
4403 INTERNET_SERVICE_HTTP, 0, 0 );
4404 ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
4406 req = HttpOpenRequestA( con, "PUT", "/upload2.txt", NULL, NULL, NULL, 0, 0 );
4407 ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
4409 ret = HttpSendRequestA( req, NULL, 0, NULL, 0 );
4410 ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
4412 status = 0xdeadbeef;
4413 size = sizeof(status);
4414 ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
4415 ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() );
4416 ok( status == 200, "got %u\n", status );
4418 InternetCloseHandle( req );
4419 InternetCloseHandle( con );
4420 InternetCloseHandle( ses );
4423 static void test_http_connection(void)
4425 struct server_info si;
4426 HANDLE hThread;
4427 DWORD id = 0, r;
4429 si.hEvent = CreateEventW(NULL, 0, 0, NULL);
4430 si.port = 7531;
4432 hThread = CreateThread(NULL, 0, server_thread, (LPVOID) &si, 0, &id);
4433 ok( hThread != NULL, "create thread failed\n");
4435 r = WaitForSingleObject(si.hEvent, 10000);
4436 ok (r == WAIT_OBJECT_0, "failed to start wininet test server\n");
4437 if (r != WAIT_OBJECT_0)
4438 return;
4440 test_basic_request(si.port, "GET", "/test1");
4441 test_proxy_indirect(si.port);
4442 test_proxy_direct(si.port);
4443 test_header_handling_order(si.port);
4444 test_basic_request(si.port, "POST", "/test5");
4445 test_basic_request(si.port, "RPC_IN_DATA", "/test5");
4446 test_basic_request(si.port, "RPC_OUT_DATA", "/test5");
4447 test_basic_request(si.port, "GET", "/test6");
4448 test_basic_request(si.port, "GET", "/testF");
4449 test_connection_header(si.port);
4450 test_header_override(si.port);
4451 test_http1_1(si.port);
4452 test_cookie_header(si.port);
4453 test_basic_authentication(si.port);
4454 test_invalid_response_headers(si.port);
4455 test_response_without_headers(si.port);
4456 test_HttpQueryInfo(si.port);
4457 test_HttpSendRequestW(si.port);
4458 test_options(si.port);
4459 test_no_content(si.port);
4460 test_conn_close(si.port);
4461 test_no_cache(si.port);
4462 test_cache_read_gzipped(si.port);
4463 test_http_status(si.port);
4464 test_premature_disconnect(si.port);
4465 test_connection_closing(si.port);
4466 test_cache_control_verb(si.port);
4467 test_successive_HttpSendRequest(si.port);
4468 test_head_request(si.port);
4469 test_request_content_length(si.port);
4470 test_accept_encoding(si.port);
4471 test_basic_auth_credentials_reuse(si.port);
4473 /* send the basic request again to shutdown the server thread */
4474 test_basic_request(si.port, "GET", "/quit");
4476 r = WaitForSingleObject(hThread, 3000);
4477 ok( r == WAIT_OBJECT_0, "thread wait failed\n");
4478 CloseHandle(hThread);
4481 static void release_cert_info(INTERNET_CERTIFICATE_INFOA *info)
4483 LocalFree(info->lpszSubjectInfo);
4484 LocalFree(info->lpszIssuerInfo);
4485 LocalFree(info->lpszProtocolName);
4486 LocalFree(info->lpszSignatureAlgName);
4487 LocalFree(info->lpszEncryptionAlgName);
4490 typedef struct {
4491 const char *ex_subject;
4492 const char *ex_issuer;
4493 } cert_struct_test_t;
4495 static const cert_struct_test_t test_winehq_org_cert = {
4496 "GT98380011\r\n"
4497 "See www.rapidssl.com/resources/cps (c)14\r\n"
4498 "Domain Control Validated - RapidSSL(R)\r\n"
4499 "*.winehq.org",
4501 "US\r\n"
4502 "GeoTrust Inc.\r\n"
4503 "RapidSSL SHA256 CA - G3"
4506 static const cert_struct_test_t test_winehq_com_cert = {
4507 "US\r\n"
4508 "Minnesota\r\n"
4509 "Saint Paul\r\n"
4510 "WineHQ\r\n"
4511 "test.winehq.com\r\n"
4512 "webmaster@winehq.org",
4514 "US\r\n"
4515 "Minnesota\r\n"
4516 "WineHQ\r\n"
4517 "test.winehq.com\r\n"
4518 "webmaster@winehq.org"
4521 static void test_cert_struct(HINTERNET req, const cert_struct_test_t *test)
4523 INTERNET_CERTIFICATE_INFOA info;
4524 DWORD size;
4525 BOOL res;
4527 memset(&info, 0x5, sizeof(info));
4529 size = sizeof(info);
4530 res = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, &info, &size);
4531 ok(res, "InternetQueryOption failed: %u\n", GetLastError());
4532 ok(size == sizeof(info), "size = %u\n", size);
4534 ok(!strcmp(info.lpszSubjectInfo, test->ex_subject), "lpszSubjectInfo = %s\n", info.lpszSubjectInfo);
4535 ok(!strcmp(info.lpszIssuerInfo, test->ex_issuer), "lpszIssuerInfo = %s\n", info.lpszIssuerInfo);
4536 ok(!info.lpszSignatureAlgName, "lpszSignatureAlgName = %s\n", info.lpszSignatureAlgName);
4537 ok(!info.lpszEncryptionAlgName, "lpszEncryptionAlgName = %s\n", info.lpszEncryptionAlgName);
4538 ok(!info.lpszProtocolName, "lpszProtocolName = %s\n", info.lpszProtocolName);
4539 ok(info.dwKeySize >= 128 && info.dwKeySize <= 256, "dwKeySize = %u\n", info.dwKeySize);
4541 release_cert_info(&info);
4544 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
4545 static void _test_security_info(unsigned line, const char *urlc, DWORD error, DWORD ex_flags)
4547 char url[INTERNET_MAX_URL_LENGTH];
4548 const CERT_CHAIN_CONTEXT *chain;
4549 DWORD flags;
4550 BOOL res;
4552 if(!pInternetGetSecurityInfoByURLA) {
4553 win_skip("pInternetGetSecurityInfoByURLA not available\n");
4554 return;
4557 strcpy(url, urlc);
4558 chain = (void*)0xdeadbeef;
4559 flags = 0xdeadbeef;
4560 res = pInternetGetSecurityInfoByURLA(url, &chain, &flags);
4561 if(error == ERROR_SUCCESS) {
4562 ok_(__FILE__,line)(res, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
4563 ok_(__FILE__,line)(chain != NULL, "chain = NULL\n");
4564 ok_(__FILE__,line)(flags == ex_flags, "flags = %x\n", flags);
4565 CertFreeCertificateChain(chain);
4566 }else {
4567 ok_(__FILE__,line)(!res && GetLastError() == error,
4568 "InternetGetSecurityInfoByURLA returned: %x(%u), expected %u\n", res, GetLastError(), error);
4572 #define test_secflags_option(a,b,c) _test_secflags_option(__LINE__,a,b,c)
4573 static void _test_secflags_option(unsigned line, HINTERNET req, DWORD ex_flags, DWORD opt_flags)
4575 DWORD flags, size;
4576 BOOL res;
4578 flags = 0xdeadbeef;
4579 size = sizeof(flags);
4580 res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
4581 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4582 ok_(__FILE__,line)((flags & ~opt_flags) == ex_flags, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n",
4583 flags, ex_flags);
4585 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
4586 flags = 0xdeadbeef;
4587 size = sizeof(flags);
4588 res = InternetQueryOptionW(req, 98, &flags, &size);
4589 ok_(__FILE__,line)(res, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
4590 ok_(__FILE__,line)((flags & ~opt_flags) == ex_flags, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n",
4591 flags, ex_flags);
4594 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
4595 static void _set_secflags(unsigned line, HINTERNET req, BOOL use_undoc, DWORD flags)
4597 BOOL res;
4599 res = InternetSetOptionW(req, use_undoc ? 99 : INTERNET_OPTION_SECURITY_FLAGS, &flags, sizeof(flags));
4600 ok_(__FILE__,line)(res, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4603 static void test_security_flags(void)
4605 INTERNET_CERTIFICATE_INFOA *cert;
4606 HINTERNET ses, conn, req;
4607 DWORD size, flags;
4608 char buf[100];
4609 BOOL res;
4611 trace("Testing security flags...\n");
4613 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
4615 ses = InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
4616 ok(ses != NULL, "InternetOpen failed\n");
4618 pInternetSetStatusCallbackA(ses, &callback);
4620 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4621 conn = InternetConnectA(ses, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT,
4622 NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0xdeadbeef);
4623 ok(conn != NULL, "InternetConnect failed with error %u\n", GetLastError());
4624 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4626 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4627 req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
4628 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
4629 0xdeadbeef);
4630 ok(req != NULL, "HttpOpenRequest failed\n");
4631 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4633 flags = 0xdeadbeef;
4634 size = sizeof(flags);
4635 res = InternetQueryOptionW(req, 98, &flags, &size);
4636 if(!res && GetLastError() == ERROR_INVALID_PARAMETER) {
4637 win_skip("Incomplete security flags support, skipping\n");
4639 close_async_handle(ses, hCompleteEvent, 2);
4640 CloseHandle(hCompleteEvent);
4641 return;
4644 test_secflags_option(req, 0, 0);
4645 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4647 set_secflags(req, TRUE, SECURITY_FLAG_IGNORE_REVOCATION);
4648 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION, 0);
4650 set_secflags(req, TRUE, SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
4651 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID, 0);
4653 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
4654 test_secflags_option(req, SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID, 0);
4656 flags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_SECURE;
4657 res = InternetSetOptionW(req, 99, &flags, sizeof(flags));
4658 ok(!res && GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE, "InternetSetOption(99) failed: %u\n", GetLastError());
4660 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
4661 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
4662 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4663 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4664 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */
4665 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */
4666 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */
4667 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */
4668 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
4669 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
4670 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
4671 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
4672 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4673 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
4674 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4676 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4677 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4679 WaitForSingleObject(hCompleteEvent, INFINITE);
4680 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
4682 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
4683 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
4684 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2);
4685 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2);
4686 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
4687 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
4688 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
4689 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
4690 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
4691 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
4692 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4693 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
4694 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4696 test_request_flags(req, 0);
4697 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4698 |SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_STRENGTH_STRONG, 0);
4700 res = InternetReadFile(req, buf, sizeof(buf), &size);
4701 ok(res, "InternetReadFile failed: %u\n", GetLastError());
4702 ok(size, "size = 0\n");
4704 /* Collect all existing persistent connections */
4705 res = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
4706 ok(res, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4708 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4709 req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
4710 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
4711 0xdeadbeef);
4712 ok(req != NULL, "HttpOpenRequest failed\n");
4713 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4715 flags = INTERNET_ERROR_MASK_COMBINED_SEC_CERT|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY;
4716 res = InternetSetOptionA(req, INTERNET_OPTION_ERROR_MASK, (void*)&flags, sizeof(flags));
4717 ok(res, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
4719 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4720 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4721 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */
4722 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */
4723 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */
4724 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */
4725 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
4726 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
4727 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4728 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4729 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
4731 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4732 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4734 WaitForSingleObject(hCompleteEvent, INFINITE);
4735 ok(req_error == ERROR_INTERNET_SEC_CERT_REV_FAILED || broken(req_error == ERROR_INTERNET_SEC_CERT_ERRORS),
4736 "req_error = %d\n", req_error);
4738 size = 0;
4739 res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, NULL, &size);
4740 ok(res || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
4741 ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %u\n", size);
4742 cert = HeapAlloc(GetProcessHeap(), 0, size);
4743 cert->lpszSubjectInfo = NULL;
4744 cert->lpszIssuerInfo = NULL;
4745 cert->lpszSignatureAlgName = (char *)0xdeadbeef;
4746 cert->lpszEncryptionAlgName = (char *)0xdeadbeef;
4747 cert->lpszProtocolName = (char *)0xdeadbeef;
4748 cert->dwKeySize = 0xdeadbeef;
4749 res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, cert, &size);
4750 ok(res, "InternetQueryOption failed: %u\n", GetLastError());
4751 if (res)
4753 ok(cert->lpszSubjectInfo && strlen(cert->lpszSubjectInfo) > 1, "expected a non-empty subject name\n");
4754 ok(cert->lpszIssuerInfo && strlen(cert->lpszIssuerInfo) > 1, "expected a non-empty issuer name\n");
4755 ok(!cert->lpszSignatureAlgName, "unexpected signature algorithm name\n");
4756 ok(!cert->lpszEncryptionAlgName, "unexpected encryption algorithm name\n");
4757 ok(!cert->lpszProtocolName, "unexpected protocol name\n");
4758 ok(cert->dwKeySize != 0xdeadbeef, "unexpected key size\n");
4760 HeapFree(GetProcessHeap(), 0, cert);
4762 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2);
4763 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2);
4764 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
4765 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
4766 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4767 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4768 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
4770 if(req_error != ERROR_INTERNET_SEC_CERT_REV_FAILED) {
4771 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error);
4773 close_async_handle(ses, hCompleteEvent, 3);
4774 CloseHandle(hCompleteEvent);
4775 return;
4778 size = sizeof(buf);
4779 res = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
4780 ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
4782 test_request_flags(req, 8);
4783 /* IE11 finds both rev failure and invalid CA. Previous versions required rev failure
4784 to be ignored before invalid CA was reported. */
4785 test_secflags_option(req, _SECURITY_FLAG_CERT_REV_FAILED, _SECURITY_FLAG_CERT_INVALID_CA);
4787 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_REVOCATION);
4788 test_secflags_option(req, _SECURITY_FLAG_CERT_REV_FAILED|SECURITY_FLAG_IGNORE_REVOCATION, _SECURITY_FLAG_CERT_INVALID_CA);
4790 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4791 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4792 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
4793 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
4794 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4795 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4796 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
4798 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4799 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4801 WaitForSingleObject(hCompleteEvent, INFINITE);
4802 ok(req_error == ERROR_INTERNET_SEC_CERT_ERRORS, "req_error = %d\n", req_error);
4804 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
4805 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
4806 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
4807 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
4808 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4809 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4810 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
4812 test_request_flags(req, INTERNET_REQFLAG_NO_HEADERS);
4813 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION|_SECURITY_FLAG_CERT_REV_FAILED|_SECURITY_FLAG_CERT_INVALID_CA, 0);
4814 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4816 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
4817 test_secflags_option(req, _SECURITY_FLAG_CERT_INVALID_CA|_SECURITY_FLAG_CERT_REV_FAILED
4818 |SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_UNKNOWN_CA, 0);
4819 test_http_version(req);
4821 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4822 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4823 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */
4824 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */
4825 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */
4826 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */
4827 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
4828 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
4829 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
4830 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
4831 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4832 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4833 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
4835 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4836 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4838 WaitForSingleObject(hCompleteEvent, INFINITE);
4839 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
4841 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2);
4842 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2);
4843 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
4844 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
4845 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
4846 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
4847 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
4848 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
4849 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4850 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4851 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
4853 test_request_flags(req, 0);
4854 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION
4855 |SECURITY_FLAG_STRENGTH_STRONG|_SECURITY_FLAG_CERT_REV_FAILED|_SECURITY_FLAG_CERT_INVALID_CA, 0);
4857 test_cert_struct(req, &test_winehq_com_cert);
4858 test_security_info("https://test.winehq.com/data/some_file.html?q", 0,
4859 _SECURITY_FLAG_CERT_INVALID_CA|_SECURITY_FLAG_CERT_REV_FAILED);
4861 res = InternetReadFile(req, buf, sizeof(buf), &size);
4862 ok(res, "InternetReadFile failed: %u\n", GetLastError());
4863 ok(size, "size = 0\n");
4865 close_async_handle(ses, hCompleteEvent, 3);
4867 /* Collect all existing persistent connections */
4868 res = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
4869 ok(res, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4871 /* Make another request, without setting security flags */
4873 ses = InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
4874 ok(ses != NULL, "InternetOpen failed\n");
4876 pInternetSetStatusCallbackA(ses, &callback);
4878 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4879 conn = InternetConnectA(ses, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT,
4880 NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0xdeadbeef);
4881 ok(conn != NULL, "InternetConnect failed with error %u\n", GetLastError());
4882 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4884 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4885 req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
4886 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
4887 0xdeadbeef);
4888 ok(req != NULL, "HttpOpenRequest failed\n");
4889 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4891 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_STRENGTH_STRONG
4892 |SECURITY_FLAG_IGNORE_REVOCATION|_SECURITY_FLAG_CERT_REV_FAILED|_SECURITY_FLAG_CERT_INVALID_CA, 0);
4893 test_http_version(req);
4895 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4896 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4897 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */
4898 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */
4899 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */
4900 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */
4901 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
4902 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
4903 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
4904 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
4905 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4906 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4908 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4909 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4911 WaitForSingleObject(hCompleteEvent, INFINITE);
4912 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
4914 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2);
4915 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2);
4916 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
4917 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
4918 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
4919 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
4920 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
4921 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
4922 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4923 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4925 test_request_flags(req, 0);
4926 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_STRENGTH_STRONG
4927 |SECURITY_FLAG_IGNORE_REVOCATION|_SECURITY_FLAG_CERT_REV_FAILED|_SECURITY_FLAG_CERT_INVALID_CA, 0);
4929 res = InternetReadFile(req, buf, sizeof(buf), &size);
4930 ok(res, "InternetReadFile failed: %u\n", GetLastError());
4931 ok(size, "size = 0\n");
4933 close_async_handle(ses, hCompleteEvent, 2);
4935 CloseHandle(hCompleteEvent);
4937 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4938 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4939 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4942 static void test_secure_connection(void)
4944 static const WCHAR gizmo5[] = {'G','i','z','m','o','5',0};
4945 static const WCHAR testsite[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
4946 static const WCHAR get[] = {'G','E','T',0};
4947 static const WCHAR testpage[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
4948 HINTERNET ses, con, req;
4949 DWORD size, flags;
4950 INTERNET_CERTIFICATE_INFOA *certificate_structA = NULL;
4951 INTERNET_CERTIFICATE_INFOW *certificate_structW = NULL;
4952 BOOL ret;
4954 ses = InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
4955 ok(ses != NULL, "InternetOpen failed\n");
4957 con = InternetConnectA(ses, "test.winehq.org",
4958 INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL,
4959 INTERNET_SERVICE_HTTP, 0, 0);
4960 ok(con != NULL, "InternetConnect failed\n");
4962 req = HttpOpenRequestA(con, "GET", "/tests/hello.html", NULL, NULL, NULL,
4963 INTERNET_FLAG_SECURE, 0);
4964 ok(req != NULL, "HttpOpenRequest failed\n");
4966 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
4967 ok(ret || broken(GetLastError() == ERROR_INTERNET_CANNOT_CONNECT),
4968 "HttpSendRequest failed: %d\n", GetLastError());
4969 if (!ret)
4971 win_skip("Cannot connect to https.\n");
4972 goto done;
4975 size = sizeof(flags);
4976 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
4977 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
4978 ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set\n");
4980 test_cert_struct(req, &test_winehq_org_cert);
4982 /* Querying the same option through InternetQueryOptionW still results in
4983 * ASCII strings being returned.
4985 size = 0;
4986 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
4987 NULL, &size);
4988 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
4989 ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size);
4990 certificate_structW = HeapAlloc(GetProcessHeap(), 0, size);
4991 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
4992 certificate_structW, &size);
4993 certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW;
4994 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
4995 if (ret)
4997 ok(certificate_structA->lpszSubjectInfo &&
4998 strlen(certificate_structA->lpszSubjectInfo) > 1,
4999 "expected a non-empty subject name\n");
5000 ok(certificate_structA->lpszIssuerInfo &&
5001 strlen(certificate_structA->lpszIssuerInfo) > 1,
5002 "expected a non-empty issuer name\n");
5003 ok(!certificate_structA->lpszSignatureAlgName,
5004 "unexpected signature algorithm name\n");
5005 ok(!certificate_structA->lpszEncryptionAlgName,
5006 "unexpected encryption algorithm name\n");
5007 ok(!certificate_structA->lpszProtocolName,
5008 "unexpected protocol name\n");
5009 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
5010 release_cert_info(certificate_structA);
5012 HeapFree(GetProcessHeap(), 0, certificate_structW);
5014 InternetCloseHandle(req);
5015 InternetCloseHandle(con);
5016 InternetCloseHandle(ses);
5018 /* Repeating the tests with the W functions has the same result: */
5019 ses = InternetOpenW(gizmo5, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
5020 ok(ses != NULL, "InternetOpen failed\n");
5022 con = InternetConnectW(ses, testsite,
5023 INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL,
5024 INTERNET_SERVICE_HTTP, 0, 0);
5025 ok(con != NULL, "InternetConnect failed\n");
5027 req = HttpOpenRequestW(con, get, testpage, NULL, NULL, NULL,
5028 INTERNET_FLAG_SECURE|INTERNET_FLAG_RELOAD, 0);
5029 ok(req != NULL, "HttpOpenRequest failed\n");
5031 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
5032 ok(ret, "HttpSendRequest failed: %d\n", GetLastError());
5034 size = sizeof(flags);
5035 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
5036 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
5037 ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set, got %x\n", flags);
5039 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
5040 NULL, &size);
5041 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
5042 ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %d\n", size);
5043 certificate_structA = HeapAlloc(GetProcessHeap(), 0, size);
5044 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
5045 certificate_structA, &size);
5046 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
5047 if (ret)
5049 ok(certificate_structA->lpszSubjectInfo &&
5050 strlen(certificate_structA->lpszSubjectInfo) > 1,
5051 "expected a non-empty subject name\n");
5052 ok(certificate_structA->lpszIssuerInfo &&
5053 strlen(certificate_structA->lpszIssuerInfo) > 1,
5054 "expected a non-empty issuer name\n");
5055 ok(!certificate_structA->lpszSignatureAlgName,
5056 "unexpected signature algorithm name\n");
5057 ok(!certificate_structA->lpszEncryptionAlgName,
5058 "unexpected encryption algorithm name\n");
5059 ok(!certificate_structA->lpszProtocolName,
5060 "unexpected protocol name\n");
5061 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
5062 release_cert_info(certificate_structA);
5064 HeapFree(GetProcessHeap(), 0, certificate_structA);
5066 /* Again, querying the same option through InternetQueryOptionW still
5067 * results in ASCII strings being returned.
5069 size = 0;
5070 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
5071 NULL, &size);
5072 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
5073 ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size);
5074 certificate_structW = HeapAlloc(GetProcessHeap(), 0, size);
5075 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
5076 certificate_structW, &size);
5077 certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW;
5078 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
5079 if (ret)
5081 ok(certificate_structA->lpszSubjectInfo &&
5082 strlen(certificate_structA->lpszSubjectInfo) > 1,
5083 "expected a non-empty subject name\n");
5084 ok(certificate_structA->lpszIssuerInfo &&
5085 strlen(certificate_structA->lpszIssuerInfo) > 1,
5086 "expected a non-empty issuer name\n");
5087 ok(!certificate_structA->lpszSignatureAlgName,
5088 "unexpected signature algorithm name\n");
5089 ok(!certificate_structA->lpszEncryptionAlgName,
5090 "unexpected encryption algorithm name\n");
5091 ok(!certificate_structA->lpszProtocolName,
5092 "unexpected protocol name\n");
5093 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
5094 release_cert_info(certificate_structA);
5096 HeapFree(GetProcessHeap(), 0, certificate_structW);
5098 done:
5099 InternetCloseHandle(req);
5100 InternetCloseHandle(con);
5101 InternetCloseHandle(ses);
5104 static void test_user_agent_header(void)
5106 HINTERNET ses, con, req;
5107 DWORD size, err;
5108 char buffer[64];
5109 BOOL ret;
5111 ses = InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
5112 ok(ses != NULL, "InternetOpen failed\n");
5114 con = InternetConnectA(ses, "test.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
5115 ok(con != NULL, "InternetConnect failed\n");
5117 req = HttpOpenRequestA(con, "GET", "/tests/hello.html", "HTTP/1.0", NULL, NULL, 0, 0);
5118 ok(req != NULL, "HttpOpenRequest failed\n");
5120 size = sizeof(buffer);
5121 ret = HttpQueryInfoA(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
5122 err = GetLastError();
5123 ok(!ret, "HttpQueryInfo succeeded\n");
5124 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
5126 ret = HttpAddRequestHeadersA(req, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
5127 ok(ret, "HttpAddRequestHeaders succeeded\n");
5129 size = sizeof(buffer);
5130 ret = HttpQueryInfoA(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
5131 err = GetLastError();
5132 ok(ret, "HttpQueryInfo failed\n");
5134 InternetCloseHandle(req);
5136 req = HttpOpenRequestA(con, "GET", "/", "HTTP/1.0", NULL, NULL, 0, 0);
5137 ok(req != NULL, "HttpOpenRequest failed\n");
5139 size = sizeof(buffer);
5140 ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
5141 err = GetLastError();
5142 ok(!ret, "HttpQueryInfo succeeded\n");
5143 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
5145 ret = HttpAddRequestHeadersA(req, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
5146 ok(ret, "HttpAddRequestHeaders failed\n");
5148 buffer[0] = 0;
5149 size = sizeof(buffer);
5150 ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
5151 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
5152 ok(!strcmp(buffer, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer);
5154 InternetCloseHandle(req);
5155 InternetCloseHandle(con);
5156 InternetCloseHandle(ses);
5159 static void test_bogus_accept_types_array(void)
5161 HINTERNET ses, con, req;
5162 static const char *types[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL };
5163 DWORD size, error;
5164 char buffer[32];
5165 BOOL ret;
5167 ses = InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT, "", "", 0);
5168 con = InternetConnectA(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
5169 req = HttpOpenRequestA(con, "POST", "/post/post_action.php", "HTTP/1.0", "", types, INTERNET_FLAG_FORMS_SUBMIT, 0);
5171 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
5173 buffer[0] = 0;
5174 size = sizeof(buffer);
5175 SetLastError(0xdeadbeef);
5176 ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
5177 error = GetLastError();
5178 ok(!ret || broken(ret), "HttpQueryInfo succeeded\n");
5179 if (!ret) ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error);
5180 ok(broken(!strcmp(buffer, ", */*, %p, , , */*")) /* IE6 */ ||
5181 broken(!strcmp(buffer, "*/*, %p, */*")) /* IE7/8 */ ||
5182 !strcmp(buffer, ""), "got '%s' expected ''\n", buffer);
5184 InternetCloseHandle(req);
5185 InternetCloseHandle(con);
5186 InternetCloseHandle(ses);
5189 struct context
5191 HANDLE event;
5192 HINTERNET req;
5195 static void WINAPI cb(HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID info, DWORD size)
5197 INTERNET_ASYNC_RESULT *result = info;
5198 struct context *ctx = (struct context *)context;
5200 trace("%p 0x%08lx %u %p 0x%08x\n", handle, context, status, info, size);
5202 switch(status) {
5203 case INTERNET_STATUS_REQUEST_COMPLETE:
5204 trace("request handle: 0x%08lx\n", result->dwResult);
5205 ctx->req = (HINTERNET)result->dwResult;
5206 SetEvent(ctx->event);
5207 break;
5208 case INTERNET_STATUS_HANDLE_CLOSING: {
5209 DWORD type = INTERNET_HANDLE_TYPE_CONNECT_HTTP, size = sizeof(type);
5211 if (InternetQueryOptionA(handle, INTERNET_OPTION_HANDLE_TYPE, &type, &size))
5212 ok(type != INTERNET_HANDLE_TYPE_CONNECT_HTTP, "unexpected callback\n");
5213 SetEvent(ctx->event);
5214 break;
5216 case INTERNET_STATUS_NAME_RESOLVED:
5217 case INTERNET_STATUS_CONNECTING_TO_SERVER:
5218 case INTERNET_STATUS_CONNECTED_TO_SERVER: {
5219 char *str = info;
5220 ok(str[0] && str[1], "Got string: %s\n", str);
5221 ok(size == strlen(str)+1, "unexpected size %u\n", size);
5226 static void test_open_url_async(void)
5228 BOOL ret;
5229 HINTERNET ses, req;
5230 DWORD size, error;
5231 struct context ctx;
5232 ULONG type;
5234 /* Collect all existing persistent connections */
5235 ret = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
5236 ok(ret, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5239 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
5240 * other versions never do. They also hang of following tests. We disable it for everything older
5241 * than IE7.
5243 if(!pInternetGetSecurityInfoByURLA) {
5244 win_skip("Skipping async open on too old wininet version.\n");
5245 return;
5248 ctx.req = NULL;
5249 ctx.event = CreateEventA(NULL, TRUE, FALSE, "Z:_home_hans_jaman-installer.exe_ev1");
5251 ses = InternetOpenA("AdvancedInstaller", 0, NULL, NULL, INTERNET_FLAG_ASYNC);
5252 ok(ses != NULL, "InternetOpen failed\n");
5254 SetLastError(0xdeadbeef);
5255 ret = InternetSetOptionA(NULL, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR));
5256 error = GetLastError();
5257 ok(!ret, "InternetSetOptionA succeeded\n");
5258 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error);
5260 ret = InternetSetOptionA(ses, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR));
5261 error = GetLastError();
5262 ok(!ret, "InternetSetOptionA failed\n");
5263 ok(error == ERROR_INTERNET_OPTION_NOT_SETTABLE, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error);
5265 pInternetSetStatusCallbackW(ses, cb);
5266 ResetEvent(ctx.event);
5268 req = InternetOpenUrlA(ses, "http://test.winehq.org", NULL, 0, 0, (DWORD_PTR)&ctx);
5269 ok(!req && GetLastError() == ERROR_IO_PENDING, "InternetOpenUrl failed\n");
5271 WaitForSingleObject(ctx.event, INFINITE);
5273 type = 0;
5274 size = sizeof(type);
5275 ret = InternetQueryOptionA(ctx.req, INTERNET_OPTION_HANDLE_TYPE, &type, &size);
5276 ok(ret, "InternetQueryOption failed: %u\n", GetLastError());
5277 ok(type == INTERNET_HANDLE_TYPE_HTTP_REQUEST,
5278 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type);
5280 size = 0;
5281 ret = HttpQueryInfoA(ctx.req, HTTP_QUERY_RAW_HEADERS_CRLF, NULL, &size, NULL);
5282 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "HttpQueryInfo failed\n");
5283 ok(size > 0, "expected size > 0\n");
5285 ResetEvent(ctx.event);
5286 InternetCloseHandle(ctx.req);
5287 WaitForSingleObject(ctx.event, INFINITE);
5289 InternetCloseHandle(ses);
5290 CloseHandle(ctx.event);
5293 enum api
5295 internet_connect = 1,
5296 http_open_request,
5297 http_send_request_ex,
5298 internet_writefile,
5299 http_end_request,
5300 internet_close_handle
5303 struct notification
5305 enum api function; /* api responsible for notification */
5306 unsigned int status; /* status received */
5307 BOOL async; /* delivered from another thread? */
5308 BOOL todo;
5309 BOOL optional;
5312 struct info
5314 enum api function;
5315 const struct notification *test;
5316 unsigned int count;
5317 unsigned int index;
5318 HANDLE wait;
5319 DWORD thread;
5320 unsigned int line;
5321 DWORD expect_result;
5322 BOOL is_aborted;
5325 static CRITICAL_SECTION notification_cs;
5327 static void CALLBACK check_notification( HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID buffer, DWORD buflen )
5329 BOOL status_ok, function_ok;
5330 struct info *info = (struct info *)context;
5331 unsigned int i;
5333 EnterCriticalSection( &notification_cs );
5335 if(info->is_aborted) {
5336 LeaveCriticalSection(&notification_cs);
5337 return;
5340 if (status == INTERNET_STATUS_HANDLE_CREATED)
5342 DWORD size = sizeof(struct info *);
5343 HttpQueryInfoA( handle, INTERNET_OPTION_CONTEXT_VALUE, &info, &size, 0 );
5344 }else if(status == INTERNET_STATUS_REQUEST_COMPLETE) {
5345 INTERNET_ASYNC_RESULT *ar = (INTERNET_ASYNC_RESULT*)buffer;
5347 ok(buflen == sizeof(*ar), "unexpected buflen = %d\n", buflen);
5348 if(info->expect_result == ERROR_SUCCESS) {
5349 ok(ar->dwResult == 1, "ar->dwResult = %ld, expected 1\n", ar->dwResult);
5350 }else {
5351 ok(!ar->dwResult, "ar->dwResult = %ld, expected 1\n", ar->dwResult);
5352 ok(ar->dwError == info->expect_result, "ar->dwError = %d, expected %d\n", ar->dwError, info->expect_result);
5356 i = info->index;
5357 if (i >= info->count)
5359 LeaveCriticalSection( &notification_cs );
5360 return;
5363 while (info->test[i].status != status &&
5364 (info->test[i].optional || info->test[i].todo) &&
5365 i < info->count - 1 &&
5366 info->test[i].function == info->test[i + 1].function)
5368 i++;
5371 status_ok = (info->test[i].status == status);
5372 function_ok = (info->test[i].function == info->function);
5374 if (!info->test[i].todo)
5376 ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status );
5377 ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
5379 if (info->test[i].async)
5380 ok(info->thread != GetCurrentThreadId(), "%u: expected thread %u got %u\n",
5381 info->line, info->thread, GetCurrentThreadId());
5383 else
5385 todo_wine ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status );
5386 if (status_ok)
5387 todo_wine ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
5389 if (i == info->count - 1 || info->test[i].function != info->test[i + 1].function) SetEvent( info->wait );
5390 info->index = i+1;
5392 LeaveCriticalSection( &notification_cs );
5395 static void setup_test( struct info *info, enum api function, unsigned int line, DWORD expect_result )
5397 info->function = function;
5398 info->line = line;
5399 info->expect_result = expect_result;
5402 struct notification_data
5404 const struct notification *test;
5405 const unsigned int count;
5406 const char *method;
5407 const char *host;
5408 const char *path;
5409 const char *data;
5410 BOOL expect_conn_failure;
5413 static const struct notification async_send_request_ex_test[] =
5415 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5416 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5417 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5418 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, TRUE, FALSE, TRUE },
5419 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE, FALSE, TRUE },
5420 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, TRUE, FALSE, TRUE },
5421 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, TRUE },
5422 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, TRUE },
5423 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, TRUE },
5424 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, TRUE },
5425 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5426 { internet_writefile, INTERNET_STATUS_SENDING_REQUEST, FALSE },
5427 { internet_writefile, INTERNET_STATUS_REQUEST_SENT, FALSE },
5428 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, TRUE },
5429 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, TRUE },
5430 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5431 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, FALSE, FALSE, TRUE },
5432 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, FALSE, FALSE, TRUE },
5433 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, },
5434 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }
5437 static const struct notification async_send_request_ex_test2[] =
5439 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5440 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5441 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5442 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, TRUE, FALSE, TRUE },
5443 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE, FALSE, TRUE },
5444 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, TRUE, FALSE, TRUE },
5445 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, TRUE, TRUE },
5446 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, TRUE, TRUE },
5447 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, TRUE },
5448 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, TRUE },
5449 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5450 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, TRUE },
5451 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, TRUE },
5452 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5453 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, FALSE, FALSE, TRUE },
5454 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, FALSE, FALSE, TRUE },
5455 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, },
5456 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }
5459 static const struct notification async_send_request_ex_resolve_failure_test[] =
5461 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5462 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5463 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5464 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE },
5465 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5466 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5467 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5468 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, FALSE, FALSE, TRUE },
5469 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, FALSE, FALSE, TRUE },
5470 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, },
5471 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }
5474 static const struct notification async_send_request_ex_chunked_test[] =
5476 { internet_connect, INTERNET_STATUS_HANDLE_CREATED },
5477 { http_open_request, INTERNET_STATUS_HANDLE_CREATED },
5478 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5479 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, TRUE, FALSE, TRUE },
5480 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE, FALSE, TRUE },
5481 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, TRUE, FALSE, TRUE },
5482 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, TRUE },
5483 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, TRUE },
5484 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, TRUE },
5485 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, TRUE },
5486 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5487 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, TRUE },
5488 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, TRUE },
5489 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5490 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION },
5491 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED },
5492 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING },
5493 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING }
5496 static const struct notification_data notification_data[] = {
5498 async_send_request_ex_chunked_test,
5499 sizeof(async_send_request_ex_chunked_test)/sizeof(async_send_request_ex_chunked_test[0]),
5500 "GET",
5501 "test.winehq.org",
5502 "tests/data.php"
5505 async_send_request_ex_test,
5506 sizeof(async_send_request_ex_test)/sizeof(async_send_request_ex_test[0]),
5507 "POST",
5508 "test.winehq.org",
5509 "tests/post.php",
5510 "Public ID=codeweavers"
5513 async_send_request_ex_test2,
5514 sizeof(async_send_request_ex_test)/sizeof(async_send_request_ex_test[0]),
5515 "POST",
5516 "test.winehq.org",
5517 "tests/post.php"
5520 async_send_request_ex_resolve_failure_test,
5521 sizeof(async_send_request_ex_resolve_failure_test)/sizeof(async_send_request_ex_resolve_failure_test[0]),
5522 "GET",
5523 "brokenhost",
5524 "index.html",
5525 NULL,
5526 TRUE
5530 static void test_async_HttpSendRequestEx(const struct notification_data *nd)
5532 BOOL ret;
5533 HINTERNET ses, req, con;
5534 struct info info;
5535 DWORD size, written, error;
5536 INTERNET_BUFFERSA b;
5537 static const char *accept[2] = {"*/*", NULL};
5538 char buffer[32];
5540 trace("Async HttpSendRequestEx test (%s %s)\n", nd->method, nd->host);
5542 InitializeCriticalSection( &notification_cs );
5544 info.test = nd->test;
5545 info.count = nd->count;
5546 info.index = 0;
5547 info.wait = CreateEventW( NULL, FALSE, FALSE, NULL );
5548 info.thread = GetCurrentThreadId();
5549 info.is_aborted = FALSE;
5551 ses = InternetOpenA( "winetest", 0, NULL, NULL, INTERNET_FLAG_ASYNC );
5552 ok( ses != NULL, "InternetOpen failed\n" );
5554 pInternetSetStatusCallbackA( ses, check_notification );
5556 setup_test( &info, internet_connect, __LINE__, ERROR_SUCCESS );
5557 con = InternetConnectA( ses, nd->host, 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, (DWORD_PTR)&info );
5558 ok( con != NULL, "InternetConnect failed %u\n", GetLastError() );
5560 WaitForSingleObject( info.wait, 10000 );
5562 setup_test( &info, http_open_request, __LINE__, ERROR_SUCCESS );
5563 req = HttpOpenRequestA( con, nd->method, nd->path, NULL, NULL, accept, 0, (DWORD_PTR)&info );
5564 ok( req != NULL, "HttpOpenRequest failed %u\n", GetLastError() );
5566 WaitForSingleObject( info.wait, 10000 );
5568 if(nd->data) {
5569 memset( &b, 0, sizeof(INTERNET_BUFFERSA) );
5570 b.dwStructSize = sizeof(INTERNET_BUFFERSA);
5571 b.lpcszHeader = "Content-Type: application/x-www-form-urlencoded";
5572 b.dwHeadersLength = strlen( b.lpcszHeader );
5573 b.dwBufferTotal = nd->data ? strlen( nd->data ) : 0;
5576 setup_test( &info, http_send_request_ex, __LINE__,
5577 nd->expect_conn_failure ? ERROR_INTERNET_NAME_NOT_RESOLVED : ERROR_SUCCESS );
5578 ret = HttpSendRequestExA( req, nd->data ? &b : NULL, NULL, 0x28, 0 );
5579 ok( !ret && GetLastError() == ERROR_IO_PENDING, "HttpSendRequestExA failed %d %u\n", ret, GetLastError() );
5581 error = WaitForSingleObject( info.wait, 10000 );
5582 if(error != WAIT_OBJECT_0) {
5583 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error);
5584 info.is_aborted = TRUE;
5585 goto abort;
5588 size = sizeof(buffer);
5589 SetLastError( 0xdeadbeef );
5590 ret = HttpQueryInfoA( req, HTTP_QUERY_CONTENT_ENCODING, buffer, &size, 0 );
5591 error = GetLastError();
5592 ok( !ret, "HttpQueryInfoA failed %u\n", GetLastError() );
5593 if(nd->expect_conn_failure) {
5594 ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error );
5595 }else {
5596 todo_wine
5597 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_STATE,
5598 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error );
5601 if (nd->data)
5603 written = 0;
5604 size = strlen( nd->data );
5605 setup_test( &info, internet_writefile, __LINE__, ERROR_SUCCESS );
5606 ret = InternetWriteFile( req, nd->data, size, &written );
5607 ok( ret, "InternetWriteFile failed %u\n", GetLastError() );
5608 ok( written == size, "expected %u got %u\n", written, size );
5610 WaitForSingleObject( info.wait, 10000 );
5612 SetLastError( 0xdeadbeef );
5613 ret = HttpEndRequestA( req, (void *)nd->data, 0x28, 0 );
5614 error = GetLastError();
5615 ok( !ret, "HttpEndRequestA succeeded\n" );
5616 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error );
5619 SetLastError( 0xdeadbeef );
5620 setup_test( &info, http_end_request, __LINE__,
5621 nd->expect_conn_failure ? ERROR_INTERNET_OPERATION_CANCELLED : ERROR_SUCCESS);
5622 ret = HttpEndRequestA( req, NULL, 0x28, 0 );
5623 error = GetLastError();
5624 ok( !ret, "HttpEndRequestA succeeded\n" );
5625 ok( error == ERROR_IO_PENDING, "expected ERROR_IO_PENDING got %u\n", error );
5627 WaitForSingleObject( info.wait, 10000 );
5629 setup_test( &info, internet_close_handle, __LINE__, ERROR_SUCCESS );
5630 abort:
5631 InternetCloseHandle( req );
5632 InternetCloseHandle( con );
5633 InternetCloseHandle( ses );
5635 WaitForSingleObject( info.wait, 10000 );
5636 Sleep(100);
5637 CloseHandle( info.wait );
5638 DeleteCriticalSection( &notification_cs );
5641 static HINTERNET closetest_session, closetest_req, closetest_conn;
5642 static BOOL closetest_closed;
5644 static void WINAPI closetest_callback(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus,
5645 LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
5647 DWORD len, type;
5648 BOOL res;
5650 trace("closetest_callback %p: %d\n", hInternet, dwInternetStatus);
5652 ok(hInternet == closetest_session || hInternet == closetest_conn || hInternet == closetest_req,
5653 "Unexpected hInternet %p\n", hInternet);
5654 if(!closetest_closed)
5655 return;
5657 len = sizeof(type);
5658 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_HANDLE_TYPE, &type, &len);
5659 ok(!res && GetLastError() == ERROR_INVALID_HANDLE,
5660 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5661 closetest_req, res, GetLastError());
5664 static void test_InternetCloseHandle(void)
5666 DWORD len, flags;
5667 BOOL res;
5669 closetest_session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
5670 ok(closetest_session != NULL,"InternetOpen failed with error %u\n", GetLastError());
5672 pInternetSetStatusCallbackA(closetest_session, closetest_callback);
5674 closetest_conn = InternetConnectA(closetest_session, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER,
5675 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
5676 ok(closetest_conn != NULL,"InternetConnect failed with error %u\n", GetLastError());
5678 closetest_req = HttpOpenRequestA(closetest_conn, "GET", "winegecko.php", NULL, NULL, NULL,
5679 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
5681 res = HttpSendRequestA(closetest_req, NULL, -1, NULL, 0);
5682 ok(!res && (GetLastError() == ERROR_IO_PENDING),
5683 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
5685 test_request_flags(closetest_req, INTERNET_REQFLAG_NO_HEADERS);
5687 res = InternetCloseHandle(closetest_session);
5688 ok(res, "InternetCloseHandle failed: %u\n", GetLastError());
5689 closetest_closed = TRUE;
5690 trace("Closed session handle\n");
5692 res = InternetCloseHandle(closetest_conn);
5693 ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(conn) failed: %x %u\n",
5694 res, GetLastError());
5696 res = InternetCloseHandle(closetest_req);
5697 ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(req) failed: %x %u\n",
5698 res, GetLastError());
5700 len = sizeof(flags);
5701 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &len);
5702 ok(!res && GetLastError() == ERROR_INVALID_HANDLE,
5703 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5704 closetest_req, res, GetLastError());
5707 static void test_connection_failure(void)
5709 HINTERNET session, connect, request;
5710 DWORD error;
5711 BOOL ret;
5713 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
5714 ok(session != NULL, "failed to get session handle\n");
5716 connect = InternetConnectA(session, "localhost", 1, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
5717 ok(connect != NULL, "failed to get connection handle\n");
5719 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, 0, 0);
5720 ok(request != NULL, "failed to get request handle\n");
5722 SetLastError(0xdeadbeef);
5723 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
5724 error = GetLastError();
5725 ok(!ret, "unexpected success\n");
5726 ok(error == ERROR_INTERNET_CANNOT_CONNECT, "wrong error %u\n", error);
5728 InternetCloseHandle(request);
5729 InternetCloseHandle(connect);
5730 InternetCloseHandle(session);
5733 static void test_default_service_port(void)
5735 HINTERNET session, connect, request;
5736 DWORD size, error;
5737 char buffer[128];
5738 BOOL ret;
5740 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
5741 ok(session != NULL, "InternetOpen failed\n");
5743 connect = InternetConnectA(session, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL,
5744 INTERNET_SERVICE_HTTP, 0, 0);
5745 ok(connect != NULL, "InternetConnect failed\n");
5747 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0);
5748 ok(request != NULL, "HttpOpenRequest failed\n");
5750 SetLastError(0xdeadbeef);
5751 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
5752 error = GetLastError();
5753 ok(!ret, "HttpSendRequest succeeded\n");
5754 ok(error == ERROR_INTERNET_SECURITY_CHANNEL_ERROR || error == ERROR_INTERNET_CANNOT_CONNECT,
5755 "got %u\n", error);
5757 size = sizeof(buffer);
5758 memset(buffer, 0, sizeof(buffer));
5759 ret = HttpQueryInfoA(request, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
5760 ok(ret, "HttpQueryInfo failed with error %u\n", GetLastError());
5761 ok(!strcmp(buffer, "test.winehq.org:80"), "Expected test.winehg.org:80, got '%s'\n", buffer);
5763 InternetCloseHandle(request);
5764 InternetCloseHandle(connect);
5766 connect = InternetConnectA(session, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL,
5767 INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0);
5768 ok(connect != NULL, "InternetConnect failed\n");
5770 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0);
5771 ok(request != NULL, "HttpOpenRequest failed\n");
5773 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
5774 todo_wine ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
5776 size = sizeof(buffer);
5777 memset(buffer, 0, sizeof(buffer));
5778 ret = HttpQueryInfoA(request, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
5779 ok(ret, "HttpQueryInfo failed with error %u\n", GetLastError());
5780 todo_wine ok(!strcmp(buffer, "test.winehq.org"), "Expected test.winehg.org, got '%s'\n", buffer);
5782 InternetCloseHandle(request);
5783 InternetCloseHandle(connect);
5785 connect = InternetConnectA(session, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL,
5786 INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0);
5787 ok(connect != NULL, "InternetConnect failed\n");
5789 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, 0, 0);
5790 ok(request != NULL, "HttpOpenRequest failed\n");
5792 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
5793 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
5795 size = sizeof(buffer);
5796 memset(buffer, 0, sizeof(buffer));
5797 ret = HttpQueryInfoA(request, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
5798 ok(ret, "HttpQueryInfo failed with error %u\n", GetLastError());
5799 todo_wine ok(!strcmp(buffer, "test.winehq.org:443"), "Expected test.winehg.org:443, got '%s'\n", buffer);
5801 InternetCloseHandle(request);
5802 InternetCloseHandle(connect);
5803 InternetCloseHandle(session);
5806 static void init_status_tests(void)
5808 memset(expect, 0, sizeof(expect));
5809 memset(optional, 0, sizeof(optional));
5810 memset(wine_allow, 0, sizeof(wine_allow));
5811 memset(notified, 0, sizeof(notified));
5812 memset(status_string, 0, sizeof(status_string));
5814 #define STATUS_STRING(status) status_string[status] = #status
5815 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME);
5816 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED);
5817 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER);
5818 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER);
5819 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST);
5820 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT);
5821 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE);
5822 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED);
5823 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED);
5824 STATUS_STRING(INTERNET_STATUS_PREFETCH);
5825 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION);
5826 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED);
5827 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED);
5828 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING);
5829 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY);
5830 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE);
5831 STATUS_STRING(INTERNET_STATUS_REDIRECT);
5832 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE);
5833 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED);
5834 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE);
5835 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT);
5836 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED);
5837 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED);
5838 STATUS_STRING(INTERNET_STATUS_P3P_HEADER);
5839 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF);
5840 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY);
5841 #undef STATUS_STRING
5844 static void WINAPI header_cb( HINTERNET handle, DWORD_PTR ctx, DWORD status, LPVOID info, DWORD len )
5846 BOOL ret;
5847 DWORD index, size;
5848 char buf[256];
5850 if (status == INTERNET_STATUS_SENDING_REQUEST)
5852 ret = HttpAddRequestHeadersA( handle, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD );
5853 ok( ret, "HttpAddRequestHeadersA failed %u\n", GetLastError() );
5854 SetEvent( (HANDLE)ctx );
5856 else if (status == INTERNET_STATUS_REQUEST_SENT)
5858 index = 0;
5859 size = sizeof(buf);
5860 ret = HttpQueryInfoA( handle, HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
5861 buf, &size, &index );
5862 ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() );
5863 ok( strstr( buf, "winetest: winetest" ) != NULL, "header missing\n" );
5864 SetEvent( (HANDLE)ctx );
5868 static void test_concurrent_header_access(void)
5870 HINTERNET ses, con, req;
5871 DWORD err;
5872 BOOL ret;
5873 HANDLE wait = CreateEventW( NULL, FALSE, FALSE, NULL );
5875 ses = InternetOpenA( "winetest", 0, NULL, NULL, INTERNET_FLAG_ASYNC );
5876 ok( ses != NULL, "InternetOpenA failed\n" );
5878 con = InternetConnectA( ses, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
5879 INTERNET_SERVICE_HTTP, 0, 0 );
5880 ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
5882 req = HttpOpenRequestA( con, NULL, "/", NULL, NULL, NULL, 0, (DWORD_PTR)wait );
5883 ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
5885 pInternetSetStatusCallbackA( req, header_cb );
5887 SetLastError( 0xdeadbeef );
5888 ret = HttpSendRequestA( req, NULL, 0, NULL, 0 );
5889 err = GetLastError();
5890 ok( !ret, "HttpSendRequestA succeeded\n" );
5891 ok( err == ERROR_IO_PENDING, "got %u\n", ERROR_IO_PENDING );
5893 WaitForSingleObject( wait, 5000 );
5894 WaitForSingleObject( wait, 5000 );
5896 InternetCloseHandle( req );
5897 InternetCloseHandle( con );
5898 InternetCloseHandle( ses );
5899 CloseHandle( wait );
5902 START_TEST(http)
5904 HMODULE hdll;
5905 hdll = GetModuleHandleA("wininet.dll");
5907 if(!GetProcAddress(hdll, "InternetGetCookieExW")) {
5908 win_skip("Too old IE (older than 6.0)\n");
5909 return;
5912 pInternetSetStatusCallbackA = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackA");
5913 pInternetSetStatusCallbackW = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackW");
5914 pInternetGetSecurityInfoByURLA = (void*)GetProcAddress(hdll, "InternetGetSecurityInfoByURLA");
5916 init_status_tests();
5917 test_InternetCloseHandle();
5918 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[0]);
5919 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[1]);
5920 InternetReadFile_test(0, &test_data[1]);
5921 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[2]);
5922 test_security_flags();
5923 InternetReadFile_test(0, &test_data[2]);
5924 InternetReadFileExA_test(INTERNET_FLAG_ASYNC);
5925 test_open_url_async();
5926 test_async_HttpSendRequestEx(&notification_data[0]);
5927 test_async_HttpSendRequestEx(&notification_data[1]);
5928 test_async_HttpSendRequestEx(&notification_data[2]);
5929 test_async_HttpSendRequestEx(&notification_data[3]);
5930 InternetOpenRequest_test();
5931 test_http_cache();
5932 InternetLockRequestFile_test();
5933 InternetOpenUrlA_test();
5934 HttpHeaders_test();
5935 test_http_connection();
5936 test_secure_connection();
5937 test_user_agent_header();
5938 test_bogus_accept_types_array();
5939 InternetReadFile_chunked_test();
5940 HttpSendRequestEx_test();
5941 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[3]);
5942 test_connection_failure();
5943 test_default_service_port();
5944 test_concurrent_header_access();