wininet: Protect the request headers array with a critical section.
[wine.git] / dlls / wininet / tests / http.c
blobca5f4affdf53cd9b26246142e1a0658226cf87ad
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 if (is_todo)
211 todo_wine ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
212 else
213 ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
214 ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
216 code = 0xdeadbeef;
217 index = 0;
218 size = sizeof(code);
219 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index);
220 ok_(__FILE__,line)(res, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
221 if (is_todo)
222 todo_wine ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
223 else
224 ok_(__FILE__,line)(!index, "index = %d, expected 0\n", code);
225 ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
227 sprintf(exbuf, "%u", excode);
229 size = sizeof(bufa);
230 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, bufa, &size, NULL);
231 ok_(__FILE__,line)(res, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
232 if (is_todo)
233 todo_wine ok_(__FILE__,line)(!strcmp(bufa, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
234 else
235 ok_(__FILE__,line)(!strcmp(bufa, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
236 ok_(__FILE__,line)(size == strlen(exbuf), "unexpected size %d for \"%s\"\n", size, exbuf);
238 size = 0;
239 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, NULL, &size, NULL);
240 ok_(__FILE__,line)(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
241 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
242 ok_(__FILE__,line)(size == strlen(exbuf)+1, "unexpected size %d for \"%s\"\n", size, exbuf);
244 size = sizeof(bufw);
245 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL);
246 ok_(__FILE__,line)(res, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
247 if (is_todo)
248 todo_wine ok_(__FILE__,line)(!strcmp_wa(bufw, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
249 else
250 ok_(__FILE__,line)(!strcmp_wa(bufw, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
251 ok_(__FILE__,line)(size == strlen(exbuf)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
253 size = 0;
254 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL);
255 ok_(__FILE__,line)(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
256 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
257 ok_(__FILE__,line)(size == (strlen(exbuf)+1)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
259 if(0) {
260 size = sizeof(bufw);
261 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, NULL, &size, NULL);
262 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
263 ok(size == sizeof(bufw), "unexpected size %d\n", size);
266 code = 0xdeadbeef;
267 index = 1;
268 size = sizeof(code);
269 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index);
270 ok_(__FILE__,line)(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
271 "[7] HttpQueryInfoA failed: %x(%d)\n", res, GetLastError());
273 code = 0xdeadbeef;
274 size = sizeof(code);
275 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_REQUEST_HEADERS, &code, &size, NULL);
276 ok_(__FILE__,line)(!res && GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST,
277 "[8] HttpQueryInfoA failed: %x(%d)\n", res, GetLastError());
280 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
281 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
282 static void _test_request_flags(unsigned line, HINTERNET req, DWORD exflags, BOOL is_todo)
284 DWORD flags, size;
285 BOOL res;
287 flags = 0xdeadbeef;
288 size = sizeof(flags);
289 res = InternetQueryOptionW(req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &size);
290 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
292 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
293 flags &= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED;
294 if(!is_todo)
295 ok_(__FILE__,line)(flags == exflags, "flags = %x, expected %x\n", flags, exflags);
296 else
297 todo_wine ok_(__FILE__,line)(flags == exflags, "flags = %x, expected %x\n", flags, exflags);
300 #define test_http_version(a) _test_http_version(__LINE__,a)
301 static void _test_http_version(unsigned line, HINTERNET req)
303 HTTP_VERSION_INFO v = {0xdeadbeef, 0xdeadbeef};
304 DWORD size;
305 BOOL res;
307 size = sizeof(v);
308 res = InternetQueryOptionW(req, INTERNET_OPTION_HTTP_VERSION, &v, &size);
309 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
310 ok_(__FILE__,line)(v.dwMajorVersion == 1, "dwMajorVersion = %d\n", v.dwMajorVersion);
311 ok_(__FILE__,line)(v.dwMinorVersion == 1, "dwMinorVersion = %d\n", v.dwMinorVersion);
314 static int close_handle_cnt;
316 static VOID WINAPI callback(
317 HINTERNET hInternet,
318 DWORD_PTR dwContext,
319 DWORD dwInternetStatus,
320 LPVOID lpvStatusInformation,
321 DWORD dwStatusInformationLength
324 CHECK_EXPECT(dwInternetStatus);
325 switch (dwInternetStatus)
327 case INTERNET_STATUS_RESOLVING_NAME:
328 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
329 GetCurrentThreadId(), hInternet, dwContext,
330 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
331 *(LPSTR)lpvStatusInformation = '\0';
332 break;
333 case INTERNET_STATUS_NAME_RESOLVED:
334 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
335 GetCurrentThreadId(), hInternet, dwContext,
336 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
337 *(LPSTR)lpvStatusInformation = '\0';
338 break;
339 case INTERNET_STATUS_CONNECTING_TO_SERVER:
340 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
341 GetCurrentThreadId(), hInternet, dwContext,
342 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
343 ok(dwStatusInformationLength == strlen(lpvStatusInformation)+1, "unexpected size %u\n",
344 dwStatusInformationLength);
345 *(LPSTR)lpvStatusInformation = '\0';
346 break;
347 case INTERNET_STATUS_CONNECTED_TO_SERVER:
348 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
349 GetCurrentThreadId(), hInternet, dwContext,
350 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
351 ok(dwStatusInformationLength == strlen(lpvStatusInformation)+1, "unexpected size %u\n",
352 dwStatusInformationLength);
353 *(LPSTR)lpvStatusInformation = '\0';
354 break;
355 case INTERNET_STATUS_SENDING_REQUEST:
356 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
357 GetCurrentThreadId(), hInternet, dwContext,
358 lpvStatusInformation,dwStatusInformationLength);
359 break;
360 case INTERNET_STATUS_REQUEST_SENT:
361 ok(dwStatusInformationLength == sizeof(DWORD),
362 "info length should be sizeof(DWORD) instead of %d\n",
363 dwStatusInformationLength);
364 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
365 GetCurrentThreadId(), hInternet, dwContext,
366 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
367 break;
368 case INTERNET_STATUS_RECEIVING_RESPONSE:
369 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
370 GetCurrentThreadId(), hInternet, dwContext,
371 lpvStatusInformation,dwStatusInformationLength);
372 break;
373 case INTERNET_STATUS_RESPONSE_RECEIVED:
374 ok(dwStatusInformationLength == sizeof(DWORD),
375 "info length should be sizeof(DWORD) instead of %d\n",
376 dwStatusInformationLength);
377 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
378 GetCurrentThreadId(), hInternet, dwContext,
379 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
380 break;
381 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
382 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
383 GetCurrentThreadId(), hInternet,dwContext,
384 lpvStatusInformation,dwStatusInformationLength);
385 break;
386 case INTERNET_STATUS_PREFETCH:
387 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
388 GetCurrentThreadId(), hInternet, dwContext,
389 lpvStatusInformation,dwStatusInformationLength);
390 break;
391 case INTERNET_STATUS_CLOSING_CONNECTION:
392 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
393 GetCurrentThreadId(), hInternet, dwContext,
394 lpvStatusInformation,dwStatusInformationLength);
395 break;
396 case INTERNET_STATUS_CONNECTION_CLOSED:
397 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
398 GetCurrentThreadId(), hInternet, dwContext,
399 lpvStatusInformation,dwStatusInformationLength);
400 break;
401 case INTERNET_STATUS_HANDLE_CREATED:
402 ok(dwStatusInformationLength == sizeof(HINTERNET),
403 "info length should be sizeof(HINTERNET) instead of %d\n",
404 dwStatusInformationLength);
405 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
406 GetCurrentThreadId(), hInternet, dwContext,
407 *(HINTERNET *)lpvStatusInformation,dwStatusInformationLength);
408 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
409 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
410 break;
411 case INTERNET_STATUS_HANDLE_CLOSING:
412 ok(dwStatusInformationLength == sizeof(HINTERNET),
413 "info length should be sizeof(HINTERNET) instead of %d\n",
414 dwStatusInformationLength);
415 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
416 GetCurrentThreadId(), hInternet, dwContext,
417 *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength);
418 if(!InterlockedDecrement(&close_handle_cnt))
419 SetEvent(hCompleteEvent);
420 break;
421 case INTERNET_STATUS_REQUEST_COMPLETE:
423 INTERNET_ASYNC_RESULT *iar = (INTERNET_ASYNC_RESULT *)lpvStatusInformation;
424 ok(dwStatusInformationLength == sizeof(INTERNET_ASYNC_RESULT),
425 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
426 dwStatusInformationLength);
427 ok(iar->dwResult == 1 || iar->dwResult == 0, "iar->dwResult = %ld\n", iar->dwResult);
428 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
429 GetCurrentThreadId(), hInternet, dwContext,
430 iar->dwResult,iar->dwError,dwStatusInformationLength);
431 req_error = iar->dwError;
432 if(!close_handle_cnt)
433 SetEvent(hCompleteEvent);
434 break;
436 case INTERNET_STATUS_REDIRECT:
437 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
438 GetCurrentThreadId(), hInternet, dwContext,
439 (LPCSTR)lpvStatusInformation, dwStatusInformationLength);
440 *(LPSTR)lpvStatusInformation = '\0';
441 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
442 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
443 break;
444 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
445 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
446 GetCurrentThreadId(), hInternet, dwContext,
447 lpvStatusInformation, dwStatusInformationLength);
448 break;
449 default:
450 trace("%04x:Callback %p 0x%lx %d %p %d\n",
451 GetCurrentThreadId(), hInternet, dwContext, dwInternetStatus,
452 lpvStatusInformation, dwStatusInformationLength);
456 static void close_async_handle(HINTERNET handle, HANDLE complete_event, int handle_cnt)
458 BOOL res;
460 close_handle_cnt = handle_cnt;
462 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
463 res = InternetCloseHandle(handle);
464 ok(res, "InternetCloseHandle failed: %u\n", GetLastError());
465 WaitForSingleObject(hCompleteEvent, INFINITE);
466 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
469 static void InternetReadFile_test(int flags, const test_data_t *test)
471 char *post_data = NULL;
472 BOOL res, on_async = TRUE;
473 CHAR buffer[4000];
474 WCHAR wbuffer[4000];
475 DWORD length, length2, index, exlen = 0, post_len = 0;
476 const char *types[2] = { "*", NULL };
477 HINTERNET hi, hic = 0, hor = 0;
479 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
481 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags,test->url);
483 trace("InternetOpenA <--\n");
484 hi = InternetOpenA((test->flags & TESTF_COMPRESSED) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
485 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
486 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
487 trace("InternetOpenA -->\n");
489 if (hi == 0x0) goto abort;
491 pInternetSetStatusCallbackA(hi,&callback);
493 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
495 trace("InternetConnectA <--\n");
496 hic=InternetConnectA(hi, test->host, INTERNET_INVALID_PORT_NUMBER,
497 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
498 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
499 trace("InternetConnectA -->\n");
501 if (hic == 0x0) goto abort;
503 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
504 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
506 trace("HttpOpenRequestA <--\n");
507 hor = HttpOpenRequestA(hic, test->post_data ? "POST" : "GET", test->path, NULL, NULL, types,
508 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
509 0xdeadbead);
510 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
512 * If the internet name can't be resolved we are probably behind
513 * a firewall or in some other way not directly connected to the
514 * Internet. Not enough reason to fail the test. Just ignore and
515 * abort.
517 } else {
518 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
520 trace("HttpOpenRequestA -->\n");
522 if (hor == 0x0) goto abort;
524 test_request_flags(hor, INTERNET_REQFLAG_NO_HEADERS);
526 length = sizeof(buffer);
527 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
528 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
529 ok(!strcmp(buffer, test->url), "Wrong URL %s, expected %s\n", buffer, test->url);
531 length = sizeof(buffer);
532 res = HttpQueryInfoA(hor, HTTP_QUERY_RAW_HEADERS, buffer, &length, 0x0);
533 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
534 ok(length == 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length);
535 ok(!strcmp(buffer, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer);
537 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
538 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
539 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
540 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT,2);
541 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED,2);
542 if (first_connection_to_test_url)
544 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
545 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
547 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
548 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
549 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, (test->flags & TESTF_REDIRECT) ? 2 : 1);
550 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, (test->flags & TESTF_REDIRECT) ? 2 : 1);
551 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, (test->flags & TESTF_REDIRECT) ? 2 : 1);
552 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, (test->flags & TESTF_REDIRECT) ? 2 : 1);
553 if(test->flags & TESTF_REDIRECT) {
554 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
555 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
557 SET_EXPECT(INTERNET_STATUS_REDIRECT);
558 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER);
559 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER);
560 if (flags & INTERNET_FLAG_ASYNC)
561 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
563 if(test->flags & TESTF_COMPRESSED) {
564 BOOL b = TRUE;
566 res = InternetSetOptionA(hor, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b));
567 ok(res || broken(!res && GetLastError() == ERROR_INTERNET_INVALID_OPTION),
568 "InternetSetOption failed: %u\n", GetLastError());
569 if(!res)
570 goto abort;
573 test_status_code(hor, 0);
575 trace("HttpSendRequestA -->\n");
576 if(test->post_data) {
577 post_len = strlen(test->post_data);
578 post_data = HeapAlloc(GetProcessHeap(), 0, post_len);
579 memcpy(post_data, test->post_data, post_len);
581 SetLastError(0xdeadbeef);
582 res = HttpSendRequestA(hor, test->headers, -1, post_data, post_len);
583 if (flags & INTERNET_FLAG_ASYNC)
584 ok(!res && (GetLastError() == ERROR_IO_PENDING),
585 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
586 else
587 ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED),
588 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
589 trace("HttpSendRequestA <--\n");
591 if (flags & INTERNET_FLAG_ASYNC) {
592 WaitForSingleObject(hCompleteEvent, INFINITE);
593 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
595 HeapFree(GetProcessHeap(), 0, post_data);
597 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
598 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED);
599 if (first_connection_to_test_url)
601 if (! proxy_active())
603 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
604 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
606 else
608 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
609 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
612 else
614 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
615 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
617 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, (test->flags & TESTF_REDIRECT) ? 2 : 1);
618 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, (test->flags & TESTF_REDIRECT) ? 2 : 1);
619 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, (test->flags & TESTF_REDIRECT) ? 2 : 1);
620 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, (test->flags & TESTF_REDIRECT) ? 2 : 1);
621 if(test->flags & TESTF_REDIRECT)
622 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
623 if (flags & INTERNET_FLAG_ASYNC)
624 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
625 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
626 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
627 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
629 test_request_flags(hor, 0);
631 length = 100;
632 res = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
633 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
635 length = sizeof(buffer)-1;
636 memset(buffer, 0x77, sizeof(buffer));
637 res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0);
638 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
639 /* show that the function writes data past the length returned */
640 ok(buffer[length-2], "Expected any header character, got 0x00\n");
641 ok(!buffer[length-1], "Expected 0x00, got %02X\n", buffer[length-1]);
642 ok(!buffer[length], "Expected 0x00, got %02X\n", buffer[length]);
643 ok(buffer[length+1] == 0x77, "Expected 0x77, got %02X\n", buffer[length+1]);
645 length2 = length;
646 res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length2,0x0);
647 ok(!res, "Expected 0x00, got %d\n", res);
648 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
649 ok(length2 == length+1, "Expected %d, got %d\n", length+1, length2);
650 /* the in length of the buffer must be +1 but the length returned does not count this */
651 length2 = length+1;
652 memset(buffer, 0x77, sizeof(buffer));
653 res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length2,0x0);
654 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
655 ok(buffer[length2] == 0x00, "Expected 0x00, got %02X\n", buffer[length2]);
656 ok(buffer[length2+1] == 0x77, "Expected 0x77, got %02X\n", buffer[length2+1]);
657 ok(length2 == length, "Value should not have changed: %d != %d\n", length2, length);
659 length = sizeof(wbuffer)-sizeof(WCHAR);
660 memset(wbuffer, 0x77, sizeof(wbuffer));
661 res = HttpQueryInfoW(hor, HTTP_QUERY_RAW_HEADERS, wbuffer, &length, 0x0);
662 ok(res, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
663 ok(length % sizeof(WCHAR) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length);
664 length /= sizeof(WCHAR);
665 /* show that the function writes data past the length returned */
666 ok(wbuffer[length-2], "Expected any header character, got 0x0000\n");
667 ok(!wbuffer[length-1], "Expected 0x0000, got %04X\n", wbuffer[length-1]);
668 ok(!wbuffer[length], "Expected 0x0000, got %04X\n", wbuffer[length]);
669 ok(wbuffer[length+1] == 0x7777 || broken(wbuffer[length+1] != 0x7777),
670 "Expected 0x7777, got %04X\n", wbuffer[length+1]);
672 length2 = length*sizeof(WCHAR);
673 res = HttpQueryInfoW(hor,HTTP_QUERY_RAW_HEADERS,wbuffer,&length2,0x0);
674 ok(!res, "Expected 0x00, got %d\n", res);
675 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
676 ok(length2 % sizeof(WCHAR) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2);
677 length2 /= sizeof(WCHAR);
678 ok(length2 == length+1, "Expected %d, got %d\n", length+1, length2);
679 /* the in length of the buffer must be +1 but the length returned does not count this */
680 length2 = (length+1)*sizeof(WCHAR);
681 memset(wbuffer, 0x77, sizeof(wbuffer));
682 res = HttpQueryInfoW(hor,HTTP_QUERY_RAW_HEADERS,wbuffer,&length2,0x0);
683 ok(res, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
684 ok(length2 % sizeof(WCHAR) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2);
685 length2 /= sizeof(WCHAR);
686 ok(!wbuffer[length2], "Expected 0x0000, got %04X\n", wbuffer[length2]);
687 ok(wbuffer[length2+1] == 0x7777, "Expected 0x7777, got %04X\n", wbuffer[length2+1]);
688 ok(length2 == length, "Value should not have changed: %d != %d\n", length2, length);
690 length = sizeof(buffer);
691 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
692 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
693 ok(!strcmp(buffer, test->redirected_url), "Wrong URL %s\n", buffer);
695 index = 0;
696 length = 0;
697 SetLastError(0xdeadbeef);
698 ok(HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,NULL,&length,&index) == FALSE,"Query worked\n");
699 if(test->flags & TESTF_COMPRESSED)
700 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
701 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
702 ok(index == 0, "Index was incremented\n");
704 index = 0;
705 length = 16;
706 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,&index);
707 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res,buffer,GetLastError());
708 if(test->flags & TESTF_COMPRESSED)
709 ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
710 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res, GetLastError());
711 ok(!res || index == 1, "Index was not incremented although result is %x (index = %u)\n", res, index);
713 length = 100;
714 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
715 buffer[length]=0;
716 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res,buffer);
718 length = 100;
719 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_ENCODING,buffer,&length,0x0);
720 buffer[length]=0;
721 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res,buffer);
723 SetLastError(0xdeadbeef);
724 res = InternetReadFile(NULL, buffer, 100, &length);
725 ok(!res, "InternetReadFile should have failed\n");
726 ok(GetLastError() == ERROR_INVALID_HANDLE,
727 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
728 GetLastError());
730 length = 100;
731 trace("Entering Query loop\n");
733 while (TRUE)
735 if (flags & INTERNET_FLAG_ASYNC)
736 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
738 /* IE11 calls those in InternetQueryDataAvailable call. */
739 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE);
740 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED);
742 length = 0;
743 res = InternetQueryDataAvailable(hor,&length,0x0,0x0);
745 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
747 if (flags & INTERNET_FLAG_ASYNC)
749 if (res)
751 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
752 if(exlen) {
753 ok(length >= exlen, "length %u < exlen %u\n", length, exlen);
754 exlen = 0;
757 else if (GetLastError() == ERROR_IO_PENDING)
759 trace("PENDING\n");
760 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
761 if(!(test->flags & TESTF_CHUNKED))
762 ok(!length, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length);
763 WaitForSingleObject(hCompleteEvent, INFINITE);
764 exlen = length;
765 ok(exlen, "length = 0\n");
766 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
767 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
768 ok(req_error, "req_error = 0\n");
769 continue;
770 }else {
771 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
773 }else {
774 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
776 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
778 trace("LENGTH %d\n", length);
779 if(test->flags & TESTF_CHUNKED)
780 ok(length <= 8192, "length = %d, expected <= 8192\n", length);
781 if (length)
783 char *buffer;
784 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
786 res = InternetReadFile(hor,buffer,length,&length);
788 buffer[length]=0;
790 trace("ReadFile -> %s %i\n",res?"TRUE":"FALSE",length);
792 if(test->content)
793 ok(!strcmp(buffer, test->content), "buffer = '%s', expected '%s'\n", buffer, test->content);
794 HeapFree(GetProcessHeap(),0,buffer);
795 }else {
796 ok(!on_async, "Returned zero size in response to request complete\n");
797 break;
799 on_async = FALSE;
801 if(test->flags & TESTF_REDIRECT) {
802 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
803 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
805 abort:
806 trace("aborting\n");
807 close_async_handle(hi, hCompleteEvent, 2);
808 CloseHandle(hCompleteEvent);
809 first_connection_to_test_url = FALSE;
812 static void InternetReadFile_chunked_test(void)
814 BOOL res;
815 CHAR buffer[4000];
816 DWORD length, got;
817 const char *types[2] = { "*", NULL };
818 HINTERNET hi, hic = 0, hor = 0;
820 trace("Starting InternetReadFile chunked test\n");
822 trace("InternetOpenA <--\n");
823 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
824 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
825 trace("InternetOpenA -->\n");
827 if (hi == 0x0) goto abort;
829 trace("InternetConnectA <--\n");
830 hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER,
831 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
832 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
833 trace("InternetConnectA -->\n");
835 if (hic == 0x0) goto abort;
837 trace("HttpOpenRequestA <--\n");
838 hor = HttpOpenRequestA(hic, "GET", "/tests/chunked", NULL, NULL, types,
839 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
840 0xdeadbead);
841 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
843 * If the internet name can't be resolved we are probably behind
844 * a firewall or in some other way not directly connected to the
845 * Internet. Not enough reason to fail the test. Just ignore and
846 * abort.
848 } else {
849 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
851 trace("HttpOpenRequestA -->\n");
853 if (hor == 0x0) goto abort;
855 trace("HttpSendRequestA -->\n");
856 SetLastError(0xdeadbeef);
857 res = HttpSendRequestA(hor, "", -1, NULL, 0);
858 ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED),
859 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
860 trace("HttpSendRequestA <--\n");
862 test_request_flags(hor, 0);
864 length = 100;
865 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
866 buffer[length]=0;
867 trace("Option CONTENT_TYPE -> %i %s\n",res,buffer);
869 SetLastError( 0xdeadbeef );
870 length = 100;
871 res = HttpQueryInfoA(hor,HTTP_QUERY_TRANSFER_ENCODING,buffer,&length,0x0);
872 buffer[length]=0;
873 trace("Option TRANSFER_ENCODING -> %i %s\n",res,buffer);
874 ok( res || ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND ),
875 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
876 ok( !strcmp( buffer, "chunked" ) || ( ! res && proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND ),
877 "Wrong transfer encoding '%s'\n", buffer );
879 SetLastError( 0xdeadbeef );
880 length = 16;
881 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
882 ok( !res, "Found CONTENT_LENGTH option '%s'\n", buffer );
883 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "Wrong error %u\n", GetLastError() );
885 length = 100;
886 trace("Entering Query loop\n");
888 while (TRUE)
890 res = InternetQueryDataAvailable(hor,&length,0x0,0x0);
891 ok(!(!res && length != 0),"InternetQueryDataAvailable failed with non-zero length\n");
892 ok(res, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
893 trace("got %u available\n",length);
894 if (length)
896 char *buffer = HeapAlloc(GetProcessHeap(),0,length+1);
898 res = InternetReadFile(hor,buffer,length,&got);
900 buffer[got]=0;
901 trace("ReadFile -> %i %i\n",res,got);
902 ok( length == got, "only got %u of %u available\n", got, length );
903 ok( buffer[got-1] == '\n', "received partial line '%s'\n", buffer );
905 HeapFree(GetProcessHeap(),0,buffer);
906 if (!got) break;
908 if (length == 0)
910 got = 0xdeadbeef;
911 res = InternetReadFile( hor, buffer, 1, &got );
912 ok( res, "InternetReadFile failed: %u\n", GetLastError() );
913 ok( !got, "got %u\n", got );
914 break;
917 abort:
918 trace("aborting\n");
919 if (hor != 0x0) {
920 res = InternetCloseHandle(hor);
921 ok (res, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
923 if (hi != 0x0) {
924 res = InternetCloseHandle(hi);
925 ok (res, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
929 static void InternetReadFileExA_test(int flags)
931 DWORD rc;
932 DWORD length;
933 const char *types[2] = { "*", NULL };
934 HINTERNET hi, hic = 0, hor = 0;
935 INTERNET_BUFFERSA inetbuffers;
937 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
939 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags);
941 trace("InternetOpenA <--\n");
942 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
943 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
944 trace("InternetOpenA -->\n");
946 if (hi == 0x0) goto abort;
948 pInternetSetStatusCallbackA(hi,&callback);
950 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
952 trace("InternetConnectA <--\n");
953 hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER,
954 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
955 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
956 trace("InternetConnectA -->\n");
958 if (hic == 0x0) goto abort;
960 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
961 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
963 trace("HttpOpenRequestA <--\n");
964 hor = HttpOpenRequestA(hic, "GET", "/tests/redirect", NULL, NULL, types,
965 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
966 0xdeadbead);
967 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
969 * If the internet name can't be resolved we are probably behind
970 * a firewall or in some other way not directly connected to the
971 * Internet. Not enough reason to fail the test. Just ignore and
972 * abort.
974 } else {
975 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
977 trace("HttpOpenRequestA -->\n");
979 if (hor == 0x0) goto abort;
981 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
982 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
983 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
984 if (first_connection_to_test_url)
986 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
987 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
989 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT, 2);
990 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
991 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
992 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, 2);
993 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, 2);
994 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
995 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
996 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
997 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
998 SET_EXPECT(INTERNET_STATUS_REDIRECT);
999 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER);
1000 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER);
1001 if (flags & INTERNET_FLAG_ASYNC)
1002 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
1003 else
1004 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
1006 trace("HttpSendRequestA -->\n");
1007 SetLastError(0xdeadbeef);
1008 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
1009 if (flags & INTERNET_FLAG_ASYNC)
1010 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
1011 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
1012 else
1013 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
1014 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
1015 trace("HttpSendRequestA <--\n");
1017 if (!rc && (GetLastError() == ERROR_IO_PENDING)) {
1018 WaitForSingleObject(hCompleteEvent, INFINITE);
1019 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
1022 if (first_connection_to_test_url)
1024 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
1025 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
1027 else
1029 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
1030 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
1032 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, 2);
1033 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, 2);
1034 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
1035 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
1036 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
1037 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
1038 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
1039 if (flags & INTERNET_FLAG_ASYNC)
1040 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1041 else
1042 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1043 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
1044 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
1045 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
1046 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
1048 /* tests invalid dwStructSize */
1049 inetbuffers.dwStructSize = sizeof(inetbuffers)+1;
1050 inetbuffers.lpcszHeader = NULL;
1051 inetbuffers.dwHeadersLength = 0;
1052 inetbuffers.dwBufferLength = 10;
1053 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10);
1054 inetbuffers.dwOffsetHigh = 1234;
1055 inetbuffers.dwOffsetLow = 5678;
1056 rc = InternetReadFileExA(hor, &inetbuffers, 0, 0xdeadcafe);
1057 ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
1058 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1059 rc ? "TRUE" : "FALSE", GetLastError());
1060 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
1062 test_request_flags(hor, 0);
1064 /* tests to see whether lpcszHeader is used - it isn't */
1065 inetbuffers.dwStructSize = sizeof(inetbuffers);
1066 inetbuffers.lpcszHeader = (LPCSTR)0xdeadbeef;
1067 inetbuffers.dwHeadersLength = 255;
1068 inetbuffers.dwBufferLength = 0;
1069 inetbuffers.lpvBuffer = NULL;
1070 inetbuffers.dwOffsetHigh = 1234;
1071 inetbuffers.dwOffsetLow = 5678;
1072 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
1073 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
1074 rc = InternetReadFileExA(hor, &inetbuffers, 0, 0xdeadcafe);
1075 ok(rc, "InternetReadFileEx failed with error %u\n", GetLastError());
1076 trace("read %i bytes\n", inetbuffers.dwBufferLength);
1077 todo_wine
1079 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1080 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1083 rc = InternetReadFileExA(NULL, &inetbuffers, 0, 0xdeadcafe);
1084 ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE),
1085 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1086 rc ? "TRUE" : "FALSE", GetLastError());
1088 length = 0;
1089 trace("Entering Query loop\n");
1091 while (TRUE)
1093 inetbuffers.dwStructSize = sizeof(inetbuffers);
1094 inetbuffers.dwBufferLength = 1024;
1095 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1);
1096 inetbuffers.dwOffsetHigh = 1234;
1097 inetbuffers.dwOffsetLow = 5678;
1099 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE);
1100 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED);
1101 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
1102 rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe);
1103 if (!rc)
1105 if (GetLastError() == ERROR_IO_PENDING)
1107 trace("InternetReadFileEx -> PENDING\n");
1108 ok(flags & INTERNET_FLAG_ASYNC,
1109 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1110 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1111 WaitForSingleObject(hCompleteEvent, INFINITE);
1112 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1113 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1114 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
1116 else
1118 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1119 break;
1122 else
1124 trace("InternetReadFileEx -> SUCCEEDED\n");
1125 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1126 if (inetbuffers.dwBufferLength)
1128 todo_wine {
1129 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1130 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1133 else
1135 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1136 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1137 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1141 trace("read %i bytes\n", inetbuffers.dwBufferLength);
1142 ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
1144 ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678,
1145 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1146 inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
1148 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
1150 if (!inetbuffers.dwBufferLength)
1151 break;
1153 length += inetbuffers.dwBufferLength;
1155 ok(length > 0, "failed to read any of the document\n");
1156 trace("Finished. Read %d bytes\n", length);
1158 abort:
1159 close_async_handle(hi, hCompleteEvent, 2);
1160 CloseHandle(hCompleteEvent);
1161 first_connection_to_test_url = FALSE;
1164 static void InternetOpenUrlA_test(void)
1166 HINTERNET myhinternet, myhttp;
1167 char buffer[0x400];
1168 DWORD size, readbytes, totalbytes=0;
1169 BOOL ret;
1171 ret = DeleteUrlCacheEntryA(TEST_URL);
1172 ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND,
1173 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret, GetLastError());
1175 myhinternet = InternetOpenA("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
1176 ok((myhinternet != 0), "InternetOpen failed, error %u\n",GetLastError());
1177 size = 0x400;
1178 ret = InternetCanonicalizeUrlA(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
1179 ok( ret, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1181 SetLastError(0);
1182 myhttp = InternetOpenUrlA(myhinternet, TEST_URL, 0, 0,
1183 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
1184 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1185 return; /* WinXP returns this when not connected to the net */
1186 ok((myhttp != 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1187 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
1188 ok( ret, "InternetReadFile failed, error %u\n",GetLastError());
1189 totalbytes += readbytes;
1190 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
1191 totalbytes += readbytes;
1192 trace("read 0x%08x bytes\n",totalbytes);
1194 InternetCloseHandle(myhttp);
1195 InternetCloseHandle(myhinternet);
1197 ret = DeleteUrlCacheEntryA(TEST_URL);
1198 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1201 static void HttpSendRequestEx_test(void)
1203 HINTERNET hSession;
1204 HINTERNET hConnect;
1205 HINTERNET hRequest;
1207 INTERNET_BUFFERSA BufferIn;
1208 DWORD dwBytesWritten, dwBytesRead, error;
1209 CHAR szBuffer[256];
1210 int i;
1211 BOOL ret;
1213 static char szPostData[] = "mode=Test";
1214 static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
1216 hSession = InternetOpenA("Wine Regression Test",
1217 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1218 ok( hSession != NULL ,"Unable to open Internet session\n");
1219 hConnect = InternetConnectA(hSession, "test.winehq.org",
1220 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1222 ok( hConnect != NULL, "Unable to connect to http://test.winehq.org\n");
1223 hRequest = HttpOpenRequestA(hConnect, "POST", "/tests/post.php",
1224 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1225 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1227 skip( "Network unreachable, skipping test\n" );
1228 goto done;
1230 ok( hRequest != NULL, "Failed to open request handle err %u\n", GetLastError());
1232 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1234 BufferIn.dwStructSize = sizeof(BufferIn);
1235 BufferIn.Next = (INTERNET_BUFFERSA*)0xdeadcab;
1236 BufferIn.lpcszHeader = szContentType;
1237 BufferIn.dwHeadersLength = sizeof(szContentType)-1;
1238 BufferIn.dwHeadersTotal = sizeof(szContentType)-1;
1239 BufferIn.lpvBuffer = szPostData;
1240 BufferIn.dwBufferLength = 3;
1241 BufferIn.dwBufferTotal = sizeof(szPostData)-1;
1242 BufferIn.dwOffsetLow = 0;
1243 BufferIn.dwOffsetHigh = 0;
1245 SetLastError(0xdeadbeef);
1246 ret = HttpSendRequestExA(hRequest, &BufferIn, NULL, 0 ,0);
1247 error = GetLastError();
1248 ok(ret, "HttpSendRequestEx Failed with error %u\n", error);
1249 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", error);
1251 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1253 for (i = 3; szPostData[i]; i++)
1254 ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten),
1255 "InternetWriteFile failed\n");
1257 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1259 ok(HttpEndRequestA(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
1261 test_request_flags(hRequest, 0);
1263 ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead),
1264 "Unable to read response\n");
1265 szBuffer[dwBytesRead] = 0;
1267 ok(dwBytesRead == 13,"Read %u bytes instead of 13\n",dwBytesRead);
1268 ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0 || broken(proxy_active()),"Got string %s\n",szBuffer);
1270 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1271 done:
1272 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1273 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1276 static void InternetOpenRequest_test(void)
1278 HINTERNET session, connect, request;
1279 static const char *types[] = { "*", "", NULL };
1280 static const WCHAR slash[] = {'/', 0}, any[] = {'*', 0}, empty[] = {0};
1281 static const WCHAR *typesW[] = { any, empty, NULL };
1282 BOOL ret;
1284 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1285 ok(session != NULL ,"Unable to open Internet session\n");
1287 connect = InternetConnectA(session, NULL, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1288 INTERNET_SERVICE_HTTP, 0, 0);
1289 ok(connect == NULL, "InternetConnectA should have failed\n");
1290 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1292 connect = InternetConnectA(session, "", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1293 INTERNET_SERVICE_HTTP, 0, 0);
1294 ok(connect == NULL, "InternetConnectA should have failed\n");
1295 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1297 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1298 INTERNET_SERVICE_HTTP, 0, 0);
1299 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1301 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1302 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1304 skip( "Network unreachable, skipping test\n" );
1305 goto done;
1307 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1309 ret = HttpSendRequestW(request, NULL, 0, NULL, 0);
1310 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1311 ok(InternetCloseHandle(request), "Close request handle failed\n");
1313 request = HttpOpenRequestW(connect, NULL, slash, NULL, NULL, typesW, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1314 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1316 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1317 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1318 ok(InternetCloseHandle(request), "Close request handle failed\n");
1320 done:
1321 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1322 ok(InternetCloseHandle(session), "Close session handle failed\n");
1325 static void test_cache_read(void)
1327 HINTERNET session, connection, req;
1328 FILETIME now, tomorrow, yesterday;
1329 BYTE content[1000], buf[2000];
1330 char file_path[MAX_PATH];
1331 ULARGE_INTEGER li;
1332 HANDLE file;
1333 DWORD size;
1334 unsigned i;
1335 BOOL res;
1337 static const char cache_only_url[] = "http://test.winehq.org/tests/cache-only";
1338 BYTE cache_headers[] = "HTTP/1.1 200 OK\r\n\r\n";
1340 trace("Testing cache read...\n");
1342 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
1344 for(i = 0; i < sizeof(content); i++)
1345 content[i] = '0' + (i%10);
1347 GetSystemTimeAsFileTime(&now);
1348 li.u.HighPart = now.dwHighDateTime;
1349 li.u.LowPart = now.dwLowDateTime;
1350 li.QuadPart += (LONGLONG)10000000 * 3600 * 24;
1351 tomorrow.dwHighDateTime = li.u.HighPart;
1352 tomorrow.dwLowDateTime = li.u.LowPart;
1353 li.QuadPart -= (LONGLONG)10000000 * 3600 * 24 * 2;
1354 yesterday.dwHighDateTime = li.u.HighPart;
1355 yesterday.dwLowDateTime = li.u.LowPart;
1357 res = CreateUrlCacheEntryA(cache_only_url, sizeof(content), "", file_path, 0);
1358 ok(res, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1360 file = CreateFileA(file_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1361 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
1363 WriteFile(file, content, sizeof(content), &size, NULL);
1364 CloseHandle(file);
1366 res = CommitUrlCacheEntryA(cache_only_url, file_path, tomorrow, yesterday, NORMAL_CACHE_ENTRY,
1367 cache_headers, sizeof(cache_headers)-1, "", 0);
1368 ok(res, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1370 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
1371 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
1373 pInternetSetStatusCallbackA(session, callback);
1375 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
1376 connection = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT,
1377 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
1378 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
1379 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
1381 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
1382 req = HttpOpenRequestA(connection, "GET", "/tests/cache-only", NULL, NULL, NULL, 0, 0xdeadbead);
1383 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
1384 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
1386 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER);
1387 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER);
1388 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST);
1389 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT);
1390 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE);
1391 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED);
1392 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
1394 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
1395 todo_wine
1396 ok(res, "HttpSendRequest failed: %u\n", GetLastError());
1398 if(res) {
1399 size = 0;
1400 res = InternetQueryDataAvailable(req, &size, 0, 0);
1401 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1402 ok(size == sizeof(content), "size = %u\n", size);
1404 size = sizeof(buf);
1405 res = InternetReadFile(req, buf, sizeof(buf), &size);
1406 ok(res, "InternetReadFile failed: %u\n", GetLastError());
1407 ok(size == sizeof(content), "size = %u\n", size);
1408 ok(!memcmp(content, buf, sizeof(content)), "unexpected content\n");
1411 close_async_handle(session, hCompleteEvent, 2);
1413 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
1414 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
1415 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
1416 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
1417 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1418 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1419 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1421 res = DeleteUrlCacheEntryA(cache_only_url);
1422 ok(res, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1424 CloseHandle(hCompleteEvent);
1427 static void test_http_cache(void)
1429 HINTERNET session, connect, request;
1430 char file_name[MAX_PATH], url[INTERNET_MAX_URL_LENGTH];
1431 DWORD size, file_size;
1432 BYTE buf[100];
1433 HANDLE file;
1434 BOOL ret;
1436 static const char *types[] = { "*", "", NULL };
1438 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1439 ok(session != NULL ,"Unable to open Internet session\n");
1441 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1442 INTERNET_SERVICE_HTTP, 0, 0);
1443 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1445 request = HttpOpenRequestA(connect, NULL, "/tests/hello.html", NULL, NULL, types, INTERNET_FLAG_NEED_FILE, 0);
1446 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1448 skip( "Network unreachable, skipping test\n" );
1450 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1451 ok(InternetCloseHandle(session), "Close session handle failed\n");
1453 return;
1455 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1457 size = sizeof(url);
1458 ret = InternetQueryOptionA(request, INTERNET_OPTION_URL, url, &size);
1459 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1460 ok(!strcmp(url, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url);
1462 size = sizeof(file_name);
1463 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1464 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1465 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1466 ok(!size, "size = %d\n", size);
1468 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1469 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1471 size = sizeof(file_name);
1472 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1473 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1475 file = CreateFileA(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
1476 FILE_ATTRIBUTE_NORMAL, NULL);
1477 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1478 file_size = GetFileSize(file, NULL);
1479 ok(file_size == 106, "file size = %u\n", file_size);
1481 size = sizeof(buf);
1482 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1483 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1484 ok(size == 100, "size = %u\n", size);
1486 file_size = GetFileSize(file, NULL);
1487 ok(file_size == 106, "file size = %u\n", file_size);
1488 CloseHandle(file);
1490 ret = DeleteFileA(file_name);
1491 ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
1493 ok(InternetCloseHandle(request), "Close request handle failed\n");
1495 file = CreateFileA(file_name, GENERIC_READ, 0, NULL, OPEN_EXISTING,
1496 FILE_ATTRIBUTE_NORMAL, NULL);
1497 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1498 CloseHandle(file);
1500 /* Send the same request, requiring it to be retrieved from the cache */
1501 request = HttpOpenRequestA(connect, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
1503 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1504 ok(ret, "HttpSendRequest failed\n");
1506 size = sizeof(buf);
1507 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1508 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1509 ok(size == 100, "size = %u\n", size);
1511 ok(InternetCloseHandle(request), "Close request handle failed\n");
1513 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1514 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1516 size = sizeof(file_name);
1517 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1518 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1519 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1520 ok(!size, "size = %d\n", size);
1522 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1523 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1525 size = sizeof(file_name);
1526 file_name[0] = 0;
1527 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1528 if (ret)
1530 file = CreateFileA(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1531 FILE_ATTRIBUTE_NORMAL, NULL);
1532 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1533 CloseHandle(file);
1535 else
1537 /* < IE8 */
1538 ok(file_name[0] == 0, "Didn't expect a file name\n");
1541 ok(InternetCloseHandle(request), "Close request handle failed\n");
1542 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1543 ok(InternetCloseHandle(session), "Close session handle failed\n");
1545 test_cache_read();
1548 static void InternetLockRequestFile_test(void)
1550 HINTERNET session, connect, request;
1551 char file_name[MAX_PATH];
1552 HANDLE lock, lock2;
1553 DWORD size;
1554 BOOL ret;
1556 static const char *types[] = { "*", "", NULL };
1558 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1559 ok(session != NULL ,"Unable to open Internet session\n");
1561 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1562 INTERNET_SERVICE_HTTP, 0, 0);
1563 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1565 request = HttpOpenRequestA(connect, NULL, "/tests/hello.html", NULL, NULL, types, INTERNET_FLAG_NEED_FILE|INTERNET_FLAG_RELOAD, 0);
1566 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1568 skip( "Network unreachable, skipping test\n" );
1570 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1571 ok(InternetCloseHandle(session), "Close session handle failed\n");
1573 return;
1575 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1577 size = sizeof(file_name);
1578 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1579 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1580 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1581 ok(!size, "size = %d\n", size);
1583 lock = NULL;
1584 ret = InternetLockRequestFile(request, &lock);
1585 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
1587 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1588 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1590 size = sizeof(file_name);
1591 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1592 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1594 ret = InternetLockRequestFile(request, &lock);
1595 ok(ret, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
1596 ok(lock != NULL, "lock == NULL\n");
1598 ret = InternetLockRequestFile(request, &lock2);
1599 ok(ret, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
1600 ok(lock == lock2, "lock != lock2\n");
1602 ret = InternetUnlockRequestFile(lock2);
1603 ok(ret, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1605 ret = DeleteFileA(file_name);
1606 ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
1608 ok(InternetCloseHandle(request), "Close request handle failed\n");
1610 ret = DeleteFileA(file_name);
1611 ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
1613 ret = InternetUnlockRequestFile(lock);
1614 ok(ret, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1616 ret = DeleteFileA(file_name);
1617 ok(ret, "Deleting file returned %x(%u)\n", ret, GetLastError());
1620 static void HttpHeaders_test(void)
1622 HINTERNET hSession;
1623 HINTERNET hConnect;
1624 HINTERNET hRequest;
1625 CHAR buffer[256];
1626 WCHAR wbuffer[256];
1627 DWORD len = 256;
1628 DWORD oldlen;
1629 DWORD index = 0;
1630 BOOL ret;
1632 hSession = InternetOpenA("Wine Regression Test",
1633 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1634 ok( hSession != NULL ,"Unable to open Internet session\n");
1635 hConnect = InternetConnectA(hSession, "test.winehq.org",
1636 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1638 ok( hConnect != NULL, "Unable to connect to http://test.winehq.org\n");
1639 hRequest = HttpOpenRequestA(hConnect, "POST", "/tests/post.php",
1640 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1641 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1643 skip( "Network unreachable, skipping test\n" );
1644 goto done;
1646 ok( hRequest != NULL, "Failed to open request handle\n");
1648 index = 0;
1649 len = sizeof(buffer);
1650 strcpy(buffer,"Warning");
1651 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1652 buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
1654 ok(HttpAddRequestHeadersA(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
1655 "Failed to add new header\n");
1657 index = 0;
1658 len = sizeof(buffer);
1659 strcpy(buffer,"Warning");
1660 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1661 buffer,&len,&index),"Unable to query header\n");
1662 ok(index == 1, "Index was not incremented\n");
1663 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1664 ok(len == 5, "Invalid length (exp. 5, got %d)\n", len);
1665 ok((len < sizeof(buffer)) && (buffer[len] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1666 len = sizeof(buffer);
1667 strcpy(buffer,"Warning");
1668 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1669 buffer,&len,&index)==0,"Second Index Should Not Exist\n");
1671 index = 0;
1672 len = 5; /* could store the string but not the NULL terminator */
1673 strcpy(buffer,"Warning");
1674 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1675 buffer,&len,&index) == FALSE,"Query succeeded on a too small buffer\n");
1676 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1677 ok(index == 0, "Index was incremented\n");
1678 ok(strcmp(buffer,"Warning")==0, "incorrect string was returned(%s)\n",buffer); /* string not touched */
1679 ok(len == 6, "Invalid length (exp. 6, got %d)\n", len); /* unlike success, the length includes the NULL-terminator */
1681 /* a call with NULL will fail but will return the length */
1682 index = 0;
1683 len = sizeof(buffer);
1684 SetLastError(0xdeadbeef);
1685 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1686 NULL,&len,&index) == FALSE,"Query worked\n");
1687 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1688 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1689 ok(index == 0, "Index was incremented\n");
1691 /* even for a len that is too small */
1692 index = 0;
1693 len = 15;
1694 SetLastError(0xdeadbeef);
1695 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1696 NULL,&len,&index) == FALSE,"Query worked\n");
1697 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1698 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1699 ok(index == 0, "Index was incremented\n");
1701 index = 0;
1702 len = 0;
1703 SetLastError(0xdeadbeef);
1704 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1705 NULL,&len,&index) == FALSE,"Query worked\n");
1706 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1707 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1708 ok(index == 0, "Index was incremented\n");
1709 oldlen = len; /* bytes; at least long enough to hold buffer & nul */
1712 /* a working query */
1713 index = 0;
1714 len = sizeof(buffer);
1715 memset(buffer, 'x', sizeof(buffer));
1716 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1717 buffer,&len,&index),"Unable to query header\n");
1718 ok(len + sizeof(CHAR) <= oldlen, "Result longer than advertised\n");
1719 ok((len < sizeof(buffer)-sizeof(CHAR)) && (buffer[len/sizeof(CHAR)] == 0),"No NUL at end\n");
1720 ok(len == strlen(buffer) * sizeof(CHAR), "Length wrong\n");
1721 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1722 ok(strncmp(buffer, "POST /tests/post.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1723 ok(strcmp(buffer + strlen(buffer) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1724 ok(index == 0, "Index was incremented\n");
1726 /* Like above two tests, but for W version */
1728 index = 0;
1729 len = 0;
1730 SetLastError(0xdeadbeef);
1731 ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1732 NULL,&len,&index) == FALSE,"Query worked\n");
1733 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1734 ok(len > 80, "Invalid length (exp. more than 80, got %d)\n", len);
1735 ok(index == 0, "Index was incremented\n");
1736 oldlen = len; /* bytes; at least long enough to hold buffer & nul */
1738 /* a working query */
1739 index = 0;
1740 len = sizeof(wbuffer);
1741 memset(wbuffer, 'x', sizeof(wbuffer));
1742 ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1743 wbuffer,&len,&index),"Unable to query header\n");
1744 ok(len + sizeof(WCHAR) <= oldlen, "Result longer than advertised\n");
1745 ok(len == lstrlenW(wbuffer) * sizeof(WCHAR), "Length wrong\n");
1746 ok((len < sizeof(wbuffer)-sizeof(WCHAR)) && (wbuffer[len/sizeof(WCHAR)] == 0),"No NUL at end\n");
1747 ok(index == 0, "Index was incremented\n");
1749 /* end of W version tests */
1751 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1752 index = 0;
1753 len = sizeof(buffer);
1754 memset(buffer, 'x', sizeof(buffer));
1755 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF,
1756 buffer,&len,&index) == TRUE,"Query failed\n");
1757 ok(len == 2, "Expected 2, got %d\n", len);
1758 ok(strcmp(buffer, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer);
1759 ok(index == 0, "Index was incremented\n");
1761 ok(HttpAddRequestHeadersA(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
1762 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1764 index = 0;
1765 len = sizeof(buffer);
1766 strcpy(buffer,"Warning");
1767 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1768 buffer,&len,&index),"Unable to query header\n");
1769 ok(index == 1, "Index was not incremented\n");
1770 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1771 len = sizeof(buffer);
1772 strcpy(buffer,"Warning");
1773 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1774 buffer,&len,&index),"Failed to get second header\n");
1775 ok(index == 2, "Index was not incremented\n");
1776 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1777 len = sizeof(buffer);
1778 strcpy(buffer,"Warning");
1779 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1780 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1782 ok(HttpAddRequestHeadersA(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1784 index = 0;
1785 len = sizeof(buffer);
1786 strcpy(buffer,"Warning");
1787 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1788 buffer,&len,&index),"Unable to query header\n");
1789 ok(index == 1, "Index was not incremented\n");
1790 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1791 len = sizeof(buffer);
1792 strcpy(buffer,"Warning");
1793 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1794 buffer,&len,&index),"Failed to get second header\n");
1795 ok(index == 2, "Index was not incremented\n");
1796 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1797 len = sizeof(buffer);
1798 strcpy(buffer,"Warning");
1799 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1800 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1802 ok(HttpAddRequestHeadersA(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1804 index = 0;
1805 len = sizeof(buffer);
1806 strcpy(buffer,"Warning");
1807 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1808 buffer,&len,&index),"Unable to query header\n");
1809 ok(index == 1, "Index was not incremented\n");
1810 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1811 len = sizeof(buffer);
1812 strcpy(buffer,"Warning");
1813 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1814 buffer,&len,&index),"Failed to get second header\n");
1815 ok(index == 2, "Index was not incremented\n");
1816 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1817 len = sizeof(buffer);
1818 strcpy(buffer,"Warning");
1819 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1820 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1822 ok(HttpAddRequestHeadersA(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1824 index = 0;
1825 len = sizeof(buffer);
1826 strcpy(buffer,"Warning");
1827 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1828 buffer,&len,&index),"Unable to query header\n");
1829 ok(index == 1, "Index was not incremented\n");
1830 ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer);
1831 len = sizeof(buffer);
1832 strcpy(buffer,"Warning");
1833 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1834 ok(index == 2, "Index was not incremented\n");
1835 ok(strcmp(buffer,"test3")==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)==0,"Third Header Should Not Exist\n");
1840 ok(HttpAddRequestHeadersA(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1842 index = 0;
1843 len = sizeof(buffer);
1844 strcpy(buffer,"Warning");
1845 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1846 ok(index == 1, "Index was not incremented\n");
1847 ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer);
1848 len = sizeof(buffer);
1849 strcpy(buffer,"Warning");
1850 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1851 ok(index == 2, "Index was not incremented\n");
1852 ok(strcmp(buffer,"test3")==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)==0,"Third Header Should Not Exist\n");
1857 ok(HttpAddRequestHeadersA(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1859 index = 0;
1860 len = sizeof(buffer);
1861 strcpy(buffer,"Warning");
1862 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1863 ok(index == 1, "Index was not incremented\n");
1864 ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer);
1865 len = sizeof(buffer);
1866 strcpy(buffer,"Warning");
1867 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1868 ok(index == 2, "Index was not incremented\n");
1869 ok(strcmp(buffer,"test3")==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)==0,"Third Header Should Not Exist\n");
1874 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");
1876 index = 0;
1877 len = sizeof(buffer);
1878 strcpy(buffer,"Warning");
1879 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1880 ok(index == 1, "Index was not incremented\n");
1881 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1882 len = sizeof(buffer);
1883 strcpy(buffer,"Warning");
1884 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1885 ok(index == 2, "Index was not incremented\n");
1886 ok(strcmp(buffer,"test7")==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)==0,"Third Header Should Not Exist\n");
1891 /* Ensure that blank headers are ignored and don't cause a failure */
1892 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");
1894 index = 0;
1895 len = sizeof(buffer);
1896 strcpy(buffer,"BlankTest");
1897 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1898 ok(index == 1, "Index was not incremented\n");
1899 ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
1901 /* Ensure that malformed header separators are ignored and don't cause a failure */
1902 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),
1903 "Failed to add header with malformed entries in list\n");
1905 index = 0;
1906 len = sizeof(buffer);
1907 strcpy(buffer,"MalformedTest");
1908 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1909 ok(index == 1, "Index was not incremented\n");
1910 ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
1911 index = 0;
1912 len = sizeof(buffer);
1913 strcpy(buffer,"MalformedTestTwo");
1914 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1915 ok(index == 1, "Index was not incremented\n");
1916 ok(strcmp(buffer,"value2")==0, "incorrect string was returned(%s)\n",buffer);
1917 index = 0;
1918 len = sizeof(buffer);
1919 strcpy(buffer,"MalformedTestThree");
1920 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1921 ok(index == 1, "Index was not incremented\n");
1922 ok(strcmp(buffer,"value3")==0, "incorrect string was returned(%s)\n",buffer);
1924 ret = HttpAddRequestHeadersA(hRequest, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD);
1925 ok(ret, "unable to add header %u\n", GetLastError());
1927 index = 0;
1928 buffer[0] = 0;
1929 len = sizeof(buffer);
1930 ret = HttpQueryInfoA(hRequest, HTTP_QUERY_AUTHORIZATION|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &len, &index);
1931 ok(ret, "unable to query header %u\n", GetLastError());
1932 ok(index == 1, "index was not incremented\n");
1933 ok(!strcmp(buffer, "Basic"), "incorrect string was returned (%s)\n", buffer);
1935 ret = HttpAddRequestHeadersA(hRequest, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE);
1936 ok(ret, "unable to remove header %u\n", GetLastError());
1938 index = 0;
1939 len = sizeof(buffer);
1940 SetLastError(0xdeadbeef);
1941 ok(!HttpQueryInfoA(hRequest, HTTP_QUERY_AUTHORIZATION|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &len, &index),
1942 "header still present\n");
1943 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "got %u\n", GetLastError());
1945 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1946 done:
1947 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1948 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1951 static const char garbagemsg[] =
1952 "Garbage: Header\r\n";
1954 static const char contmsg[] =
1955 "HTTP/1.1 100 Continue\r\n";
1957 static const char expandcontmsg[] =
1958 "HTTP/1.1 100 Continue\r\n"
1959 "Server: winecontinue\r\n"
1960 "Tag: something witty\r\n"
1961 "\r\n";
1963 static const char okmsg[] =
1964 "HTTP/1.1 200 OK\r\n"
1965 "Server: winetest\r\n"
1966 "\r\n";
1968 static const char okmsg2[] =
1969 "HTTP/1.1 200 OK\r\n"
1970 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1971 "Server: winetest\r\n"
1972 "Content-Length: 0\r\n"
1973 "Set-Cookie: one\r\n"
1974 "Set-Cookie: two\r\n"
1975 "\r\n";
1977 static const char notokmsg[] =
1978 "HTTP/1.1 400 Bad Request\r\n"
1979 "Server: winetest\r\n"
1980 "\r\n";
1982 static const char noauthmsg[] =
1983 "HTTP/1.1 401 Unauthorized\r\n"
1984 "Server: winetest\r\n"
1985 "Connection: close\r\n"
1986 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1987 "\r\n";
1989 static const char noauthmsg2[] =
1990 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
1991 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
1992 "\0d`0|6\n"
1993 "Server: winetest\r\n";
1995 static const char proxymsg[] =
1996 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1997 "Server: winetest\r\n"
1998 "Proxy-Connection: close\r\n"
1999 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
2000 "\r\n";
2002 static const char page1[] =
2003 "<HTML>\r\n"
2004 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
2005 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
2006 "</HTML>\r\n\r\n";
2008 static const char ok_with_length[] =
2009 "HTTP/1.1 200 OK\r\n"
2010 "Connection: Keep-Alive\r\n"
2011 "Content-Length: 18\r\n\r\n"
2012 "HTTP/1.1 211 OK\r\n\r\n";
2014 static const char ok_with_length2[] =
2015 "HTTP/1.1 210 OK\r\n"
2016 "Connection: Keep-Alive\r\n"
2017 "Content-Length: 19\r\n\r\n"
2018 "HTTP/1.1 211 OK\r\n\r\n";
2020 struct server_info {
2021 HANDLE hEvent;
2022 int port;
2025 static int test_cache_gzip;
2026 static const char *send_buffer;
2028 static DWORD CALLBACK server_thread(LPVOID param)
2030 struct server_info *si = param;
2031 int r, c = -1, i, on, count = 0;
2032 SOCKET s;
2033 struct sockaddr_in sa;
2034 char buffer[0x100];
2035 WSADATA wsaData;
2036 int last_request = 0;
2037 char host_header[22];
2038 static BOOL test_b = FALSE;
2039 static int test_no_cache = 0;
2041 WSAStartup(MAKEWORD(1,1), &wsaData);
2043 s = socket(AF_INET, SOCK_STREAM, 0);
2044 if (s == INVALID_SOCKET)
2045 return 1;
2047 on = 1;
2048 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof on);
2050 memset(&sa, 0, sizeof sa);
2051 sa.sin_family = AF_INET;
2052 sa.sin_port = htons(si->port);
2053 sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
2055 r = bind(s, (struct sockaddr*) &sa, sizeof sa);
2056 if (r<0)
2057 return 1;
2059 listen(s, 0);
2061 SetEvent(si->hEvent);
2063 sprintf(host_header, "Host: localhost:%d", si->port);
2067 if(c == -1)
2068 c = accept(s, NULL, NULL);
2070 memset(buffer, 0, sizeof buffer);
2071 for(i=0; i<(sizeof buffer-1); i++)
2073 r = recv(c, &buffer[i], 1, 0);
2074 if (r != 1)
2075 break;
2076 if (i<4) continue;
2077 if (buffer[i-2] == '\n' && buffer[i] == '\n' &&
2078 buffer[i-3] == '\r' && buffer[i-1] == '\r')
2079 break;
2081 if (strstr(buffer, "GET /test1"))
2083 if (!strstr(buffer, "Content-Length: 0"))
2085 send(c, okmsg, sizeof okmsg-1, 0);
2086 send(c, page1, sizeof page1-1, 0);
2088 else
2089 send(c, notokmsg, sizeof notokmsg-1, 0);
2091 if (strstr(buffer, "/test2"))
2093 if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2095 send(c, okmsg, sizeof okmsg-1, 0);
2096 send(c, page1, sizeof page1-1, 0);
2098 else
2099 send(c, proxymsg, sizeof proxymsg-1, 0);
2101 if (strstr(buffer, "/test3"))
2103 if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
2104 send(c, okmsg, sizeof okmsg-1, 0);
2105 else
2106 send(c, noauthmsg, sizeof noauthmsg-1, 0);
2108 if (strstr(buffer, "/test4"))
2110 if (strstr(buffer, "Connection: Close"))
2111 send(c, okmsg, sizeof okmsg-1, 0);
2112 else
2113 send(c, notokmsg, sizeof notokmsg-1, 0);
2115 if (strstr(buffer, "POST /test5") ||
2116 strstr(buffer, "RPC_IN_DATA /test5") ||
2117 strstr(buffer, "RPC_OUT_DATA /test5"))
2119 if (strstr(buffer, "Content-Length: 0"))
2121 send(c, okmsg, sizeof okmsg-1, 0);
2122 send(c, page1, sizeof page1-1, 0);
2124 else
2125 send(c, notokmsg, sizeof notokmsg-1, 0);
2127 if (strstr(buffer, "GET /test6"))
2129 send(c, contmsg, sizeof contmsg-1, 0);
2130 send(c, contmsg, sizeof contmsg-1, 0);
2131 send(c, okmsg, sizeof okmsg-1, 0);
2132 send(c, page1, sizeof page1-1, 0);
2134 if (strstr(buffer, "POST /test7"))
2136 if (strstr(buffer, "Content-Length: 100"))
2138 send(c, okmsg, sizeof okmsg-1, 0);
2139 send(c, page1, sizeof page1-1, 0);
2141 else
2142 send(c, notokmsg, sizeof notokmsg-1, 0);
2144 if (strstr(buffer, "/test8"))
2146 if (!strstr(buffer, "Connection: Close") &&
2147 strstr(buffer, "Connection: Keep-Alive") &&
2148 !strstr(buffer, "Cache-Control: no-cache") &&
2149 !strstr(buffer, "Pragma: no-cache") &&
2150 strstr(buffer, host_header))
2151 send(c, okmsg, sizeof okmsg-1, 0);
2152 else
2153 send(c, notokmsg, sizeof notokmsg-1, 0);
2155 if (strstr(buffer, "/test9"))
2157 if (!strstr(buffer, "Connection: Close") &&
2158 !strstr(buffer, "Connection: Keep-Alive") &&
2159 !strstr(buffer, "Cache-Control: no-cache") &&
2160 !strstr(buffer, "Pragma: no-cache") &&
2161 strstr(buffer, host_header))
2162 send(c, okmsg, sizeof okmsg-1, 0);
2163 else
2164 send(c, notokmsg, sizeof notokmsg-1, 0);
2166 if (strstr(buffer, "/testA"))
2168 if (!strstr(buffer, "Connection: Close") &&
2169 !strstr(buffer, "Connection: Keep-Alive") &&
2170 (strstr(buffer, "Cache-Control: no-cache") ||
2171 strstr(buffer, "Pragma: no-cache")) &&
2172 strstr(buffer, host_header))
2173 send(c, okmsg, sizeof okmsg-1, 0);
2174 else
2175 send(c, notokmsg, sizeof notokmsg-1, 0);
2177 if (!test_b && strstr(buffer, "/testB HTTP/1.1"))
2179 test_b = TRUE;
2180 send(c, okmsg, sizeof okmsg-1, 0);
2181 recvfrom(c, buffer, sizeof buffer, 0, NULL, NULL);
2182 send(c, okmsg, sizeof okmsg-1, 0);
2184 if (strstr(buffer, "/testC"))
2186 if (strstr(buffer, "Cookie: cookie=biscuit"))
2187 send(c, okmsg, sizeof okmsg-1, 0);
2188 else
2189 send(c, notokmsg, sizeof notokmsg-1, 0);
2191 if (strstr(buffer, "/testD"))
2193 send(c, okmsg2, sizeof okmsg2-1, 0);
2195 if (strstr(buffer, "/testE"))
2197 send(c, noauthmsg2, sizeof noauthmsg2-1, 0);
2199 if (strstr(buffer, "GET /quit"))
2201 send(c, okmsg, sizeof okmsg-1, 0);
2202 send(c, page1, sizeof page1-1, 0);
2203 last_request = 1;
2205 if (strstr(buffer, "GET /testF"))
2207 send(c, expandcontmsg, sizeof expandcontmsg-1, 0);
2208 send(c, garbagemsg, sizeof garbagemsg-1, 0);
2209 send(c, contmsg, sizeof contmsg-1, 0);
2210 send(c, garbagemsg, sizeof garbagemsg-1, 0);
2211 send(c, okmsg, sizeof okmsg-1, 0);
2212 send(c, page1, sizeof page1-1, 0);
2214 if (strstr(buffer, "GET /testG"))
2216 send(c, page1, sizeof page1-1, 0);
2219 if (strstr(buffer, "GET /testJ"))
2221 if (count == 0)
2223 count++;
2224 send(c, ok_with_length, sizeof(ok_with_length)-1, 0);
2226 else
2228 send(c, ok_with_length2, sizeof(ok_with_length2)-1, 0);
2229 count = 0;
2232 if (strstr(buffer, "GET /testH"))
2234 send(c, ok_with_length2, sizeof(ok_with_length2)-1, 0);
2235 recvfrom(c, buffer, sizeof(buffer), 0, NULL, NULL);
2236 send(c, ok_with_length, sizeof(ok_with_length)-1, 0);
2239 if (strstr(buffer, "GET /test_no_content"))
2241 static const char nocontentmsg[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2242 send(c, nocontentmsg, sizeof(nocontentmsg)-1, 0);
2244 if (strstr(buffer, "GET /test_conn_close"))
2246 static const char conn_close_response[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2247 send(c, conn_close_response, sizeof(conn_close_response)-1, 0);
2248 WaitForSingleObject(conn_close_event, INFINITE);
2249 trace("closing connection\n");
2251 if (strstr(buffer, "GET /test_cache_control_no_cache"))
2253 static const char no_cache_response[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2254 if(!test_no_cache++)
2255 send(c, no_cache_response, sizeof(no_cache_response)-1, 0);
2256 else
2257 send(c, okmsg, sizeof(okmsg)-1, 0);
2259 if (strstr(buffer, "GET /test_cache_control_no_store"))
2261 static const char no_cache_response[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2262 send(c, no_cache_response, sizeof(no_cache_response)-1, 0);
2264 if (strstr(buffer, "GET /test_cache_gzip"))
2266 static const char gzip_response[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2267 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2268 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2269 if(!test_cache_gzip++)
2270 send(c, gzip_response, sizeof(gzip_response), 0);
2271 else
2272 send(c, notokmsg, sizeof(notokmsg)-1, 0);
2274 if (strstr(buffer, "HEAD /test_head")) {
2275 static const char head_response[] =
2276 "HTTP/1.1 200 OK\r\n"
2277 "Connection: Keep-Alive\r\n"
2278 "Content-Length: 100\r\n"
2279 "\r\n";
2281 send(c, head_response, sizeof(head_response), 0);
2282 continue;
2284 if (strstr(buffer, "GET /send_from_buffer"))
2285 send(c, send_buffer, strlen(send_buffer), 0);
2286 if (strstr(buffer, "/test_cache_control_verb"))
2288 if (!memcmp(buffer, "GET ", sizeof("GET ")-1) &&
2289 !strstr(buffer, "Cache-Control: no-cache\r\n")) send(c, okmsg, sizeof(okmsg)-1, 0);
2290 else if (strstr(buffer, "Cache-Control: no-cache\r\n")) send(c, okmsg, sizeof(okmsg)-1, 0);
2291 else send(c, notokmsg, sizeof(notokmsg)-1, 0);
2293 if (strstr(buffer, "GET /test_premature_disconnect"))
2294 trace("closing connection\n");
2296 shutdown(c, 2);
2297 closesocket(c);
2298 c = -1;
2299 } while (!last_request);
2301 closesocket(s);
2303 return 0;
2306 static void test_basic_request(int port, const char *verb, const char *url)
2308 HINTERNET hi, hc, hr;
2309 DWORD r, count, error;
2310 char buffer[0x100];
2312 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2313 ok(hi != NULL, "open failed\n");
2315 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2316 ok(hc != NULL, "connect failed\n");
2318 hr = HttpOpenRequestA(hc, verb, url, NULL, NULL, NULL, 0, 0);
2319 ok(hr != NULL, "HttpOpenRequest failed\n");
2321 SetLastError(0xdeadbeef);
2322 r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
2323 error = GetLastError();
2324 ok(error == ERROR_SUCCESS || broken(error != ERROR_SUCCESS), "expected ERROR_SUCCESS, got %u\n", error);
2325 ok(r, "HttpSendRequest failed\n");
2327 count = 0;
2328 memset(buffer, 0, sizeof buffer);
2329 SetLastError(0xdeadbeef);
2330 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
2331 ok(r, "InternetReadFile failed %u\n", GetLastError());
2332 ok(count == sizeof page1 - 1, "count was wrong\n");
2333 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong, got: %s\n", buffer);
2335 InternetCloseHandle(hr);
2336 InternetCloseHandle(hc);
2337 InternetCloseHandle(hi);
2340 static void test_proxy_indirect(int port)
2342 HINTERNET hi, hc, hr;
2343 DWORD r, sz;
2344 char buffer[0x40];
2346 hi = InternetOpenA(NULL, 0, NULL, NULL, 0);
2347 ok(hi != NULL, "open failed\n");
2349 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2350 ok(hc != NULL, "connect failed\n");
2352 hr = HttpOpenRequestA(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
2353 ok(hr != NULL, "HttpOpenRequest failed\n");
2355 r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
2356 ok(r, "HttpSendRequest failed %u\n", GetLastError());
2358 sz = sizeof buffer;
2359 r = HttpQueryInfoA(hr, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL);
2360 ok(r || GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo failed: %d\n", GetLastError());
2361 if (!r)
2363 skip("missing proxy header, not testing remaining proxy headers\n");
2364 goto out;
2366 ok(!strcmp(buffer, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2368 test_status_code(hr, 407);
2369 test_request_flags(hr, 0);
2371 sz = sizeof buffer;
2372 r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL);
2373 ok(r, "HttpQueryInfo failed\n");
2374 ok(!strcmp(buffer, "Proxy Authentication Required"), "proxy text wrong\n");
2376 sz = sizeof buffer;
2377 r = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &sz, NULL);
2378 ok(r, "HttpQueryInfo failed\n");
2379 ok(!strcmp(buffer, "HTTP/1.1"), "http version wrong\n");
2381 sz = sizeof buffer;
2382 r = HttpQueryInfoA(hr, HTTP_QUERY_SERVER, buffer, &sz, NULL);
2383 ok(r, "HttpQueryInfo failed\n");
2384 ok(!strcmp(buffer, "winetest"), "http server wrong\n");
2386 sz = sizeof buffer;
2387 r = HttpQueryInfoA(hr, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL);
2388 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo should fail\n");
2389 ok(r == FALSE, "HttpQueryInfo failed\n");
2391 out:
2392 InternetCloseHandle(hr);
2393 InternetCloseHandle(hc);
2394 InternetCloseHandle(hi);
2397 static void test_proxy_direct(int port)
2399 HINTERNET hi, hc, hr;
2400 DWORD r, sz, error;
2401 char buffer[0x40], *url;
2402 WCHAR bufferW[0x40];
2403 static const char url_fmt[] = "http://test.winehq.org:%u/test2";
2404 static CHAR username[] = "mike",
2405 password[] = "1101",
2406 useragent[] = "winetest";
2407 static const WCHAR usernameW[] = {'m','i','k','e',0},
2408 passwordW[] = {'1','1','0','1',0},
2409 useragentW[] = {'w','i','n','e','t','e','s','t',0};
2411 /* specify proxy type without the proxy and bypass */
2412 SetLastError(0xdeadbeef);
2413 hi = InternetOpenW(NULL, INTERNET_OPEN_TYPE_PROXY, NULL, NULL, 0);
2414 error = GetLastError();
2415 ok(error == ERROR_INVALID_PARAMETER ||
2416 broken(error == ERROR_SUCCESS) /* WinXPProSP2 */, "got %u\n", error);
2417 ok(hi == NULL || broken(!!hi) /* WinXPProSP2 */, "open should have failed\n");
2419 sprintf(buffer, "localhost:%d\n", port);
2420 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0);
2421 ok(hi != NULL, "open failed\n");
2423 /* try connect without authorization */
2424 hc = InternetConnectA(hi, "test.winehq.org", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2425 ok(hc != NULL, "connect failed\n");
2427 hr = HttpOpenRequestA(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
2428 ok(hr != NULL, "HttpOpenRequest failed\n");
2430 sz = 0;
2431 SetLastError(0xdeadbeef);
2432 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, NULL, &sz);
2433 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2434 ok(!r, "unexpected success\n");
2435 ok(sz == 1, "got %u\n", sz);
2437 sz = 0;
2438 SetLastError(0xdeadbeef);
2439 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, NULL, &sz);
2440 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2441 ok(!r, "unexpected success\n");
2442 ok(sz == 1, "got %u\n", sz);
2444 sz = sizeof(buffer);
2445 SetLastError(0xdeadbeef);
2446 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz);
2447 ok(r, "unexpected failure %u\n", GetLastError());
2448 ok(!sz, "got %u\n", sz);
2450 sz = sizeof(buffer);
2451 SetLastError(0xdeadbeef);
2452 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2453 ok(r, "unexpected failure %u\n", GetLastError());
2454 ok(!sz, "got %u\n", sz);
2456 sz = 0;
2457 SetLastError(0xdeadbeef);
2458 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, NULL, &sz);
2459 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2460 ok(!r, "unexpected success\n");
2461 ok(sz == 1, "got %u\n", sz);
2463 sz = 0;
2464 SetLastError(0xdeadbeef);
2465 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, NULL, &sz);
2466 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2467 ok(!r, "unexpected success\n");
2468 ok(sz == 1, "got %u\n", sz);
2470 sz = sizeof(buffer);
2471 SetLastError(0xdeadbeef);
2472 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz);
2473 ok(r, "unexpected failure %u\n", GetLastError());
2474 ok(!sz, "got %u\n", sz);
2476 sz = sizeof(buffer);
2477 SetLastError(0xdeadbeef);
2478 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz);
2479 ok(r, "unexpected failure %u\n", GetLastError());
2480 ok(!sz, "got %u\n", sz);
2482 sz = 0;
2483 SetLastError(0xdeadbeef);
2484 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, NULL, &sz);
2485 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2486 ok(!r, "unexpected success\n");
2487 ok(sz == 34, "got %u\n", sz);
2489 sz = sizeof(buffer);
2490 SetLastError(0xdeadbeef);
2491 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz);
2492 ok(r, "unexpected failure %u\n", GetLastError());
2493 ok(sz == 33, "got %u\n", sz);
2495 r = HttpSendRequestW(hr, NULL, 0, NULL, 0);
2496 ok(r || broken(!r), "HttpSendRequest failed %u\n", GetLastError());
2497 if (!r)
2499 win_skip("skipping proxy tests on broken wininet\n");
2500 goto done;
2503 test_status_code(hr, 407);
2505 /* set the user + password then try again */
2506 r = InternetSetOptionA(hi, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2507 ok(!r, "unexpected success\n");
2509 r = InternetSetOptionA(hc, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2510 ok(r, "failed to set user\n");
2512 r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2513 ok(r, "failed to set user\n");
2515 buffer[0] = 0;
2516 sz = 3;
2517 SetLastError(0xdeadbeef);
2518 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2519 ok(!r, "unexpected failure %u\n", GetLastError());
2520 ok(!buffer[0], "got %s\n", buffer);
2521 ok(sz == strlen(username) + 1, "got %u\n", sz);
2523 buffer[0] = 0;
2524 sz = 0;
2525 SetLastError(0xdeadbeef);
2526 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2527 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2528 ok(!r, "unexpected success\n");
2529 ok(sz == strlen(username) + 1, "got %u\n", sz);
2531 bufferW[0] = 0;
2532 sz = 0;
2533 SetLastError(0xdeadbeef);
2534 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_USERNAME, bufferW, &sz);
2535 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2536 ok(!r, "unexpected success\n");
2537 ok(sz == (lstrlenW(usernameW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2539 buffer[0] = 0;
2540 sz = sizeof(buffer);
2541 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2542 ok(r, "failed to get username\n");
2543 ok(!strcmp(buffer, username), "got %s\n", buffer);
2544 ok(sz == strlen(username), "got %u\n", sz);
2546 buffer[0] = 0;
2547 sz = sizeof(bufferW);
2548 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_USERNAME, bufferW, &sz);
2549 ok(r, "failed to get username\n");
2550 ok(!lstrcmpW(bufferW, usernameW), "wrong username\n");
2551 ok(sz == lstrlenW(usernameW), "got %u\n", sz);
2553 r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, username, 1);
2554 ok(r, "failed to set user\n");
2556 buffer[0] = 0;
2557 sz = sizeof(buffer);
2558 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2559 ok(r, "failed to get username\n");
2560 ok(!strcmp(buffer, username), "got %s\n", buffer);
2561 ok(sz == strlen(username), "got %u\n", sz);
2563 r = InternetSetOptionA(hi, INTERNET_OPTION_USER_AGENT, useragent, 1);
2564 ok(r, "failed to set useragent\n");
2566 buffer[0] = 0;
2567 sz = 0;
2568 SetLastError(0xdeadbeef);
2569 r = InternetQueryOptionA(hi, INTERNET_OPTION_USER_AGENT, buffer, &sz);
2570 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2571 ok(!r, "unexpected success\n");
2572 ok(sz == strlen(useragent) + 1, "got %u\n", sz);
2574 buffer[0] = 0;
2575 sz = sizeof(buffer);
2576 r = InternetQueryOptionA(hi, INTERNET_OPTION_USER_AGENT, buffer, &sz);
2577 ok(r, "failed to get user agent\n");
2578 ok(!strcmp(buffer, useragent), "got %s\n", buffer);
2579 ok(sz == strlen(useragent), "got %u\n", sz);
2581 bufferW[0] = 0;
2582 sz = 0;
2583 SetLastError(0xdeadbeef);
2584 r = InternetQueryOptionW(hi, INTERNET_OPTION_USER_AGENT, bufferW, &sz);
2585 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2586 ok(!r, "unexpected success\n");
2587 ok(sz == (lstrlenW(useragentW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2589 bufferW[0] = 0;
2590 sz = sizeof(bufferW);
2591 r = InternetQueryOptionW(hi, INTERNET_OPTION_USER_AGENT, bufferW, &sz);
2592 ok(r, "failed to get user agent\n");
2593 ok(!lstrcmpW(bufferW, useragentW), "wrong user agent\n");
2594 ok(sz == lstrlenW(useragentW), "got %u\n", sz);
2596 r = InternetSetOptionA(hr, INTERNET_OPTION_USERNAME, username, 1);
2597 ok(r, "failed to set user\n");
2599 buffer[0] = 0;
2600 sz = 0;
2601 SetLastError(0xdeadbeef);
2602 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz);
2603 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2604 ok(!r, "unexpected success\n");
2605 ok(sz == strlen(username) + 1, "got %u\n", sz);
2607 buffer[0] = 0;
2608 sz = sizeof(buffer);
2609 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz);
2610 ok(r, "failed to get user\n");
2611 ok(!strcmp(buffer, username), "got %s\n", buffer);
2612 ok(sz == strlen(username), "got %u\n", sz);
2614 bufferW[0] = 0;
2615 sz = 0;
2616 SetLastError(0xdeadbeef);
2617 r = InternetQueryOptionW(hr, INTERNET_OPTION_USERNAME, bufferW, &sz);
2618 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2619 ok(!r, "unexpected success\n");
2620 ok(sz == (lstrlenW(usernameW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2622 bufferW[0] = 0;
2623 sz = sizeof(bufferW);
2624 r = InternetQueryOptionW(hr, INTERNET_OPTION_USERNAME, bufferW, &sz);
2625 ok(r, "failed to get user\n");
2626 ok(!lstrcmpW(bufferW, usernameW), "wrong user\n");
2627 ok(sz == lstrlenW(usernameW), "got %u\n", sz);
2629 r = InternetSetOptionA(hr, INTERNET_OPTION_PASSWORD, password, 1);
2630 ok(r, "failed to set password\n");
2632 buffer[0] = 0;
2633 sz = 0;
2634 SetLastError(0xdeadbeef);
2635 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz);
2636 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2637 ok(!r, "unexpected success\n");
2638 ok(sz == strlen(password) + 1, "got %u\n", sz);
2640 buffer[0] = 0;
2641 sz = sizeof(buffer);
2642 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz);
2643 ok(r, "failed to get password\n");
2644 ok(!strcmp(buffer, password), "got %s\n", buffer);
2645 ok(sz == strlen(password), "got %u\n", sz);
2647 bufferW[0] = 0;
2648 sz = 0;
2649 SetLastError(0xdeadbeef);
2650 r = InternetQueryOptionW(hr, INTERNET_OPTION_PASSWORD, bufferW, &sz);
2651 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2652 ok(!r, "unexpected success\n");
2653 ok(sz == (lstrlenW(passwordW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2655 bufferW[0] = 0;
2656 sz = sizeof(bufferW);
2657 r = InternetQueryOptionW(hr, INTERNET_OPTION_PASSWORD, bufferW, &sz);
2658 ok(r, "failed to get password\n");
2659 ok(!lstrcmpW(bufferW, passwordW), "wrong password\n");
2660 ok(sz == lstrlenW(passwordW), "got %u\n", sz);
2662 url = HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt) + 11);
2663 sprintf(url, url_fmt, port);
2664 buffer[0] = 0;
2665 sz = 0;
2666 SetLastError(0xdeadbeef);
2667 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz);
2668 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2669 ok(!r, "unexpected success\n");
2670 ok(sz == strlen(url) + 1, "got %u\n", sz);
2672 buffer[0] = 0;
2673 sz = sizeof(buffer);
2674 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz);
2675 ok(r, "failed to get url\n");
2676 ok(!strcmp(buffer, url), "got %s\n", buffer);
2677 ok(sz == strlen(url), "got %u\n", sz);
2679 bufferW[0] = 0;
2680 sz = 0;
2681 SetLastError(0xdeadbeef);
2682 r = InternetQueryOptionW(hr, INTERNET_OPTION_URL, bufferW, &sz);
2683 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2684 ok(!r, "unexpected success\n");
2685 ok(sz == (strlen(url) + 1) * sizeof(WCHAR), "got %u\n", sz);
2687 bufferW[0] = 0;
2688 sz = sizeof(bufferW);
2689 r = InternetQueryOptionW(hr, INTERNET_OPTION_URL, bufferW, &sz);
2690 ok(r, "failed to get url\n");
2691 ok(!strcmp_wa(bufferW, url), "wrong url\n");
2692 ok(sz == strlen(url), "got %u\n", sz);
2693 HeapFree(GetProcessHeap(), 0, url);
2695 r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, password, 4);
2696 ok(r, "failed to set password\n");
2698 buffer[0] = 0;
2699 sz = 0;
2700 SetLastError(0xdeadbeef);
2701 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz);
2702 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2703 ok(!r, "unexpected success\n");
2704 ok(sz == strlen(password) + 1, "got %u\n", sz);
2706 buffer[0] = 0;
2707 sz = sizeof(buffer);
2708 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz);
2709 ok(r, "failed to get password\n");
2710 ok(!strcmp(buffer, password), "got %s\n", buffer);
2711 ok(sz == strlen(password), "got %u\n", sz);
2713 bufferW[0] = 0;
2714 sz = 0;
2715 SetLastError(0xdeadbeef);
2716 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_PASSWORD, bufferW, &sz);
2717 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2718 ok(!r, "unexpected success\n");
2719 ok(sz == (lstrlenW(passwordW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2721 bufferW[0] = 0;
2722 sz = sizeof(bufferW);
2723 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_PASSWORD, bufferW, &sz);
2724 ok(r, "failed to get password\n");
2725 ok(!lstrcmpW(bufferW, passwordW), "wrong password\n");
2726 ok(sz == lstrlenW(passwordW), "got %u\n", sz);
2728 r = HttpSendRequestW(hr, NULL, 0, NULL, 0);
2729 if (!r)
2731 win_skip("skipping proxy tests on broken wininet\n");
2732 goto done;
2734 ok(r, "HttpSendRequest failed %u\n", GetLastError());
2735 sz = sizeof buffer;
2736 r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
2737 ok(r, "HttpQueryInfo failed\n");
2738 ok(!strcmp(buffer, "200"), "proxy code wrong\n");
2740 done:
2741 InternetCloseHandle(hr);
2742 InternetCloseHandle(hc);
2743 InternetCloseHandle(hi);
2746 static void test_header_handling_order(int port)
2748 static const char authorization[] = "Authorization: Basic dXNlcjpwd2Q=";
2749 static const char connection[] = "Connection: Close";
2750 static const char *types[2] = { "*", NULL };
2751 char data[32];
2752 HINTERNET session, connect, request;
2753 DWORD size, status, data_len;
2754 BOOL ret;
2756 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2757 ok(session != NULL, "InternetOpen failed\n");
2759 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2760 ok(connect != NULL, "InternetConnect failed\n");
2762 request = HttpOpenRequestA(connect, NULL, "/test3", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2763 ok(request != NULL, "HttpOpenRequest failed\n");
2765 ret = HttpAddRequestHeadersA(request, authorization, ~0u, HTTP_ADDREQ_FLAG_ADD);
2766 ok(ret, "HttpAddRequestHeaders failed\n");
2768 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
2769 ok(ret, "HttpSendRequest failed\n");
2771 test_status_code(request, 200);
2772 test_request_flags(request, 0);
2774 InternetCloseHandle(request);
2776 request = HttpOpenRequestA(connect, NULL, "/test4", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2777 ok(request != NULL, "HttpOpenRequest failed\n");
2779 ret = HttpSendRequestA(request, connection, ~0u, NULL, 0);
2780 ok(ret, "HttpSendRequest failed\n");
2782 status = 0;
2783 size = sizeof(status);
2784 ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2785 ok(ret, "HttpQueryInfo failed\n");
2786 ok(status == 200 || status == 400 /* IE6 */, "got status %u, expected 200 or 400\n", status);
2788 InternetCloseHandle(request);
2789 InternetCloseHandle(connect);
2791 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2792 ok(connect != NULL, "InternetConnect failed\n");
2794 request = HttpOpenRequestA(connect, "POST", "/test7", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2795 ok(request != NULL, "HttpOpenRequest failed\n");
2797 ret = HttpAddRequestHeadersA(request, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
2798 ok(ret, "HttpAddRequestHeaders failed\n");
2800 ret = HttpSendRequestA(request, connection, ~0u, NULL, 0);
2801 ok(ret, "HttpSendRequest failed\n");
2803 status = 0;
2804 size = sizeof(status);
2805 ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2806 ok(ret, "HttpQueryInfo failed\n");
2807 ok(status == 200, "got status %u, expected 200\n", status);
2809 InternetCloseHandle(request);
2810 InternetCloseHandle(connect);
2812 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2813 ok(connect != NULL, "InternetConnect failed\n");
2815 request = HttpOpenRequestA(connect, "POST", "/test7b", NULL, NULL, types, 0, 0);
2816 ok(request != NULL, "HttpOpenRequest failed\n");
2818 ret = HttpAddRequestHeadersA(request, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
2819 ok(ret, "HttpAddRequestHeaders failed\n");
2821 data_len = sizeof(data);
2822 memset(data, 'a', sizeof(data));
2823 ret = HttpSendRequestA(request, connection, ~0u, data, data_len);
2824 ok(ret, "HttpSendRequest failed\n");
2826 status = 0;
2827 size = sizeof(status);
2828 ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2829 ok(ret, "HttpQueryInfo failed\n");
2830 ok(status == 200, "got status %u, expected 200\n", status);
2832 InternetCloseHandle(request);
2833 InternetCloseHandle(connect);
2834 InternetCloseHandle(session);
2837 static void test_connection_header(int port)
2839 HINTERNET ses, con, req;
2840 BOOL ret;
2842 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2843 ok(ses != NULL, "InternetOpen failed\n");
2845 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2846 ok(con != NULL, "InternetConnect failed\n");
2848 req = HttpOpenRequestA(con, NULL, "/test8", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2849 ok(req != NULL, "HttpOpenRequest failed\n");
2851 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2852 ok(ret, "HttpSendRequest failed\n");
2854 test_status_code(req, 200);
2856 InternetCloseHandle(req);
2858 req = HttpOpenRequestA(con, NULL, "/test9", NULL, NULL, NULL, 0, 0);
2859 ok(req != NULL, "HttpOpenRequest failed\n");
2861 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2862 ok(ret, "HttpSendRequest failed\n");
2864 test_status_code(req, 200);
2866 InternetCloseHandle(req);
2868 req = HttpOpenRequestA(con, NULL, "/test9", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
2869 ok(req != NULL, "HttpOpenRequest failed\n");
2871 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2872 ok(ret, "HttpSendRequest failed\n");
2874 test_status_code(req, 200);
2876 InternetCloseHandle(req);
2878 req = HttpOpenRequestA(con, "POST", "/testA", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
2879 ok(req != NULL, "HttpOpenRequest failed\n");
2881 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2882 ok(ret, "HttpSendRequest failed\n");
2884 test_status_code(req, 200);
2886 InternetCloseHandle(req);
2887 InternetCloseHandle(con);
2888 InternetCloseHandle(ses);
2891 static void test_http1_1(int port)
2893 HINTERNET ses, con, req;
2894 BOOL ret;
2896 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2897 ok(ses != NULL, "InternetOpen failed\n");
2899 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2900 ok(con != NULL, "InternetConnect failed\n");
2902 req = HttpOpenRequestA(con, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2903 ok(req != NULL, "HttpOpenRequest failed\n");
2905 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2906 if (ret)
2908 InternetCloseHandle(req);
2910 req = HttpOpenRequestA(con, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2911 ok(req != NULL, "HttpOpenRequest failed\n");
2913 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2914 ok(ret, "HttpSendRequest failed\n");
2917 InternetCloseHandle(req);
2918 InternetCloseHandle(con);
2919 InternetCloseHandle(ses);
2922 static void test_connection_closing(int port)
2924 HINTERNET session, connection, req;
2925 DWORD res;
2927 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
2929 session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
2930 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
2932 pInternetSetStatusCallbackA(session, callback);
2934 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2935 connection = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
2936 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
2937 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2939 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2940 req = HttpOpenRequestA(connection, "GET", "/testJ", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0xdeadbeaf);
2941 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
2942 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2944 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
2945 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
2946 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
2947 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
2948 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
2949 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
2950 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
2951 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
2952 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION);
2953 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED);
2954 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2956 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
2957 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2958 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2959 WaitForSingleObject(hCompleteEvent, INFINITE);
2960 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2962 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
2963 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
2964 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
2965 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
2966 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
2967 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
2968 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
2969 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
2970 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
2971 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
2972 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
2974 test_status_code(req, 200);
2976 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
2977 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
2978 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
2979 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
2980 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
2981 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
2982 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
2983 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
2984 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2986 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
2987 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2988 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2989 WaitForSingleObject(hCompleteEvent, INFINITE);
2990 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2992 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
2993 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
2994 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
2995 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
2996 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
2997 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
2998 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
2999 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3000 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3002 test_status_code(req, 210);
3004 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3005 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3006 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3007 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3008 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3009 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3010 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3011 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3012 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION);
3013 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED);
3014 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3016 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
3017 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3018 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3019 WaitForSingleObject(hCompleteEvent, INFINITE);
3020 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3022 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3023 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3024 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3025 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3026 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3027 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3028 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3029 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3030 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3031 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3032 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3034 test_status_code(req, 200);
3036 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION);
3037 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED);
3039 close_async_handle(session, hCompleteEvent, 2);
3040 CloseHandle(hCompleteEvent);
3043 static void test_successive_HttpSendRequest(int port)
3045 HINTERNET session, connection, req;
3046 DWORD res;
3048 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
3050 session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
3051 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
3053 pInternetSetStatusCallbackA(session, callback);
3055 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3056 connection = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
3057 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
3058 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3060 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3061 req = HttpOpenRequestA(connection, "GET", "/testH", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0xdeadbeaf);
3062 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
3063 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3065 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3066 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3067 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3068 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3069 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3070 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3071 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3072 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3073 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3075 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
3076 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3077 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3078 WaitForSingleObject(hCompleteEvent, INFINITE);
3079 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3081 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3082 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3083 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3084 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3085 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3086 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3087 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3088 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3089 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3091 test_status_code(req, 210);
3093 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3094 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3095 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3096 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3097 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3098 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3099 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION);
3100 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED);
3101 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3103 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
3104 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3105 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3106 WaitForSingleObject(hCompleteEvent, INFINITE);
3107 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3109 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3110 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3111 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3112 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3113 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3114 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3115 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3116 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3117 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3119 test_status_code(req, 200);
3121 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION);
3122 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED);
3124 close_async_handle(session, hCompleteEvent, 2);
3125 CloseHandle(hCompleteEvent);
3128 static void test_no_content(int port)
3130 HINTERNET session, connection, req;
3131 DWORD res;
3133 trace("Testing 204 no content response...\n");
3135 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
3137 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
3138 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
3140 pInternetSetStatusCallbackA(session, callback);
3142 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3143 connection = InternetConnectA(session, "localhost", port,
3144 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
3145 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
3146 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3148 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3149 req = HttpOpenRequestA(connection, "GET", "/test_no_content", NULL, NULL, NULL,
3150 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
3151 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
3152 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3154 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3155 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3156 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3157 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3158 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3159 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3160 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3161 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
3162 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
3163 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3165 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
3166 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3167 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3168 WaitForSingleObject(hCompleteEvent, INFINITE);
3169 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3171 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3172 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3173 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3174 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3175 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3176 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3177 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3178 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3180 close_async_handle(session, hCompleteEvent, 2);
3181 CloseHandle(hCompleteEvent);
3184 * The connection should be closed before closing handle. This is true for most
3185 * wininet versions (including Wine), but some old win2k versions fail to do that.
3187 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3188 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3191 static void test_conn_close(int port)
3193 HINTERNET session, connection, req;
3194 DWORD res, avail, size;
3195 BYTE buf[1024];
3197 trace("Testing connection close connection...\n");
3199 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
3200 conn_close_event = CreateEventW(NULL, FALSE, FALSE, NULL);
3202 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
3203 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
3205 pInternetSetStatusCallbackA(session, callback);
3207 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3208 connection = InternetConnectA(session, "localhost", port,
3209 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
3210 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
3211 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3213 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3214 req = HttpOpenRequestA(connection, "GET", "/test_conn_close", NULL, NULL, NULL,
3215 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
3216 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
3217 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3219 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3220 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3221 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3222 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3223 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3224 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3225 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3226 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3228 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
3229 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3230 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3231 WaitForSingleObject(hCompleteEvent, INFINITE);
3232 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3234 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3235 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3236 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3237 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3238 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3239 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3240 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3241 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3243 avail = 0;
3244 res = InternetQueryDataAvailable(req, &avail, 0, 0);
3245 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3246 ok(avail != 0, "avail = 0\n");
3248 size = 0;
3249 res = InternetReadFile(req, buf, avail, &size);
3250 ok(res, "InternetReadFile failed: %u\n", GetLastError());
3252 /* IE11 calls those in InternetQueryDataAvailable call. */
3253 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE);
3254 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED);
3256 res = InternetQueryDataAvailable(req, &avail, 0, 0);
3257 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3258 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3259 ok(!avail, "avail = %u, expected 0\n", avail);
3261 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3263 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
3264 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
3265 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3266 SetEvent(conn_close_event);
3267 WaitForSingleObject(hCompleteEvent, INFINITE);
3268 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3269 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3270 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3271 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3272 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3274 close_async_handle(session, hCompleteEvent, 2);
3275 CloseHandle(hCompleteEvent);
3278 static void test_no_cache(int port)
3280 static const char cache_control_no_cache[] = "/test_cache_control_no_cache";
3281 static const char cache_control_no_store[] = "/test_cache_control_no_store";
3282 static const char cache_url_fmt[] = "http://localhost:%d%s";
3284 char cache_url[256], buf[256];
3285 HINTERNET ses, con, req;
3286 DWORD read, size;
3287 BOOL ret;
3289 trace("Testing no-cache header\n");
3291 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3292 ok(ses != NULL,"InternetOpen failed with error %u\n", GetLastError());
3294 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3295 ok(con != NULL, "InternetConnect failed with error %u\n", GetLastError());
3297 req = HttpOpenRequestA(con, NULL, cache_control_no_cache, NULL, NULL, NULL, 0, 0);
3298 ok(req != NULL, "HttpOpenRequest failed\n");
3300 sprintf(cache_url, cache_url_fmt, port, cache_control_no_cache);
3301 DeleteUrlCacheEntryA(cache_url);
3303 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3304 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3305 size = 0;
3306 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
3307 size += read;
3308 ok(size == 12, "read %d bytes of data\n", size);
3309 InternetCloseHandle(req);
3311 req = HttpOpenRequestA(con, NULL, cache_control_no_cache, NULL, NULL, NULL, 0, 0);
3312 ok(req != NULL, "HttpOpenRequest failed\n");
3314 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3315 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3316 size = 0;
3317 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
3318 size += read;
3319 ok(size == 0, "read %d bytes of data\n", size);
3320 InternetCloseHandle(req);
3321 DeleteUrlCacheEntryA(cache_url);
3323 req = HttpOpenRequestA(con, NULL, cache_control_no_store, NULL, NULL, NULL, 0, 0);
3324 ok(req != NULL, "HttpOpenRequest failed\n");
3326 sprintf(cache_url, cache_url_fmt, port, cache_control_no_store);
3327 DeleteUrlCacheEntryA(cache_url);
3329 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3330 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3331 size = 0;
3332 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
3333 size += read;
3334 ok(size == 12, "read %d bytes of data\n", size);
3335 InternetCloseHandle(req);
3337 ret = DeleteUrlCacheEntryA(cache_url);
3338 ok(!ret && GetLastError()==ERROR_FILE_NOT_FOUND, "cache entry should not exist\n");
3340 InternetCloseHandle(con);
3341 InternetCloseHandle(ses);
3344 static void test_cache_read_gzipped(int port)
3346 static const char cache_url_fmt[] = "http://localhost:%d%s";
3347 static const char get_gzip[] = "/test_cache_gzip";
3348 static const char content[] = "gzip test\n";
3349 static const char text_html[] = "text/html";
3350 static const char raw_header[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3352 HINTERNET ses, con, req;
3353 DWORD read, size;
3354 char cache_url[256], buf[256];
3355 BOOL ret;
3357 trace("Testing reading compressed content from cache\n");
3359 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3360 ok(ses != NULL,"InternetOpen failed with error %u\n", GetLastError());
3362 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3363 ok(con != NULL, "InternetConnect failed with error %u\n", GetLastError());
3365 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, 0, 0);
3366 ok(req != NULL, "HttpOpenRequest failed\n");
3368 ret = TRUE;
3369 ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
3370 if(!ret && GetLastError()==ERROR_INTERNET_INVALID_OPTION) {
3371 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3372 InternetCloseHandle(req);
3373 InternetCloseHandle(con);
3374 InternetCloseHandle(ses);
3375 return;
3377 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3379 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3380 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3381 size = 0;
3382 while(InternetReadFile(req, buf+size, sizeof(buf)-size, &read) && read)
3383 size += read;
3384 ok(size == 10, "read %d bytes of data\n", size);
3385 buf[size] = 0;
3386 ok(!strncmp(buf, content, size), "incorrect page content: %s\n", buf);
3388 size = sizeof(buf)-1;
3389 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_TYPE, buf, &size, 0);
3390 ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3391 buf[size] = 0;
3392 ok(!strncmp(text_html, buf, size), "buf = %s\n", buf);
3394 size = sizeof(buf)-1;
3395 ret = HttpQueryInfoA(req, HTTP_QUERY_RAW_HEADERS_CRLF, buf, &size, 0);
3396 ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3397 buf[size] = 0;
3398 ok(!strncmp(raw_header, buf, size), "buf = %s\n", buf);
3399 InternetCloseHandle(req);
3401 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
3402 ok(req != NULL, "HttpOpenRequest failed\n");
3404 ret = TRUE;
3405 ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
3406 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3408 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3409 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3410 size = 0;
3411 while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read)
3412 size += read;
3413 todo_wine ok(size == 10, "read %d bytes of data\n", size);
3414 buf[size] = 0;
3415 ok(!strncmp(buf, content, size), "incorrect page content: %s\n", buf);
3417 size = sizeof(buf);
3418 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
3419 ok(!ret && GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND,
3420 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3421 ret, GetLastError());
3423 size = sizeof(buf)-1;
3424 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_TYPE, buf, &size, 0);
3425 todo_wine ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3426 buf[size] = 0;
3427 todo_wine ok(!strncmp(text_html, buf, size), "buf = %s\n", buf);
3428 InternetCloseHandle(req);
3430 /* Decompression doesn't work while reading from cache */
3431 test_cache_gzip = 0;
3432 sprintf(cache_url, cache_url_fmt, port, get_gzip);
3433 DeleteUrlCacheEntryA(cache_url);
3435 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, 0, 0);
3436 ok(req != NULL, "HttpOpenRequest failed\n");
3438 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3439 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3440 size = 0;
3441 while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read)
3442 size += read;
3443 ok(size == 31, "read %d bytes of data\n", size);
3444 InternetCloseHandle(req);
3446 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
3447 ok(req != NULL, "HttpOpenRequest failed\n");
3449 ret = TRUE;
3450 ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
3451 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3453 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3454 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3455 size = 0;
3456 while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read)
3457 size += read;
3458 todo_wine ok(size == 31, "read %d bytes of data\n", size);
3460 size = sizeof(buf);
3461 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
3462 todo_wine ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3463 InternetCloseHandle(req);
3465 InternetCloseHandle(con);
3466 InternetCloseHandle(ses);
3468 DeleteUrlCacheEntryA(cache_url);
3471 static void test_HttpSendRequestW(int port)
3473 static const WCHAR header[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3474 HINTERNET ses, con, req;
3475 DWORD error;
3476 BOOL ret;
3478 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
3479 ok(ses != NULL, "InternetOpen failed\n");
3481 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3482 ok(con != NULL, "InternetConnect failed\n");
3484 req = HttpOpenRequestA(con, NULL, "/test1", NULL, NULL, NULL, 0, 0);
3485 ok(req != NULL, "HttpOpenRequest failed\n");
3487 SetLastError(0xdeadbeef);
3488 ret = HttpSendRequestW(req, header, ~0u, NULL, 0);
3489 error = GetLastError();
3490 ok(!ret, "HttpSendRequestW succeeded\n");
3491 ok(error == ERROR_IO_PENDING ||
3492 broken(error == ERROR_HTTP_HEADER_NOT_FOUND) || /* IE6 */
3493 broken(error == ERROR_INVALID_PARAMETER), /* IE5 */
3494 "got %u expected ERROR_IO_PENDING\n", error);
3496 InternetCloseHandle(req);
3497 InternetCloseHandle(con);
3498 InternetCloseHandle(ses);
3501 static void test_cookie_header(int port)
3503 HINTERNET ses, con, req;
3504 DWORD size, error;
3505 BOOL ret;
3506 char buffer[64];
3508 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3509 ok(ses != NULL, "InternetOpen failed\n");
3511 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3512 ok(con != NULL, "InternetConnect failed\n");
3514 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3516 req = HttpOpenRequestA(con, NULL, "/testC", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3517 ok(req != NULL, "HttpOpenRequest failed\n");
3519 buffer[0] = 0;
3520 size = sizeof(buffer);
3521 SetLastError(0xdeadbeef);
3522 ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3523 error = GetLastError();
3524 ok(!ret, "HttpQueryInfo succeeded\n");
3525 ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error);
3527 ret = HttpAddRequestHeadersA(req, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD);
3528 ok(ret, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3530 buffer[0] = 0;
3531 size = sizeof(buffer);
3532 ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3533 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
3534 ok(!strcmp(buffer, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer);
3536 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3537 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
3539 test_status_code(req, 200);
3541 buffer[0] = 0;
3542 size = sizeof(buffer);
3543 ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3544 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
3545 ok(!strcmp(buffer, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer);
3547 InternetCloseHandle(req);
3548 InternetCloseHandle(con);
3549 InternetCloseHandle(ses);
3552 static void test_basic_authentication(int port)
3554 HINTERNET session, connect, request;
3555 BOOL ret;
3557 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3558 ok(session != NULL, "InternetOpen failed\n");
3560 connect = InternetConnectA(session, "localhost", port, "user", "pwd", INTERNET_SERVICE_HTTP, 0, 0);
3561 ok(connect != NULL, "InternetConnect failed\n");
3563 request = HttpOpenRequestA(connect, NULL, "/test3", NULL, NULL, NULL, 0, 0);
3564 ok(request != NULL, "HttpOpenRequest failed\n");
3566 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
3567 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
3569 test_status_code(request, 200);
3570 test_request_flags(request, 0);
3572 InternetCloseHandle(request);
3573 InternetCloseHandle(connect);
3574 InternetCloseHandle(session);
3577 static void test_premature_disconnect(int port)
3579 HINTERNET session, connect, request;
3580 DWORD err;
3581 BOOL ret;
3583 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3584 ok(session != NULL, "InternetOpen failed\n");
3586 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3587 ok(connect != NULL, "InternetConnect failed\n");
3589 request = HttpOpenRequestA(connect, NULL, "/premature_disconnect", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3590 ok(request != NULL, "HttpOpenRequest failed\n");
3592 SetLastError(0xdeadbeef);
3593 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
3594 err = GetLastError();
3595 todo_wine ok(!ret, "HttpSendRequest succeeded\n");
3596 todo_wine ok(err == ERROR_HTTP_INVALID_SERVER_RESPONSE, "got %u\n", err);
3598 InternetCloseHandle(request);
3599 InternetCloseHandle(connect);
3600 InternetCloseHandle(session);
3603 static void test_invalid_response_headers(int port)
3605 HINTERNET session, connect, request;
3606 DWORD size;
3607 BOOL ret;
3608 char buffer[256];
3610 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3611 ok(session != NULL, "InternetOpen failed\n");
3613 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3614 ok(connect != NULL, "InternetConnect failed\n");
3616 request = HttpOpenRequestA(connect, NULL, "/testE", NULL, NULL, NULL, 0, 0);
3617 ok(request != NULL, "HttpOpenRequest failed\n");
3619 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
3620 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
3622 test_status_code(request, 401);
3623 test_request_flags(request, 0);
3625 buffer[0] = 0;
3626 size = sizeof(buffer);
3627 ret = HttpQueryInfoA( request, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
3628 ok(ret, "HttpQueryInfo failed\n");
3629 ok(!strcmp(buffer, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
3630 "headers wrong \"%s\"\n", buffer);
3632 buffer[0] = 0;
3633 size = sizeof(buffer);
3634 ret = HttpQueryInfoA( request, HTTP_QUERY_SERVER, buffer, &size, NULL);
3635 ok(ret, "HttpQueryInfo failed\n");
3636 ok(!strcmp(buffer, "winetest"), "server wrong \"%s\"\n", buffer);
3638 InternetCloseHandle(request);
3639 InternetCloseHandle(connect);
3640 InternetCloseHandle(session);
3643 static void test_response_without_headers(int port)
3645 HINTERNET hi, hc, hr;
3646 DWORD r, count, size;
3647 char buffer[1024];
3649 SetLastError(0xdeadbeef);
3650 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3651 ok(hi != NULL, "open failed %u\n", GetLastError());
3653 SetLastError(0xdeadbeef);
3654 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3655 ok(hc != NULL, "connect failed %u\n", GetLastError());
3657 SetLastError(0xdeadbeef);
3658 hr = HttpOpenRequestA(hc, NULL, "/testG", NULL, NULL, NULL, 0, 0);
3659 ok(hr != NULL, "HttpOpenRequest failed %u\n", GetLastError());
3661 test_request_flags(hr, INTERNET_REQFLAG_NO_HEADERS);
3663 SetLastError(0xdeadbeef);
3664 r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
3665 ok(r, "HttpSendRequest failed %u\n", GetLastError());
3667 test_request_flags_todo(hr, INTERNET_REQFLAG_NO_HEADERS);
3669 count = 0;
3670 memset(buffer, 0, sizeof buffer);
3671 SetLastError(0xdeadbeef);
3672 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
3673 ok(r, "InternetReadFile failed %u\n", GetLastError());
3674 todo_wine ok(count == sizeof page1 - 1, "count was wrong\n");
3675 todo_wine ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
3677 test_status_code(hr, 200);
3678 test_request_flags_todo(hr, INTERNET_REQFLAG_NO_HEADERS);
3680 buffer[0] = 0;
3681 size = sizeof(buffer);
3682 SetLastError(0xdeadbeef);
3683 r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, NULL );
3684 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
3685 ok(!strcmp(buffer, "OK"), "expected OK got: \"%s\"\n", buffer);
3687 buffer[0] = 0;
3688 size = sizeof(buffer);
3689 SetLastError(0xdeadbeef);
3690 r = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &size, NULL);
3691 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
3692 ok(!strcmp(buffer, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer);
3694 buffer[0] = 0;
3695 size = sizeof(buffer);
3696 SetLastError(0xdeadbeef);
3697 r = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
3698 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
3699 ok(!strcmp(buffer, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer);
3701 InternetCloseHandle(hr);
3702 InternetCloseHandle(hc);
3703 InternetCloseHandle(hi);
3706 static void test_head_request(int port)
3708 DWORD len, content_length;
3709 HINTERNET ses, con, req;
3710 BYTE buf[100];
3711 BOOL ret;
3713 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3714 ok(ses != NULL, "InternetOpen failed\n");
3716 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3717 ok(con != NULL, "InternetConnect failed\n");
3719 req = HttpOpenRequestA(con, "HEAD", "/test_head", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3720 ok(req != NULL, "HttpOpenRequest failed\n");
3722 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3723 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
3725 len = sizeof(content_length);
3726 content_length = -1;
3727 ret = HttpQueryInfoA(req, HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_CONTENT_LENGTH, &content_length, &len, 0);
3728 ok(ret, "HttpQueryInfo dailed: %u\n", GetLastError());
3729 ok(len == sizeof(DWORD), "len = %u\n", len);
3730 ok(content_length == 100, "content_length = %u\n", content_length);
3732 len = -1;
3733 ret = InternetReadFile(req, buf, sizeof(buf), &len);
3734 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
3736 len = -1;
3737 ret = InternetReadFile(req, buf, sizeof(buf), &len);
3738 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
3740 InternetCloseHandle(req);
3741 InternetCloseHandle(con);
3742 InternetCloseHandle(ses);
3745 static void test_HttpQueryInfo(int port)
3747 HINTERNET hi, hc, hr;
3748 DWORD size, index, error;
3749 char buffer[1024];
3750 BOOL ret;
3752 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3753 ok(hi != NULL, "InternetOpen failed\n");
3755 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3756 ok(hc != NULL, "InternetConnect failed\n");
3758 hr = HttpOpenRequestA(hc, NULL, "/testD", NULL, NULL, NULL, 0, 0);
3759 ok(hr != NULL, "HttpOpenRequest failed\n");
3761 size = sizeof(buffer);
3762 ret = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
3763 error = GetLastError();
3764 ok(!ret || broken(ret), "HttpQueryInfo succeeded\n");
3765 if (!ret) ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error);
3767 ret = HttpSendRequestA(hr, NULL, 0, NULL, 0);
3768 ok(ret, "HttpSendRequest failed\n");
3770 index = 0;
3771 size = sizeof(buffer);
3772 ret = HttpQueryInfoA(hr, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &index);
3773 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3774 ok(index == 1, "expected 1 got %u\n", index);
3776 index = 0;
3777 size = sizeof(buffer);
3778 ret = HttpQueryInfoA(hr, HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME, buffer, &size, &index);
3779 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3780 ok(index == 1, "expected 1 got %u\n", index);
3782 index = 0;
3783 size = sizeof(buffer);
3784 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
3785 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3786 ok(index == 0, "expected 0 got %u\n", index);
3788 size = sizeof(buffer);
3789 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
3790 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3791 ok(index == 0, "expected 0 got %u\n", index);
3793 index = 0xdeadbeef; /* invalid start index */
3794 size = sizeof(buffer);
3795 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
3796 todo_wine ok(!ret, "HttpQueryInfo should have failed\n");
3797 todo_wine ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
3798 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
3800 index = 0;
3801 size = sizeof(buffer);
3802 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS_CRLF, buffer, &size, &index);
3803 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3804 ok(index == 0, "expected 0 got %u\n", index);
3806 size = sizeof(buffer);
3807 ret = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
3808 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3809 ok(index == 0, "expected 0 got %u\n", index);
3811 size = sizeof(buffer);
3812 ret = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &size, &index);
3813 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3814 ok(index == 0, "expected 0 got %u\n", index);
3816 test_status_code(hr, 200);
3818 index = 0xdeadbeef;
3819 size = sizeof(buffer);
3820 ret = HttpQueryInfoA(hr, HTTP_QUERY_FORWARDED, buffer, &size, &index);
3821 ok(!ret, "HttpQueryInfo succeeded\n");
3822 ok(index == 0xdeadbeef, "expected 0xdeadbeef got %u\n", index);
3824 index = 0;
3825 size = sizeof(buffer);
3826 ret = HttpQueryInfoA(hr, HTTP_QUERY_SERVER, buffer, &size, &index);
3827 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3828 ok(index == 1, "expected 1 got %u\n", index);
3830 index = 0;
3831 size = sizeof(buffer);
3832 strcpy(buffer, "Server");
3833 ret = HttpQueryInfoA(hr, HTTP_QUERY_CUSTOM, buffer, &size, &index);
3834 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3835 ok(index == 1, "expected 1 got %u\n", index);
3837 index = 0;
3838 size = sizeof(buffer);
3839 ret = HttpQueryInfoA(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
3840 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3841 ok(index == 1, "expected 1 got %u\n", index);
3843 size = sizeof(buffer);
3844 ret = HttpQueryInfoA(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
3845 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3846 ok(index == 2, "expected 2 got %u\n", index);
3848 InternetCloseHandle(hr);
3849 InternetCloseHandle(hc);
3850 InternetCloseHandle(hi);
3853 static void test_options(int port)
3855 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi;
3856 HINTERNET ses, con, req;
3857 DWORD size, error;
3858 DWORD_PTR ctx;
3859 BOOL ret;
3861 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3862 ok(ses != NULL, "InternetOpen failed\n");
3864 SetLastError(0xdeadbeef);
3865 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, 0);
3866 error = GetLastError();
3867 ok(!ret, "InternetSetOption succeeded\n");
3868 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3870 SetLastError(0xdeadbeef);
3871 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, sizeof(ctx));
3872 ok(!ret, "InternetSetOption succeeded\n");
3873 error = GetLastError();
3874 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3876 SetLastError(0xdeadbeef);
3877 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, 0);
3878 ok(!ret, "InternetSetOption succeeded\n");
3879 error = GetLastError();
3880 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3882 ctx = 1;
3883 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
3884 ok(ret, "InternetSetOption failed %u\n", GetLastError());
3886 SetLastError(0xdeadbeef);
3887 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, NULL);
3888 error = GetLastError();
3889 ok(!ret, "InternetQueryOption succeeded\n");
3890 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3892 SetLastError(0xdeadbeef);
3893 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, NULL);
3894 error = GetLastError();
3895 ok(!ret, "InternetQueryOption succeeded\n");
3896 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3898 size = 0;
3899 SetLastError(0xdeadbeef);
3900 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, &size);
3901 error = GetLastError();
3902 ok(!ret, "InternetQueryOption succeeded\n");
3903 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
3905 size = sizeof(ctx);
3906 SetLastError(0xdeadbeef);
3907 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3908 error = GetLastError();
3909 ok(!ret, "InternetQueryOption succeeded\n");
3910 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error);
3912 ctx = 0xdeadbeef;
3913 size = sizeof(ctx);
3914 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3915 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3916 ok(ctx == 1, "expected 1 got %lu\n", ctx);
3918 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3919 ok(con != NULL, "InternetConnect failed\n");
3921 ctx = 0xdeadbeef;
3922 size = sizeof(ctx);
3923 ret = InternetQueryOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3924 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3925 ok(ctx == 0, "expected 0 got %lu\n", ctx);
3927 ctx = 2;
3928 ret = InternetSetOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
3929 ok(ret, "InternetSetOption failed %u\n", GetLastError());
3931 ctx = 0xdeadbeef;
3932 size = sizeof(ctx);
3933 ret = InternetQueryOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3934 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3935 ok(ctx == 2, "expected 2 got %lu\n", ctx);
3937 req = HttpOpenRequestA(con, NULL, "/test1", NULL, NULL, NULL, 0, 0);
3938 ok(req != NULL, "HttpOpenRequest failed\n");
3940 ctx = 0xdeadbeef;
3941 size = sizeof(ctx);
3942 ret = InternetQueryOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3943 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3944 ok(ctx == 0, "expected 0 got %lu\n", ctx);
3946 ctx = 3;
3947 ret = InternetSetOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
3948 ok(ret, "InternetSetOption failed %u\n", GetLastError());
3950 ctx = 0xdeadbeef;
3951 size = sizeof(ctx);
3952 ret = InternetQueryOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3953 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3954 ok(ctx == 3, "expected 3 got %lu\n", ctx);
3956 size = sizeof(idsi);
3957 ret = InternetQueryOptionA(req, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO, &idsi, &size);
3958 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3960 size = 0;
3961 SetLastError(0xdeadbeef);
3962 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, NULL, &size);
3963 error = GetLastError();
3964 ok(!ret, "InternetQueryOption succeeded\n");
3965 ok(error == ERROR_INTERNET_INVALID_OPERATION, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error);
3967 /* INTERNET_OPTION_PROXY */
3968 SetLastError(0xdeadbeef);
3969 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, NULL);
3970 error = GetLastError();
3971 ok(!ret, "InternetQueryOption succeeded\n");
3972 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3974 SetLastError(0xdeadbeef);
3975 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, &ctx, NULL);
3976 error = GetLastError();
3977 ok(!ret, "InternetQueryOption succeeded\n");
3978 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3980 size = 0;
3981 SetLastError(0xdeadbeef);
3982 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, &size);
3983 error = GetLastError();
3984 ok(!ret, "InternetQueryOption succeeded\n");
3985 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
3986 ok(size >= sizeof(INTERNET_PROXY_INFOA), "expected size to be greater or equal to the struct size\n");
3988 InternetCloseHandle(req);
3989 InternetCloseHandle(con);
3990 InternetCloseHandle(ses);
3993 typedef struct {
3994 const char *response_text;
3995 int status_code;
3996 const char *status_text;
3997 const char *raw_headers;
3998 } http_status_test_t;
4000 static const http_status_test_t http_status_tests[] = {
4002 "HTTP/1.1 200 OK\r\n"
4003 "Content-Length: 1\r\n"
4004 "\r\nx",
4005 200,
4006 "OK"
4009 "HTTP/1.1 404 Fail\r\n"
4010 "Content-Length: 1\r\n"
4011 "\r\nx",
4012 404,
4013 "Fail"
4016 "HTTP/1.1 200\r\n"
4017 "Content-Length: 1\r\n"
4018 "\r\nx",
4019 200,
4023 "HTTP/1.1 410 \r\n"
4024 "Content-Length: 1\r\n"
4025 "\r\nx",
4026 410,
4031 static void test_http_status(int port)
4033 HINTERNET ses, con, req;
4034 char buf[1000];
4035 DWORD i, size;
4036 BOOL res;
4038 for(i=0; i < sizeof(http_status_tests)/sizeof(*http_status_tests); i++) {
4039 send_buffer = http_status_tests[i].response_text;
4041 ses = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4042 ok(ses != NULL, "InternetOpen failed\n");
4044 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4045 ok(con != NULL, "InternetConnect failed\n");
4047 req = HttpOpenRequestA(con, NULL, "/send_from_buffer", NULL, NULL, NULL, 0, 0);
4048 ok(req != NULL, "HttpOpenRequest failed\n");
4050 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4051 ok(res, "HttpSendRequest failed\n");
4053 test_status_code(req, http_status_tests[i].status_code);
4055 size = sizeof(buf);
4056 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_TEXT, buf, &size, NULL);
4057 ok(res, "HttpQueryInfo failed: %u\n", GetLastError());
4058 ok(!strcmp(buf, http_status_tests[i].status_text), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
4059 i, buf, http_status_tests[i].status_text);
4061 InternetCloseHandle(req);
4062 InternetCloseHandle(con);
4063 InternetCloseHandle(ses);
4067 static void test_cache_control_verb(int port)
4069 HINTERNET session, connect, request;
4070 BOOL ret;
4072 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4073 ok(session != NULL, "InternetOpen failed\n");
4075 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4076 ok(connect != NULL, "InternetConnect failed\n");
4078 request = HttpOpenRequestA(connect, "RPC_OUT_DATA", "/test_cache_control_verb", NULL, NULL, NULL,
4079 INTERNET_FLAG_NO_CACHE_WRITE, 0);
4080 ok(request != NULL, "HttpOpenRequest failed\n");
4081 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4082 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4083 test_status_code(request, 200);
4084 InternetCloseHandle(request);
4086 request = HttpOpenRequestA(connect, "POST", "/test_cache_control_verb", NULL, NULL, NULL,
4087 INTERNET_FLAG_NO_CACHE_WRITE, 0);
4088 ok(request != NULL, "HttpOpenRequest failed\n");
4089 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4090 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4091 test_status_code(request, 200);
4092 InternetCloseHandle(request);
4094 request = HttpOpenRequestA(connect, "HEAD", "/test_cache_control_verb", NULL, NULL, NULL,
4095 INTERNET_FLAG_NO_CACHE_WRITE, 0);
4096 ok(request != NULL, "HttpOpenRequest failed\n");
4097 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4098 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4099 test_status_code(request, 200);
4100 InternetCloseHandle(request);
4102 request = HttpOpenRequestA(connect, "GET", "/test_cache_control_verb", NULL, NULL, NULL,
4103 INTERNET_FLAG_NO_CACHE_WRITE, 0);
4104 ok(request != NULL, "HttpOpenRequest failed\n");
4105 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4106 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4107 test_status_code(request, 200);
4108 InternetCloseHandle(request);
4110 InternetCloseHandle(connect);
4111 InternetCloseHandle(session);
4114 static void test_http_connection(void)
4116 struct server_info si;
4117 HANDLE hThread;
4118 DWORD id = 0, r;
4120 si.hEvent = CreateEventW(NULL, 0, 0, NULL);
4121 si.port = 7531;
4123 hThread = CreateThread(NULL, 0, server_thread, (LPVOID) &si, 0, &id);
4124 ok( hThread != NULL, "create thread failed\n");
4126 r = WaitForSingleObject(si.hEvent, 10000);
4127 ok (r == WAIT_OBJECT_0, "failed to start wininet test server\n");
4128 if (r != WAIT_OBJECT_0)
4129 return;
4131 test_basic_request(si.port, "GET", "/test1");
4132 test_proxy_indirect(si.port);
4133 test_proxy_direct(si.port);
4134 test_header_handling_order(si.port);
4135 test_basic_request(si.port, "POST", "/test5");
4136 test_basic_request(si.port, "RPC_IN_DATA", "/test5");
4137 test_basic_request(si.port, "RPC_OUT_DATA", "/test5");
4138 test_basic_request(si.port, "GET", "/test6");
4139 test_basic_request(si.port, "GET", "/testF");
4140 test_connection_header(si.port);
4141 test_http1_1(si.port);
4142 test_cookie_header(si.port);
4143 test_basic_authentication(si.port);
4144 test_invalid_response_headers(si.port);
4145 test_response_without_headers(si.port);
4146 test_HttpQueryInfo(si.port);
4147 test_HttpSendRequestW(si.port);
4148 test_options(si.port);
4149 test_no_content(si.port);
4150 test_conn_close(si.port);
4151 test_no_cache(si.port);
4152 test_cache_read_gzipped(si.port);
4153 test_http_status(si.port);
4154 test_premature_disconnect(si.port);
4155 test_connection_closing(si.port);
4156 test_cache_control_verb(si.port);
4157 test_successive_HttpSendRequest(si.port);
4158 test_head_request(si.port);
4160 /* send the basic request again to shutdown the server thread */
4161 test_basic_request(si.port, "GET", "/quit");
4163 r = WaitForSingleObject(hThread, 3000);
4164 ok( r == WAIT_OBJECT_0, "thread wait failed\n");
4165 CloseHandle(hThread);
4168 static void release_cert_info(INTERNET_CERTIFICATE_INFOA *info)
4170 LocalFree(info->lpszSubjectInfo);
4171 LocalFree(info->lpszIssuerInfo);
4172 LocalFree(info->lpszProtocolName);
4173 LocalFree(info->lpszSignatureAlgName);
4174 LocalFree(info->lpszEncryptionAlgName);
4177 typedef struct {
4178 const char *ex_subject;
4179 const char *ex_issuer;
4180 } cert_struct_test_t;
4182 static const cert_struct_test_t test_winehq_org_cert = {
4183 "GT98380011\r\n"
4184 "See www.rapidssl.com/resources/cps (c)14\r\n"
4185 "Domain Control Validated - RapidSSL(R)\r\n"
4186 "*.winehq.org",
4188 "US\r\n"
4189 "GeoTrust Inc.\r\n"
4190 "RapidSSL SHA256 CA - G3"
4193 static const cert_struct_test_t test_winehq_com_cert = {
4194 "US\r\n"
4195 "Minnesota\r\n"
4196 "Saint Paul\r\n"
4197 "WineHQ\r\n"
4198 "test.winehq.com\r\n"
4199 "webmaster@winehq.org",
4201 "US\r\n"
4202 "Minnesota\r\n"
4203 "WineHQ\r\n"
4204 "test.winehq.com\r\n"
4205 "webmaster@winehq.org"
4208 static void test_cert_struct(HINTERNET req, const cert_struct_test_t *test)
4210 INTERNET_CERTIFICATE_INFOA info;
4211 DWORD size;
4212 BOOL res;
4214 memset(&info, 0x5, sizeof(info));
4216 size = sizeof(info);
4217 res = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, &info, &size);
4218 ok(res, "InternetQueryOption failed: %u\n", GetLastError());
4219 ok(size == sizeof(info), "size = %u\n", size);
4221 ok(!strcmp(info.lpszSubjectInfo, test->ex_subject), "lpszSubjectInfo = %s\n", info.lpszSubjectInfo);
4222 ok(!strcmp(info.lpszIssuerInfo, test->ex_issuer), "lpszIssuerInfo = %s\n", info.lpszIssuerInfo);
4223 ok(!info.lpszSignatureAlgName, "lpszSignatureAlgName = %s\n", info.lpszSignatureAlgName);
4224 ok(!info.lpszEncryptionAlgName, "lpszEncryptionAlgName = %s\n", info.lpszEncryptionAlgName);
4225 ok(!info.lpszProtocolName, "lpszProtocolName = %s\n", info.lpszProtocolName);
4226 ok(info.dwKeySize == 128 || info.dwKeySize == 256, "dwKeySize = %u\n", info.dwKeySize);
4228 release_cert_info(&info);
4231 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
4232 static void _test_security_info(unsigned line, const char *urlc, DWORD error, DWORD ex_flags)
4234 char url[INTERNET_MAX_URL_LENGTH];
4235 const CERT_CHAIN_CONTEXT *chain;
4236 DWORD flags;
4237 BOOL res;
4239 if(!pInternetGetSecurityInfoByURLA) {
4240 win_skip("pInternetGetSecurityInfoByURLA not available\n");
4241 return;
4244 strcpy(url, urlc);
4245 chain = (void*)0xdeadbeef;
4246 flags = 0xdeadbeef;
4247 res = pInternetGetSecurityInfoByURLA(url, &chain, &flags);
4248 if(error == ERROR_SUCCESS) {
4249 ok_(__FILE__,line)(res, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
4250 ok_(__FILE__,line)(chain != NULL, "chain = NULL\n");
4251 ok_(__FILE__,line)(flags == ex_flags, "flags = %x\n", flags);
4252 CertFreeCertificateChain(chain);
4253 }else {
4254 ok_(__FILE__,line)(!res && GetLastError() == error,
4255 "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res, GetLastError(), error);
4259 #define test_secflags_option(a,b,c) _test_secflags_option(__LINE__,a,b,c)
4260 static void _test_secflags_option(unsigned line, HINTERNET req, DWORD ex_flags, DWORD opt_flags)
4262 DWORD flags, size;
4263 BOOL res;
4265 flags = 0xdeadbeef;
4266 size = sizeof(flags);
4267 res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
4268 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4269 ok_(__FILE__,line)((flags & ~opt_flags) == ex_flags, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n",
4270 flags, ex_flags);
4272 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
4273 flags = 0xdeadbeef;
4274 size = sizeof(flags);
4275 res = InternetQueryOptionW(req, 98, &flags, &size);
4276 ok_(__FILE__,line)(res, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
4277 ok_(__FILE__,line)((flags & ~opt_flags) == ex_flags, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n",
4278 flags, ex_flags);
4281 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
4282 static void _set_secflags(unsigned line, HINTERNET req, BOOL use_undoc, DWORD flags)
4284 BOOL res;
4286 res = InternetSetOptionW(req, use_undoc ? 99 : INTERNET_OPTION_SECURITY_FLAGS, &flags, sizeof(flags));
4287 ok_(__FILE__,line)(res, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4290 static void test_security_flags(void)
4292 INTERNET_CERTIFICATE_INFOA *cert;
4293 HINTERNET ses, conn, req;
4294 DWORD size, flags;
4295 char buf[100];
4296 BOOL res;
4298 trace("Testing security flags...\n");
4300 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
4302 ses = InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
4303 ok(ses != NULL, "InternetOpen failed\n");
4305 pInternetSetStatusCallbackA(ses, &callback);
4307 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4308 conn = InternetConnectA(ses, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT,
4309 NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0xdeadbeef);
4310 ok(conn != NULL, "InternetConnect failed with error %u\n", GetLastError());
4311 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4313 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4314 req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
4315 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
4316 0xdeadbeef);
4317 ok(req != NULL, "HttpOpenRequest failed\n");
4318 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4320 flags = 0xdeadbeef;
4321 size = sizeof(flags);
4322 res = InternetQueryOptionW(req, 98, &flags, &size);
4323 if(!res && GetLastError() == ERROR_INVALID_PARAMETER) {
4324 win_skip("Incomplete security flags support, skipping\n");
4326 close_async_handle(ses, hCompleteEvent, 2);
4327 CloseHandle(hCompleteEvent);
4328 return;
4331 test_secflags_option(req, 0, 0);
4332 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4334 set_secflags(req, TRUE, SECURITY_FLAG_IGNORE_REVOCATION);
4335 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION, 0);
4337 set_secflags(req, TRUE, SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
4338 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID, 0);
4340 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
4341 test_secflags_option(req, SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID, 0);
4343 flags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_SECURE;
4344 res = InternetSetOptionW(req, 99, &flags, sizeof(flags));
4345 ok(!res && GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE, "InternetSetOption(99) failed: %u\n", GetLastError());
4347 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
4348 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
4349 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4350 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4351 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */
4352 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */
4353 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */
4354 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */
4355 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
4356 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
4357 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
4358 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
4359 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4360 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
4361 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4363 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4364 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4366 WaitForSingleObject(hCompleteEvent, INFINITE);
4367 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
4369 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
4370 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
4371 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2);
4372 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2);
4373 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
4374 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
4375 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
4376 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
4377 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
4378 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
4379 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4380 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
4381 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4383 test_request_flags(req, 0);
4384 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4385 |SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_STRENGTH_STRONG, 0);
4387 res = InternetReadFile(req, buf, sizeof(buf), &size);
4388 ok(res, "InternetReadFile failed: %u\n", GetLastError());
4389 ok(size, "size = 0\n");
4391 /* Collect all existing persistent connections */
4392 res = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
4393 ok(res, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4395 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4396 req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
4397 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
4398 0xdeadbeef);
4399 ok(req != NULL, "HttpOpenRequest failed\n");
4400 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4402 flags = INTERNET_ERROR_MASK_COMBINED_SEC_CERT|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY;
4403 res = InternetSetOptionA(req, INTERNET_OPTION_ERROR_MASK, (void*)&flags, sizeof(flags));
4404 ok(res, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
4406 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4407 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4408 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */
4409 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */
4410 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */
4411 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */
4412 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
4413 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
4414 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4415 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4416 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
4418 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4419 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4421 WaitForSingleObject(hCompleteEvent, INFINITE);
4422 ok(req_error == ERROR_INTERNET_SEC_CERT_REV_FAILED || broken(req_error == ERROR_INTERNET_SEC_CERT_ERRORS),
4423 "req_error = %d\n", req_error);
4425 size = 0;
4426 res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, NULL, &size);
4427 ok(res || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
4428 ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %u\n", size);
4429 cert = HeapAlloc(GetProcessHeap(), 0, size);
4430 cert->lpszSubjectInfo = NULL;
4431 cert->lpszIssuerInfo = NULL;
4432 cert->lpszSignatureAlgName = (char *)0xdeadbeef;
4433 cert->lpszEncryptionAlgName = (char *)0xdeadbeef;
4434 cert->lpszProtocolName = (char *)0xdeadbeef;
4435 cert->dwKeySize = 0xdeadbeef;
4436 res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, cert, &size);
4437 ok(res, "InternetQueryOption failed: %u\n", GetLastError());
4438 if (res)
4440 ok(cert->lpszSubjectInfo && strlen(cert->lpszSubjectInfo) > 1, "expected a non-empty subject name\n");
4441 ok(cert->lpszIssuerInfo && strlen(cert->lpszIssuerInfo) > 1, "expected a non-empty issuer name\n");
4442 ok(!cert->lpszSignatureAlgName, "unexpected signature algorithm name\n");
4443 ok(!cert->lpszEncryptionAlgName, "unexpected encryption algorithm name\n");
4444 ok(!cert->lpszProtocolName, "unexpected protocol name\n");
4445 ok(cert->dwKeySize != 0xdeadbeef, "unexpected key size\n");
4447 HeapFree(GetProcessHeap(), 0, cert);
4449 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2);
4450 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2);
4451 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
4452 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
4453 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4454 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4455 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
4457 if(req_error != ERROR_INTERNET_SEC_CERT_REV_FAILED) {
4458 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error);
4460 close_async_handle(ses, hCompleteEvent, 3);
4461 CloseHandle(hCompleteEvent);
4462 return;
4465 size = sizeof(buf);
4466 res = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
4467 ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
4469 test_request_flags(req, 8);
4470 /* IE11 finds both rev failure and invalid CA. Previous versions required rev failure
4471 to be ignored before invalid CA was reported. */
4472 test_secflags_option(req, _SECURITY_FLAG_CERT_REV_FAILED, _SECURITY_FLAG_CERT_INVALID_CA);
4474 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_REVOCATION);
4475 test_secflags_option(req, _SECURITY_FLAG_CERT_REV_FAILED|SECURITY_FLAG_IGNORE_REVOCATION, _SECURITY_FLAG_CERT_INVALID_CA);
4477 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4478 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4479 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
4480 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
4481 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4482 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4483 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
4485 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4486 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4488 WaitForSingleObject(hCompleteEvent, INFINITE);
4489 ok(req_error == ERROR_INTERNET_SEC_CERT_ERRORS, "req_error = %d\n", req_error);
4491 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
4492 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
4493 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
4494 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
4495 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4496 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4497 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
4499 test_request_flags(req, INTERNET_REQFLAG_NO_HEADERS);
4500 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION|_SECURITY_FLAG_CERT_REV_FAILED|_SECURITY_FLAG_CERT_INVALID_CA, 0);
4501 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4503 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
4504 test_secflags_option(req, _SECURITY_FLAG_CERT_INVALID_CA|_SECURITY_FLAG_CERT_REV_FAILED
4505 |SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_UNKNOWN_CA, 0);
4506 test_http_version(req);
4508 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4509 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4510 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */
4511 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */
4512 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */
4513 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */
4514 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
4515 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
4516 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
4517 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
4518 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4519 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4520 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
4522 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4523 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4525 WaitForSingleObject(hCompleteEvent, INFINITE);
4526 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
4528 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2);
4529 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2);
4530 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
4531 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
4532 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
4533 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
4534 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
4535 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
4536 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4537 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4538 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
4540 test_request_flags(req, 0);
4541 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION
4542 |SECURITY_FLAG_STRENGTH_STRONG|_SECURITY_FLAG_CERT_REV_FAILED|_SECURITY_FLAG_CERT_INVALID_CA, 0);
4544 test_cert_struct(req, &test_winehq_com_cert);
4545 test_security_info("https://test.winehq.com/data/some_file.html?q", 0,
4546 _SECURITY_FLAG_CERT_INVALID_CA|_SECURITY_FLAG_CERT_REV_FAILED);
4548 res = InternetReadFile(req, buf, sizeof(buf), &size);
4549 ok(res, "InternetReadFile failed: %u\n", GetLastError());
4550 ok(size, "size = 0\n");
4552 close_async_handle(ses, hCompleteEvent, 3);
4554 /* Collect all existing persistent connections */
4555 res = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
4556 ok(res, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4558 /* Make another request, without setting security flags */
4560 ses = InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
4561 ok(ses != NULL, "InternetOpen failed\n");
4563 pInternetSetStatusCallbackA(ses, &callback);
4565 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4566 conn = InternetConnectA(ses, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT,
4567 NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0xdeadbeef);
4568 ok(conn != NULL, "InternetConnect failed with error %u\n", GetLastError());
4569 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4571 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4572 req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
4573 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
4574 0xdeadbeef);
4575 ok(req != NULL, "HttpOpenRequest failed\n");
4576 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4578 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_STRENGTH_STRONG
4579 |SECURITY_FLAG_IGNORE_REVOCATION|_SECURITY_FLAG_CERT_REV_FAILED|_SECURITY_FLAG_CERT_INVALID_CA, 0);
4580 test_http_version(req);
4582 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4583 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4584 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */
4585 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */
4586 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */
4587 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */
4588 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
4589 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
4590 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
4591 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
4592 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4593 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4595 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4596 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4598 WaitForSingleObject(hCompleteEvent, INFINITE);
4599 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
4601 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2);
4602 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2);
4603 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
4604 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
4605 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
4606 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
4607 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
4608 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
4609 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4610 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4612 test_request_flags(req, 0);
4613 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_STRENGTH_STRONG
4614 |SECURITY_FLAG_IGNORE_REVOCATION|_SECURITY_FLAG_CERT_REV_FAILED|_SECURITY_FLAG_CERT_INVALID_CA, 0);
4616 res = InternetReadFile(req, buf, sizeof(buf), &size);
4617 ok(res, "InternetReadFile failed: %u\n", GetLastError());
4618 ok(size, "size = 0\n");
4620 close_async_handle(ses, hCompleteEvent, 2);
4622 CloseHandle(hCompleteEvent);
4624 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4625 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4626 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4629 static void test_secure_connection(void)
4631 static const WCHAR gizmo5[] = {'G','i','z','m','o','5',0};
4632 static const WCHAR testsite[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
4633 static const WCHAR get[] = {'G','E','T',0};
4634 static const WCHAR testpage[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
4635 HINTERNET ses, con, req;
4636 DWORD size, flags;
4637 INTERNET_CERTIFICATE_INFOA *certificate_structA = NULL;
4638 INTERNET_CERTIFICATE_INFOW *certificate_structW = NULL;
4639 BOOL ret;
4641 ses = InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
4642 ok(ses != NULL, "InternetOpen failed\n");
4644 con = InternetConnectA(ses, "test.winehq.org",
4645 INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL,
4646 INTERNET_SERVICE_HTTP, 0, 0);
4647 ok(con != NULL, "InternetConnect failed\n");
4649 req = HttpOpenRequestA(con, "GET", "/tests/hello.html", NULL, NULL, NULL,
4650 INTERNET_FLAG_SECURE, 0);
4651 ok(req != NULL, "HttpOpenRequest failed\n");
4653 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
4654 ok(ret, "HttpSendRequest failed: %d\n", GetLastError());
4656 size = sizeof(flags);
4657 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
4658 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
4659 ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set\n");
4661 test_cert_struct(req, &test_winehq_org_cert);
4663 /* Querying the same option through InternetQueryOptionW still results in
4664 * ASCII strings being returned.
4666 size = 0;
4667 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
4668 NULL, &size);
4669 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
4670 ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size);
4671 certificate_structW = HeapAlloc(GetProcessHeap(), 0, size);
4672 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
4673 certificate_structW, &size);
4674 certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW;
4675 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
4676 if (ret)
4678 ok(certificate_structA->lpszSubjectInfo &&
4679 strlen(certificate_structA->lpszSubjectInfo) > 1,
4680 "expected a non-empty subject name\n");
4681 ok(certificate_structA->lpszIssuerInfo &&
4682 strlen(certificate_structA->lpszIssuerInfo) > 1,
4683 "expected a non-empty issuer name\n");
4684 ok(!certificate_structA->lpszSignatureAlgName,
4685 "unexpected signature algorithm name\n");
4686 ok(!certificate_structA->lpszEncryptionAlgName,
4687 "unexpected encryption algorithm name\n");
4688 ok(!certificate_structA->lpszProtocolName,
4689 "unexpected protocol name\n");
4690 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
4691 release_cert_info(certificate_structA);
4693 HeapFree(GetProcessHeap(), 0, certificate_structW);
4695 InternetCloseHandle(req);
4696 InternetCloseHandle(con);
4697 InternetCloseHandle(ses);
4699 /* Repeating the tests with the W functions has the same result: */
4700 ses = InternetOpenW(gizmo5, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
4701 ok(ses != NULL, "InternetOpen failed\n");
4703 con = InternetConnectW(ses, testsite,
4704 INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL,
4705 INTERNET_SERVICE_HTTP, 0, 0);
4706 ok(con != NULL, "InternetConnect failed\n");
4708 req = HttpOpenRequestW(con, get, testpage, NULL, NULL, NULL,
4709 INTERNET_FLAG_SECURE|INTERNET_FLAG_RELOAD, 0);
4710 ok(req != NULL, "HttpOpenRequest failed\n");
4712 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
4713 ok(ret, "HttpSendRequest failed: %d\n", GetLastError());
4715 size = sizeof(flags);
4716 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
4717 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
4718 ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set, got %x\n", flags);
4720 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
4721 NULL, &size);
4722 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
4723 ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %d\n", size);
4724 certificate_structA = HeapAlloc(GetProcessHeap(), 0, size);
4725 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
4726 certificate_structA, &size);
4727 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
4728 if (ret)
4730 ok(certificate_structA->lpszSubjectInfo &&
4731 strlen(certificate_structA->lpszSubjectInfo) > 1,
4732 "expected a non-empty subject name\n");
4733 ok(certificate_structA->lpszIssuerInfo &&
4734 strlen(certificate_structA->lpszIssuerInfo) > 1,
4735 "expected a non-empty issuer name\n");
4736 ok(!certificate_structA->lpszSignatureAlgName,
4737 "unexpected signature algorithm name\n");
4738 ok(!certificate_structA->lpszEncryptionAlgName,
4739 "unexpected encryption algorithm name\n");
4740 ok(!certificate_structA->lpszProtocolName,
4741 "unexpected protocol name\n");
4742 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
4743 release_cert_info(certificate_structA);
4745 HeapFree(GetProcessHeap(), 0, certificate_structA);
4747 /* Again, querying the same option through InternetQueryOptionW still
4748 * results in ASCII strings being returned.
4750 size = 0;
4751 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
4752 NULL, &size);
4753 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
4754 ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size);
4755 certificate_structW = HeapAlloc(GetProcessHeap(), 0, size);
4756 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
4757 certificate_structW, &size);
4758 certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW;
4759 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
4760 if (ret)
4762 ok(certificate_structA->lpszSubjectInfo &&
4763 strlen(certificate_structA->lpszSubjectInfo) > 1,
4764 "expected a non-empty subject name\n");
4765 ok(certificate_structA->lpszIssuerInfo &&
4766 strlen(certificate_structA->lpszIssuerInfo) > 1,
4767 "expected a non-empty issuer name\n");
4768 ok(!certificate_structA->lpszSignatureAlgName,
4769 "unexpected signature algorithm name\n");
4770 ok(!certificate_structA->lpszEncryptionAlgName,
4771 "unexpected encryption algorithm name\n");
4772 ok(!certificate_structA->lpszProtocolName,
4773 "unexpected protocol name\n");
4774 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
4775 release_cert_info(certificate_structA);
4777 HeapFree(GetProcessHeap(), 0, certificate_structW);
4779 InternetCloseHandle(req);
4780 InternetCloseHandle(con);
4781 InternetCloseHandle(ses);
4784 static void test_user_agent_header(void)
4786 HINTERNET ses, con, req;
4787 DWORD size, err;
4788 char buffer[64];
4789 BOOL ret;
4791 ses = InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
4792 ok(ses != NULL, "InternetOpen failed\n");
4794 con = InternetConnectA(ses, "test.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4795 ok(con != NULL, "InternetConnect failed\n");
4797 req = HttpOpenRequestA(con, "GET", "/tests/hello.html", "HTTP/1.0", NULL, NULL, 0, 0);
4798 ok(req != NULL, "HttpOpenRequest failed\n");
4800 size = sizeof(buffer);
4801 ret = HttpQueryInfoA(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4802 err = GetLastError();
4803 ok(!ret, "HttpQueryInfo succeeded\n");
4804 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
4806 ret = HttpAddRequestHeadersA(req, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
4807 ok(ret, "HttpAddRequestHeaders succeeded\n");
4809 size = sizeof(buffer);
4810 ret = HttpQueryInfoA(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4811 err = GetLastError();
4812 ok(ret, "HttpQueryInfo failed\n");
4814 InternetCloseHandle(req);
4816 req = HttpOpenRequestA(con, "GET", "/", "HTTP/1.0", NULL, NULL, 0, 0);
4817 ok(req != NULL, "HttpOpenRequest failed\n");
4819 size = sizeof(buffer);
4820 ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4821 err = GetLastError();
4822 ok(!ret, "HttpQueryInfo succeeded\n");
4823 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
4825 ret = HttpAddRequestHeadersA(req, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
4826 ok(ret, "HttpAddRequestHeaders failed\n");
4828 buffer[0] = 0;
4829 size = sizeof(buffer);
4830 ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4831 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
4832 ok(!strcmp(buffer, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer);
4834 InternetCloseHandle(req);
4835 InternetCloseHandle(con);
4836 InternetCloseHandle(ses);
4839 static void test_bogus_accept_types_array(void)
4841 HINTERNET ses, con, req;
4842 static const char *types[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL };
4843 DWORD size, error;
4844 char buffer[32];
4845 BOOL ret;
4847 ses = InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT, "", "", 0);
4848 con = InternetConnectA(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4849 req = HttpOpenRequestA(con, "POST", "/post/post_action.php", "HTTP/1.0", "", types, INTERNET_FLAG_FORMS_SUBMIT, 0);
4851 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
4853 buffer[0] = 0;
4854 size = sizeof(buffer);
4855 SetLastError(0xdeadbeef);
4856 ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4857 error = GetLastError();
4858 ok(!ret || broken(ret), "HttpQueryInfo succeeded\n");
4859 if (!ret) ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error);
4860 ok(broken(!strcmp(buffer, ", */*, %p, , , */*")) /* IE6 */ ||
4861 broken(!strcmp(buffer, "*/*, %p, */*")) /* IE7/8 */ ||
4862 !strcmp(buffer, ""), "got '%s' expected ''\n", buffer);
4864 InternetCloseHandle(req);
4865 InternetCloseHandle(con);
4866 InternetCloseHandle(ses);
4869 struct context
4871 HANDLE event;
4872 HINTERNET req;
4875 static void WINAPI cb(HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID info, DWORD size)
4877 INTERNET_ASYNC_RESULT *result = info;
4878 struct context *ctx = (struct context *)context;
4880 trace("%p 0x%08lx %u %p 0x%08x\n", handle, context, status, info, size);
4882 switch(status) {
4883 case INTERNET_STATUS_REQUEST_COMPLETE:
4884 trace("request handle: 0x%08lx\n", result->dwResult);
4885 ctx->req = (HINTERNET)result->dwResult;
4886 SetEvent(ctx->event);
4887 break;
4888 case INTERNET_STATUS_HANDLE_CLOSING: {
4889 DWORD type = INTERNET_HANDLE_TYPE_CONNECT_HTTP, size = sizeof(type);
4891 if (InternetQueryOptionA(handle, INTERNET_OPTION_HANDLE_TYPE, &type, &size))
4892 ok(type != INTERNET_HANDLE_TYPE_CONNECT_HTTP, "unexpected callback\n");
4893 SetEvent(ctx->event);
4894 break;
4896 case INTERNET_STATUS_NAME_RESOLVED:
4897 case INTERNET_STATUS_CONNECTING_TO_SERVER:
4898 case INTERNET_STATUS_CONNECTED_TO_SERVER: {
4899 char *str = info;
4900 ok(str[0] && str[1], "Got string: %s\n", str);
4901 ok(size == strlen(str)+1, "unexpected size %u\n", size);
4906 static void test_open_url_async(void)
4908 BOOL ret;
4909 HINTERNET ses, req;
4910 DWORD size, error;
4911 struct context ctx;
4912 ULONG type;
4914 /* Collect all existing persistent connections */
4915 ret = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
4916 ok(ret, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4919 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
4920 * other versions never do. They also hang of following tests. We disable it for everything older
4921 * than IE7.
4923 if(!pInternetGetSecurityInfoByURLA) {
4924 win_skip("Skipping async open on too old wininet version.\n");
4925 return;
4928 ctx.req = NULL;
4929 ctx.event = CreateEventA(NULL, TRUE, FALSE, "Z:_home_hans_jaman-installer.exe_ev1");
4931 ses = InternetOpenA("AdvancedInstaller", 0, NULL, NULL, INTERNET_FLAG_ASYNC);
4932 ok(ses != NULL, "InternetOpen failed\n");
4934 SetLastError(0xdeadbeef);
4935 ret = InternetSetOptionA(NULL, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR));
4936 error = GetLastError();
4937 ok(!ret, "InternetSetOptionA succeeded\n");
4938 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error);
4940 ret = InternetSetOptionA(ses, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR));
4941 error = GetLastError();
4942 ok(!ret, "InternetSetOptionA failed\n");
4943 ok(error == ERROR_INTERNET_OPTION_NOT_SETTABLE, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error);
4945 pInternetSetStatusCallbackW(ses, cb);
4946 ResetEvent(ctx.event);
4948 req = InternetOpenUrlA(ses, "http://test.winehq.org", NULL, 0, 0, (DWORD_PTR)&ctx);
4949 ok(!req && GetLastError() == ERROR_IO_PENDING, "InternetOpenUrl failed\n");
4951 WaitForSingleObject(ctx.event, INFINITE);
4953 type = 0;
4954 size = sizeof(type);
4955 ret = InternetQueryOptionA(ctx.req, INTERNET_OPTION_HANDLE_TYPE, &type, &size);
4956 ok(ret, "InternetQueryOption failed: %u\n", GetLastError());
4957 ok(type == INTERNET_HANDLE_TYPE_HTTP_REQUEST,
4958 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type);
4960 size = 0;
4961 ret = HttpQueryInfoA(ctx.req, HTTP_QUERY_RAW_HEADERS_CRLF, NULL, &size, NULL);
4962 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "HttpQueryInfo failed\n");
4963 ok(size > 0, "expected size > 0\n");
4965 ResetEvent(ctx.event);
4966 InternetCloseHandle(ctx.req);
4967 WaitForSingleObject(ctx.event, INFINITE);
4969 InternetCloseHandle(ses);
4970 CloseHandle(ctx.event);
4973 enum api
4975 internet_connect = 1,
4976 http_open_request,
4977 http_send_request_ex,
4978 internet_writefile,
4979 http_end_request,
4980 internet_close_handle
4983 struct notification
4985 enum api function; /* api responsible for notification */
4986 unsigned int status; /* status received */
4987 BOOL async; /* delivered from another thread? */
4988 BOOL todo;
4989 BOOL optional;
4992 struct info
4994 enum api function;
4995 const struct notification *test;
4996 unsigned int count;
4997 unsigned int index;
4998 HANDLE wait;
4999 DWORD thread;
5000 unsigned int line;
5001 DWORD expect_result;
5002 BOOL is_aborted;
5005 static CRITICAL_SECTION notification_cs;
5007 static void CALLBACK check_notification( HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID buffer, DWORD buflen )
5009 BOOL status_ok, function_ok;
5010 struct info *info = (struct info *)context;
5011 unsigned int i;
5013 EnterCriticalSection( &notification_cs );
5015 if(info->is_aborted) {
5016 LeaveCriticalSection(&notification_cs);
5017 return;
5020 if (status == INTERNET_STATUS_HANDLE_CREATED)
5022 DWORD size = sizeof(struct info *);
5023 HttpQueryInfoA( handle, INTERNET_OPTION_CONTEXT_VALUE, &info, &size, 0 );
5024 }else if(status == INTERNET_STATUS_REQUEST_COMPLETE) {
5025 INTERNET_ASYNC_RESULT *ar = (INTERNET_ASYNC_RESULT*)buffer;
5027 ok(buflen == sizeof(*ar), "unexpected buflen = %d\n", buflen);
5028 if(info->expect_result == ERROR_SUCCESS) {
5029 ok(ar->dwResult == 1, "ar->dwResult = %ld, expected 1\n", ar->dwResult);
5030 }else {
5031 ok(!ar->dwResult, "ar->dwResult = %ld, expected 1\n", ar->dwResult);
5032 ok(ar->dwError == info->expect_result, "ar->dwError = %d, expected %d\n", ar->dwError, info->expect_result);
5036 i = info->index;
5037 if (i >= info->count)
5039 LeaveCriticalSection( &notification_cs );
5040 return;
5043 while (info->test[i].status != status &&
5044 (info->test[i].optional || info->test[i].todo) &&
5045 i < info->count - 1 &&
5046 info->test[i].function == info->test[i + 1].function)
5048 i++;
5051 status_ok = (info->test[i].status == status);
5052 function_ok = (info->test[i].function == info->function);
5054 if (!info->test[i].todo)
5056 ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status );
5057 ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
5059 if (info->test[i].async)
5060 ok(info->thread != GetCurrentThreadId(), "%u: expected thread %u got %u\n",
5061 info->line, info->thread, GetCurrentThreadId());
5063 else
5065 todo_wine ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status );
5066 if (status_ok)
5067 todo_wine ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
5069 if (i == info->count - 1 || info->test[i].function != info->test[i + 1].function) SetEvent( info->wait );
5070 info->index = i+1;
5072 LeaveCriticalSection( &notification_cs );
5075 static void setup_test( struct info *info, enum api function, unsigned int line, DWORD expect_result )
5077 info->function = function;
5078 info->line = line;
5079 info->expect_result = expect_result;
5082 struct notification_data
5084 const struct notification *test;
5085 const unsigned int count;
5086 const char *method;
5087 const char *host;
5088 const char *path;
5089 const char *data;
5090 BOOL expect_conn_failure;
5093 static const struct notification async_send_request_ex_test[] =
5095 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5096 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5097 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5098 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, TRUE, FALSE, TRUE },
5099 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE, FALSE, TRUE },
5100 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, TRUE, FALSE, TRUE },
5101 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, TRUE },
5102 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, TRUE },
5103 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, TRUE },
5104 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, TRUE },
5105 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5106 { internet_writefile, INTERNET_STATUS_SENDING_REQUEST, FALSE },
5107 { internet_writefile, INTERNET_STATUS_REQUEST_SENT, FALSE },
5108 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, TRUE },
5109 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, TRUE },
5110 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5111 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, FALSE, FALSE, TRUE },
5112 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, FALSE, FALSE, TRUE },
5113 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, },
5114 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }
5117 static const struct notification async_send_request_ex_test2[] =
5119 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5120 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5121 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5122 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, TRUE, FALSE, TRUE },
5123 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE, FALSE, TRUE },
5124 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, TRUE, FALSE, TRUE },
5125 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, TRUE, TRUE },
5126 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, TRUE, TRUE },
5127 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, TRUE },
5128 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, TRUE },
5129 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5130 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, TRUE },
5131 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, TRUE },
5132 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5133 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, FALSE, FALSE, TRUE },
5134 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, FALSE, FALSE, TRUE },
5135 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, },
5136 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }
5139 static const struct notification async_send_request_ex_resolve_failure_test[] =
5141 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5142 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5143 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5144 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE },
5145 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5146 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5147 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5148 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, FALSE, FALSE, TRUE },
5149 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, FALSE, FALSE, TRUE },
5150 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, },
5151 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }
5154 static const struct notification async_send_request_ex_chunked_test[] =
5156 { internet_connect, INTERNET_STATUS_HANDLE_CREATED },
5157 { http_open_request, INTERNET_STATUS_HANDLE_CREATED },
5158 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5159 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, TRUE, FALSE, TRUE },
5160 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE, FALSE, TRUE },
5161 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, TRUE, FALSE, TRUE },
5162 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, TRUE },
5163 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, TRUE },
5164 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, TRUE },
5165 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, TRUE },
5166 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5167 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, TRUE },
5168 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, TRUE },
5169 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5170 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION },
5171 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED },
5172 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING },
5173 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING }
5176 static const struct notification_data notification_data[] = {
5178 async_send_request_ex_chunked_test,
5179 sizeof(async_send_request_ex_chunked_test)/sizeof(async_send_request_ex_chunked_test[0]),
5180 "GET",
5181 "test.winehq.org",
5182 "tests/data.php"
5185 async_send_request_ex_test,
5186 sizeof(async_send_request_ex_test)/sizeof(async_send_request_ex_test[0]),
5187 "POST",
5188 "test.winehq.org",
5189 "tests/post.php",
5190 "Public ID=codeweavers"
5193 async_send_request_ex_test2,
5194 sizeof(async_send_request_ex_test)/sizeof(async_send_request_ex_test[0]),
5195 "POST",
5196 "test.winehq.org",
5197 "tests/post.php"
5200 async_send_request_ex_resolve_failure_test,
5201 sizeof(async_send_request_ex_resolve_failure_test)/sizeof(async_send_request_ex_resolve_failure_test[0]),
5202 "GET",
5203 "brokenhost",
5204 "index.html",
5205 NULL,
5206 TRUE
5210 static void test_async_HttpSendRequestEx(const struct notification_data *nd)
5212 BOOL ret;
5213 HINTERNET ses, req, con;
5214 struct info info;
5215 DWORD size, written, error;
5216 INTERNET_BUFFERSA b;
5217 static const char *accept[2] = {"*/*", NULL};
5218 char buffer[32];
5220 trace("Async HttpSendRequestEx test (%s %s)\n", nd->method, nd->host);
5222 InitializeCriticalSection( &notification_cs );
5224 info.test = nd->test;
5225 info.count = nd->count;
5226 info.index = 0;
5227 info.wait = CreateEventW( NULL, FALSE, FALSE, NULL );
5228 info.thread = GetCurrentThreadId();
5229 info.is_aborted = FALSE;
5231 ses = InternetOpenA( "winetest", 0, NULL, NULL, INTERNET_FLAG_ASYNC );
5232 ok( ses != NULL, "InternetOpen failed\n" );
5234 pInternetSetStatusCallbackA( ses, check_notification );
5236 setup_test( &info, internet_connect, __LINE__, ERROR_SUCCESS );
5237 con = InternetConnectA( ses, nd->host, 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, (DWORD_PTR)&info );
5238 ok( con != NULL, "InternetConnect failed %u\n", GetLastError() );
5240 WaitForSingleObject( info.wait, 10000 );
5242 setup_test( &info, http_open_request, __LINE__, ERROR_SUCCESS );
5243 req = HttpOpenRequestA( con, nd->method, nd->path, NULL, NULL, accept, 0, (DWORD_PTR)&info );
5244 ok( req != NULL, "HttpOpenRequest failed %u\n", GetLastError() );
5246 WaitForSingleObject( info.wait, 10000 );
5248 if(nd->data) {
5249 memset( &b, 0, sizeof(INTERNET_BUFFERSA) );
5250 b.dwStructSize = sizeof(INTERNET_BUFFERSA);
5251 b.lpcszHeader = "Content-Type: application/x-www-form-urlencoded";
5252 b.dwHeadersLength = strlen( b.lpcszHeader );
5253 b.dwBufferTotal = nd->data ? strlen( nd->data ) : 0;
5256 setup_test( &info, http_send_request_ex, __LINE__,
5257 nd->expect_conn_failure ? ERROR_INTERNET_NAME_NOT_RESOLVED : ERROR_SUCCESS );
5258 ret = HttpSendRequestExA( req, nd->data ? &b : NULL, NULL, 0x28, 0 );
5259 ok( !ret && GetLastError() == ERROR_IO_PENDING, "HttpSendRequestExA failed %d %u\n", ret, GetLastError() );
5261 error = WaitForSingleObject( info.wait, 10000 );
5262 if(error != WAIT_OBJECT_0) {
5263 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error);
5264 info.is_aborted = TRUE;
5265 goto abort;
5268 size = sizeof(buffer);
5269 SetLastError( 0xdeadbeef );
5270 ret = HttpQueryInfoA( req, HTTP_QUERY_CONTENT_ENCODING, buffer, &size, 0 );
5271 error = GetLastError();
5272 ok( !ret, "HttpQueryInfoA failed %u\n", GetLastError() );
5273 if(nd->expect_conn_failure) {
5274 ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error );
5275 }else {
5276 todo_wine
5277 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_STATE,
5278 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error );
5281 if (nd->data)
5283 written = 0;
5284 size = strlen( nd->data );
5285 setup_test( &info, internet_writefile, __LINE__, ERROR_SUCCESS );
5286 ret = InternetWriteFile( req, nd->data, size, &written );
5287 ok( ret, "InternetWriteFile failed %u\n", GetLastError() );
5288 ok( written == size, "expected %u got %u\n", written, size );
5290 WaitForSingleObject( info.wait, 10000 );
5292 SetLastError( 0xdeadbeef );
5293 ret = HttpEndRequestA( req, (void *)nd->data, 0x28, 0 );
5294 error = GetLastError();
5295 ok( !ret, "HttpEndRequestA succeeded\n" );
5296 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error );
5299 SetLastError( 0xdeadbeef );
5300 setup_test( &info, http_end_request, __LINE__,
5301 nd->expect_conn_failure ? ERROR_INTERNET_OPERATION_CANCELLED : ERROR_SUCCESS);
5302 ret = HttpEndRequestA( req, NULL, 0x28, 0 );
5303 error = GetLastError();
5304 ok( !ret, "HttpEndRequestA succeeded\n" );
5305 ok( error == ERROR_IO_PENDING, "expected ERROR_IO_PENDING got %u\n", error );
5307 WaitForSingleObject( info.wait, 10000 );
5309 setup_test( &info, internet_close_handle, __LINE__, ERROR_SUCCESS );
5310 abort:
5311 InternetCloseHandle( req );
5312 InternetCloseHandle( con );
5313 InternetCloseHandle( ses );
5315 WaitForSingleObject( info.wait, 10000 );
5316 Sleep(100);
5317 CloseHandle( info.wait );
5320 static HINTERNET closetest_session, closetest_req, closetest_conn;
5321 static BOOL closetest_closed;
5323 static void WINAPI closetest_callback(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus,
5324 LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
5326 DWORD len, type;
5327 BOOL res;
5329 trace("closetest_callback %p: %d\n", hInternet, dwInternetStatus);
5331 ok(hInternet == closetest_session || hInternet == closetest_conn || hInternet == closetest_req,
5332 "Unexpected hInternet %p\n", hInternet);
5333 if(!closetest_closed)
5334 return;
5336 len = sizeof(type);
5337 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_HANDLE_TYPE, &type, &len);
5338 ok(!res && GetLastError() == ERROR_INVALID_HANDLE,
5339 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5340 closetest_req, res, GetLastError());
5343 static void test_InternetCloseHandle(void)
5345 DWORD len, flags;
5346 BOOL res;
5348 closetest_session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
5349 ok(closetest_session != NULL,"InternetOpen failed with error %u\n", GetLastError());
5351 pInternetSetStatusCallbackA(closetest_session, closetest_callback);
5353 closetest_conn = InternetConnectA(closetest_session, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER,
5354 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
5355 ok(closetest_conn != NULL,"InternetConnect failed with error %u\n", GetLastError());
5357 closetest_req = HttpOpenRequestA(closetest_conn, "GET", "winegecko.php", NULL, NULL, NULL,
5358 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
5360 res = HttpSendRequestA(closetest_req, NULL, -1, NULL, 0);
5361 ok(!res && (GetLastError() == ERROR_IO_PENDING),
5362 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
5364 test_request_flags(closetest_req, INTERNET_REQFLAG_NO_HEADERS);
5366 res = InternetCloseHandle(closetest_session);
5367 ok(res, "InternetCloseHandle failed: %u\n", GetLastError());
5368 closetest_closed = TRUE;
5369 trace("Closed session handle\n");
5371 res = InternetCloseHandle(closetest_conn);
5372 ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(conn) failed: %x %u\n",
5373 res, GetLastError());
5375 res = InternetCloseHandle(closetest_req);
5376 ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(req) failed: %x %u\n",
5377 res, GetLastError());
5379 len = sizeof(flags);
5380 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &len);
5381 ok(!res && GetLastError() == ERROR_INVALID_HANDLE,
5382 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5383 closetest_req, res, GetLastError());
5386 static void test_connection_failure(void)
5388 HINTERNET session, connect, request;
5389 DWORD error;
5390 BOOL ret;
5392 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
5393 ok(session != NULL, "failed to get session handle\n");
5395 connect = InternetConnectA(session, "localhost", 1, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
5396 ok(connect != NULL, "failed to get connection handle\n");
5398 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, 0, 0);
5399 ok(request != NULL, "failed to get request handle\n");
5401 SetLastError(0xdeadbeef);
5402 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
5403 error = GetLastError();
5404 ok(!ret, "unexpected success\n");
5405 ok(error == ERROR_INTERNET_CANNOT_CONNECT, "wrong error %u\n", error);
5407 InternetCloseHandle(request);
5408 InternetCloseHandle(connect);
5409 InternetCloseHandle(session);
5412 static void test_default_service_port(void)
5414 HINTERNET session, connect, request;
5415 DWORD error;
5416 BOOL ret;
5418 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
5419 ok(session != NULL, "InternetOpen failed\n");
5421 connect = InternetConnectA(session, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL,
5422 INTERNET_SERVICE_HTTP, 0, 0);
5423 ok(connect != NULL, "InternetConnect failed\n");
5425 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0);
5426 ok(request != NULL, "HttpOpenRequest failed\n");
5428 SetLastError(0xdeadbeef);
5429 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
5430 error = GetLastError();
5431 ok(!ret, "HttpSendRequest succeeded\n");
5432 ok(error == ERROR_INTERNET_SECURITY_CHANNEL_ERROR || error == ERROR_INTERNET_CANNOT_CONNECT,
5433 "got %u\n", error);
5435 InternetCloseHandle(request);
5436 InternetCloseHandle(connect);
5437 InternetCloseHandle(session);
5440 static void init_status_tests(void)
5442 memset(expect, 0, sizeof(expect));
5443 memset(optional, 0, sizeof(optional));
5444 memset(wine_allow, 0, sizeof(wine_allow));
5445 memset(notified, 0, sizeof(notified));
5446 memset(status_string, 0, sizeof(status_string));
5448 #define STATUS_STRING(status) status_string[status] = #status
5449 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME);
5450 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED);
5451 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER);
5452 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER);
5453 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST);
5454 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT);
5455 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE);
5456 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED);
5457 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED);
5458 STATUS_STRING(INTERNET_STATUS_PREFETCH);
5459 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION);
5460 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED);
5461 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED);
5462 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING);
5463 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY);
5464 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE);
5465 STATUS_STRING(INTERNET_STATUS_REDIRECT);
5466 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE);
5467 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED);
5468 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE);
5469 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT);
5470 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED);
5471 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED);
5472 STATUS_STRING(INTERNET_STATUS_P3P_HEADER);
5473 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF);
5474 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY);
5475 #undef STATUS_STRING
5478 static void WINAPI header_cb( HINTERNET handle, DWORD_PTR ctx, DWORD status, LPVOID info, DWORD len )
5480 if (status == INTERNET_STATUS_REQUEST_COMPLETE) SetEvent( (HANDLE)ctx );
5483 static void test_concurrent_header_access(void)
5485 HINTERNET ses, con, req;
5486 DWORD index, len, err;
5487 BOOL ret;
5488 char buf[128];
5489 HANDLE wait = CreateEventW( NULL, FALSE, FALSE, NULL );
5491 ses = InternetOpenA( "winetest", 0, NULL, NULL, INTERNET_FLAG_ASYNC );
5492 ok( ses != NULL, "InternetOpenA failed\n" );
5494 con = InternetConnectA( ses, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
5495 INTERNET_SERVICE_HTTP, 0, 0 );
5496 ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
5498 req = HttpOpenRequestA( con, NULL, "/", NULL, NULL, NULL, 0, (DWORD_PTR)wait );
5499 ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
5501 pInternetSetStatusCallbackA( req, header_cb );
5503 SetLastError( 0xdeadbeef );
5504 ret = HttpSendRequestA( req, NULL, 0, NULL, 0 );
5505 err = GetLastError();
5506 ok( !ret, "HttpSendRequestA succeeded\n" );
5507 ok( err == ERROR_IO_PENDING, "got %u\n", ERROR_IO_PENDING );
5509 ret = HttpAddRequestHeadersA( req, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD );
5510 ok( ret, "HttpAddRequestHeadersA failed %u\n", GetLastError() );
5512 index = 0;
5513 len = sizeof(buf);
5514 ret = HttpQueryInfoA( req, HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
5515 buf, &len, &index );
5516 ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() );
5517 ok( strstr( buf, "winetest: winetest" ) != NULL, "header missing\n" );
5519 WaitForSingleObject( wait, 5000 );
5521 InternetCloseHandle( req );
5522 InternetCloseHandle( con );
5523 InternetCloseHandle( ses );
5524 CloseHandle( wait );
5527 START_TEST(http)
5529 HMODULE hdll;
5530 hdll = GetModuleHandleA("wininet.dll");
5532 if(!GetProcAddress(hdll, "InternetGetCookieExW")) {
5533 win_skip("Too old IE (older than 6.0)\n");
5534 return;
5537 pInternetSetStatusCallbackA = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackA");
5538 pInternetSetStatusCallbackW = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackW");
5539 pInternetGetSecurityInfoByURLA = (void*)GetProcAddress(hdll, "InternetGetSecurityInfoByURLA");
5541 init_status_tests();
5542 test_InternetCloseHandle();
5543 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[0]);
5544 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[1]);
5545 InternetReadFile_test(0, &test_data[1]);
5546 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[2]);
5547 test_security_flags();
5548 InternetReadFile_test(0, &test_data[2]);
5549 InternetReadFileExA_test(INTERNET_FLAG_ASYNC);
5550 test_open_url_async();
5551 test_async_HttpSendRequestEx(&notification_data[0]);
5552 test_async_HttpSendRequestEx(&notification_data[1]);
5553 test_async_HttpSendRequestEx(&notification_data[2]);
5554 test_async_HttpSendRequestEx(&notification_data[3]);
5555 InternetOpenRequest_test();
5556 test_http_cache();
5557 InternetLockRequestFile_test();
5558 InternetOpenUrlA_test();
5559 HttpHeaders_test();
5560 test_http_connection();
5561 test_secure_connection();
5562 test_user_agent_header();
5563 test_bogus_accept_types_array();
5564 InternetReadFile_chunked_test();
5565 HttpSendRequestEx_test();
5566 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[3]);
5567 test_connection_failure();
5568 test_default_service_port();
5569 test_concurrent_header_access();