[WININET_WINETEST] Sync with Wine Staging 1.7.47. CORE-9924
[reactos.git] / rostests / winetests / wininet / http.c
1 /*
2 * Wininet - HTTP tests
3 *
4 * Copyright 2002 Aric Stewart
5 * Copyright 2004 Mike McCormack
6 * Copyright 2005 Hans Leidekker
7 *
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.
12 *
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.
17 *
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
21 */
22
23 #include <stdarg.h>
24 #include <stdio.h>
25 //#include <stdlib.h>
26
27 #define WIN32_NO_STATUS
28 #define _INC_WINDOWS
29
30 #include <windef.h>
31 #include <winbase.h>
32 #include <winreg.h>
33 #include <winnls.h>
34 #include <wincrypt.h>
35 #include <wininet.h>
36 #include <winsock.h>
37
38 #include <wine/test.h>
39
40 /* Undocumented security flags */
41 #define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
42 #define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
43 #define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
44 #define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
45
46 #define TEST_URL "http://test.winehq.org/tests/hello.html"
47
48 static BOOL first_connection_to_test_url = TRUE;
49
50 /* Adapted from dlls/urlmon/tests/protocol.c */
51
52 #define SET_EXPECT2(status, num) \
53 expect[status] = num
54
55 #define SET_EXPECT(status) \
56 SET_EXPECT2(status, 1)
57
58 #define SET_OPTIONAL2(status, num) \
59 optional[status] = num
60
61 #define SET_OPTIONAL(status) \
62 SET_OPTIONAL2(status, 1)
63
64 /* SET_WINE_ALLOW's should be used with an appropriate
65 * todo_wine CHECK_NOTIFIED at a later point in the code */
66 #define SET_WINE_ALLOW2(status, num) \
67 wine_allow[status] = num
68
69 #define SET_WINE_ALLOW(status) \
70 SET_WINE_ALLOW2(status, 1)
71
72 #define CHECK_EXPECT(status) \
73 do { \
74 if (!expect[status] && !optional[status] && wine_allow[status]) \
75 { \
76 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
77 status < MAX_INTERNET_STATUS && status_string[status] ? \
78 status_string[status] : "unknown"); \
79 wine_allow[status]--; \
80 } \
81 else \
82 { \
83 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
84 status < MAX_INTERNET_STATUS && status_string[status] ? \
85 status_string[status] : "unknown"); \
86 if (expect[status]) expect[status]--; \
87 else if(optional[status]) optional[status]--; \
88 } \
89 notified[status]++; \
90 }while(0)
91
92 /* CLEAR_NOTIFIED used in cases when notification behavior
93 * differs between Windows versions */
94 #define CLEAR_NOTIFIED(status) \
95 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
96
97 #define CHECK_NOTIFIED2(status, num) \
98 do { \
99 ok(notified[status] + optional[status] == (num), \
100 "expected status %d (%s) %d times, received %d times\n", \
101 status, status < MAX_INTERNET_STATUS && status_string[status] ? \
102 status_string[status] : "unknown", (num), notified[status]); \
103 CLEAR_NOTIFIED(status); \
104 }while(0)
105
106 #define CHECK_NOTIFIED(status) \
107 CHECK_NOTIFIED2(status, 1)
108
109 #define CHECK_NOT_NOTIFIED(status) \
110 CHECK_NOTIFIED2(status, 0)
111
112 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
113 static int expect[MAX_INTERNET_STATUS], optional[MAX_INTERNET_STATUS],
114 wine_allow[MAX_INTERNET_STATUS], notified[MAX_INTERNET_STATUS];
115 static const char *status_string[MAX_INTERNET_STATUS];
116
117 static HANDLE hCompleteEvent, conn_close_event;
118 static DWORD req_error;
119
120 #define TESTF_REDIRECT 0x01
121 #define TESTF_COMPRESSED 0x02
122 #define TESTF_CHUNKED 0x04
123
124 typedef struct {
125 const char *url;
126 const char *redirected_url;
127 const char *host;
128 const char *path;
129 const char *headers;
130 DWORD flags;
131 const char *post_data;
132 const char *content;
133 } test_data_t;
134
135 static const test_data_t test_data[] = {
136 {
137 "http://test.winehq.org/tests/data.php",
138 "http://test.winehq.org/tests/data.php",
139 "test.winehq.org",
140 "/tests/data.php",
141 "",
142 TESTF_CHUNKED
143 },
144 {
145 "http://test.winehq.org/tests/redirect",
146 "http://test.winehq.org/tests/hello.html",
147 "test.winehq.org",
148 "/tests/redirect",
149 "",
150 TESTF_REDIRECT
151 },
152 {
153 "http://test.winehq.org/tests/gzip.php",
154 "http://test.winehq.org/tests/gzip.php",
155 "test.winehq.org",
156 "/tests/gzip.php",
157 "Accept-Encoding: gzip, deflate",
158 TESTF_COMPRESSED
159 },
160 {
161 "http://test.winehq.org/tests/post.php",
162 "http://test.winehq.org/tests/post.php",
163 "test.winehq.org",
164 "/tests/post.php",
165 "Content-Type: application/x-www-form-urlencoded",
166 0,
167 "mode=Test",
168 "mode => Test\n"
169 }
170 };
171
172 static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackA)(HINTERNET ,INTERNET_STATUS_CALLBACK);
173 static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackW)(HINTERNET ,INTERNET_STATUS_CALLBACK);
174 static BOOL (WINAPI *pInternetGetSecurityInfoByURLA)(LPSTR,PCCERT_CHAIN_CONTEXT*,DWORD*);
175
176 static int strcmp_wa(LPCWSTR strw, const char *stra)
177 {
178 WCHAR buf[512];
179 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
180 return lstrcmpW(strw, buf);
181 }
182
183 static BOOL proxy_active(void)
184 {
185 HKEY internet_settings;
186 DWORD proxy_enable;
187 DWORD size;
188
189 if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
190 0, KEY_QUERY_VALUE, &internet_settings) != ERROR_SUCCESS)
191 return FALSE;
192
193 size = sizeof(DWORD);
194 if (RegQueryValueExA(internet_settings, "ProxyEnable", NULL, NULL, (LPBYTE) &proxy_enable, &size) != ERROR_SUCCESS)
195 proxy_enable = 0;
196
197 RegCloseKey(internet_settings);
198
199 return proxy_enable != 0;
200 }
201
202 #define test_status_code(a,b) _test_status_code(__LINE__,a,b, FALSE)
203 #define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)
204 static void _test_status_code(unsigned line, HINTERNET req, DWORD excode, BOOL is_todo)
205 {
206 DWORD code, size, index;
207 char exbuf[10], bufa[10];
208 WCHAR bufw[10];
209 BOOL res;
210
211 code = 0xdeadbeef;
212 size = sizeof(code);
213 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, NULL);
214 ok_(__FILE__,line)(res, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
215 if (is_todo)
216 todo_wine ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
217 else
218 ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
219 ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
220
221 code = 0xdeadbeef;
222 index = 0;
223 size = sizeof(code);
224 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index);
225 ok_(__FILE__,line)(res, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
226 if (is_todo)
227 todo_wine ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
228 else
229 ok_(__FILE__,line)(!index, "index = %d, expected 0\n", code);
230 ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
231
232 sprintf(exbuf, "%u", excode);
233
234 size = sizeof(bufa);
235 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, bufa, &size, NULL);
236 ok_(__FILE__,line)(res, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
237 if (is_todo)
238 todo_wine ok_(__FILE__,line)(!strcmp(bufa, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
239 else
240 ok_(__FILE__,line)(!strcmp(bufa, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
241 ok_(__FILE__,line)(size == strlen(exbuf), "unexpected size %d for \"%s\"\n", size, exbuf);
242
243 size = 0;
244 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, NULL, &size, NULL);
245 ok_(__FILE__,line)(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
246 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
247 ok_(__FILE__,line)(size == strlen(exbuf)+1, "unexpected size %d for \"%s\"\n", size, exbuf);
248
249 size = sizeof(bufw);
250 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL);
251 ok_(__FILE__,line)(res, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
252 if (is_todo)
253 todo_wine ok_(__FILE__,line)(!strcmp_wa(bufw, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
254 else
255 ok_(__FILE__,line)(!strcmp_wa(bufw, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
256 ok_(__FILE__,line)(size == strlen(exbuf)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
257
258 size = 0;
259 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL);
260 ok_(__FILE__,line)(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
261 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
262 ok_(__FILE__,line)(size == (strlen(exbuf)+1)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
263
264 if(0) {
265 size = sizeof(bufw);
266 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, NULL, &size, NULL);
267 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
268 ok(size == sizeof(bufw), "unexpected size %d\n", size);
269 }
270
271 code = 0xdeadbeef;
272 index = 1;
273 size = sizeof(code);
274 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index);
275 ok_(__FILE__,line)(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
276 "[7] HttpQueryInfoA failed: %x(%d)\n", res, GetLastError());
277
278 code = 0xdeadbeef;
279 size = sizeof(code);
280 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_REQUEST_HEADERS, &code, &size, NULL);
281 ok_(__FILE__,line)(!res && GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST,
282 "[8] HttpQueryInfoA failed: %x(%d)\n", res, GetLastError());
283 }
284
285 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
286 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
287 static void _test_request_flags(unsigned line, HINTERNET req, DWORD exflags, BOOL is_todo)
288 {
289 DWORD flags, size;
290 BOOL res;
291
292 flags = 0xdeadbeef;
293 size = sizeof(flags);
294 res = InternetQueryOptionW(req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &size);
295 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
296
297 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
298 flags &= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED;
299 if(!is_todo)
300 ok_(__FILE__,line)(flags == exflags, "flags = %x, expected %x\n", flags, exflags);
301 else
302 todo_wine ok_(__FILE__,line)(flags == exflags, "flags = %x, expected %x\n", flags, exflags);
303 }
304
305 #define test_http_version(a) _test_http_version(__LINE__,a)
306 static void _test_http_version(unsigned line, HINTERNET req)
307 {
308 HTTP_VERSION_INFO v = {0xdeadbeef, 0xdeadbeef};
309 DWORD size;
310 BOOL res;
311
312 size = sizeof(v);
313 res = InternetQueryOptionW(req, INTERNET_OPTION_HTTP_VERSION, &v, &size);
314 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
315 ok_(__FILE__,line)(v.dwMajorVersion == 1, "dwMajorVersion = %d\n", v.dwMajorVersion);
316 ok_(__FILE__,line)(v.dwMinorVersion == 1, "dwMinorVersion = %d\n", v.dwMinorVersion);
317 }
318
319 static int close_handle_cnt;
320
321 static VOID WINAPI callback(
322 HINTERNET hInternet,
323 DWORD_PTR dwContext,
324 DWORD dwInternetStatus,
325 LPVOID lpvStatusInformation,
326 DWORD dwStatusInformationLength
327 )
328 {
329 CHECK_EXPECT(dwInternetStatus);
330 switch (dwInternetStatus)
331 {
332 case INTERNET_STATUS_RESOLVING_NAME:
333 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
334 GetCurrentThreadId(), hInternet, dwContext,
335 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
336 *(LPSTR)lpvStatusInformation = '\0';
337 break;
338 case INTERNET_STATUS_NAME_RESOLVED:
339 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
340 GetCurrentThreadId(), hInternet, dwContext,
341 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
342 *(LPSTR)lpvStatusInformation = '\0';
343 break;
344 case INTERNET_STATUS_CONNECTING_TO_SERVER:
345 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
346 GetCurrentThreadId(), hInternet, dwContext,
347 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
348 ok(dwStatusInformationLength == strlen(lpvStatusInformation)+1, "unexpected size %u\n",
349 dwStatusInformationLength);
350 *(LPSTR)lpvStatusInformation = '\0';
351 break;
352 case INTERNET_STATUS_CONNECTED_TO_SERVER:
353 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
354 GetCurrentThreadId(), hInternet, dwContext,
355 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
356 ok(dwStatusInformationLength == strlen(lpvStatusInformation)+1, "unexpected size %u\n",
357 dwStatusInformationLength);
358 *(LPSTR)lpvStatusInformation = '\0';
359 break;
360 case INTERNET_STATUS_SENDING_REQUEST:
361 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
362 GetCurrentThreadId(), hInternet, dwContext,
363 lpvStatusInformation,dwStatusInformationLength);
364 break;
365 case INTERNET_STATUS_REQUEST_SENT:
366 ok(dwStatusInformationLength == sizeof(DWORD),
367 "info length should be sizeof(DWORD) instead of %d\n",
368 dwStatusInformationLength);
369 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
370 GetCurrentThreadId(), hInternet, dwContext,
371 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
372 break;
373 case INTERNET_STATUS_RECEIVING_RESPONSE:
374 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
375 GetCurrentThreadId(), hInternet, dwContext,
376 lpvStatusInformation,dwStatusInformationLength);
377 break;
378 case INTERNET_STATUS_RESPONSE_RECEIVED:
379 ok(dwStatusInformationLength == sizeof(DWORD),
380 "info length should be sizeof(DWORD) instead of %d\n",
381 dwStatusInformationLength);
382 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
383 GetCurrentThreadId(), hInternet, dwContext,
384 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
385 break;
386 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
387 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
388 GetCurrentThreadId(), hInternet,dwContext,
389 lpvStatusInformation,dwStatusInformationLength);
390 break;
391 case INTERNET_STATUS_PREFETCH:
392 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
393 GetCurrentThreadId(), hInternet, dwContext,
394 lpvStatusInformation,dwStatusInformationLength);
395 break;
396 case INTERNET_STATUS_CLOSING_CONNECTION:
397 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
398 GetCurrentThreadId(), hInternet, dwContext,
399 lpvStatusInformation,dwStatusInformationLength);
400 break;
401 case INTERNET_STATUS_CONNECTION_CLOSED:
402 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
403 GetCurrentThreadId(), hInternet, dwContext,
404 lpvStatusInformation,dwStatusInformationLength);
405 break;
406 case INTERNET_STATUS_HANDLE_CREATED:
407 ok(dwStatusInformationLength == sizeof(HINTERNET),
408 "info length should be sizeof(HINTERNET) instead of %d\n",
409 dwStatusInformationLength);
410 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
411 GetCurrentThreadId(), hInternet, dwContext,
412 *(HINTERNET *)lpvStatusInformation,dwStatusInformationLength);
413 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
414 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
415 break;
416 case INTERNET_STATUS_HANDLE_CLOSING:
417 ok(dwStatusInformationLength == sizeof(HINTERNET),
418 "info length should be sizeof(HINTERNET) instead of %d\n",
419 dwStatusInformationLength);
420 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
421 GetCurrentThreadId(), hInternet, dwContext,
422 *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength);
423 if(!InterlockedDecrement(&close_handle_cnt))
424 SetEvent(hCompleteEvent);
425 break;
426 case INTERNET_STATUS_REQUEST_COMPLETE:
427 {
428 INTERNET_ASYNC_RESULT *iar = (INTERNET_ASYNC_RESULT *)lpvStatusInformation;
429 ok(dwStatusInformationLength == sizeof(INTERNET_ASYNC_RESULT),
430 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
431 dwStatusInformationLength);
432 ok(iar->dwResult == 1 || iar->dwResult == 0, "iar->dwResult = %ld\n", iar->dwResult);
433 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
434 GetCurrentThreadId(), hInternet, dwContext,
435 iar->dwResult,iar->dwError,dwStatusInformationLength);
436 req_error = iar->dwError;
437 if(!close_handle_cnt)
438 SetEvent(hCompleteEvent);
439 break;
440 }
441 case INTERNET_STATUS_REDIRECT:
442 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
443 GetCurrentThreadId(), hInternet, dwContext,
444 (LPCSTR)lpvStatusInformation, dwStatusInformationLength);
445 *(LPSTR)lpvStatusInformation = '\0';
446 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
447 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
448 break;
449 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
450 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
451 GetCurrentThreadId(), hInternet, dwContext,
452 lpvStatusInformation, dwStatusInformationLength);
453 break;
454 default:
455 trace("%04x:Callback %p 0x%lx %d %p %d\n",
456 GetCurrentThreadId(), hInternet, dwContext, dwInternetStatus,
457 lpvStatusInformation, dwStatusInformationLength);
458 }
459 }
460
461 static void close_async_handle(HINTERNET handle, HANDLE complete_event, int handle_cnt)
462 {
463 BOOL res;
464
465 close_handle_cnt = handle_cnt;
466
467 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
468 res = InternetCloseHandle(handle);
469 ok(res, "InternetCloseHandle failed: %u\n", GetLastError());
470 WaitForSingleObject(hCompleteEvent, INFINITE);
471 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
472 }
473
474 static void InternetReadFile_test(int flags, const test_data_t *test)
475 {
476 char *post_data = NULL;
477 BOOL res, on_async = TRUE;
478 CHAR buffer[4000];
479 WCHAR wbuffer[4000];
480 DWORD length, length2, index, exlen = 0, post_len = 0;
481 const char *types[2] = { "*", NULL };
482 HINTERNET hi, hic = 0, hor = 0;
483
484 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
485
486 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags,test->url);
487
488 trace("InternetOpenA <--\n");
489 hi = InternetOpenA((test->flags & TESTF_COMPRESSED) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
490 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
491 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
492 trace("InternetOpenA -->\n");
493
494 if (hi == 0x0) goto abort;
495
496 pInternetSetStatusCallbackA(hi,&callback);
497
498 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
499
500 trace("InternetConnectA <--\n");
501 hic=InternetConnectA(hi, test->host, INTERNET_INVALID_PORT_NUMBER,
502 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
503 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
504 trace("InternetConnectA -->\n");
505
506 if (hic == 0x0) goto abort;
507
508 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
509 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
510
511 trace("HttpOpenRequestA <--\n");
512 hor = HttpOpenRequestA(hic, test->post_data ? "POST" : "GET", test->path, NULL, NULL, types,
513 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
514 0xdeadbead);
515 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
516 /*
517 * If the internet name can't be resolved we are probably behind
518 * a firewall or in some other way not directly connected to the
519 * Internet. Not enough reason to fail the test. Just ignore and
520 * abort.
521 */
522 } else {
523 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
524 }
525 trace("HttpOpenRequestA -->\n");
526
527 if (hor == 0x0) goto abort;
528
529 test_request_flags(hor, INTERNET_REQFLAG_NO_HEADERS);
530
531 length = sizeof(buffer);
532 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
533 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
534 ok(!strcmp(buffer, test->url), "Wrong URL %s, expected %s\n", buffer, test->url);
535
536 length = sizeof(buffer);
537 res = HttpQueryInfoA(hor, HTTP_QUERY_RAW_HEADERS, buffer, &length, 0x0);
538 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
539 ok(length == 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length);
540 ok(!strcmp(buffer, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer);
541
542 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
543 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
544 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
545 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT,2);
546 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED,2);
547 if (first_connection_to_test_url)
548 {
549 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
550 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
551 }
552 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
553 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
554 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, (test->flags & TESTF_REDIRECT) ? 2 : 1);
555 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, (test->flags & TESTF_REDIRECT) ? 2 : 1);
556 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, (test->flags & TESTF_REDIRECT) ? 2 : 1);
557 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, (test->flags & TESTF_REDIRECT) ? 2 : 1);
558 if(test->flags & TESTF_REDIRECT) {
559 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
560 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
561 }
562 SET_EXPECT(INTERNET_STATUS_REDIRECT);
563 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER);
564 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER);
565 if (flags & INTERNET_FLAG_ASYNC)
566 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
567
568 if(test->flags & TESTF_COMPRESSED) {
569 BOOL b = TRUE;
570
571 res = InternetSetOptionA(hor, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b));
572 ok(res || broken(!res && GetLastError() == ERROR_INTERNET_INVALID_OPTION),
573 "InternetSetOption failed: %u\n", GetLastError());
574 if(!res)
575 goto abort;
576 }
577
578 test_status_code(hor, 0);
579
580 trace("HttpSendRequestA -->\n");
581 if(test->post_data) {
582 post_len = strlen(test->post_data);
583 post_data = HeapAlloc(GetProcessHeap(), 0, post_len);
584 memcpy(post_data, test->post_data, post_len);
585 }
586 SetLastError(0xdeadbeef);
587 res = HttpSendRequestA(hor, test->headers, -1, post_data, post_len);
588 if (flags & INTERNET_FLAG_ASYNC)
589 ok(!res && (GetLastError() == ERROR_IO_PENDING),
590 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
591 else
592 ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED),
593 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
594 trace("HttpSendRequestA <--\n");
595
596 if (flags & INTERNET_FLAG_ASYNC) {
597 WaitForSingleObject(hCompleteEvent, INFINITE);
598 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
599 }
600 HeapFree(GetProcessHeap(), 0, post_data);
601
602 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
603 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED);
604 if (first_connection_to_test_url)
605 {
606 if (! proxy_active())
607 {
608 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
609 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
610 }
611 else
612 {
613 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
614 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
615 }
616 }
617 else
618 {
619 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
620 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
621 }
622 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, (test->flags & TESTF_REDIRECT) ? 2 : 1);
623 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, (test->flags & TESTF_REDIRECT) ? 2 : 1);
624 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, (test->flags & TESTF_REDIRECT) ? 2 : 1);
625 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, (test->flags & TESTF_REDIRECT) ? 2 : 1);
626 if(test->flags & TESTF_REDIRECT)
627 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
628 if (flags & INTERNET_FLAG_ASYNC)
629 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
630 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
631 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
632 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
633
634 test_request_flags(hor, 0);
635
636 length = 100;
637 res = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
638 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
639
640 length = sizeof(buffer)-1;
641 memset(buffer, 0x77, sizeof(buffer));
642 res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0);
643 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
644 /* show that the function writes data past the length returned */
645 ok(buffer[length-2], "Expected any header character, got 0x00\n");
646 ok(!buffer[length-1], "Expected 0x00, got %02X\n", buffer[length-1]);
647 ok(!buffer[length], "Expected 0x00, got %02X\n", buffer[length]);
648 ok(buffer[length+1] == 0x77, "Expected 0x77, got %02X\n", buffer[length+1]);
649
650 length2 = length;
651 res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length2,0x0);
652 ok(!res, "Expected 0x00, got %d\n", res);
653 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
654 ok(length2 == length+1, "Expected %d, got %d\n", length+1, length2);
655 /* the in length of the buffer must be +1 but the length returned does not count this */
656 length2 = length+1;
657 memset(buffer, 0x77, sizeof(buffer));
658 res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length2,0x0);
659 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
660 ok(buffer[length2] == 0x00, "Expected 0x00, got %02X\n", buffer[length2]);
661 ok(buffer[length2+1] == 0x77, "Expected 0x77, got %02X\n", buffer[length2+1]);
662 ok(length2 == length, "Value should not have changed: %d != %d\n", length2, length);
663
664 length = sizeof(wbuffer)-sizeof(WCHAR);
665 memset(wbuffer, 0x77, sizeof(wbuffer));
666 res = HttpQueryInfoW(hor, HTTP_QUERY_RAW_HEADERS, wbuffer, &length, 0x0);
667 ok(res, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
668 ok(length % sizeof(WCHAR) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length);
669 length /= sizeof(WCHAR);
670 /* show that the function writes data past the length returned */
671 ok(wbuffer[length-2], "Expected any header character, got 0x0000\n");
672 ok(!wbuffer[length-1], "Expected 0x0000, got %04X\n", wbuffer[length-1]);
673 ok(!wbuffer[length], "Expected 0x0000, got %04X\n", wbuffer[length]);
674 ok(wbuffer[length+1] == 0x7777 || broken(wbuffer[length+1] != 0x7777),
675 "Expected 0x7777, got %04X\n", wbuffer[length+1]);
676
677 length2 = length*sizeof(WCHAR);
678 res = HttpQueryInfoW(hor,HTTP_QUERY_RAW_HEADERS,wbuffer,&length2,0x0);
679 ok(!res, "Expected 0x00, got %d\n", res);
680 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
681 ok(length2 % sizeof(WCHAR) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2);
682 length2 /= sizeof(WCHAR);
683 ok(length2 == length+1, "Expected %d, got %d\n", length+1, length2);
684 /* the in length of the buffer must be +1 but the length returned does not count this */
685 length2 = (length+1)*sizeof(WCHAR);
686 memset(wbuffer, 0x77, sizeof(wbuffer));
687 res = HttpQueryInfoW(hor,HTTP_QUERY_RAW_HEADERS,wbuffer,&length2,0x0);
688 ok(res, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
689 ok(length2 % sizeof(WCHAR) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2);
690 length2 /= sizeof(WCHAR);
691 ok(!wbuffer[length2], "Expected 0x0000, got %04X\n", wbuffer[length2]);
692 ok(wbuffer[length2+1] == 0x7777, "Expected 0x7777, got %04X\n", wbuffer[length2+1]);
693 ok(length2 == length, "Value should not have changed: %d != %d\n", length2, length);
694
695 length = sizeof(buffer);
696 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
697 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
698 ok(!strcmp(buffer, test->redirected_url), "Wrong URL %s\n", buffer);
699
700 index = 0;
701 length = 0;
702 SetLastError(0xdeadbeef);
703 ok(HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,NULL,&length,&index) == FALSE,"Query worked\n");
704 if(test->flags & TESTF_COMPRESSED)
705 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
706 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
707 ok(index == 0, "Index was incremented\n");
708
709 index = 0;
710 length = 16;
711 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,&index);
712 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res,buffer,GetLastError());
713 if(test->flags & TESTF_COMPRESSED)
714 ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
715 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res, GetLastError());
716 ok(!res || index == 1, "Index was not incremented although result is %x (index = %u)\n", res, index);
717
718 length = 100;
719 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
720 buffer[length]=0;
721 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res,buffer);
722
723 length = 100;
724 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_ENCODING,buffer,&length,0x0);
725 buffer[length]=0;
726 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res,buffer);
727
728 SetLastError(0xdeadbeef);
729 res = InternetReadFile(NULL, buffer, 100, &length);
730 ok(!res, "InternetReadFile should have failed\n");
731 ok(GetLastError() == ERROR_INVALID_HANDLE,
732 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
733 GetLastError());
734
735 length = 100;
736 trace("Entering Query loop\n");
737
738 while (TRUE)
739 {
740 if (flags & INTERNET_FLAG_ASYNC)
741 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
742
743 /* IE11 calls those in InternetQueryDataAvailable call. */
744 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE);
745 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED);
746
747 length = 0;
748 res = InternetQueryDataAvailable(hor,&length,0x0,0x0);
749
750 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
751
752 if (flags & INTERNET_FLAG_ASYNC)
753 {
754 if (res)
755 {
756 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
757 if(exlen) {
758 ok(length >= exlen, "length %u < exlen %u\n", length, exlen);
759 exlen = 0;
760 }
761 }
762 else if (GetLastError() == ERROR_IO_PENDING)
763 {
764 trace("PENDING\n");
765 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
766 if(!(test->flags & TESTF_CHUNKED))
767 ok(!length, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length);
768 WaitForSingleObject(hCompleteEvent, INFINITE);
769 exlen = length;
770 ok(exlen, "length = 0\n");
771 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
772 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
773 ok(req_error, "req_error = 0\n");
774 continue;
775 }else {
776 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
777 }
778 }else {
779 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
780 }
781 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
782
783 trace("LENGTH %d\n", length);
784 if(test->flags & TESTF_CHUNKED)
785 ok(length <= 8192, "length = %d, expected <= 8192\n", length);
786 if (length)
787 {
788 char *buffer;
789 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
790
791 res = InternetReadFile(hor,buffer,length,&length);
792
793 buffer[length]=0;
794
795 trace("ReadFile -> %s %i\n",res?"TRUE":"FALSE",length);
796
797 if(test->content)
798 ok(!strcmp(buffer, test->content), "buffer = '%s', expected '%s'\n", buffer, test->content);
799 HeapFree(GetProcessHeap(),0,buffer);
800 }else {
801 ok(!on_async, "Returned zero size in response to request complete\n");
802 break;
803 }
804 on_async = FALSE;
805 }
806 if(test->flags & TESTF_REDIRECT) {
807 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
808 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
809 }
810 abort:
811 trace("aborting\n");
812 close_async_handle(hi, hCompleteEvent, 2);
813 CloseHandle(hCompleteEvent);
814 first_connection_to_test_url = FALSE;
815 }
816
817 static void InternetReadFile_chunked_test(void)
818 {
819 BOOL res;
820 CHAR buffer[4000];
821 DWORD length, got;
822 const char *types[2] = { "*", NULL };
823 HINTERNET hi, hic = 0, hor = 0;
824
825 trace("Starting InternetReadFile chunked test\n");
826
827 trace("InternetOpenA <--\n");
828 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
829 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
830 trace("InternetOpenA -->\n");
831
832 if (hi == 0x0) goto abort;
833
834 trace("InternetConnectA <--\n");
835 hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER,
836 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
837 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
838 trace("InternetConnectA -->\n");
839
840 if (hic == 0x0) goto abort;
841
842 trace("HttpOpenRequestA <--\n");
843 hor = HttpOpenRequestA(hic, "GET", "/tests/chunked", NULL, NULL, types,
844 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
845 0xdeadbead);
846 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
847 /*
848 * If the internet name can't be resolved we are probably behind
849 * a firewall or in some other way not directly connected to the
850 * Internet. Not enough reason to fail the test. Just ignore and
851 * abort.
852 */
853 } else {
854 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
855 }
856 trace("HttpOpenRequestA -->\n");
857
858 if (hor == 0x0) goto abort;
859
860 trace("HttpSendRequestA -->\n");
861 SetLastError(0xdeadbeef);
862 res = HttpSendRequestA(hor, "", -1, NULL, 0);
863 ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED),
864 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
865 trace("HttpSendRequestA <--\n");
866
867 test_request_flags(hor, 0);
868
869 length = 100;
870 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
871 buffer[length]=0;
872 trace("Option CONTENT_TYPE -> %i %s\n",res,buffer);
873
874 SetLastError( 0xdeadbeef );
875 length = 100;
876 res = HttpQueryInfoA(hor,HTTP_QUERY_TRANSFER_ENCODING,buffer,&length,0x0);
877 buffer[length]=0;
878 trace("Option TRANSFER_ENCODING -> %i %s\n",res,buffer);
879 ok( res || ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND ),
880 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
881 ok( !strcmp( buffer, "chunked" ) || ( ! res && proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND ),
882 "Wrong transfer encoding '%s'\n", buffer );
883
884 SetLastError( 0xdeadbeef );
885 length = 16;
886 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
887 ok( !res, "Found CONTENT_LENGTH option '%s'\n", buffer );
888 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "Wrong error %u\n", GetLastError() );
889
890 length = 100;
891 trace("Entering Query loop\n");
892
893 while (TRUE)
894 {
895 res = InternetQueryDataAvailable(hor,&length,0x0,0x0);
896 ok(!(!res && length != 0),"InternetQueryDataAvailable failed with non-zero length\n");
897 ok(res, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
898 trace("got %u available\n",length);
899 if (length)
900 {
901 char *buffer = HeapAlloc(GetProcessHeap(),0,length+1);
902
903 res = InternetReadFile(hor,buffer,length,&got);
904
905 buffer[got]=0;
906 trace("ReadFile -> %i %i\n",res,got);
907 ok( length == got, "only got %u of %u available\n", got, length );
908 ok( buffer[got-1] == '\n', "received partial line '%s'\n", buffer );
909
910 HeapFree(GetProcessHeap(),0,buffer);
911 if (!got) break;
912 }
913 if (length == 0)
914 {
915 got = 0xdeadbeef;
916 res = InternetReadFile( hor, buffer, 1, &got );
917 ok( res, "InternetReadFile failed: %u\n", GetLastError() );
918 ok( !got, "got %u\n", got );
919 break;
920 }
921 }
922 abort:
923 trace("aborting\n");
924 if (hor != 0x0) {
925 res = InternetCloseHandle(hor);
926 ok (res, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
927 }
928 if (hi != 0x0) {
929 res = InternetCloseHandle(hi);
930 ok (res, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
931 }
932 }
933
934 static void InternetReadFileExA_test(int flags)
935 {
936 DWORD rc;
937 DWORD length;
938 const char *types[2] = { "*", NULL };
939 HINTERNET hi, hic = 0, hor = 0;
940 INTERNET_BUFFERSA inetbuffers;
941
942 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
943
944 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags);
945
946 trace("InternetOpenA <--\n");
947 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
948 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
949 trace("InternetOpenA -->\n");
950
951 if (hi == 0x0) goto abort;
952
953 pInternetSetStatusCallbackA(hi,&callback);
954
955 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
956
957 trace("InternetConnectA <--\n");
958 hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER,
959 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
960 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
961 trace("InternetConnectA -->\n");
962
963 if (hic == 0x0) goto abort;
964
965 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
966 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
967
968 trace("HttpOpenRequestA <--\n");
969 hor = HttpOpenRequestA(hic, "GET", "/tests/redirect", NULL, NULL, types,
970 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
971 0xdeadbead);
972 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
973 /*
974 * If the internet name can't be resolved we are probably behind
975 * a firewall or in some other way not directly connected to the
976 * Internet. Not enough reason to fail the test. Just ignore and
977 * abort.
978 */
979 } else {
980 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
981 }
982 trace("HttpOpenRequestA -->\n");
983
984 if (hor == 0x0) goto abort;
985
986 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
987 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
988 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
989 if (first_connection_to_test_url)
990 {
991 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
992 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
993 }
994 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT, 2);
995 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
996 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
997 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, 2);
998 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, 2);
999 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
1000 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
1001 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
1002 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
1003 SET_EXPECT(INTERNET_STATUS_REDIRECT);
1004 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER);
1005 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER);
1006 if (flags & INTERNET_FLAG_ASYNC)
1007 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
1008 else
1009 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
1010
1011 trace("HttpSendRequestA -->\n");
1012 SetLastError(0xdeadbeef);
1013 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
1014 if (flags & INTERNET_FLAG_ASYNC)
1015 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
1016 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
1017 else
1018 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
1019 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
1020 trace("HttpSendRequestA <--\n");
1021
1022 if (!rc && (GetLastError() == ERROR_IO_PENDING)) {
1023 WaitForSingleObject(hCompleteEvent, INFINITE);
1024 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
1025 }
1026
1027 if (first_connection_to_test_url)
1028 {
1029 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
1030 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
1031 }
1032 else
1033 {
1034 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
1035 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
1036 }
1037 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, 2);
1038 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, 2);
1039 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
1040 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
1041 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
1042 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
1043 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
1044 if (flags & INTERNET_FLAG_ASYNC)
1045 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1046 else
1047 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1048 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
1049 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
1050 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
1051 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
1052
1053 /* tests invalid dwStructSize */
1054 inetbuffers.dwStructSize = sizeof(inetbuffers)+1;
1055 inetbuffers.lpcszHeader = NULL;
1056 inetbuffers.dwHeadersLength = 0;
1057 inetbuffers.dwBufferLength = 10;
1058 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10);
1059 inetbuffers.dwOffsetHigh = 1234;
1060 inetbuffers.dwOffsetLow = 5678;
1061 rc = InternetReadFileExA(hor, &inetbuffers, 0, 0xdeadcafe);
1062 ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
1063 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1064 rc ? "TRUE" : "FALSE", GetLastError());
1065 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
1066
1067 test_request_flags(hor, 0);
1068
1069 /* tests to see whether lpcszHeader is used - it isn't */
1070 inetbuffers.dwStructSize = sizeof(inetbuffers);
1071 inetbuffers.lpcszHeader = (LPCSTR)0xdeadbeef;
1072 inetbuffers.dwHeadersLength = 255;
1073 inetbuffers.dwBufferLength = 0;
1074 inetbuffers.lpvBuffer = NULL;
1075 inetbuffers.dwOffsetHigh = 1234;
1076 inetbuffers.dwOffsetLow = 5678;
1077 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
1078 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
1079 rc = InternetReadFileExA(hor, &inetbuffers, 0, 0xdeadcafe);
1080 ok(rc, "InternetReadFileEx failed with error %u\n", GetLastError());
1081 trace("read %i bytes\n", inetbuffers.dwBufferLength);
1082 todo_wine
1083 {
1084 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1085 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1086 }
1087
1088 rc = InternetReadFileExA(NULL, &inetbuffers, 0, 0xdeadcafe);
1089 ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE),
1090 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1091 rc ? "TRUE" : "FALSE", GetLastError());
1092
1093 length = 0;
1094 trace("Entering Query loop\n");
1095
1096 while (TRUE)
1097 {
1098 inetbuffers.dwStructSize = sizeof(inetbuffers);
1099 inetbuffers.dwBufferLength = 1024;
1100 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1);
1101 inetbuffers.dwOffsetHigh = 1234;
1102 inetbuffers.dwOffsetLow = 5678;
1103
1104 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE);
1105 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED);
1106 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
1107 rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe);
1108 if (!rc)
1109 {
1110 if (GetLastError() == ERROR_IO_PENDING)
1111 {
1112 trace("InternetReadFileEx -> PENDING\n");
1113 ok(flags & INTERNET_FLAG_ASYNC,
1114 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1115 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1116 WaitForSingleObject(hCompleteEvent, INFINITE);
1117 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1118 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1119 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
1120 }
1121 else
1122 {
1123 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1124 break;
1125 }
1126 }
1127 else
1128 {
1129 trace("InternetReadFileEx -> SUCCEEDED\n");
1130 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1131 if (inetbuffers.dwBufferLength)
1132 {
1133 todo_wine {
1134 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1135 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1136 }
1137 }
1138 else
1139 {
1140 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1141 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1142 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1143 }
1144 }
1145
1146 trace("read %i bytes\n", inetbuffers.dwBufferLength);
1147 ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
1148
1149 ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678,
1150 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1151 inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
1152
1153 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
1154
1155 if (!inetbuffers.dwBufferLength)
1156 break;
1157
1158 length += inetbuffers.dwBufferLength;
1159 }
1160 ok(length > 0, "failed to read any of the document\n");
1161 trace("Finished. Read %d bytes\n", length);
1162
1163 abort:
1164 close_async_handle(hi, hCompleteEvent, 2);
1165 CloseHandle(hCompleteEvent);
1166 first_connection_to_test_url = FALSE;
1167 }
1168
1169 static void InternetOpenUrlA_test(void)
1170 {
1171 HINTERNET myhinternet, myhttp;
1172 char buffer[0x400];
1173 DWORD size, readbytes, totalbytes=0;
1174 BOOL ret;
1175
1176 ret = DeleteUrlCacheEntryA(TEST_URL);
1177 ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND,
1178 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret, GetLastError());
1179
1180 myhinternet = InternetOpenA("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
1181 ok((myhinternet != 0), "InternetOpen failed, error %u\n",GetLastError());
1182 size = 0x400;
1183 ret = InternetCanonicalizeUrlA(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
1184 ok( ret, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1185
1186 SetLastError(0);
1187 myhttp = InternetOpenUrlA(myhinternet, TEST_URL, 0, 0,
1188 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
1189 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1190 return; /* WinXP returns this when not connected to the net */
1191 ok((myhttp != 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1192 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
1193 ok( ret, "InternetReadFile failed, error %u\n",GetLastError());
1194 totalbytes += readbytes;
1195 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
1196 totalbytes += readbytes;
1197 trace("read 0x%08x bytes\n",totalbytes);
1198
1199 InternetCloseHandle(myhttp);
1200 InternetCloseHandle(myhinternet);
1201
1202 ret = DeleteUrlCacheEntryA(TEST_URL);
1203 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1204 }
1205
1206 static void HttpSendRequestEx_test(void)
1207 {
1208 HINTERNET hSession;
1209 HINTERNET hConnect;
1210 HINTERNET hRequest;
1211
1212 INTERNET_BUFFERSA BufferIn;
1213 DWORD dwBytesWritten, dwBytesRead, error;
1214 CHAR szBuffer[256];
1215 int i;
1216 BOOL ret;
1217
1218 static char szPostData[] = "mode=Test";
1219 static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
1220
1221 hSession = InternetOpenA("Wine Regression Test",
1222 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1223 ok( hSession != NULL ,"Unable to open Internet session\n");
1224 hConnect = InternetConnectA(hSession, "test.winehq.org",
1225 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1226 0);
1227 ok( hConnect != NULL, "Unable to connect to http://test.winehq.org\n");
1228 hRequest = HttpOpenRequestA(hConnect, "POST", "/tests/post.php",
1229 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1230 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1231 {
1232 skip( "Network unreachable, skipping test\n" );
1233 goto done;
1234 }
1235 ok( hRequest != NULL, "Failed to open request handle err %u\n", GetLastError());
1236
1237 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1238
1239 BufferIn.dwStructSize = sizeof(BufferIn);
1240 BufferIn.Next = (INTERNET_BUFFERSA*)0xdeadcab;
1241 BufferIn.lpcszHeader = szContentType;
1242 BufferIn.dwHeadersLength = sizeof(szContentType)-1;
1243 BufferIn.dwHeadersTotal = sizeof(szContentType)-1;
1244 BufferIn.lpvBuffer = szPostData;
1245 BufferIn.dwBufferLength = 3;
1246 BufferIn.dwBufferTotal = sizeof(szPostData)-1;
1247 BufferIn.dwOffsetLow = 0;
1248 BufferIn.dwOffsetHigh = 0;
1249
1250 SetLastError(0xdeadbeef);
1251 ret = HttpSendRequestExA(hRequest, &BufferIn, NULL, 0 ,0);
1252 error = GetLastError();
1253 ok(ret, "HttpSendRequestEx Failed with error %u\n", error);
1254 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", error);
1255
1256 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1257
1258 for (i = 3; szPostData[i]; i++)
1259 ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten),
1260 "InternetWriteFile failed\n");
1261
1262 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1263
1264 ok(HttpEndRequestA(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
1265
1266 test_request_flags(hRequest, 0);
1267
1268 ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead),
1269 "Unable to read response\n");
1270 szBuffer[dwBytesRead] = 0;
1271
1272 ok(dwBytesRead == 13,"Read %u bytes instead of 13\n",dwBytesRead);
1273 ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0 || broken(proxy_active()),"Got string %s\n",szBuffer);
1274
1275 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1276 done:
1277 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1278 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1279 }
1280
1281 static void InternetOpenRequest_test(void)
1282 {
1283 HINTERNET session, connect, request;
1284 static const char *types[] = { "*", "", NULL };
1285 static const WCHAR slash[] = {'/', 0}, any[] = {'*', 0}, empty[] = {0};
1286 static const WCHAR *typesW[] = { any, empty, NULL };
1287 BOOL ret;
1288
1289 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1290 ok(session != NULL ,"Unable to open Internet session\n");
1291
1292 connect = InternetConnectA(session, NULL, 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 NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1296
1297 connect = InternetConnectA(session, "", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1298 INTERNET_SERVICE_HTTP, 0, 0);
1299 ok(connect == NULL, "InternetConnectA should have failed\n");
1300 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1301
1302 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1303 INTERNET_SERVICE_HTTP, 0, 0);
1304 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1305
1306 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1307 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1308 {
1309 skip( "Network unreachable, skipping test\n" );
1310 goto done;
1311 }
1312 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1313
1314 ret = HttpSendRequestW(request, NULL, 0, NULL, 0);
1315 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1316 ok(InternetCloseHandle(request), "Close request handle failed\n");
1317
1318 request = HttpOpenRequestW(connect, NULL, slash, NULL, NULL, typesW, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1319 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1320
1321 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1322 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1323 ok(InternetCloseHandle(request), "Close request handle failed\n");
1324
1325 done:
1326 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1327 ok(InternetCloseHandle(session), "Close session handle failed\n");
1328 }
1329
1330 static void test_cache_read(void)
1331 {
1332 HINTERNET session, connection, req;
1333 FILETIME now, tomorrow, yesterday;
1334 BYTE content[1000], buf[2000];
1335 char file_path[MAX_PATH];
1336 ULARGE_INTEGER li;
1337 HANDLE file;
1338 DWORD size;
1339 unsigned i;
1340 BOOL res;
1341
1342 static const char cache_only_url[] = "http://test.winehq.org/tests/cache-only";
1343 BYTE cache_headers[] = "HTTP/1.1 200 OK\r\n\r\n";
1344
1345 trace("Testing cache read...\n");
1346
1347 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
1348
1349 for(i = 0; i < sizeof(content); i++)
1350 content[i] = '0' + (i%10);
1351
1352 GetSystemTimeAsFileTime(&now);
1353 li.u.HighPart = now.dwHighDateTime;
1354 li.u.LowPart = now.dwLowDateTime;
1355 li.QuadPart += (LONGLONG)10000000 * 3600 * 24;
1356 tomorrow.dwHighDateTime = li.u.HighPart;
1357 tomorrow.dwLowDateTime = li.u.LowPart;
1358 li.QuadPart -= (LONGLONG)10000000 * 3600 * 24 * 2;
1359 yesterday.dwHighDateTime = li.u.HighPart;
1360 yesterday.dwLowDateTime = li.u.LowPart;
1361
1362 res = CreateUrlCacheEntryA(cache_only_url, sizeof(content), "", file_path, 0);
1363 ok(res, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1364
1365 file = CreateFileA(file_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1366 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
1367
1368 WriteFile(file, content, sizeof(content), &size, NULL);
1369 CloseHandle(file);
1370
1371 res = CommitUrlCacheEntryA(cache_only_url, file_path, tomorrow, yesterday, NORMAL_CACHE_ENTRY,
1372 cache_headers, sizeof(cache_headers)-1, "", 0);
1373 ok(res, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1374
1375 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
1376 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
1377
1378 pInternetSetStatusCallbackA(session, callback);
1379
1380 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
1381 connection = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT,
1382 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
1383 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
1384 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
1385
1386 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
1387 req = HttpOpenRequestA(connection, "GET", "/tests/cache-only", NULL, NULL, NULL, 0, 0xdeadbead);
1388 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
1389 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
1390
1391 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER);
1392 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER);
1393 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST);
1394 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT);
1395 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE);
1396 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED);
1397 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
1398
1399 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
1400 todo_wine
1401 ok(res, "HttpSendRequest failed: %u\n", GetLastError());
1402
1403 if(res) {
1404 size = 0;
1405 res = InternetQueryDataAvailable(req, &size, 0, 0);
1406 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1407 ok(size == sizeof(content), "size = %u\n", size);
1408
1409 size = sizeof(buf);
1410 res = InternetReadFile(req, buf, sizeof(buf), &size);
1411 ok(res, "InternetReadFile failed: %u\n", GetLastError());
1412 ok(size == sizeof(content), "size = %u\n", size);
1413 ok(!memcmp(content, buf, sizeof(content)), "unexpected content\n");
1414 }
1415
1416 close_async_handle(session, hCompleteEvent, 2);
1417
1418 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
1419 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
1420 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
1421 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
1422 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1423 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1424 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1425
1426 res = DeleteUrlCacheEntryA(cache_only_url);
1427 ok(res, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1428
1429 CloseHandle(hCompleteEvent);
1430 }
1431
1432 static void test_http_cache(void)
1433 {
1434 HINTERNET session, connect, request;
1435 char file_name[MAX_PATH], url[INTERNET_MAX_URL_LENGTH];
1436 DWORD size, file_size;
1437 BYTE buf[100];
1438 HANDLE file;
1439 BOOL ret;
1440 FILETIME filetime_zero = {0};
1441
1442 static const char cached_content[] = "data read from cache";
1443 static const char *types[] = { "*", "", NULL };
1444
1445 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1446 ok(session != NULL ,"Unable to open Internet session\n");
1447
1448 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1449 INTERNET_SERVICE_HTTP, 0, 0);
1450 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1451
1452 request = HttpOpenRequestA(connect, NULL, "/tests/hello.html", NULL, NULL, types, INTERNET_FLAG_NEED_FILE, 0);
1453 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1454 {
1455 skip( "Network unreachable, skipping test\n" );
1456
1457 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1458 ok(InternetCloseHandle(session), "Close session handle failed\n");
1459
1460 return;
1461 }
1462 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1463
1464 size = sizeof(url);
1465 ret = InternetQueryOptionA(request, INTERNET_OPTION_URL, url, &size);
1466 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1467 ok(!strcmp(url, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url);
1468
1469 size = sizeof(file_name);
1470 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1471 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1472 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1473 ok(!size, "size = %d\n", size);
1474
1475 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1476 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1477
1478 size = sizeof(file_name);
1479 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1480 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1481
1482 file = CreateFileA(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
1483 FILE_ATTRIBUTE_NORMAL, NULL);
1484 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1485 file_size = GetFileSize(file, NULL);
1486 ok(file_size == 106, "file size = %u\n", file_size);
1487
1488 size = sizeof(buf);
1489 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1490 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1491 ok(size == 100, "size = %u\n", size);
1492
1493 file_size = GetFileSize(file, NULL);
1494 ok(file_size == 106, "file size = %u\n", file_size);
1495 CloseHandle(file);
1496
1497 ret = DeleteFileA(file_name);
1498 ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
1499
1500 ok(InternetCloseHandle(request), "Close request handle failed\n");
1501
1502 file = CreateFileA(file_name, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1503 FILE_ATTRIBUTE_NORMAL, NULL);
1504 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1505 ret = WriteFile(file, cached_content, sizeof(cached_content), &size, NULL);
1506 ok(ret && size, "WriteFile failed: %d, %d\n", ret, size);
1507 ret = CommitUrlCacheEntryA(url, file_name, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY, NULL, 0, NULL, 0);
1508 ok(ret, "CommitUrlCacheEntry failed: %d\n", GetLastError());
1509 CloseHandle(file);
1510
1511 /* Send the same request, requiring it to be retrieved from the cache */
1512 request = HttpOpenRequestA(connect, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
1513
1514 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1515 ok(ret, "HttpSendRequest failed\n");
1516
1517 size = sizeof(buf);
1518 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1519 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1520 ok(size == 100, "size = %u\n", size);
1521 buf[99] = 0;
1522 todo_wine ok(!strcmp((char*)buf, cached_content), "incorrect page data: %s\n", (char*)buf);
1523
1524 ok(InternetCloseHandle(request), "Close request handle failed\n");
1525
1526 DeleteUrlCacheEntryA(url);
1527 request = HttpOpenRequestA(connect, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
1528 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1529 todo_wine ok(!ret, "HttpSendRequest succeeded\n");
1530 if(!ret)
1531 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError() = %d\n", GetLastError());
1532 ok(InternetCloseHandle(request), "Close request handle failed\n");
1533
1534 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1535 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1536
1537 size = sizeof(file_name);
1538 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1539 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1540 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1541 ok(!size, "size = %d\n", size);
1542
1543 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1544 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1545
1546 size = sizeof(file_name);
1547 file_name[0] = 0;
1548 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1549 if (ret)
1550 {
1551 file = CreateFileA(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1552 FILE_ATTRIBUTE_NORMAL, NULL);
1553 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1554 CloseHandle(file);
1555 }
1556 else
1557 {
1558 /* < IE8 */
1559 ok(file_name[0] == 0, "Didn't expect a file name\n");
1560 }
1561
1562 ok(InternetCloseHandle(request), "Close request handle failed\n");
1563 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1564 ok(InternetCloseHandle(session), "Close session handle failed\n");
1565
1566 test_cache_read();
1567 }
1568
1569 static void InternetLockRequestFile_test(void)
1570 {
1571 HINTERNET session, connect, request;
1572 char file_name[MAX_PATH];
1573 HANDLE lock, lock2;
1574 DWORD size;
1575 BOOL ret;
1576
1577 static const char *types[] = { "*", "", NULL };
1578
1579 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1580 ok(session != NULL ,"Unable to open Internet session\n");
1581
1582 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1583 INTERNET_SERVICE_HTTP, 0, 0);
1584 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1585
1586 request = HttpOpenRequestA(connect, NULL, "/tests/hello.html", NULL, NULL, types, INTERNET_FLAG_NEED_FILE|INTERNET_FLAG_RELOAD, 0);
1587 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1588 {
1589 skip( "Network unreachable, skipping test\n" );
1590
1591 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1592 ok(InternetCloseHandle(session), "Close session handle failed\n");
1593
1594 return;
1595 }
1596 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1597
1598 size = sizeof(file_name);
1599 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1600 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1601 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1602 ok(!size, "size = %d\n", size);
1603
1604 lock = NULL;
1605 ret = InternetLockRequestFile(request, &lock);
1606 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
1607
1608 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1609 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1610
1611 size = sizeof(file_name);
1612 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1613 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1614
1615 ret = InternetLockRequestFile(request, &lock);
1616 ok(ret, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
1617 ok(lock != NULL, "lock == NULL\n");
1618
1619 ret = InternetLockRequestFile(request, &lock2);
1620 ok(ret, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
1621 ok(lock == lock2, "lock != lock2\n");
1622
1623 ret = InternetUnlockRequestFile(lock2);
1624 ok(ret, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1625
1626 ret = DeleteFileA(file_name);
1627 ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
1628
1629 ok(InternetCloseHandle(request), "Close request handle failed\n");
1630
1631 ret = DeleteFileA(file_name);
1632 ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
1633
1634 ret = InternetUnlockRequestFile(lock);
1635 ok(ret, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1636
1637 ret = DeleteFileA(file_name);
1638 ok(ret, "Deleting file returned %x(%u)\n", ret, GetLastError());
1639 }
1640
1641 static void HttpHeaders_test(void)
1642 {
1643 HINTERNET hSession;
1644 HINTERNET hConnect;
1645 HINTERNET hRequest;
1646 CHAR buffer[256];
1647 WCHAR wbuffer[256];
1648 DWORD len = 256;
1649 DWORD oldlen;
1650 DWORD index = 0;
1651 BOOL ret;
1652
1653 hSession = InternetOpenA("Wine Regression Test",
1654 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1655 ok( hSession != NULL ,"Unable to open Internet session\n");
1656 hConnect = InternetConnectA(hSession, "test.winehq.org",
1657 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1658 0);
1659 ok( hConnect != NULL, "Unable to connect to http://test.winehq.org\n");
1660 hRequest = HttpOpenRequestA(hConnect, "POST", "/tests/post.php",
1661 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1662 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1663 {
1664 skip( "Network unreachable, skipping test\n" );
1665 goto done;
1666 }
1667 ok( hRequest != NULL, "Failed to open request handle\n");
1668
1669 index = 0;
1670 len = sizeof(buffer);
1671 strcpy(buffer,"Warning");
1672 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1673 buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
1674
1675 ok(HttpAddRequestHeadersA(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
1676 "Failed to add new header\n");
1677
1678 index = 0;
1679 len = sizeof(buffer);
1680 strcpy(buffer,"Warning");
1681 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1682 buffer,&len,&index),"Unable to query header\n");
1683 ok(index == 1, "Index was not incremented\n");
1684 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1685 ok(len == 5, "Invalid length (exp. 5, got %d)\n", len);
1686 ok((len < sizeof(buffer)) && (buffer[len] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1687 len = sizeof(buffer);
1688 strcpy(buffer,"Warning");
1689 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1690 buffer,&len,&index)==0,"Second Index Should Not Exist\n");
1691
1692 index = 0;
1693 len = 5; /* could store the string but not the NULL terminator */
1694 strcpy(buffer,"Warning");
1695 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1696 buffer,&len,&index) == FALSE,"Query succeeded on a too small buffer\n");
1697 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1698 ok(index == 0, "Index was incremented\n");
1699 ok(strcmp(buffer,"Warning")==0, "incorrect string was returned(%s)\n",buffer); /* string not touched */
1700 ok(len == 6, "Invalid length (exp. 6, got %d)\n", len); /* unlike success, the length includes the NULL-terminator */
1701
1702 /* a call with NULL will fail but will return the length */
1703 index = 0;
1704 len = sizeof(buffer);
1705 SetLastError(0xdeadbeef);
1706 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1707 NULL,&len,&index) == FALSE,"Query worked\n");
1708 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1709 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1710 ok(index == 0, "Index was incremented\n");
1711
1712 /* even for a len that is too small */
1713 index = 0;
1714 len = 15;
1715 SetLastError(0xdeadbeef);
1716 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1717 NULL,&len,&index) == FALSE,"Query worked\n");
1718 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1719 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1720 ok(index == 0, "Index was incremented\n");
1721
1722 index = 0;
1723 len = 0;
1724 SetLastError(0xdeadbeef);
1725 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1726 NULL,&len,&index) == FALSE,"Query worked\n");
1727 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1728 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1729 ok(index == 0, "Index was incremented\n");
1730 oldlen = len; /* bytes; at least long enough to hold buffer & nul */
1731
1732
1733 /* a working query */
1734 index = 0;
1735 len = sizeof(buffer);
1736 memset(buffer, 'x', sizeof(buffer));
1737 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1738 buffer,&len,&index),"Unable to query header\n");
1739 ok(len + sizeof(CHAR) <= oldlen, "Result longer than advertised\n");
1740 ok((len < sizeof(buffer)-sizeof(CHAR)) && (buffer[len/sizeof(CHAR)] == 0),"No NUL at end\n");
1741 ok(len == strlen(buffer) * sizeof(CHAR), "Length wrong\n");
1742 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1743 ok(strncmp(buffer, "POST /tests/post.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1744 ok(strcmp(buffer + strlen(buffer) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1745 ok(index == 0, "Index was incremented\n");
1746
1747 /* Like above two tests, but for W version */
1748
1749 index = 0;
1750 len = 0;
1751 SetLastError(0xdeadbeef);
1752 ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1753 NULL,&len,&index) == FALSE,"Query worked\n");
1754 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1755 ok(len > 80, "Invalid length (exp. more than 80, got %d)\n", len);
1756 ok(index == 0, "Index was incremented\n");
1757 oldlen = len; /* bytes; at least long enough to hold buffer & nul */
1758
1759 /* a working query */
1760 index = 0;
1761 len = sizeof(wbuffer);
1762 memset(wbuffer, 'x', sizeof(wbuffer));
1763 ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1764 wbuffer,&len,&index),"Unable to query header\n");
1765 ok(len + sizeof(WCHAR) <= oldlen, "Result longer than advertised\n");
1766 ok(len == lstrlenW(wbuffer) * sizeof(WCHAR), "Length wrong\n");
1767 ok((len < sizeof(wbuffer)-sizeof(WCHAR)) && (wbuffer[len/sizeof(WCHAR)] == 0),"No NUL at end\n");
1768 ok(index == 0, "Index was incremented\n");
1769
1770 /* end of W version tests */
1771
1772 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1773 index = 0;
1774 len = sizeof(buffer);
1775 memset(buffer, 'x', sizeof(buffer));
1776 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF,
1777 buffer,&len,&index) == TRUE,"Query failed\n");
1778 ok(len == 2, "Expected 2, got %d\n", len);
1779 ok(strcmp(buffer, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer);
1780 ok(index == 0, "Index was incremented\n");
1781
1782 ok(HttpAddRequestHeadersA(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
1783 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1784
1785 index = 0;
1786 len = sizeof(buffer);
1787 strcpy(buffer,"Warning");
1788 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1789 buffer,&len,&index),"Unable to query header\n");
1790 ok(index == 1, "Index was not incremented\n");
1791 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1792 len = sizeof(buffer);
1793 strcpy(buffer,"Warning");
1794 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1795 buffer,&len,&index),"Failed to get second header\n");
1796 ok(index == 2, "Index was not incremented\n");
1797 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1798 len = sizeof(buffer);
1799 strcpy(buffer,"Warning");
1800 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1801 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1802
1803 ok(HttpAddRequestHeadersA(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1804
1805 index = 0;
1806 len = sizeof(buffer);
1807 strcpy(buffer,"Warning");
1808 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1809 buffer,&len,&index),"Unable to query header\n");
1810 ok(index == 1, "Index was not incremented\n");
1811 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1812 len = sizeof(buffer);
1813 strcpy(buffer,"Warning");
1814 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1815 buffer,&len,&index),"Failed to get second header\n");
1816 ok(index == 2, "Index was not incremented\n");
1817 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1818 len = sizeof(buffer);
1819 strcpy(buffer,"Warning");
1820 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1821 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1822
1823 ok(HttpAddRequestHeadersA(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1824
1825 index = 0;
1826 len = sizeof(buffer);
1827 strcpy(buffer,"Warning");
1828 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1829 buffer,&len,&index),"Unable to query header\n");
1830 ok(index == 1, "Index was not incremented\n");
1831 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1832 len = sizeof(buffer);
1833 strcpy(buffer,"Warning");
1834 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1835 buffer,&len,&index),"Failed to get second header\n");
1836 ok(index == 2, "Index was not incremented\n");
1837 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1838 len = sizeof(buffer);
1839 strcpy(buffer,"Warning");
1840 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1841 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1842
1843 ok(HttpAddRequestHeadersA(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1844
1845 index = 0;
1846 len = sizeof(buffer);
1847 strcpy(buffer,"Warning");
1848 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1849 buffer,&len,&index),"Unable to query header\n");
1850 ok(index == 1, "Index was not incremented\n");
1851 ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer);
1852 len = sizeof(buffer);
1853 strcpy(buffer,"Warning");
1854 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1855 ok(index == 2, "Index was not incremented\n");
1856 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1857 len = sizeof(buffer);
1858 strcpy(buffer,"Warning");
1859 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1860
1861 ok(HttpAddRequestHeadersA(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1862
1863 index = 0;
1864 len = sizeof(buffer);
1865 strcpy(buffer,"Warning");
1866 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1867 ok(index == 1, "Index was not incremented\n");
1868 ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer);
1869 len = sizeof(buffer);
1870 strcpy(buffer,"Warning");
1871 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1872 ok(index == 2, "Index was not incremented\n");
1873 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1874 len = sizeof(buffer);
1875 strcpy(buffer,"Warning");
1876 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1877
1878 ok(HttpAddRequestHeadersA(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1879
1880 index = 0;
1881 len = sizeof(buffer);
1882 strcpy(buffer,"Warning");
1883 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1884 ok(index == 1, "Index was not incremented\n");
1885 ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer);
1886 len = sizeof(buffer);
1887 strcpy(buffer,"Warning");
1888 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1889 ok(index == 2, "Index was not incremented\n");
1890 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1891 len = sizeof(buffer);
1892 strcpy(buffer,"Warning");
1893 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1894
1895 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");
1896
1897 index = 0;
1898 len = sizeof(buffer);
1899 strcpy(buffer,"Warning");
1900 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1901 ok(index == 1, "Index was not incremented\n");
1902 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1903 len = sizeof(buffer);
1904 strcpy(buffer,"Warning");
1905 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1906 ok(index == 2, "Index was not incremented\n");
1907 ok(strcmp(buffer,"test7")==0, "incorrect string was returned(%s)\n",buffer);
1908 len = sizeof(buffer);
1909 strcpy(buffer,"Warning");
1910 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1911
1912 /* Ensure that blank headers are ignored and don't cause a failure */
1913 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");
1914
1915 index = 0;
1916 len = sizeof(buffer);
1917 strcpy(buffer,"BlankTest");
1918 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1919 ok(index == 1, "Index was not incremented\n");
1920 ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
1921
1922 /* Ensure that malformed header separators are ignored and don't cause a failure */
1923 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),
1924 "Failed to add header with malformed entries in list\n");
1925
1926 index = 0;
1927 len = sizeof(buffer);
1928 strcpy(buffer,"MalformedTest");
1929 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1930 ok(index == 1, "Index was not incremented\n");
1931 ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
1932 index = 0;
1933 len = sizeof(buffer);
1934 strcpy(buffer,"MalformedTestTwo");
1935 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1936 ok(index == 1, "Index was not incremented\n");
1937 ok(strcmp(buffer,"value2")==0, "incorrect string was returned(%s)\n",buffer);
1938 index = 0;
1939 len = sizeof(buffer);
1940 strcpy(buffer,"MalformedTestThree");
1941 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1942 ok(index == 1, "Index was not incremented\n");
1943 ok(strcmp(buffer,"value3")==0, "incorrect string was returned(%s)\n",buffer);
1944
1945 ret = HttpAddRequestHeadersA(hRequest, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD);
1946 ok(ret, "unable to add header %u\n", GetLastError());
1947
1948 index = 0;
1949 buffer[0] = 0;
1950 len = sizeof(buffer);
1951 ret = HttpQueryInfoA(hRequest, HTTP_QUERY_AUTHORIZATION|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &len, &index);
1952 ok(ret, "unable to query header %u\n", GetLastError());
1953 ok(index == 1, "index was not incremented\n");
1954 ok(!strcmp(buffer, "Basic"), "incorrect string was returned (%s)\n", buffer);
1955
1956 ret = HttpAddRequestHeadersA(hRequest, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE);
1957 ok(ret, "unable to remove header %u\n", GetLastError());
1958
1959 index = 0;
1960 len = sizeof(buffer);
1961 SetLastError(0xdeadbeef);
1962 ok(!HttpQueryInfoA(hRequest, HTTP_QUERY_AUTHORIZATION|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &len, &index),
1963 "header still present\n");
1964 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "got %u\n", GetLastError());
1965
1966 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1967 done:
1968 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1969 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1970 }
1971
1972 static const char garbagemsg[] =
1973 "Garbage: Header\r\n";
1974
1975 static const char contmsg[] =
1976 "HTTP/1.1 100 Continue\r\n";
1977
1978 static const char expandcontmsg[] =
1979 "HTTP/1.1 100 Continue\r\n"
1980 "Server: winecontinue\r\n"
1981 "Tag: something witty\r\n"
1982 "\r\n";
1983
1984 static const char okmsg[] =
1985 "HTTP/1.1 200 OK\r\n"
1986 "Server: winetest\r\n"
1987 "\r\n";
1988
1989 static const char okmsg2[] =
1990 "HTTP/1.1 200 OK\r\n"
1991 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1992 "Server: winetest\r\n"
1993 "Content-Length: 0\r\n"
1994 "Set-Cookie: one\r\n"
1995 "Set-Cookie: two\r\n"
1996 "\r\n";
1997
1998 static const char okmsg_cookie_path[] =
1999 "HTTP/1.1 200 OK\r\n"
2000 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
2001 "Server: winetest\r\n"
2002 "Content-Length: 0\r\n"
2003 "Set-Cookie: subcookie2=data; path=/test_cookie_set_path\r\n"
2004 "\r\n";
2005
2006 static const char okmsg_cookie[] =
2007 "HTTP/1.1 200 OK\r\n"
2008 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
2009 "Server: winetest\r\n"
2010 "Content-Length: 0\r\n"
2011 "Set-Cookie: testcookie=testvalue\r\n"
2012 "\r\n";
2013
2014 static const char notokmsg[] =
2015 "HTTP/1.1 400 Bad Request\r\n"
2016 "Server: winetest\r\n"
2017 "\r\n";
2018
2019 static const char noauthmsg[] =
2020 "HTTP/1.1 401 Unauthorized\r\n"
2021 "Server: winetest\r\n"
2022 "Connection: close\r\n"
2023 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
2024 "\r\n";
2025
2026 static const char noauthmsg2[] =
2027 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
2028 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
2029 "\0d`0|6\n"
2030 "Server: winetest\r\n";
2031
2032 static const char proxymsg[] =
2033 "HTTP/1.1 407 Proxy Authentication Required\r\n"
2034 "Server: winetest\r\n"
2035 "Proxy-Connection: close\r\n"
2036 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
2037 "\r\n";
2038
2039 static const char page1[] =
2040 "<HTML>\r\n"
2041 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
2042 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
2043 "</HTML>\r\n\r\n";
2044
2045 static const char ok_with_length[] =
2046 "HTTP/1.1 200 OK\r\n"
2047 "Connection: Keep-Alive\r\n"
2048 "Content-Length: 18\r\n\r\n"
2049 "HTTP/1.1 211 OK\r\n\r\n";
2050
2051 static const char ok_with_length2[] =
2052 "HTTP/1.1 210 OK\r\n"
2053 "Connection: Keep-Alive\r\n"
2054 "Content-Length: 19\r\n\r\n"
2055 "HTTP/1.1 211 OK\r\n\r\n";
2056
2057 struct server_info {
2058 HANDLE hEvent;
2059 int port;
2060 };
2061
2062 static int test_cache_gzip;
2063 static const char *send_buffer;
2064
2065 static DWORD CALLBACK server_thread(LPVOID param)
2066 {
2067 struct server_info *si = param;
2068 int r, c = -1, i, on, count = 0;
2069 SOCKET s;
2070 struct sockaddr_in sa;
2071 char buffer[0x100];
2072 WSADATA wsaData;
2073 int last_request = 0;
2074 char host_header[22];
2075 char host_header_override[30];
2076 static BOOL test_b = FALSE;
2077 static int test_no_cache = 0;
2078
2079 WSAStartup(MAKEWORD(1,1), &wsaData);
2080
2081 s = socket(AF_INET, SOCK_STREAM, 0);
2082 if (s == INVALID_SOCKET)
2083 return 1;
2084
2085 on = 1;
2086 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof on);
2087
2088 memset(&sa, 0, sizeof sa);
2089 sa.sin_family = AF_INET;
2090 sa.sin_port = htons(si->port);
2091 sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
2092
2093 r = bind(s, (struct sockaddr*) &sa, sizeof sa);
2094 if (r<0)
2095 return 1;
2096
2097 listen(s, 0);
2098
2099 SetEvent(si->hEvent);
2100
2101 sprintf(host_header, "Host: localhost:%d", si->port);
2102 sprintf(host_header_override, "Host: test.local:%d\r\n", si->port);
2103
2104 do
2105 {
2106 if(c == -1)
2107 c = accept(s, NULL, NULL);
2108
2109 memset(buffer, 0, sizeof buffer);
2110 for(i=0; i<(sizeof buffer-1); i++)
2111 {
2112 r = recv(c, &buffer[i], 1, 0);
2113 if (r != 1)
2114 break;
2115 if (i<4) continue;
2116 if (buffer[i-2] == '\n' && buffer[i] == '\n' &&
2117 buffer[i-3] == '\r' && buffer[i-1] == '\r')
2118 break;
2119 }
2120 if (strstr(buffer, "GET /test1"))
2121 {
2122 if (!strstr(buffer, "Content-Length: 0"))
2123 {
2124 send(c, okmsg, sizeof okmsg-1, 0);
2125 send(c, page1, sizeof page1-1, 0);
2126 }
2127 else
2128 send(c, notokmsg, sizeof notokmsg-1, 0);
2129 }
2130 if (strstr(buffer, "/test2"))
2131 {
2132 if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2133 {
2134 send(c, okmsg, sizeof okmsg-1, 0);
2135 send(c, page1, sizeof page1-1, 0);
2136 }
2137 else
2138 send(c, proxymsg, sizeof proxymsg-1, 0);
2139 }
2140 if (strstr(buffer, "/test3"))
2141 {
2142 if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
2143 send(c, okmsg, sizeof okmsg-1, 0);
2144 else
2145 send(c, noauthmsg, sizeof noauthmsg-1, 0);
2146 }
2147 if (strstr(buffer, "/test4"))
2148 {
2149 if (strstr(buffer, "Connection: Close"))
2150 send(c, okmsg, sizeof okmsg-1, 0);
2151 else
2152 send(c, notokmsg, sizeof notokmsg-1, 0);
2153 }
2154 if (strstr(buffer, "POST /test5") ||
2155 strstr(buffer, "RPC_IN_DATA /test5") ||
2156 strstr(buffer, "RPC_OUT_DATA /test5"))
2157 {
2158 if (strstr(buffer, "Content-Length: 0"))
2159 {
2160 send(c, okmsg, sizeof okmsg-1, 0);
2161 send(c, page1, sizeof page1-1, 0);
2162 }
2163 else
2164 send(c, notokmsg, sizeof notokmsg-1, 0);
2165 }
2166 if (strstr(buffer, "GET /test6"))
2167 {
2168 send(c, contmsg, sizeof contmsg-1, 0);
2169 send(c, contmsg, sizeof contmsg-1, 0);
2170 send(c, okmsg, sizeof okmsg-1, 0);
2171 send(c, page1, sizeof page1-1, 0);
2172 }
2173 if (strstr(buffer, "POST /test7"))
2174 {
2175 if (strstr(buffer, "Content-Length: 100"))
2176 {
2177 send(c, okmsg, sizeof okmsg-1, 0);
2178 send(c, page1, sizeof page1-1, 0);
2179 }
2180 else
2181 send(c, notokmsg, sizeof notokmsg-1, 0);
2182 }
2183 if (strstr(buffer, "/test8"))
2184 {
2185 if (!strstr(buffer, "Connection: Close") &&
2186 strstr(buffer, "Connection: Keep-Alive") &&
2187 !strstr(buffer, "Cache-Control: no-cache") &&
2188 !strstr(buffer, "Pragma: no-cache") &&
2189 strstr(buffer, host_header))
2190 send(c, okmsg, sizeof okmsg-1, 0);
2191 else
2192 send(c, notokmsg, sizeof notokmsg-1, 0);
2193 }
2194 if (strstr(buffer, "/test9"))
2195 {
2196 if (!strstr(buffer, "Connection: Close") &&
2197 !strstr(buffer, "Connection: Keep-Alive") &&
2198 !strstr(buffer, "Cache-Control: no-cache") &&
2199 !strstr(buffer, "Pragma: no-cache") &&
2200 strstr(buffer, host_header))
2201 send(c, okmsg, sizeof okmsg-1, 0);
2202 else
2203 send(c, notokmsg, sizeof notokmsg-1, 0);
2204 }
2205 if (strstr(buffer, "/testA"))
2206 {
2207 if (!strstr(buffer, "Connection: Close") &&
2208 !strstr(buffer, "Connection: Keep-Alive") &&
2209 (strstr(buffer, "Cache-Control: no-cache") ||
2210 strstr(buffer, "Pragma: no-cache")) &&
2211 strstr(buffer, host_header))
2212 send(c, okmsg, sizeof okmsg-1, 0);
2213 else
2214 send(c, notokmsg, sizeof notokmsg-1, 0);
2215 }
2216 if (!test_b && strstr(buffer, "/testB HTTP/1.1"))
2217 {
2218 test_b = TRUE;
2219 send(c, okmsg, sizeof okmsg-1, 0);
2220 recvfrom(c, buffer, sizeof buffer, 0, NULL, NULL);
2221 send(c, okmsg, sizeof okmsg-1, 0);
2222 }
2223 if (strstr(buffer, "/testC"))
2224 {
2225 if (strstr(buffer, "cookie=biscuit"))
2226 send(c, okmsg, sizeof okmsg-1, 0);
2227 else
2228 send(c, notokmsg, sizeof notokmsg-1, 0);
2229 }
2230 if (strstr(buffer, "/testD"))
2231 {
2232 send(c, okmsg2, sizeof okmsg2-1, 0);
2233 }
2234 if (strstr(buffer, "/testE"))
2235 {
2236 send(c, noauthmsg2, sizeof noauthmsg2-1, 0);
2237 }
2238 if (strstr(buffer, "GET /quit"))
2239 {
2240 send(c, okmsg, sizeof okmsg-1, 0);
2241 send(c, page1, sizeof page1-1, 0);
2242 last_request = 1;
2243 }
2244 if (strstr(buffer, "GET /testF"))
2245 {
2246 send(c, expandcontmsg, sizeof expandcontmsg-1, 0);
2247 send(c, garbagemsg, sizeof garbagemsg-1, 0);
2248 send(c, contmsg, sizeof contmsg-1, 0);
2249 send(c, garbagemsg, sizeof garbagemsg-1, 0);
2250 send(c, okmsg, sizeof okmsg-1, 0);
2251 send(c, page1, sizeof page1-1, 0);
2252 }
2253 if (strstr(buffer, "GET /testG"))
2254 {
2255 send(c, page1, sizeof page1-1, 0);
2256 }
2257
2258 if (strstr(buffer, "GET /testJ"))
2259 {
2260 if (count == 0)
2261 {
2262 count++;
2263 send(c, ok_with_length, sizeof(ok_with_length)-1, 0);
2264 }
2265 else
2266 {
2267 send(c, ok_with_length2, sizeof(ok_with_length2)-1, 0);
2268 count = 0;
2269 }
2270 }
2271 if (strstr(buffer, "GET /testH"))
2272 {
2273 send(c, ok_with_length2, sizeof(ok_with_length2)-1, 0);
2274 recvfrom(c, buffer, sizeof(buffer), 0, NULL, NULL);
2275 send(c, ok_with_length, sizeof(ok_with_length)-1, 0);
2276 }
2277
2278 if (strstr(buffer, "GET /test_no_content"))
2279 {
2280 static const char nocontentmsg[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2281 send(c, nocontentmsg, sizeof(nocontentmsg)-1, 0);
2282 }
2283 if (strstr(buffer, "GET /test_conn_close"))
2284 {
2285 static const char conn_close_response[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2286 send(c, conn_close_response, sizeof(conn_close_response)-1, 0);
2287 WaitForSingleObject(conn_close_event, INFINITE);
2288 trace("closing connection\n");
2289 }
2290 if (strstr(buffer, "GET /test_cache_control_no_cache"))
2291 {
2292 static const char no_cache_response[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2293 if(!test_no_cache++)
2294 send(c, no_cache_response, sizeof(no_cache_response)-1, 0);
2295 else
2296 send(c, okmsg, sizeof(okmsg)-1, 0);
2297 }
2298 if (strstr(buffer, "GET /test_cache_control_no_store"))
2299 {
2300 static const char no_cache_response[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2301 send(c, no_cache_response, sizeof(no_cache_response)-1, 0);
2302 }
2303 if (strstr(buffer, "GET /test_cache_gzip"))
2304 {
2305 static const char gzip_response[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2306 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2307 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2308 if(!test_cache_gzip++)
2309 send(c, gzip_response, sizeof(gzip_response), 0);
2310 else
2311 send(c, notokmsg, sizeof(notokmsg)-1, 0);
2312 }
2313 if (strstr(buffer, "HEAD /test_head")) {
2314 static const char head_response[] =
2315 "HTTP/1.1 200 OK\r\n"
2316 "Connection: Keep-Alive\r\n"
2317 "Content-Length: 100\r\n"
2318 "\r\n";
2319
2320 send(c, head_response, sizeof(head_response), 0);
2321 continue;
2322 }
2323 if (strstr(buffer, "GET /send_from_buffer"))
2324 send(c, send_buffer, strlen(send_buffer), 0);
2325 if (strstr(buffer, "/test_cache_control_verb"))
2326 {
2327 if (!memcmp(buffer, "GET ", sizeof("GET ")-1) &&
2328 !strstr(buffer, "Cache-Control: no-cache\r\n")) send(c, okmsg, sizeof(okmsg)-1, 0);
2329 else if (strstr(buffer, "Cache-Control: no-cache\r\n")) send(c, okmsg, sizeof(okmsg)-1, 0);
2330 else send(c, notokmsg, sizeof(notokmsg)-1, 0);
2331 }
2332 if (strstr(buffer, "/test_request_content_length"))
2333 {
2334 static char msg[] = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\n\r\n";
2335 static int seen_content_length;
2336
2337 if (!seen_content_length)
2338 {
2339 if (strstr(buffer, "Content-Length: 0"))
2340 {
2341 seen_content_length = 1;
2342 send(c, msg, sizeof msg-1, 0);
2343 }
2344 else send(c, notokmsg, sizeof notokmsg-1, 0);
2345 WaitForSingleObject(hCompleteEvent, 5000);
2346 }
2347 else
2348 {
2349 if (strstr(buffer, "Content-Length: 0")) send(c, msg, sizeof msg-1, 0);
2350 else send(c, notokmsg, sizeof notokmsg-1, 0);
2351 WaitForSingleObject(hCompleteEvent, 5000);
2352 }
2353 }
2354 if (strstr(buffer, "GET /test_premature_disconnect"))
2355 trace("closing connection\n");
2356 if (strstr(buffer, "/test_accept_encoding_http10"))
2357 {
2358 if (strstr(buffer, "Accept-Encoding: gzip"))
2359 send(c, okmsg, sizeof okmsg-1, 0);
2360 else
2361 send(c, notokmsg, sizeof notokmsg-1, 0);
2362 }
2363 if (strstr(buffer, "HEAD /upload.txt"))
2364 {
2365 if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
2366 send(c, okmsg, sizeof okmsg-1, 0);
2367 else
2368 send(c, noauthmsg, sizeof noauthmsg-1, 0);
2369 }
2370 if (strstr(buffer, "PUT /upload2.txt"))
2371 {
2372 if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
2373 send(c, okmsg, sizeof okmsg-1, 0);
2374 else
2375 send(c, notokmsg, sizeof notokmsg-1, 0);
2376 }
2377 if (strstr(buffer, "/test_cookie_path1"))
2378 {
2379 if (strstr(buffer, "subcookie=data"))
2380 send(c, okmsg, sizeof okmsg-1, 0);
2381 else
2382 send(c, notokmsg, sizeof notokmsg-1, 0);
2383 }
2384 if (strstr(buffer, "/test_cookie_path2"))
2385 {
2386 if (strstr(buffer, "subcookie2=data"))
2387 send(c, okmsg, sizeof okmsg-1, 0);
2388 else
2389 send(c, notokmsg, sizeof notokmsg-1, 0);
2390 }
2391 if (strstr(buffer, "/test_cookie_set_path"))
2392 {
2393 send(c, okmsg_cookie_path, sizeof okmsg_cookie_path-1, 0);
2394 }
2395 if (strstr(buffer, "/test_cookie_merge"))
2396 {
2397 if (strstr(buffer, "subcookie=data") &&
2398 !strstr(buffer, "manual_cookie=test"))
2399 send(c, okmsg, sizeof okmsg-1, 0);
2400 else
2401 send(c, notokmsg, sizeof notokmsg-1, 0);
2402 }
2403 if (strstr(buffer, "/test_cookie_set_host_override"))
2404 {
2405 send(c, okmsg_cookie, sizeof okmsg_cookie-1, 0);
2406 }
2407 if (strstr(buffer, "/test_cookie_check_host_override"))
2408 {
2409 if (strstr(buffer, "Cookie:") && strstr(buffer, "testcookie=testvalue"))
2410 send(c, okmsg, sizeof okmsg-1, 0);
2411 else
2412 send(c, notokmsg, sizeof notokmsg-1, 0);
2413 }
2414 if (strstr(buffer, "/test_cookie_check_different_host"))
2415 {
2416 if (!strstr(buffer, "foo") &&
2417 strstr(buffer, "cookie=biscuit"))
2418 send(c, okmsg, sizeof okmsg-1, 0);
2419 else
2420 send(c, notokmsg, sizeof notokmsg-1, 0);
2421 }
2422 if (strstr(buffer, "/test_host_override"))
2423 {
2424 if (strstr(buffer, host_header_override))
2425 send(c, okmsg, sizeof okmsg-1, 0);
2426 else
2427 send(c, notokmsg, sizeof notokmsg-1, 0);
2428 }
2429 if (strstr(buffer, "HEAD /test_auth_host1"))
2430 {
2431 if (strstr(buffer, "Authorization: Basic dGVzdDE6cGFzcw=="))
2432 send(c, okmsg, sizeof okmsg-1, 0);
2433 else
2434 send(c, noauthmsg, sizeof noauthmsg-1, 0);
2435 }
2436 if (strstr(buffer, "HEAD /test_auth_host2"))
2437 {
2438 if (strstr(buffer, "Authorization: Basic dGVzdDE6cGFzczI="))
2439 send(c, okmsg, sizeof okmsg-1, 0);
2440 else
2441 send(c, noauthmsg, sizeof noauthmsg-1, 0);
2442 }
2443 shutdown(c, 2);
2444 closesocket(c);
2445 c = -1;
2446 } while (!last_request);
2447
2448 closesocket(s);
2449
2450 return 0;
2451 }
2452
2453 static void test_basic_request(int port, const char *verb, const char *url)
2454 {
2455 HINTERNET hi, hc, hr;
2456 DWORD r, count, error;
2457 char buffer[0x100];
2458
2459 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2460 ok(hi != NULL, "open failed\n");
2461
2462 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2463 ok(hc != NULL, "connect failed\n");
2464
2465 hr = HttpOpenRequestA(hc, verb, url, NULL, NULL, NULL, 0, 0);
2466 ok(hr != NULL, "HttpOpenRequest failed\n");
2467
2468 SetLastError(0xdeadbeef);
2469 r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
2470 error = GetLastError();
2471 ok(error == ERROR_SUCCESS || broken(error != ERROR_SUCCESS), "expected ERROR_SUCCESS, got %u\n", error);
2472 ok(r, "HttpSendRequest failed\n");
2473
2474 count = 0;
2475 memset(buffer, 0, sizeof buffer);
2476 SetLastError(0xdeadbeef);
2477 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
2478 ok(r, "InternetReadFile failed %u\n", GetLastError());
2479 ok(count == sizeof page1 - 1, "count was wrong\n");
2480 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong, got: %s\n", buffer);
2481
2482 InternetCloseHandle(hr);
2483 InternetCloseHandle(hc);
2484 InternetCloseHandle(hi);
2485 }
2486
2487 static void test_proxy_indirect(int port)
2488 {
2489 HINTERNET hi, hc, hr;
2490 DWORD r, sz;
2491 char buffer[0x40];
2492
2493 hi = InternetOpenA(NULL, 0, NULL, NULL, 0);
2494 ok(hi != NULL, "open failed\n");
2495
2496 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2497 ok(hc != NULL, "connect failed\n");
2498
2499 hr = HttpOpenRequestA(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
2500 ok(hr != NULL, "HttpOpenRequest failed\n");
2501
2502 r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
2503 ok(r, "HttpSendRequest failed %u\n", GetLastError());
2504
2505 sz = sizeof buffer;
2506 r = HttpQueryInfoA(hr, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL);
2507 ok(r || GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo failed: %d\n", GetLastError());
2508 if (!r)
2509 {
2510 skip("missing proxy header, not testing remaining proxy headers\n");
2511 goto out;
2512 }
2513 ok(!strcmp(buffer, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2514
2515 test_status_code(hr, 407);
2516 test_request_flags(hr, 0);
2517
2518 sz = sizeof buffer;
2519 r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL);
2520 ok(r, "HttpQueryInfo failed\n");
2521 ok(!strcmp(buffer, "Proxy Authentication Required"), "proxy text wrong\n");
2522
2523 sz = sizeof buffer;
2524 r = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &sz, NULL);
2525 ok(r, "HttpQueryInfo failed\n");
2526 ok(!strcmp(buffer, "HTTP/1.1"), "http version wrong\n");
2527
2528 sz = sizeof buffer;
2529 r = HttpQueryInfoA(hr, HTTP_QUERY_SERVER, buffer, &sz, NULL);
2530 ok(r, "HttpQueryInfo failed\n");
2531 ok(!strcmp(buffer, "winetest"), "http server wrong\n");
2532
2533 sz = sizeof buffer;
2534 r = HttpQueryInfoA(hr, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL);
2535 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo should fail\n");
2536 ok(r == FALSE, "HttpQueryInfo failed\n");
2537
2538 out:
2539 InternetCloseHandle(hr);
2540 InternetCloseHandle(hc);
2541 InternetCloseHandle(hi);
2542 }
2543
2544 static void test_proxy_direct(int port)
2545 {
2546 HINTERNET hi, hc, hr;
2547 DWORD r, sz, error;
2548 char buffer[0x40], *url;
2549 WCHAR bufferW[0x40];
2550 static const char url_fmt[] = "http://test.winehq.org:%u/test2";
2551 static CHAR username[] = "mike",
2552 password[] = "1101",
2553 useragent[] = "winetest";
2554 static const WCHAR usernameW[] = {'m','i','k','e',0},
2555 passwordW[] = {'1','1','0','1',0},
2556 useragentW[] = {'w','i','n','e','t','e','s','t',0};
2557
2558 /* specify proxy type without the proxy and bypass */
2559 SetLastError(0xdeadbeef);
2560 hi = InternetOpenW(NULL, INTERNET_OPEN_TYPE_PROXY, NULL, NULL, 0);
2561 error = GetLastError();
2562 ok(error == ERROR_INVALID_PARAMETER ||
2563 broken(error == ERROR_SUCCESS) /* WinXPProSP2 */, "got %u\n", error);
2564 ok(hi == NULL || broken(!!hi) /* WinXPProSP2 */, "open should have failed\n");
2565
2566 sprintf(buffer, "localhost:%d\n", port);
2567 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0);
2568 ok(hi != NULL, "open failed\n");
2569
2570 /* try connect without authorization */
2571 hc = InternetConnectA(hi, "test.winehq.org", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2572 ok(hc != NULL, "connect failed\n");
2573
2574 hr = HttpOpenRequestA(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
2575 ok(hr != NULL, "HttpOpenRequest failed\n");
2576
2577 sz = 0;
2578 SetLastError(0xdeadbeef);
2579 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, NULL, &sz);
2580 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2581 ok(!r, "unexpected success\n");
2582 ok(sz == 1, "got %u\n", sz);
2583
2584 sz = 0;
2585 SetLastError(0xdeadbeef);
2586 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, NULL, &sz);
2587 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2588 ok(!r, "unexpected success\n");
2589 ok(sz == 1, "got %u\n", sz);
2590
2591 sz = sizeof(buffer);
2592 SetLastError(0xdeadbeef);
2593 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz);
2594 ok(r, "unexpected failure %u\n", GetLastError());
2595 ok(!sz, "got %u\n", sz);
2596
2597 sz = sizeof(buffer);
2598 SetLastError(0xdeadbeef);
2599 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2600 ok(r, "unexpected failure %u\n", GetLastError());
2601 ok(!sz, "got %u\n", sz);
2602
2603 sz = 0;
2604 SetLastError(0xdeadbeef);
2605 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, NULL, &sz);
2606 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2607 ok(!r, "unexpected success\n");
2608 ok(sz == 1, "got %u\n", sz);
2609
2610 sz = 0;
2611 SetLastError(0xdeadbeef);
2612 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, NULL, &sz);
2613 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2614 ok(!r, "unexpected success\n");
2615 ok(sz == 1, "got %u\n", sz);
2616
2617 sz = sizeof(buffer);
2618 SetLastError(0xdeadbeef);
2619 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz);
2620 ok(r, "unexpected failure %u\n", GetLastError());
2621 ok(!sz, "got %u\n", sz);
2622
2623 sz = sizeof(buffer);
2624 SetLastError(0xdeadbeef);
2625 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz);
2626 ok(r, "unexpected failure %u\n", GetLastError());
2627 ok(!sz, "got %u\n", sz);
2628
2629 sz = 0;
2630 SetLastError(0xdeadbeef);
2631 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, NULL, &sz);
2632 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2633 ok(!r, "unexpected success\n");
2634 ok(sz == 34, "got %u\n", sz);
2635
2636 sz = sizeof(buffer);
2637 SetLastError(0xdeadbeef);
2638 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz);
2639 ok(r, "unexpected failure %u\n", GetLastError());
2640 ok(sz == 33, "got %u\n", sz);
2641
2642 r = HttpSendRequestW(hr, NULL, 0, NULL, 0);
2643 ok(r || broken(!r), "HttpSendRequest failed %u\n", GetLastError());
2644 if (!r)
2645 {
2646 win_skip("skipping proxy tests on broken wininet\n");
2647 goto done;
2648 }
2649
2650 test_status_code(hr, 407);
2651
2652 /* set the user + password then try again */
2653 r = InternetSetOptionA(hi, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2654 ok(!r, "unexpected success\n");
2655
2656 r = InternetSetOptionA(hc, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2657 ok(r, "failed to set user\n");
2658
2659 r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2660 ok(r, "failed to set user\n");
2661
2662 buffer[0] = 0;
2663 sz = 3;
2664 SetLastError(0xdeadbeef);
2665 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2666 ok(!r, "unexpected failure %u\n", GetLastError());
2667 ok(!buffer[0], "got %s\n", buffer);
2668 ok(sz == strlen(username) + 1, "got %u\n", sz);
2669
2670 buffer[0] = 0;
2671 sz = 0;
2672 SetLastError(0xdeadbeef);
2673 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2674 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2675 ok(!r, "unexpected success\n");
2676 ok(sz == strlen(username) + 1, "got %u\n", sz);
2677
2678 bufferW[0] = 0;
2679 sz = 0;
2680 SetLastError(0xdeadbeef);
2681 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_USERNAME, bufferW, &sz);
2682 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2683 ok(!r, "unexpected success\n");
2684 ok(sz == (lstrlenW(usernameW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2685
2686 buffer[0] = 0;
2687 sz = sizeof(buffer);
2688 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2689 ok(r, "failed to get username\n");
2690 ok(!strcmp(buffer, username), "got %s\n", buffer);
2691 ok(sz == strlen(username), "got %u\n", sz);
2692
2693 buffer[0] = 0;
2694 sz = sizeof(bufferW);
2695 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_USERNAME, bufferW, &sz);
2696 ok(r, "failed to get username\n");
2697 ok(!lstrcmpW(bufferW, usernameW), "wrong username\n");
2698 ok(sz == lstrlenW(usernameW), "got %u\n", sz);
2699
2700 r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, username, 1);
2701 ok(r, "failed to set user\n");
2702
2703 buffer[0] = 0;
2704 sz = sizeof(buffer);
2705 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2706 ok(r, "failed to get username\n");
2707 ok(!strcmp(buffer, username), "got %s\n", buffer);
2708 ok(sz == strlen(username), "got %u\n", sz);
2709
2710 r = InternetSetOptionA(hi, INTERNET_OPTION_USER_AGENT, useragent, 1);
2711 ok(r, "failed to set useragent\n");
2712
2713 buffer[0] = 0;
2714 sz = 0;
2715 SetLastError(0xdeadbeef);
2716 r = InternetQueryOptionA(hi, INTERNET_OPTION_USER_AGENT, buffer, &sz);
2717 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2718 ok(!r, "unexpected success\n");
2719 ok(sz == strlen(useragent) + 1, "got %u\n", sz);
2720
2721 buffer[0] = 0;
2722 sz = sizeof(buffer);
2723 r = InternetQueryOptionA(hi, INTERNET_OPTION_USER_AGENT, buffer, &sz);
2724 ok(r, "failed to get user agent\n");
2725 ok(!strcmp(buffer, useragent), "got %s\n", buffer);
2726 ok(sz == strlen(useragent), "got %u\n", sz);
2727
2728 bufferW[0] = 0;
2729 sz = 0;
2730 SetLastError(0xdeadbeef);
2731 r = InternetQueryOptionW(hi, INTERNET_OPTION_USER_AGENT, bufferW, &sz);
2732 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2733 ok(!r, "unexpected success\n");
2734 ok(sz == (lstrlenW(useragentW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2735
2736 bufferW[0] = 0;
2737 sz = sizeof(bufferW);
2738 r = InternetQueryOptionW(hi, INTERNET_OPTION_USER_AGENT, bufferW, &sz);
2739 ok(r, "failed to get user agent\n");
2740 ok(!lstrcmpW(bufferW, useragentW), "wrong user agent\n");
2741 ok(sz == lstrlenW(useragentW), "got %u\n", sz);
2742
2743 r = InternetSetOptionA(hr, INTERNET_OPTION_USERNAME, username, 1);
2744 ok(r, "failed to set user\n");
2745
2746 buffer[0] = 0;
2747 sz = 0;
2748 SetLastError(0xdeadbeef);
2749 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz);
2750 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2751 ok(!r, "unexpected success\n");
2752 ok(sz == strlen(username) + 1, "got %u\n", sz);
2753
2754 buffer[0] = 0;
2755 sz = sizeof(buffer);
2756 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz);
2757 ok(r, "failed to get user\n");
2758 ok(!strcmp(buffer, username), "got %s\n", buffer);
2759 ok(sz == strlen(username), "got %u\n", sz);
2760
2761 bufferW[0] = 0;
2762 sz = 0;
2763 SetLastError(0xdeadbeef);
2764 r = InternetQueryOptionW(hr, INTERNET_OPTION_USERNAME, bufferW, &sz);
2765 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2766 ok(!r, "unexpected success\n");
2767 ok(sz == (lstrlenW(usernameW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2768
2769 bufferW[0] = 0;
2770 sz = sizeof(bufferW);
2771 r = InternetQueryOptionW(hr, INTERNET_OPTION_USERNAME, bufferW, &sz);
2772 ok(r, "failed to get user\n");
2773 ok(!lstrcmpW(bufferW, usernameW), "wrong user\n");
2774 ok(sz == lstrlenW(usernameW), "got %u\n", sz);
2775
2776 r = InternetSetOptionA(hr, INTERNET_OPTION_PASSWORD, password, 1);
2777 ok(r, "failed to set password\n");
2778
2779 buffer[0] = 0;
2780 sz = 0;
2781 SetLastError(0xdeadbeef);
2782 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz);
2783 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2784 ok(!r, "unexpected success\n");
2785 ok(sz == strlen(password) + 1, "got %u\n", sz);
2786
2787 buffer[0] = 0;
2788 sz = sizeof(buffer);
2789 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz);
2790 ok(r, "failed to get password\n");
2791 ok(!strcmp(buffer, password), "got %s\n", buffer);
2792 ok(sz == strlen(password), "got %u\n", sz);
2793
2794 bufferW[0] = 0;
2795 sz = 0;
2796 SetLastError(0xdeadbeef);
2797 r = InternetQueryOptionW(hr, INTERNET_OPTION_PASSWORD, bufferW, &sz);
2798 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2799 ok(!r, "unexpected success\n");
2800 ok(sz == (lstrlenW(passwordW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2801
2802 bufferW[0] = 0;
2803 sz = sizeof(bufferW);
2804 r = InternetQueryOptionW(hr, INTERNET_OPTION_PASSWORD, bufferW, &sz);
2805 ok(r, "failed to get password\n");
2806 ok(!lstrcmpW(bufferW, passwordW), "wrong password\n");
2807 ok(sz == lstrlenW(passwordW), "got %u\n", sz);
2808
2809 url = HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt) + 11);
2810 sprintf(url, url_fmt, port);
2811 buffer[0] = 0;
2812 sz = 0;
2813 SetLastError(0xdeadbeef);
2814 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz);
2815 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2816 ok(!r, "unexpected success\n");
2817 ok(sz == strlen(url) + 1, "got %u\n", sz);
2818
2819 buffer[0] = 0;
2820 sz = sizeof(buffer);
2821 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz);
2822 ok(r, "failed to get url\n");
2823 ok(!strcmp(buffer, url), "got %s\n", buffer);
2824 ok(sz == strlen(url), "got %u\n", sz);
2825
2826 bufferW[0] = 0;
2827 sz = 0;
2828 SetLastError(0xdeadbeef);
2829 r = InternetQueryOptionW(hr, INTERNET_OPTION_URL, bufferW, &sz);
2830 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2831 ok(!r, "unexpected success\n");
2832 ok(sz == (strlen(url) + 1) * sizeof(WCHAR), "got %u\n", sz);
2833
2834 bufferW[0] = 0;
2835 sz = sizeof(bufferW);
2836 r = InternetQueryOptionW(hr, INTERNET_OPTION_URL, bufferW, &sz);
2837 ok(r, "failed to get url\n");
2838 ok(!strcmp_wa(bufferW, url), "wrong url\n");
2839 ok(sz == strlen(url), "got %u\n", sz);
2840 HeapFree(GetProcessHeap(), 0, url);
2841
2842 r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, password, 4);
2843 ok(r, "failed to set password\n");
2844
2845 buffer[0] = 0;
2846 sz = 0;
2847 SetLastError(0xdeadbeef);
2848 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz);
2849 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2850 ok(!r, "unexpected success\n");
2851 ok(sz == strlen(password) + 1, "got %u\n", sz);
2852
2853 buffer[0] = 0;
2854 sz = sizeof(buffer);
2855 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz);
2856 ok(r, "failed to get password\n");
2857 ok(!strcmp(buffer, password), "got %s\n", buffer);
2858 ok(sz == strlen(password), "got %u\n", sz);
2859
2860 bufferW[0] = 0;
2861 sz = 0;
2862 SetLastError(0xdeadbeef);
2863 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_PASSWORD, bufferW, &sz);
2864 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2865 ok(!r, "unexpected success\n");
2866 ok(sz == (lstrlenW(passwordW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2867
2868 bufferW[0] = 0;
2869 sz = sizeof(bufferW);
2870 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_PASSWORD, bufferW, &sz);
2871 ok(r, "failed to get password\n");
2872 ok(!lstrcmpW(bufferW, passwordW), "wrong password\n");
2873 ok(sz == lstrlenW(passwordW), "got %u\n", sz);
2874
2875 r = HttpSendRequestW(hr, NULL, 0, NULL, 0);
2876 if (!r)
2877 {
2878 win_skip("skipping proxy tests on broken wininet\n");
2879 goto done;
2880 }
2881 ok(r, "HttpSendRequest failed %u\n", GetLastError());
2882 sz = sizeof buffer;
2883 r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
2884 ok(r, "HttpQueryInfo failed\n");
2885 ok(!strcmp(buffer, "200"), "proxy code wrong\n");
2886
2887 done:
2888 InternetCloseHandle(hr);
2889 InternetCloseHandle(hc);
2890 InternetCloseHandle(hi);
2891 }
2892
2893 static void test_header_handling_order(int port)
2894 {
2895 static const char authorization[] = "Authorization: Basic dXNlcjpwd2Q=";
2896 static const char connection[] = "Connection: Close";
2897 static const char *types[2] = { "*", NULL };
2898 char data[32];
2899 HINTERNET session, connect, request;
2900 DWORD size, status, data_len;
2901 BOOL ret;
2902
2903 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2904 ok(session != NULL, "InternetOpen failed\n");
2905
2906 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2907 ok(connect != NULL, "InternetConnect failed\n");
2908
2909 request = HttpOpenRequestA(connect, NULL, "/test3", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2910 ok(request != NULL, "HttpOpenRequest failed\n");
2911
2912 ret = HttpAddRequestHeadersA(request, authorization, ~0u, HTTP_ADDREQ_FLAG_ADD);
2913 ok(ret, "HttpAddRequestHeaders failed\n");
2914
2915 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
2916 ok(ret, "HttpSendRequest failed\n");
2917
2918 test_status_code(request, 200);
2919 test_request_flags(request, 0);
2920
2921 InternetCloseHandle(request);
2922
2923 request = HttpOpenRequestA(connect, NULL, "/test4", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2924 ok(request != NULL, "HttpOpenRequest failed\n");
2925
2926 ret = HttpSendRequestA(request, connection, ~0u, NULL, 0);
2927 ok(ret, "HttpSendRequest failed\n");
2928
2929 status = 0;
2930 size = sizeof(status);
2931 ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2932 ok(ret, "HttpQueryInfo failed\n");
2933 ok(status == 200 || status == 400 /* IE6 */, "got status %u, expected 200 or 400\n", status);
2934
2935 InternetCloseHandle(request);
2936 InternetCloseHandle(connect);
2937
2938 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2939 ok(connect != NULL, "InternetConnect failed\n");
2940
2941 request = HttpOpenRequestA(connect, "POST", "/test7", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2942 ok(request != NULL, "HttpOpenRequest failed\n");
2943
2944 ret = HttpAddRequestHeadersA(request, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
2945 ok(ret, "HttpAddRequestHeaders failed\n");
2946
2947 ret = HttpSendRequestA(request, connection, ~0u, NULL, 0);
2948 ok(ret, "HttpSendRequest failed\n");
2949
2950 status = 0;
2951 size = sizeof(status);
2952 ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2953 ok(ret, "HttpQueryInfo failed\n");
2954 ok(status == 200, "got status %u, expected 200\n", status);
2955
2956 InternetCloseHandle(request);
2957 InternetCloseHandle(connect);
2958
2959 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2960 ok(connect != NULL, "InternetConnect failed\n");
2961
2962 request = HttpOpenRequestA(connect, "POST", "/test7b", NULL, NULL, types, 0, 0);
2963 ok(request != NULL, "HttpOpenRequest failed\n");
2964
2965 ret = HttpAddRequestHeadersA(request, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
2966 ok(ret, "HttpAddRequestHeaders failed\n");
2967
2968 data_len = sizeof(data);
2969 memset(data, 'a', sizeof(data));
2970 ret = HttpSendRequestA(request, connection, ~0u, data, data_len);
2971 ok(ret, "HttpSendRequest failed\n");
2972
2973 status = 0;
2974 size = sizeof(status);
2975 ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2976 ok(ret, "HttpQueryInfo failed\n");
2977 ok(status == 200, "got status %u, expected 200\n", status);
2978
2979 InternetCloseHandle(request);
2980 InternetCloseHandle(connect);
2981 InternetCloseHandle(session);
2982 }
2983
2984 static void test_connection_header(int port)
2985 {
2986 HINTERNET ses, con, req;
2987 BOOL ret;
2988
2989 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2990 ok(ses != NULL, "InternetOpen failed\n");
2991
2992 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2993 ok(con != NULL, "InternetConnect failed\n");
2994
2995 req = HttpOpenRequestA(con, NULL, "/test8", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2996 ok(req != NULL, "HttpOpenRequest failed\n");
2997
2998 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2999 ok(ret, "HttpSendRequest failed\n");
3000
3001 test_status_code(req, 200);
3002
3003 InternetCloseHandle(req);
3004
3005 req = HttpOpenRequestA(con, NULL, "/test9", NULL, NULL, NULL, 0, 0);
3006 ok(req != NULL, "HttpOpenRequest failed\n");
3007
3008 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3009 ok(ret, "HttpSendRequest failed\n");
3010
3011 test_status_code(req, 200);
3012
3013 InternetCloseHandle(req);
3014
3015 req = HttpOpenRequestA(con, NULL, "/test9", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
3016 ok(req != NULL, "HttpOpenRequest failed\n");
3017
3018 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3019 ok(ret, "HttpSendRequest failed\n");
3020
3021 test_status_code(req, 200);
3022
3023 InternetCloseHandle(req);
3024
3025 req = HttpOpenRequestA(con, "POST", "/testA", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
3026 ok(req != NULL, "HttpOpenRequest failed\n");
3027
3028 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3029 ok(ret, "HttpSendRequest failed\n");
3030
3031 test_status_code(req, 200);
3032
3033 InternetCloseHandle(req);
3034 InternetCloseHandle(con);
3035 InternetCloseHandle(ses);
3036 }
3037
3038 static void test_header_override(int port)
3039 {
3040 char buffer[128], host_header_override[30], full_url[128];
3041 HINTERNET ses, con, req;
3042 DWORD size, count, err;
3043 BOOL ret;
3044
3045 sprintf(host_header_override, "Host: test.local:%d\r\n", port);
3046 sprintf(full_url, "http://localhost:%d/test_host_override", port);
3047
3048 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3049 ok(ses != NULL, "InternetOpen failed\n");
3050
3051 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3052 ok(con != NULL, "InternetConnect failed\n");
3053
3054 req = HttpOpenRequestA(con, NULL, "/test_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3055 ok(req != NULL, "HttpOpenRequest failed\n");
3056
3057 size = sizeof(buffer) - 1;
3058 count = 0;
3059 memset(buffer, 0, sizeof(buffer));
3060 ret = HttpQueryInfoA(req, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &count);
3061 err = GetLastError();
3062 ok(!ret, "HttpQueryInfo succeeded\n");
3063 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err);
3064
3065 size = sizeof(buffer) - 1;
3066 memset(buffer, 0, sizeof(buffer));
3067 ret = InternetQueryOptionA(req, INTERNET_OPTION_URL, buffer, &size);
3068 ok(ret, "InternetQueryOption failed\n");
3069 ok(!strcmp(full_url, buffer), "Expected %s, got %s\n", full_url, buffer);
3070
3071 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_COALESCE);
3072 ok(ret, "HttpAddRequestHeaders failed\n");
3073
3074 size = sizeof(buffer) - 1;
3075 count = 0;
3076 memset(buffer, 0, sizeof(buffer));
3077 ret = HttpQueryInfoA(req, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &count);
3078 ok(ret, "HttpQueryInfo failed\n");
3079
3080 size = sizeof(buffer) - 1;
3081 memset(buffer, 0, sizeof(buffer));
3082 ret = InternetQueryOptionA(req, INTERNET_OPTION_URL, buffer, &size);
3083 ok(ret, "InternetQueryOption failed\n");
3084 ok(!strcmp(full_url, buffer), "Expected %s, got %s\n", full_url, buffer);
3085
3086 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3087 ok(ret, "HttpSendRequest failed\n");
3088
3089 test_status_code(req, 200);
3090
3091 InternetCloseHandle(req);
3092 req = HttpOpenRequestA(con, NULL, "/test_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3093 ok(req != NULL, "HttpOpenRequest failed\n");
3094
3095 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_COALESCE);
3096 ok(ret, "HttpAddRequestHeaders failed\n");
3097
3098 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_COALESCE);
3099 ok(ret, "HttpAddRequestHeaders failed\n");
3100
3101 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3102 ok(ret, "HttpSendRequest failed\n");
3103
3104 test_status_code(req, 400);
3105
3106 InternetCloseHandle(req);
3107 req = HttpOpenRequestA(con, NULL, "/test_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3108 ok(req != NULL, "HttpOpenRequest failed\n");
3109
3110 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD);
3111 ok(ret, "HttpAddRequestHeaders failed\n");
3112
3113 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3114 ok(ret, "HttpSendRequest failed\n");
3115
3116 test_status_code(req, 200);
3117
3118 InternetCloseHandle(req);
3119 req = HttpOpenRequestA(con, NULL, "/test_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3120 ok(req != NULL, "HttpOpenRequest failed\n");
3121
3122 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_REPLACE);
3123 err = GetLastError();
3124 ok(!ret, "HttpAddRequestHeaders succeeded\n");
3125 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err);
3126
3127 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3128 ok(ret, "HttpSendRequest failed\n");
3129
3130 test_status_code(req, 400);
3131
3132 InternetCloseHandle(req);
3133 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3134 req = HttpOpenRequestA(con, NULL, "/testC", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3135 ok(req != NULL, "HttpOpenRequest failed\n");
3136
3137 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD);
3138 ok(ret, "HttpAddRequestHeaders failed\n");
3139
3140 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3141 ok(ret, "HttpSendRequest failed\n");
3142
3143 test_status_code(req, 200);
3144
3145 InternetCloseHandle(req);
3146 req = HttpOpenRequestA(con, NULL, "/test_cookie_set_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3147 ok(req != NULL, "HttpOpenRequest failed\n");
3148
3149 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD);
3150 ok(ret, "HttpAddRequestHeaders failed\n");
3151
3152 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3153 ok(ret, "HttpSendRequest failed\n");
3154
3155 test_status_code(req, 200);
3156
3157 InternetCloseHandle(req);
3158 req = HttpOpenRequestA(con, NULL, "/test_cookie_check_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3159 ok(req != NULL, "HttpOpenRequest failed\n");
3160
3161 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD);
3162 ok(ret, "HttpAddRequestHeaders failed\n");
3163
3164 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3165 ok(ret, "HttpSendRequest failed\n");
3166
3167 test_status_code(req, 200);
3168
3169 InternetCloseHandle(req);
3170 req = HttpOpenRequestA(con, NULL, "/test_cookie_check_host_override", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3171 ok(req != NULL, "HttpOpenRequest failed\n");
3172
3173 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3174 ok(ret, "HttpSendRequest failed\n");
3175
3176 test_status_code(req, 200);
3177
3178 InternetCloseHandle(req);
3179 InternetSetCookieA("http://test.local", "foo", "bar");
3180 req = HttpOpenRequestA(con, NULL, "/test_cookie_check_different_host", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3181 ok(req != NULL, "HttpOpenRequest failed\n");
3182
3183 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3184 ok(ret, "HttpSendRequest failed\n");
3185
3186 test_status_code(req, 200);
3187
3188 InternetCloseHandle(req);
3189 req = HttpOpenRequestA(con, NULL, "/test_cookie_check_different_host", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3190 ok(req != NULL, "HttpOpenRequest failed\n");
3191
3192 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD);
3193 ok(ret, "HttpAddRequestHeaders failed\n");
3194
3195 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3196 ok(ret, "HttpSendRequest failed\n");
3197
3198 test_status_code(req, 200);
3199
3200 InternetCloseHandle(req);
3201 InternetCloseHandle(con);
3202 InternetCloseHandle(ses);
3203
3204 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3205 ok(ses != NULL, "InternetOpenA failed\n");
3206
3207 con = InternetConnectA(ses, "localhost", port, "test1", "pass", INTERNET_SERVICE_HTTP, 0, 0);
3208 ok(con != NULL, "InternetConnectA failed %u\n", GetLastError());
3209
3210 req = HttpOpenRequestA( con, "HEAD", "/test_auth_host1", NULL, NULL, NULL, 0, 0);
3211 ok(req != NULL, "HttpOpenRequestA failed %u\n", GetLastError());
3212
3213 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3214 ok(ret, "HttpSendRequestA failed %u\n", GetLastError());
3215
3216 test_status_code(req, 200);
3217
3218 InternetCloseHandle(req);
3219 InternetCloseHandle(con);
3220 InternetCloseHandle(ses);
3221
3222 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3223 ok(ses != NULL, "InternetOpenA failed\n");
3224
3225 con = InternetConnectA( ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3226 ok(con != NULL, "InternetConnectA failed %u\n", GetLastError());
3227
3228 req = HttpOpenRequestA(con, "HEAD", "/test_auth_host1", NULL, NULL, NULL, 0, 0);
3229 ok(req != NULL, "HttpOpenRequestA failed %u\n", GetLastError());
3230
3231 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD);
3232 ok(ret, "HttpAddRequestHeaders failed\n");
3233
3234 ret = HttpSendRequestA( req, NULL, 0, NULL, 0 );
3235 ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
3236
3237 test_status_code(req, 200);
3238
3239 InternetCloseHandle(req);
3240 InternetCloseHandle(con);
3241 InternetCloseHandle(ses);
3242
3243 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3244 ok(ses != NULL, "InternetOpenA failed\n");
3245
3246 con = InternetConnectA(ses, "localhost", port, "test1", "pass2", INTERNET_SERVICE_HTTP, 0, 0);
3247 ok(con != NULL, "InternetConnectA failed %u\n", GetLastError());
3248
3249 req = HttpOpenRequestA(con, "HEAD", "/test_auth_host2", NULL, NULL, NULL, 0, 0);
3250 ok(req != NULL, "HttpOpenRequestA failed %u\n", GetLastError());
3251
3252 ret = HttpAddRequestHeadersA(req, host_header_override, ~0u, HTTP_ADDREQ_FLAG_ADD);
3253 ok(ret, "HttpAddRequestHeaders failed\n");
3254
3255 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3256 ok(ret, "HttpSendRequestA failed %u\n", GetLastError());
3257
3258 test_status_code(req, 200);
3259
3260 InternetCloseHandle(req);
3261 InternetCloseHandle(con);
3262 InternetCloseHandle(ses);
3263
3264 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3265 ok(ses != NULL, "InternetOpenA failed\n");
3266
3267 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3268 ok(con != NULL, "InternetConnectA failed %u\n", GetLastError());
3269
3270 req = HttpOpenRequestA(con, "HEAD", "/test_auth_host2", NULL, NULL, NULL, 0, 0);
3271 ok(req != NULL, "HttpOpenRequestA failed %u\n", GetLastError());
3272
3273 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3274 ok(ret, "HttpSendRequestA failed %u\n", GetLastError());
3275
3276 test_status_code(req, 200);
3277
3278 InternetCloseHandle(req);
3279 InternetCloseHandle(con);
3280 InternetCloseHandle(ses);
3281 }
3282
3283 static void test_http1_1(int port)
3284 {
3285 HINTERNET ses, con, req;
3286 BOOL ret;
3287
3288 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3289 ok(ses != NULL, "InternetOpen failed\n");
3290
3291 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3292 ok(con != NULL, "InternetConnect failed\n");
3293
3294 req = HttpOpenRequestA(con, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3295 ok(req != NULL, "HttpOpenRequest failed\n");
3296
3297 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3298 if (ret)
3299 {
3300 InternetCloseHandle(req);
3301
3302 req = HttpOpenRequestA(con, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3303 ok(req != NULL, "HttpOpenRequest failed\n");
3304
3305 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3306 ok(ret, "HttpSendRequest failed\n");
3307 }
3308
3309 InternetCloseHandle(req);
3310 InternetCloseHandle(con);
3311 InternetCloseHandle(ses);
3312 }
3313
3314 static void test_connection_closing(int port)
3315 {
3316 HINTERNET session, connection, req;
3317 DWORD res;
3318
3319 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
3320
3321 session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
3322 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
3323
3324 pInternetSetStatusCallbackA(session, callback);
3325
3326 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3327 connection = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
3328 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
3329 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3330
3331 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3332 req = HttpOpenRequestA(connection, "GET", "/testJ", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0xdeadbeaf);
3333 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
3334 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3335
3336 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3337 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3338 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3339 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3340 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3341 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3342 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3343 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3344 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION);
3345 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED);
3346 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3347
3348 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
3349 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3350 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3351 WaitForSingleObject(hCompleteEvent, INFINITE);
3352 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3353
3354 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3355 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3356 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3357 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3358 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3359 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3360 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3361 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3362 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3363 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3364 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3365
3366 test_status_code(req, 200);
3367
3368 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3369 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3370 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3371 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3372 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3373 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3374 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3375 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3376 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3377
3378 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
3379 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3380 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3381 WaitForSingleObject(hCompleteEvent, INFINITE);
3382 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3383
3384 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3385 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3386 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3387 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3388 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3389 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3390 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3391 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3392 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3393
3394 test_status_code(req, 210);
3395
3396 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3397 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3398 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3399 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3400 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3401 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3402 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3403 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3404 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION);
3405 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED);
3406 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3407
3408 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
3409 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3410 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3411 WaitForSingleObject(hCompleteEvent, INFINITE);
3412 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3413
3414 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3415 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3416 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3417 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3418 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3419 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3420 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3421 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3422 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3423 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3424 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3425
3426 test_status_code(req, 200);
3427
3428 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION);
3429 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED);
3430
3431 close_async_handle(session, hCompleteEvent, 2);
3432 CloseHandle(hCompleteEvent);
3433 }
3434
3435 static void test_successive_HttpSendRequest(int port)
3436 {
3437 HINTERNET session, connection, req;
3438 DWORD res;
3439
3440 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
3441
3442 session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
3443 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
3444
3445 pInternetSetStatusCallbackA(session, callback);
3446
3447 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3448 connection = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
3449 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
3450 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3451
3452 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3453 req = HttpOpenRequestA(connection, "GET", "/testH", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0xdeadbeaf);
3454 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
3455 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3456
3457 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3458 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3459 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3460 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3461 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3462 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3463 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3464 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3465 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3466
3467 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
3468 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3469 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3470 WaitForSingleObject(hCompleteEvent, INFINITE);
3471 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3472
3473 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3474 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3475 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3476 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3477 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3478 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3479 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3480 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3481 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3482
3483 test_status_code(req, 210);
3484
3485 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3486 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3487 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3488 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3489 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3490 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3491 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION);
3492 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED);
3493 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3494
3495 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
3496 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3497 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3498 WaitForSingleObject(hCompleteEvent, INFINITE);
3499 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3500
3501 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3502 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3503 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3504 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3505 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3506 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3507 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3508 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3509 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3510
3511 test_status_code(req, 200);
3512
3513 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION);
3514 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED);
3515
3516 close_async_handle(session, hCompleteEvent, 2);
3517 CloseHandle(hCompleteEvent);
3518 }
3519
3520 static void test_no_content(int port)
3521 {
3522 HINTERNET session, connection, req;
3523 DWORD res;
3524
3525 trace("Testing 204 no content response...\n");
3526
3527 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
3528
3529 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
3530 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
3531
3532 pInternetSetStatusCallbackA(session, callback);
3533
3534 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3535 connection = InternetConnectA(session, "localhost", port,
3536 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
3537 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
3538 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3539
3540 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3541 req = HttpOpenRequestA(connection, "GET", "/test_no_content", NULL, NULL, NULL,
3542 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
3543 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
3544 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3545
3546 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3547 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3548 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3549 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3550 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3551 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3552 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3553 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
3554 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
3555 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3556
3557 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
3558 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3559 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3560 WaitForSingleObject(hCompleteEvent, INFINITE);
3561 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3562
3563 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3564 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3565 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3566 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3567 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3568 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3569 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3570 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3571
3572 close_async_handle(session, hCompleteEvent, 2);
3573 CloseHandle(hCompleteEvent);
3574
3575 /*
3576 * The connection should be closed before closing handle. This is true for most
3577 * wininet versions (including Wine), but some old win2k versions fail to do that.
3578 */
3579 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3580 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3581 }
3582
3583 static void test_conn_close(int port)
3584 {
3585 HINTERNET session, connection, req;
3586 DWORD res, avail, size;
3587 BYTE buf[1024];
3588
3589 trace("Testing connection close connection...\n");
3590
3591 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
3592 conn_close_event = CreateEventW(NULL, FALSE, FALSE, NULL);
3593
3594 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
3595 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
3596
3597 pInternetSetStatusCallbackA(session, callback);
3598
3599 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3600 connection = InternetConnectA(session, "localhost", port,
3601 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
3602 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
3603 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3604
3605 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3606 req = HttpOpenRequestA(connection, "GET", "/test_conn_close", NULL, NULL, NULL,
3607 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
3608 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
3609 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3610
3611 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3612 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3613 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3614 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3615 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3616 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3617 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3618 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3619
3620 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
3621 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3622 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3623 WaitForSingleObject(hCompleteEvent, INFINITE);
3624 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3625
3626 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3627 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3628 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3629 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3630 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3631 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3632 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3633 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3634
3635 avail = 0;
3636 res = InternetQueryDataAvailable(req, &avail, 0, 0);
3637 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3638 ok(avail != 0, "avail = 0\n");
3639
3640 size = 0;
3641 res = InternetReadFile(req, buf, avail, &size);
3642 ok(res, "InternetReadFile failed: %u\n", GetLastError());
3643
3644 /* IE11 calls those in InternetQueryDataAvailable call. */
3645 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE);
3646 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED);
3647
3648 res = InternetQueryDataAvailable(req, &avail, 0, 0);
3649 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3650 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3651 ok(!avail, "avail = %u, expected 0\n", avail);
3652
3653 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3654
3655 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
3656 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
3657 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3658 SetEvent(conn_close_event);
3659 #ifdef ROSTESTS_73_FIXED
3660 WaitForSingleObject(hCompleteEvent, INFINITE);
3661 #else /* ROSTESTS_73_FIXED */
3662 ok(WaitForSingleObject(hCompleteEvent, 5000) == WAIT_OBJECT_0, "Wait timed out\n");
3663 #endif /* ROSTESTS_73_FIXED */
3664 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3665 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3666 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3667 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3668 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3669
3670 close_async_handle(session, hCompleteEvent, 2);
3671 CloseHandle(hCompleteEvent);
3672 }
3673
3674 static void test_no_cache(int port)
3675 {
3676 static const char cache_control_no_cache[] = "/test_cache_control_no_cache";
3677 static const char cache_control_no_store[] = "/test_cache_control_no_store";
3678 static const char cache_url_fmt[] = "http://localhost:%d%s";
3679
3680 char cache_url[256], buf[256];
3681 HINTERNET ses, con, req;
3682 DWORD read, size;
3683 BOOL ret;
3684
3685 trace("Testing no-cache header\n");
3686
3687 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3688 ok(ses != NULL,"InternetOpen failed with error %u\n", GetLastError());
3689
3690 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3691 ok(con != NULL, "InternetConnect failed with error %u\n", GetLastError());
3692
3693 req = HttpOpenRequestA(con, NULL, cache_control_no_cache, NULL, NULL, NULL, 0, 0);
3694 ok(req != NULL, "HttpOpenRequest failed\n");
3695
3696 sprintf(cache_url, cache_url_fmt, port, cache_control_no_cache);
3697 DeleteUrlCacheEntryA(cache_url);
3698
3699 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3700 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3701 size = 0;
3702 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
3703 size += read;
3704 ok(size == 12, "read %d bytes of data\n", size);
3705 InternetCloseHandle(req);
3706
3707 req = HttpOpenRequestA(con, NULL, cache_control_no_cache, NULL, NULL, NULL, 0, 0);
3708 ok(req != NULL, "HttpOpenRequest failed\n");
3709
3710 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3711 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3712 size = 0;
3713 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
3714 size += read;
3715 ok(size == 0, "read %d bytes of data\n", size);
3716 InternetCloseHandle(req);
3717 DeleteUrlCacheEntryA(cache_url);
3718
3719 req = HttpOpenRequestA(con, NULL, cache_control_no_store, NULL, NULL, NULL, 0, 0);
3720 ok(req != NULL, "HttpOpenRequest failed\n");
3721
3722 sprintf(cache_url, cache_url_fmt, port, cache_control_no_store);
3723 DeleteUrlCacheEntryA(cache_url);
3724
3725 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3726 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3727 size = 0;
3728 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
3729 size += read;
3730 ok(size == 12, "read %d bytes of data\n", size);
3731 InternetCloseHandle(req);
3732
3733 ret = DeleteUrlCacheEntryA(cache_url);
3734 ok(!ret && GetLastError()==ERROR_FILE_NOT_FOUND, "cache entry should not exist\n");
3735
3736 InternetCloseHandle(con);
3737 InternetCloseHandle(ses);
3738 }
3739
3740 static void test_cache_read_gzipped(int port)
3741 {
3742 static const char cache_url_fmt[] = "http://localhost:%d%s";
3743 static const char get_gzip[] = "/test_cache_gzip";
3744 static const char content[] = "gzip test\n";
3745 static const char text_html[] = "text/html";
3746 static const char raw_header[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3747
3748 HINTERNET ses, con, req;
3749 DWORD read, size;
3750 char cache_url[256], buf[256];
3751 BOOL ret;
3752
3753 trace("Testing reading compressed content from cache\n");
3754
3755 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3756 ok(ses != NULL,"InternetOpen failed with error %u\n", GetLastError());
3757
3758 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3759 ok(con != NULL, "InternetConnect failed with error %u\n", GetLastError());
3760
3761 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, 0, 0);
3762 ok(req != NULL, "HttpOpenRequest failed\n");
3763
3764 ret = TRUE;
3765 ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
3766 if(!ret && GetLastError()==ERROR_INTERNET_INVALID_OPTION) {
3767 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3768 InternetCloseHandle(req);
3769 InternetCloseHandle(con);
3770 InternetCloseHandle(ses);
3771 return;
3772 }
3773 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3774
3775 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3776 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3777 size = 0;
3778 while(InternetReadFile(req, buf+size, sizeof(buf)-size, &read) && read)
3779 size += read;
3780 ok(size == 10, "read %d bytes of data\n", size);
3781 buf[size] = 0;
3782 ok(!strncmp(buf, content, size), "incorrect page content: %s\n", buf);
3783
3784 size = sizeof(buf)-1;
3785 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_TYPE, buf, &size, 0);
3786 ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3787 buf[size] = 0;
3788 ok(!strncmp(text_html, buf, size), "buf = %s\n", buf);
3789
3790 size = sizeof(buf)-1;
3791 ret = HttpQueryInfoA(req, HTTP_QUERY_RAW_HEADERS_CRLF, buf, &size, 0);
3792 ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3793 buf[size] = 0;
3794 ok(!strncmp(raw_header, buf, size), "buf = %s\n", buf);
3795 InternetCloseHandle(req);
3796
3797 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
3798 ok(req != NULL, "HttpOpenRequest failed\n");
3799
3800 ret = TRUE;
3801 ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
3802 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3803
3804 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3805 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3806 size = 0;
3807 while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read)
3808 size += read;
3809 todo_wine ok(size == 10, "read %d bytes of data\n", size);
3810 buf[size] = 0;
3811 ok(!strncmp(buf, content, size), "incorrect page content: %s\n", buf);
3812
3813 size = sizeof(buf);
3814 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
3815 ok(!ret && GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND,
3816 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3817 ret, GetLastError());
3818
3819 size = sizeof(buf)-1;
3820 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_TYPE, buf, &size, 0);
3821 todo_wine ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3822 buf[size] = 0;
3823 todo_wine ok(!strncmp(text_html, buf, size), "buf = %s\n", buf);
3824 InternetCloseHandle(req);
3825
3826 /* Decompression doesn't work while reading from cache */
3827 test_cache_gzip = 0;
3828 sprintf(cache_url, cache_url_fmt, port, get_gzip);
3829 DeleteUrlCacheEntryA(cache_url);
3830
3831 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, 0, 0);
3832 ok(req != NULL, "HttpOpenRequest failed\n");
3833
3834 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3835 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3836 size = 0;
3837 while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read)
3838 size += read;
3839 ok(size == 31, "read %d bytes of data\n", size);
3840 InternetCloseHandle(req);
3841
3842 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
3843 ok(req != NULL, "HttpOpenRequest failed\n");
3844
3845 ret = TRUE;
3846 ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
3847 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3848
3849 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3850 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3851 size = 0;
3852 while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read)
3853 size += read;
3854 todo_wine ok(size == 31, "read %d bytes of data\n", size);
3855
3856 size = sizeof(buf);
3857 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
3858 todo_wine ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3859 InternetCloseHandle(req);
3860
3861 InternetCloseHandle(con);
3862 InternetCloseHandle(ses);
3863
3864 DeleteUrlCacheEntryA(cache_url);
3865 }
3866
3867 static void test_HttpSendRequestW(int port)
3868 {
3869 static const WCHAR header[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3870 HINTERNET ses, con, req;
3871 DWORD error;
3872 BOOL ret;
3873
3874 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
3875 ok(ses != NULL, "InternetOpen failed\n");
3876
3877 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3878 ok(con != NULL, "InternetConnect failed\n");
3879
3880 req = HttpOpenRequestA(con, NULL, "/test1", NULL, NULL, NULL, 0, 0);
3881 ok(req != NULL, "HttpOpenRequest failed\n");
3882
3883 SetLastError(0xdeadbeef);
3884 ret = HttpSendRequestW(req, header, ~0u, NULL, 0);
3885 error = GetLastError();
3886 ok(!ret, "HttpSendRequestW succeeded\n");
3887 ok(error == ERROR_IO_PENDING ||
3888 broken(error == ERROR_HTTP_HEADER_NOT_FOUND) || /* IE6 */
3889 broken(error == ERROR_INVALID_PARAMETER), /* IE5 */
3890 "got %u expected ERROR_IO_PENDING\n", error);
3891
3892 InternetCloseHandle(req);
3893 InternetCloseHandle(con);
3894 InternetCloseHandle(ses);
3895 }
3896
3897 static void test_cookie_header(int port)
3898 {
3899 HINTERNET ses, con, req;
3900 DWORD size, error;
3901 BOOL ret;
3902 char buffer[256];
3903
3904 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3905 ok(ses != NULL, "InternetOpen failed\n");
3906
3907 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3908 ok(con != NULL, "InternetConnect failed\n");
3909
3910 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3911
3912 req = HttpOpenRequestA(con, NULL, "/testC", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3913 ok(req != NULL, "HttpOpenRequest failed\n");
3914
3915 buffer[0] = 0;
3916 size = sizeof(buffer);
3917 SetLastError(0xdeadbeef);
3918 ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3919 error = GetLastError();
3920 ok(!ret, "HttpQueryInfo succeeded\n");
3921 ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error);
3922
3923 ret = HttpAddRequestHeadersA(req, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD);
3924 ok(ret, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3925
3926 buffer[0] = 0;
3927 size = sizeof(buffer);
3928 ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3929 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
3930 ok(!!strstr(buffer, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer);
3931
3932 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3933 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
3934
3935 test_status_code(req, 200);
3936
3937 buffer[0] = 0;
3938 size = sizeof(buffer);
3939 ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3940 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
3941 ok(!strstr(buffer, "cookie=not biscuit"), "'%s' should not contain \'cookie=not biscuit\'\n", buffer);
3942 ok(!!strstr(buffer, "cookie=biscuit"), "'%s' should contain \'cookie=biscuit\'\n", buffer);
3943
3944 InternetCloseHandle(req);
3945
3946 InternetSetCookieA("http://localhost/testCCCC", "subcookie", "data");
3947
3948 req = HttpOpenRequestA(con, NULL, "/test_cookie_path1", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3949 ok(req != NULL, "HttpOpenRequest failed\n");
3950
3951 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3952 ok(ret, "HttpSendRequest failed\n");
3953
3954 test_status_code(req, 200);
3955 InternetCloseHandle(req);
3956
3957 req = HttpOpenRequestA(con, NULL, "/test_cookie_path1/abc", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3958 ok(req != NULL, "HttpOpenRequest failed\n");
3959
3960 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3961 ok(ret, "HttpSendRequest failed\n");
3962
3963 test_status_code(req, 200);
3964 InternetCloseHandle(req);
3965
3966 req = HttpOpenRequestA(con, NULL, "/test_cookie_set_path", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3967 ok(req != NULL, "HttpOpenRequest failed\n");
3968
3969 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3970 ok(ret, "HttpSendRequest failed\n");
3971
3972 test_status_code(req, 200);
3973 InternetCloseHandle(req);
3974
3975 req = HttpOpenRequestA(con, NULL, "/test_cookie_path2", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3976 ok(req != NULL, "HttpOpenRequest failed\n");
3977
3978 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3979 ok(ret, "HttpSendRequest failed\n");
3980
3981 test_status_code(req, 400);
3982 InternetCloseHandle(req);
3983
3984 req = HttpOpenRequestA(con, NULL, "/test_cookie_merge", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3985 ok(req != NULL, "HttpOpenRequest failed\n");
3986
3987 ret = HttpAddRequestHeadersA(req, "Cookie: manual_cookie=test\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD);
3988 ok(ret, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3989
3990 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3991 ok(ret, "HttpSendRequest failed\n");
3992
3993 test_status_code(req, 200);
3994 InternetCloseHandle(req);
3995
3996 InternetCloseHandle(con);
3997 InternetCloseHandle(ses);
3998 }
3999
4000 static void test_basic_authentication(int port)
4001 {
4002 HINTERNET session, connect, request;
4003 BOOL ret;
4004
4005 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4006 ok(session != NULL, "InternetOpen failed\n");
4007
4008 connect = InternetConnectA(session, "localhost", port, "user", "pwd", INTERNET_SERVICE_HTTP, 0, 0);
4009 ok(connect != NULL, "InternetConnect failed\n");
4010
4011 request = HttpOpenRequestA(connect, NULL, "/test3", NULL, NULL, NULL, 0, 0);
4012 ok(request != NULL, "HttpOpenRequest failed\n");
4013
4014 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4015 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4016
4017 test_status_code(request, 200);
4018 test_request_flags(request, 0);
4019
4020 InternetCloseHandle(request);
4021 InternetCloseHandle(connect);
4022 InternetCloseHandle(session);
4023 }
4024
4025 static void test_premature_disconnect(int port)
4026 {
4027 HINTERNET session, connect, request;
4028 DWORD err;
4029 BOOL ret;
4030
4031 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4032 ok(session != NULL, "InternetOpen failed\n");
4033
4034 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4035 ok(connect != NULL, "InternetConnect failed\n");
4036
4037 request = HttpOpenRequestA(connect, NULL, "/premature_disconnect", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
4038 ok(request != NULL, "HttpOpenRequest failed\n");
4039
4040 SetLastError(0xdeadbeef);
4041 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4042 err = GetLastError();
4043 todo_wine ok(!ret, "HttpSendRequest succeeded\n");
4044 todo_wine ok(err == ERROR_HTTP_INVALID_SERVER_RESPONSE, "got %u\n", err);
4045
4046 InternetCloseHandle(request);
4047 InternetCloseHandle(connect);
4048 InternetCloseHandle(session);
4049 }
4050
4051 static void test_invalid_response_headers(int port)
4052 {
4053 HINTERNET session, connect, request;
4054 DWORD size;
4055 BOOL ret;
4056 char buffer[256];
4057
4058 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4059 ok(session != NULL, "InternetOpen failed\n");
4060
4061 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4062 ok(connect != NULL, "InternetConnect failed\n");
4063
4064 request = HttpOpenRequestA(connect, NULL, "/testE", NULL, NULL, NULL, 0, 0);
4065 ok(request != NULL, "HttpOpenRequest failed\n");
4066
4067 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4068 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4069
4070 test_status_code(request, 401);
4071 test_request_flags(request, 0);
4072
4073 buffer[0] = 0;
4074 size = sizeof(buffer);
4075 ret = HttpQueryInfoA( request, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
4076 ok(ret, "HttpQueryInfo failed\n");
4077 ok(!strcmp(buffer, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
4078 "headers wrong \"%s\"\n", buffer);
4079
4080 buffer[0] = 0;
4081 size = sizeof(buffer);
4082 ret = HttpQueryInfoA( request, HTTP_QUERY_SERVER, buffer, &size, NULL);
4083 ok(ret, "HttpQueryInfo failed\n");
4084 ok(!strcmp(buffer, "winetest"), "server wrong \"%s\"\n", buffer);
4085
4086 InternetCloseHandle(request);
4087 InternetCloseHandle(connect);
4088 InternetCloseHandle(session);
4089 }
4090
4091 static void test_response_without_headers(int port)
4092 {
4093 HINTERNET hi, hc, hr;
4094 DWORD r, count, size;
4095 char buffer[1024];
4096
4097 SetLastError(0xdeadbeef);
4098 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4099 ok(hi != NULL, "open failed %u\n", GetLastError());
4100
4101 SetLastError(0xdeadbeef);
4102 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4103 ok(hc != NULL, "connect failed %u\n", GetLastError());
4104
4105 SetLastError(0xdeadbeef);
4106 hr = HttpOpenRequestA(hc, NULL, "/testG", NULL, NULL, NULL, 0, 0);
4107 ok(hr != NULL, "HttpOpenRequest failed %u\n", GetLastError());
4108
4109 test_request_flags(hr, INTERNET_REQFLAG_NO_HEADERS);
4110
4111 SetLastError(0xdeadbeef);
4112 r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
4113 ok(r, "HttpSendRequest failed %u\n", GetLastError());
4114
4115 test_request_flags_todo(hr, INTERNET_REQFLAG_NO_HEADERS);
4116
4117 count = 0;
4118 memset(buffer, 0, sizeof buffer);
4119 SetLastError(0xdeadbeef);
4120 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
4121 ok(r, "InternetReadFile failed %u\n", GetLastError());
4122 todo_wine ok(count == sizeof page1 - 1, "count was wrong\n");
4123 todo_wine ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
4124
4125 test_status_code(hr, 200);
4126 test_request_flags_todo(hr, INTERNET_REQFLAG_NO_HEADERS);
4127
4128 buffer[0] = 0;
4129 size = sizeof(buffer);
4130 SetLastError(0xdeadbeef);
4131 r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, NULL );
4132 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
4133 ok(!strcmp(buffer, "OK"), "expected OK got: \"%s\"\n", buffer);
4134
4135 buffer[0] = 0;
4136 size = sizeof(buffer);
4137 SetLastError(0xdeadbeef);
4138 r = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &size, NULL);
4139 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
4140 ok(!strcmp(buffer, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer);
4141
4142 buffer[0] = 0;
4143 size = sizeof(buffer);
4144 SetLastError(0xdeadbeef);
4145 r = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
4146 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
4147 ok(!strcmp(buffer, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer);
4148
4149 InternetCloseHandle(hr);
4150 InternetCloseHandle(hc);
4151 InternetCloseHandle(hi);
4152 }
4153
4154 static void test_head_request(int port)
4155 {
4156 DWORD len, content_length;
4157 HINTERNET ses, con, req;
4158 BYTE buf[100];
4159 BOOL ret;
4160
4161 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4162 ok(ses != NULL, "InternetOpen failed\n");
4163
4164 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4165 ok(con != NULL, "InternetConnect failed\n");
4166
4167 req = HttpOpenRequestA(con, "HEAD", "/test_head", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
4168 ok(req != NULL, "HttpOpenRequest failed\n");
4169
4170 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
4171 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
4172
4173 len = sizeof(content_length);
4174 content_length = -1;
4175 ret = HttpQueryInfoA(req, HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_CONTENT_LENGTH, &content_length, &len, 0);
4176 ok(ret, "HttpQueryInfo dailed: %u\n", GetLastError());
4177 ok(len == sizeof(DWORD), "len = %u\n", len);
4178 ok(content_length == 100, "content_length = %u\n", content_length);
4179
4180 len = -1;
4181 ret = InternetReadFile(req, buf, sizeof(buf), &len);
4182 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
4183
4184 len = -1;
4185 ret = InternetReadFile(req, buf, sizeof(buf), &len);
4186 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
4187
4188 InternetCloseHandle(req);
4189 InternetCloseHandle(con);
4190 InternetCloseHandle(ses);
4191 }
4192
4193 static void test_HttpQueryInfo(int port)
4194 {
4195 HINTERNET hi, hc, hr;
4196 DWORD size, index, error;
4197 char buffer[1024];
4198 BOOL ret;
4199
4200 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4201 ok(hi != NULL, "InternetOpen failed\n");
4202
4203 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4204 ok(hc != NULL, "InternetConnect failed\n");
4205
4206 hr = HttpOpenRequestA(hc, NULL, "/testD", NULL, NULL, NULL, 0, 0);
4207 ok(hr != NULL, "HttpOpenRequest failed\n");
4208
4209 size = sizeof(buffer);
4210 ret = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
4211 error = GetLastError();
4212 ok(!ret || broken(ret), "HttpQueryInfo succeeded\n");
4213 if (!ret) ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error);
4214
4215 ret = HttpSendRequestA(hr, NULL, 0, NULL, 0);
4216 ok(ret, "HttpSendRequest failed\n");
4217
4218 index = 0;
4219 size = sizeof(buffer);
4220 ret = HttpQueryInfoA(hr, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &index);
4221 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4222 ok(index == 1, "expected 1 got %u\n", index);
4223
4224 index = 0;
4225 size = sizeof(buffer);
4226 ret = HttpQueryInfoA(hr, HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME, buffer, &size, &index);
4227 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4228 ok(index == 1, "expected 1 got %u\n", index);
4229
4230 index = 0;
4231 size = sizeof(buffer);
4232 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
4233 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4234 ok(index == 0, "expected 0 got %u\n", index);
4235
4236 size = sizeof(buffer);
4237 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
4238 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4239 ok(index == 0, "expected 0 got %u\n", index);
4240
4241 index = 0xdeadbeef; /* invalid start index */
4242 size = sizeof(buffer);
4243 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
4244 todo_wine ok(!ret, "HttpQueryInfo should have failed\n");
4245 todo_wine ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
4246 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
4247
4248 index = 0;
4249 size = sizeof(buffer);
4250 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS_CRLF, buffer, &size, &index);
4251 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4252 ok(index == 0, "expected 0 got %u\n", index);
4253
4254 size = sizeof(buffer);
4255 ret = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
4256 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4257 ok(index == 0, "expected 0 got %u\n", index);
4258
4259 size = sizeof(buffer);
4260 ret = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &size, &index);
4261 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4262 ok(index == 0, "expected 0 got %u\n", index);
4263
4264 test_status_code(hr, 200);
4265
4266 index = 0xdeadbeef;
4267 size = sizeof(buffer);
4268 ret = HttpQueryInfoA(hr, HTTP_QUERY_FORWARDED, buffer, &size, &index);
4269 ok(!ret, "HttpQueryInfo succeeded\n");
4270 ok(index == 0xdeadbeef, "expected 0xdeadbeef got %u\n", index);
4271
4272 index = 0;
4273 size = sizeof(buffer);
4274 ret = HttpQueryInfoA(hr, HTTP_QUERY_SERVER, buffer, &size, &index);
4275 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4276 ok(index == 1, "expected 1 got %u\n", index);
4277
4278 index = 0;
4279 size = sizeof(buffer);
4280 strcpy(buffer, "Server");
4281 ret = HttpQueryInfoA(hr, HTTP_QUERY_CUSTOM, buffer, &size, &index);
4282 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4283 ok(index == 1, "expected 1 got %u\n", index);
4284
4285 index = 0;
4286 size = sizeof(buffer);
4287 ret = HttpQueryInfoA(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
4288 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4289 ok(index == 1, "expected 1 got %u\n", index);
4290
4291 size = sizeof(buffer);
4292 ret = HttpQueryInfoA(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
4293 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
4294 ok(index == 2, "expected 2 got %u\n", index);
4295
4296 InternetCloseHandle(hr);
4297 InternetCloseHandle(hc);
4298 InternetCloseHandle(hi);
4299 }
4300
4301 static void test_options(int port)
4302 {
4303 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi;
4304 HINTERNET ses, con, req;
4305 DWORD size, error;
4306 DWORD_PTR ctx;
4307 BOOL ret;
4308
4309 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4310 ok(ses != NULL, "InternetOpen failed\n");
4311
4312 SetLastError(0xdeadbeef);
4313 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, 0);
4314 error = GetLastError();
4315 ok(!ret, "InternetSetOption succeeded\n");
4316 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
4317
4318 SetLastError(0xdeadbeef);
4319 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, sizeof(ctx));
4320 ok(!ret, "InternetSetOption succeeded\n");
4321 error = GetLastError();
4322 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
4323
4324 SetLastError(0xdeadbeef);
4325 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, 0);
4326 ok(!ret, "InternetSetOption succeeded\n");
4327 error = GetLastError();
4328 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
4329
4330 ctx = 1;
4331 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
4332 ok(ret, "InternetSetOption failed %u\n", GetLastError());
4333
4334 SetLastError(0xdeadbeef);
4335 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, NULL);
4336 error = GetLastError();
4337 ok(!ret, "InternetQueryOption succeeded\n");
4338 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
4339
4340 SetLastError(0xdeadbeef);
4341 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, NULL);
4342 error = GetLastError();
4343 ok(!ret, "InternetQueryOption succeeded\n");
4344 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
4345
4346 size = 0;
4347 SetLastError(0xdeadbeef);
4348 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, &size);
4349 error = GetLastError();
4350 ok(!ret, "InternetQueryOption succeeded\n");
4351 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
4352
4353 size = sizeof(ctx);
4354 SetLastError(0xdeadbeef);
4355 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
4356 error = GetLastError();
4357 ok(!ret, "InternetQueryOption succeeded\n");
4358 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error);
4359
4360 ctx = 0xdeadbeef;
4361 size = sizeof(ctx);
4362 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
4363 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
4364 ok(ctx == 1, "expected 1 got %lu\n", ctx);
4365
4366 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4367 ok(con != NULL, "InternetConnect failed\n");
4368
4369 ctx = 0xdeadbeef;
4370 size = sizeof(ctx);
4371 ret = InternetQueryOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
4372 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
4373 ok(ctx == 0, "expected 0 got %lu\n", ctx);
4374
4375 ctx = 2;
4376 ret = InternetSetOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
4377 ok(ret, "InternetSetOption failed %u\n", GetLastError());
4378
4379 ctx = 0xdeadbeef;
4380 size = sizeof(ctx);
4381 ret = InternetQueryOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
4382 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
4383 ok(ctx == 2, "expected 2 got %lu\n", ctx);
4384
4385 req = HttpOpenRequestA(con, NULL, "/test1", NULL, NULL, NULL, 0, 0);
4386 ok(req != NULL, "HttpOpenRequest failed\n");
4387
4388 ctx = 0xdeadbeef;
4389 size = sizeof(ctx);
4390 ret = InternetQueryOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
4391 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
4392 ok(ctx == 0, "expected 0 got %lu\n", ctx);
4393
4394 ctx = 3;
4395 ret = InternetSetOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
4396 ok(ret, "InternetSetOption failed %u\n", GetLastError());
4397
4398 ctx = 0xdeadbeef;
4399 size = sizeof(ctx);
4400 ret = InternetQueryOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
4401 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
4402 ok(ctx == 3, "expected 3 got %lu\n", ctx);
4403
4404 size = sizeof(idsi);
4405 ret = InternetQueryOptionA(req, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO, &idsi, &size);
4406 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
4407
4408 size = 0;
4409 SetLastError(0xdeadbeef);
4410 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, NULL, &size);
4411 error = GetLastError();
4412 ok(!ret, "InternetQueryOption succeeded\n");
4413 ok(error == ERROR_INTERNET_INVALID_OPERATION, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error);
4414
4415 /* INTERNET_OPTION_PROXY */
4416 SetLastError(0xdeadbeef);
4417 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, NULL);
4418 error = GetLastError();
4419 ok(!ret, "InternetQueryOption succeeded\n");
4420 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
4421
4422 SetLastError(0xdeadbeef);
4423 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, &ctx, NULL);
4424 error = GetLastError();
4425 ok(!ret, "InternetQueryOption succeeded\n");
4426 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
4427
4428 size = 0;
4429 SetLastError(0xdeadbeef);
4430 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, &size);
4431 error = GetLastError();
4432 ok(!ret, "InternetQueryOption succeeded\n");
4433 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
4434 ok(size >= sizeof(INTERNET_PROXY_INFOA), "expected size to be greater or equal to the struct size\n");
4435
4436 InternetCloseHandle(req);
4437 InternetCloseHandle(con);
4438 InternetCloseHandle(ses);
4439 }
4440
4441 typedef struct {
4442 const char *response_text;
4443 int status_code;
4444 const char *status_text;
4445 const char *raw_headers;
4446 } http_status_test_t;
4447
4448 static const http_status_test_t http_status_tests[] = {
4449 {
4450 "HTTP/1.1 200 OK\r\n"
4451 "Content-Length: 1\r\n"
4452 "\r\nx",
4453 200,
4454 "OK"
4455 },
4456 {
4457 "HTTP/1.1 404 Fail\r\n"
4458 "Content-Length: 1\r\n"
4459 "\r\nx",
4460 404,
4461 "Fail"
4462 },
4463 {
4464 "HTTP/1.1 200\r\n"
4465 "Content-Length: 1\r\n"
4466 "\r\nx",
4467 200,
4468 ""
4469 },
4470 {
4471 "HTTP/1.1 410 \r\n"
4472 "Content-Length: 1\r\n"
4473 "\r\nx",
4474 410,
4475 ""
4476 }
4477 };
4478
4479 static void test_http_status(int port)
4480 {
4481 HINTERNET ses, con, req;
4482 char buf[1000];
4483 DWORD i, size;
4484 BOOL res;
4485
4486 for(i=0; i < sizeof(http_status_tests)/sizeof(*http_status_tests); i++) {
4487 send_buffer = http_status_tests[i].response_text;
4488
4489 ses = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4490 ok(ses != NULL, "InternetOpen failed\n");
4491
4492 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4493 ok(con != NULL, "InternetConnect failed\n");
4494
4495 req = HttpOpenRequestA(con, NULL, "/send_from_buffer", NULL, NULL, NULL, 0, 0);
4496 ok(req != NULL, "HttpOpenRequest failed\n");
4497
4498 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4499 ok(res, "HttpSendRequest failed\n");
4500
4501 test_status_code(req, http_status_tests[i].status_code);
4502
4503 size = sizeof(buf);
4504 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_TEXT, buf, &size, NULL);
4505 ok(res, "HttpQueryInfo failed: %u\n", GetLastError());
4506 ok(!strcmp(buf, http_status_tests[i].status_text), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
4507 i, buf, http_status_tests[i].status_text);
4508
4509 InternetCloseHandle(req);
4510 InternetCloseHandle(con);
4511 InternetCloseHandle(ses);
4512 }
4513 }
4514
4515 static void test_cache_control_verb(int port)
4516 {
4517 HINTERNET session, connect, request;
4518 BOOL ret;
4519
4520 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4521 ok(session != NULL, "InternetOpen failed\n");
4522
4523 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4524 ok(connect != NULL, "InternetConnect failed\n");
4525
4526 request = HttpOpenRequestA(connect, "RPC_OUT_DATA", "/test_cache_control_verb", NULL, NULL, NULL,
4527 INTERNET_FLAG_NO_CACHE_WRITE, 0);
4528 ok(request != NULL, "HttpOpenRequest failed\n");
4529 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4530 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4531 test_status_code(request, 200);
4532 InternetCloseHandle(request);
4533
4534 request = HttpOpenRequestA(connect, "POST", "/test_cache_control_verb", NULL, NULL, NULL,
4535 INTERNET_FLAG_NO_CACHE_WRITE, 0);
4536 ok(request != NULL, "HttpOpenRequest failed\n");
4537 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4538 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4539 test_status_code(request, 200);
4540 InternetCloseHandle(request);
4541
4542 request = HttpOpenRequestA(connect, "HEAD", "/test_cache_control_verb", NULL, NULL, NULL,
4543 INTERNET_FLAG_NO_CACHE_WRITE, 0);
4544 ok(request != NULL, "HttpOpenRequest failed\n");
4545 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4546 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4547 test_status_code(request, 200);
4548 InternetCloseHandle(request);
4549
4550 request = HttpOpenRequestA(connect, "GET", "/test_cache_control_verb", NULL, NULL, NULL,
4551 INTERNET_FLAG_NO_CACHE_WRITE, 0);
4552 ok(request != NULL, "HttpOpenRequest failed\n");
4553 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
4554 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4555 test_status_code(request, 200);
4556 InternetCloseHandle(request);
4557
4558 InternetCloseHandle(connect);
4559 InternetCloseHandle(session);
4560 }
4561
4562 static void test_request_content_length(int port)
4563 {
4564 char data[] = {'t','e','s','t'};
4565 HINTERNET ses, con, req;
4566 BOOL ret;
4567
4568 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
4569
4570 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4571 ok(ses != NULL, "InternetOpen failed\n");
4572
4573 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4574 ok(con != NULL, "InternetConnect failed\n");
4575
4576 /* On XP there is a weird bug that the following tests fail if certain cookies
4577 * are set. We workaround this problem by passing INTERNET_FLAG_NO_COOKIES as flag. */
4578 req = HttpOpenRequestA(con, "POST", "/test_request_content_length", NULL, NULL, NULL,
4579 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_NO_COOKIES, 0);
4580 ok(req != NULL, "HttpOpenRequest failed\n");
4581
4582 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
4583 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4584 test_status_code(req, 200);
4585
4586 SetEvent(hCompleteEvent);
4587
4588 ret = HttpSendRequestA(req, NULL, 0, data, sizeof(data));
4589 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
4590 test_status_code(req, 200);
4591
4592 SetEvent(hCompleteEvent);
4593
4594 InternetCloseHandle(req);
4595 InternetCloseHandle(con);
4596 InternetCloseHandle(ses);
4597 CloseHandle(hCompleteEvent);
4598 }
4599
4600 static void test_accept_encoding(int port)
4601 {
4602 HINTERNET ses, con, req;
4603 BOOL ret;
4604
4605 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
4606 ok(ses != NULL, "InternetOpen failed\n");
4607
4608 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4609 ok(con != NULL, "InternetConnect failed\n");
4610
4611 req = HttpOpenRequestA(con, "GET", "/test_accept_encoding_http10", "HTTP/1.0", NULL, NULL, 0, 0);
4612 ok(req != NULL, "HttpOpenRequest failed\n");
4613
4614 ret = HttpAddRequestHeadersA(req, "Accept-Encoding: gzip\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD);
4615 ok(ret, "HttpAddRequestHeaders failed\n");
4616
4617 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
4618 ok(ret, "HttpSendRequestA failed\n");
4619
4620 test_status_code(req, 200);
4621
4622 InternetCloseHandle(req);
4623
4624 req = HttpOpenRequestA(con, "GET", "/test_accept_encoding_http10", "HTTP/1.0", NULL, NULL, 0, 0);
4625 ok(req != NULL, "HttpOpenRequest failed\n");
4626
4627 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", ~0u, NULL, 0);
4628 ok(ret, "HttpSendRequestA failed\n");
4629
4630 test_status_code(req, 200);
4631
4632 InternetCloseHandle(req);
4633 InternetCloseHandle(con);
4634 InternetCloseHandle(ses);
4635 }
4636
4637 static void test_basic_auth_credentials_reuse(int port)
4638 {
4639 HINTERNET ses, con, req;
4640 DWORD status, size;
4641 BOOL ret;
4642
4643 ses = InternetOpenA( "winetest", 0, NULL, NULL, 0 );
4644 ok( ses != NULL, "InternetOpenA failed\n" );
4645
4646 con = InternetConnectA( ses, "localhost", port, "user", "pwd",
4647 INTERNET_SERVICE_HTTP, 0, 0 );
4648 ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
4649
4650 req = HttpOpenRequestA( con, "HEAD", "/upload.txt", NULL, NULL, NULL, 0, 0 );
4651 ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
4652
4653 ret = HttpSendRequestA( req, NULL, 0, NULL, 0 );
4654 ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
4655
4656 status = 0xdeadbeef;
4657 size = sizeof(status);
4658 ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
4659 ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() );
4660 ok( status == 200, "got %u\n", status );
4661
4662 InternetCloseHandle( req );
4663 InternetCloseHandle( con );
4664 InternetCloseHandle( ses );
4665
4666 ses = InternetOpenA( "winetest", 0, NULL, NULL, 0 );
4667 ok( ses != NULL, "InternetOpenA failed\n" );
4668
4669 con = InternetConnectA( ses, "localhost", port, NULL, NULL,
4670 INTERNET_SERVICE_HTTP, 0, 0 );
4671 ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
4672
4673 req = HttpOpenRequestA( con, "PUT", "/upload2.txt", NULL, NULL, NULL, 0, 0 );
4674 ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
4675
4676 ret = HttpSendRequestA( req, NULL, 0, NULL, 0 );
4677 ok( ret, "HttpSendRequestA failed %u\n", GetLastError() );
4678
4679 status = 0xdeadbeef;
4680 size = sizeof(status);
4681 ret = HttpQueryInfoA( req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
4682 ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() );
4683 ok( status == 200, "got %u\n", status );
4684
4685 InternetCloseHandle( req );
4686 InternetCloseHandle( con );
4687 InternetCloseHandle( ses );
4688 }
4689
4690 static void test_http_connection(void)
4691 {
4692 struct server_info si;
4693 HANDLE hThread;
4694 DWORD id = 0, r;
4695
4696 si.hEvent = CreateEventW(NULL, 0, 0, NULL);
4697 si.port = 7531;
4698
4699 hThread = CreateThread(NULL, 0, server_thread, (LPVOID) &si, 0, &id);
4700 ok( hThread != NULL, "create thread failed\n");
4701
4702 r = WaitForSingleObject(si.hEvent, 10000);
4703 ok (r == WAIT_OBJECT_0, "failed to start wininet test server\n");
4704 if (r != WAIT_OBJECT_0)
4705 return;
4706
4707 test_basic_request(si.port, "GET", "/test1");
4708 test_proxy_indirect(si.port);
4709 test_proxy_direct(si.port);
4710 test_header_handling_order(si.port);
4711 test_basic_request(si.port, "POST", "/test5");
4712 test_basic_request(si.port, "RPC_IN_DATA", "/test5");
4713 test_basic_request(si.port, "RPC_OUT_DATA", "/test5");
4714 test_basic_request(si.port, "GET", "/test6");
4715 test_basic_request(si.port, "GET", "/testF");
4716 test_connection_header(si.port);
4717 test_header_override(si.port);
4718 test_http1_1(si.port);
4719 test_cookie_header(si.port);
4720 test_basic_authentication(si.port);
4721 test_invalid_response_headers(si.port);
4722 test_response_without_headers(si.port);
4723 test_HttpQueryInfo(si.port);
4724 test_HttpSendRequestW(si.port);
4725 test_options(si.port);
4726 test_no_content(si.port);
4727 test_conn_close(si.port);
4728 test_no_cache(si.port);
4729 test_cache_read_gzipped(si.port);
4730 test_http_status(si.port);
4731 test_premature_disconnect(si.port);
4732 test_connection_closing(si.port);
4733 test_cache_control_verb(si.port);
4734 test_successive_HttpSendRequest(si.port);
4735 test_head_request(si.port);
4736 test_request_content_length(si.port);
4737 test_accept_encoding(si.port);
4738 test_basic_auth_credentials_reuse(si.port);
4739
4740 /* send the basic request again to shutdown the server thread */
4741 test_basic_request(si.port, "GET", "/quit");
4742
4743 r = WaitForSingleObject(hThread, 3000);
4744 ok( r == WAIT_OBJECT_0, "thread wait failed\n");
4745 CloseHandle(hThread);
4746 }
4747
4748 static void release_cert_info(INTERNET_CERTIFICATE_INFOA *info)
4749 {
4750 LocalFree(info->lpszSubjectInfo);
4751 LocalFree(info->lpszIssuerInfo);
4752 LocalFree(info->lpszProtocolName);
4753 LocalFree(info->lpszSignatureAlgName);
4754 LocalFree(info->lpszEncryptionAlgName);
4755 }
4756
4757 typedef struct {
4758 const char *ex_subject;
4759 const char *ex_issuer;
4760 } cert_struct_test_t;
4761
4762 static const cert_struct_test_t test_winehq_org_cert = {
4763 "GT98380011\r\n"
4764 "See www.rapidssl.com/resources/cps (c)14\r\n"
4765 "Domain Control Validated - RapidSSL(R)\r\n"
4766 "*.winehq.org",
4767
4768 "US\r\n"
4769 "GeoTrust Inc.\r\n"
4770 "RapidSSL SHA256 CA - G3"
4771 };
4772
4773 static const cert_struct_test_t test_winehq_com_cert = {
4774 "US\r\n"
4775 "Minnesota\r\n"
4776 "Saint Paul\r\n"
4777 "WineHQ\r\n"
4778 "test.winehq.com\r\n"
4779 "webmaster@winehq.org",
4780
4781 "US\r\n"
4782 "Minnesota\r\n"
4783 "WineHQ\r\n"
4784 "test.winehq.com\r\n"
4785 "webmaster@winehq.org"
4786 };
4787
4788 static void test_cert_struct(HINTERNET req, const cert_struct_test_t *test)
4789 {
4790 INTERNET_CERTIFICATE_INFOA info;
4791 DWORD size;
4792 BOOL res;
4793
4794 memset(&info, 0x5, sizeof(info));
4795
4796 size = sizeof(info);
4797 res = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, &info, &size);
4798 ok(res, "InternetQueryOption failed: %u\n", GetLastError());
4799 ok(size == sizeof(info), "size = %u\n", size);
4800
4801 ok(!strcmp(info.lpszSubjectInfo, test->ex_subject), "lpszSubjectInfo = %s\n", info.lpszSubjectInfo);
4802 ok(!strcmp(info.lpszIssuerInfo, test->ex_issuer), "lpszIssuerInfo = %s\n", info.lpszIssuerInfo);
4803 ok(!info.lpszSignatureAlgName, "lpszSignatureAlgName = %s\n", info.lpszSignatureAlgName);
4804 ok(!info.lpszEncryptionAlgName, "lpszEncryptionAlgName = %s\n", info.lpszEncryptionAlgName);
4805 ok(!info.lpszProtocolName, "lpszProtocolName = %s\n", info.lpszProtocolName);
4806 ok(info.dwKeySize >= 128 && info.dwKeySize <= 256, "dwKeySize = %u\n", info.dwKeySize);
4807
4808 release_cert_info(&info);
4809 }
4810
4811 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
4812 static void _test_security_info(unsigned line, const char *urlc, DWORD error, DWORD ex_flags)
4813 {
4814 char url[INTERNET_MAX_URL_LENGTH];
4815 const CERT_CHAIN_CONTEXT *chain;
4816 DWORD flags;
4817 BOOL res;
4818
4819 if(!pInternetGetSecurityInfoByURLA) {
4820 win_skip("pInternetGetSecurityInfoByURLA not available\n");
4821 return;
4822 }
4823
4824 strcpy(url, urlc);
4825 chain = (void*)0xdeadbeef;
4826 flags = 0xdeadbeef;
4827 res = pInternetGetSecurityInfoByURLA(url, &chain, &flags);
4828 if(error == ERROR_SUCCESS) {
4829 ok_(__FILE__,line)(res, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
4830 ok_(__FILE__,line)(chain != NULL, "chain = NULL\n");
4831 ok_(__FILE__,line)(flags == ex_flags, "flags = %x\n", flags);
4832 CertFreeCertificateChain(chain);
4833 }else {
4834 ok_(__FILE__,line)(!res && GetLastError() == error,
4835 "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res, GetLastError(), error);
4836 }
4837 }
4838
4839 #define test_secflags_option(a,b,c) _test_secflags_option(__LINE__,a,b,c)
4840 static void _test_secflags_option(unsigned line, HINTERNET req, DWORD ex_flags, DWORD opt_flags)
4841 {
4842 DWORD flags, size;
4843 BOOL res;
4844
4845 flags = 0xdeadbeef;
4846 size = sizeof(flags);
4847 res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
4848 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4849 ok_(__FILE__,line)((flags & ~opt_flags) == ex_flags, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n",
4850 flags, ex_flags);
4851
4852 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
4853 flags = 0xdeadbeef;
4854 size = sizeof(flags);
4855 res = InternetQueryOptionW(req, 98, &flags, &size);
4856 ok_(__FILE__,line)(res, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
4857 ok_(__FILE__,line)((flags & ~opt_flags) == ex_flags, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n",
4858 flags, ex_flags);
4859 }
4860
4861 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
4862 static void _set_secflags(unsigned line, HINTERNET req, BOOL use_undoc, DWORD flags)
4863 {
4864 BOOL res;
4865
4866 res = InternetSetOptionW(req, use_undoc ? 99 : INTERNET_OPTION_SECURITY_FLAGS, &flags, sizeof(flags));
4867 ok_(__FILE__,line)(res, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4868 }
4869
4870 static void test_security_flags(void)
4871 {
4872 INTERNET_CERTIFICATE_INFOA *cert;
4873 HINTERNET ses, conn, req;
4874 DWORD size, flags;
4875 char buf[100];
4876 BOOL res;
4877
4878 trace("Testing security flags...\n");
4879
4880 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
4881
4882 ses = InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
4883 ok(ses != NULL, "InternetOpen failed\n");
4884
4885 pInternetSetStatusCallbackA(ses, &callback);
4886
4887 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4888 conn = InternetConnectA(ses, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT,
4889 NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0xdeadbeef);
4890 ok(conn != NULL, "InternetConnect failed with error %u\n", GetLastError());
4891 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4892
4893 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4894 req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
4895 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
4896 0xdeadbeef);
4897 ok(req != NULL, "HttpOpenRequest failed\n");
4898 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4899
4900 flags = 0xdeadbeef;
4901 size = sizeof(flags);
4902 res = InternetQueryOptionW(req, 98, &flags, &size);
4903 if(!res && GetLastError() == ERROR_INVALID_PARAMETER) {
4904 win_skip("Incomplete security flags support, skipping\n");
4905
4906 close_async_handle(ses, hCompleteEvent, 2);
4907 CloseHandle(hCompleteEvent);
4908 return;
4909 }
4910
4911 test_secflags_option(req, 0, 0);
4912 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4913
4914 set_secflags(req, TRUE, SECURITY_FLAG_IGNORE_REVOCATION);
4915 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION, 0);
4916
4917 set_secflags(req, TRUE, SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
4918 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID, 0);
4919
4920 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
4921 test_secflags_option(req, SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID, 0);
4922
4923 flags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_SECURE;
4924 res = InternetSetOptionW(req, 99, &flags, sizeof(flags));
4925 ok(!res && GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE, "InternetSetOption(99) failed: %u\n", GetLastError());
4926
4927 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
4928 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
4929 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4930 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4931 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */
4932 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */
4933 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */
4934 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */
4935 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
4936 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
4937 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
4938 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
4939 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4940 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
4941 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4942
4943 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4944 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4945
4946 WaitForSingleObject(hCompleteEvent, INFINITE);
4947 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
4948
4949 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
4950 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
4951 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2);
4952 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2);
4953 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
4954 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
4955 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
4956 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
4957 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
4958 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
4959 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4960 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
4961 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4962
4963 test_request_flags(req, 0);
4964 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4965 |SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_STRENGTH_STRONG, 0);
4966
4967 res = InternetReadFile(req, buf, sizeof(buf), &size);
4968 ok(res, "InternetReadFile failed: %u\n", GetLastError());
4969 ok(size, "size = 0\n");
4970
4971 /* Collect all existing persistent connections */
4972 res = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
4973 ok(res, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4974
4975 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4976 req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
4977 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
4978 0xdeadbeef);
4979 ok(req != NULL, "HttpOpenRequest failed\n");
4980 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4981
4982 flags = INTERNET_ERROR_MASK_COMBINED_SEC_CERT|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY;
4983 res = InternetSetOptionA(req, INTERNET_OPTION_ERROR_MASK, (void*)&flags, sizeof(flags));
4984 ok(res, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
4985
4986 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4987 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4988 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */
4989 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */
4990 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */
4991 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */
4992 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
4993 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
4994 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4995 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4996 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
4997
4998 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4999 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
5000
5001 WaitForSingleObject(hCompleteEvent, INFINITE);
5002 ok(req_error == ERROR_INTERNET_SEC_CERT_REV_FAILED || broken(req_error == ERROR_INTERNET_SEC_CERT_ERRORS),
5003 "req_error = %d\n", req_error);
5004
5005 size = 0;
5006 res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, NULL, &size);
5007 ok(res || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
5008 ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %u\n", size);
5009 cert = HeapAlloc(GetProcessHeap(), 0, size);
5010 cert->lpszSubjectInfo = NULL;
5011 cert->lpszIssuerInfo = NULL;
5012 cert->lpszSignatureAlgName = (char *)0xdeadbeef;
5013 cert->lpszEncryptionAlgName = (char *)0xdeadbeef;
5014 cert->lpszProtocolName = (char *)0xdeadbeef;
5015 cert->dwKeySize = 0xdeadbeef;
5016 res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, cert, &size);
5017 ok(res, "InternetQueryOption failed: %u\n", GetLastError());
5018 if (res)
5019 {
5020 ok(cert->lpszSubjectInfo && strlen(cert->lpszSubjectInfo) > 1, "expected a non-empty subject name\n");
5021 ok(cert->lpszIssuerInfo && strlen(cert->lpszIssuerInfo) > 1, "expected a non-empty issuer name\n");
5022 ok(!cert->lpszSignatureAlgName, "unexpected signature algorithm name\n");
5023 ok(!cert->lpszEncryptionAlgName, "unexpected encryption algorithm name\n");
5024 ok(!cert->lpszProtocolName, "unexpected protocol name\n");
5025 ok(cert->dwKeySize != 0xdeadbeef, "unexpected key size\n");
5026 }
5027 HeapFree(GetProcessHeap(), 0, cert);
5028
5029 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2);
5030 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2);
5031 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
5032 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
5033 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
5034 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
5035 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
5036
5037 if(req_error != ERROR_INTERNET_SEC_CERT_REV_FAILED) {
5038 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error);
5039
5040 close_async_handle(ses, hCompleteEvent, 3);
5041 CloseHandle(hCompleteEvent);
5042 return;
5043 }
5044
5045 size = sizeof(buf);
5046 res = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
5047 ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
5048
5049 test_request_flags(req, 8);
5050 /* IE11 finds both rev failure and invalid CA. Previous versions required rev failure
5051 to be ignored before invalid CA was reported. */
5052 test_secflags_option(req, _SECURITY_FLAG_CERT_REV_FAILED, _SECURITY_FLAG_CERT_INVALID_CA);
5053
5054 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_REVOCATION);
5055 test_secflags_option(req, _SECURITY_FLAG_CERT_REV_FAILED|SECURITY_FLAG_IGNORE_REVOCATION, _SECURITY_FLAG_CERT_INVALID_CA);
5056
5057 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
5058 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
5059 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
5060 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
5061 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
5062 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
5063 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
5064
5065 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
5066 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
5067
5068 WaitForSingleObject(hCompleteEvent, INFINITE);
5069 ok(req_error == ERROR_INTERNET_SEC_CERT_ERRORS, "req_error = %d\n", req_error);
5070
5071 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
5072 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
5073 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
5074 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
5075 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
5076 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
5077 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
5078
5079 test_request_flags(req, INTERNET_REQFLAG_NO_HEADERS);
5080 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION|_SECURITY_FLAG_CERT_REV_FAILED|_SECURITY_FLAG_CERT_INVALID_CA, 0);
5081 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
5082
5083 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
5084 test_secflags_option(req, _SECURITY_FLAG_CERT_INVALID_CA|_SECURITY_FLAG_CERT_REV_FAILED
5085 |SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_UNKNOWN_CA, 0);
5086 test_http_version(req);
5087
5088 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
5089 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
5090 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */
5091 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */
5092 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */
5093 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */
5094 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
5095 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
5096 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
5097 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
5098 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
5099 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
5100 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
5101
5102 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
5103 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
5104
5105 WaitForSingleObject(hCompleteEvent, INFINITE);
5106 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
5107
5108 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2);
5109 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2);
5110 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
5111 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
5112 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
5113 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
5114 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
5115 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
5116 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
5117 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
5118 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
5119
5120 test_request_flags(req, 0);
5121 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION
5122 |SECURITY_FLAG_STRENGTH_STRONG|_SECURITY_FLAG_CERT_REV_FAILED|_SECURITY_FLAG_CERT_INVALID_CA, 0);
5123
5124 test_cert_struct(req, &test_winehq_com_cert);
5125 test_security_info("https://test.winehq.com/data/some_file.html?q", 0,
5126 _SECURITY_FLAG_CERT_INVALID_CA|_SECURITY_FLAG_CERT_REV_FAILED);
5127
5128 res = InternetReadFile(req, buf, sizeof(buf), &size);
5129 ok(res, "InternetReadFile failed: %u\n", GetLastError());
5130 ok(size, "size = 0\n");
5131
5132 close_async_handle(ses, hCompleteEvent, 3);
5133
5134 /* Collect all existing persistent connections */
5135 res = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
5136 ok(res, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5137
5138 /* Make another request, without setting security flags */
5139
5140 ses = InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
5141 ok(ses != NULL, "InternetOpen failed\n");
5142
5143 pInternetSetStatusCallbackA(ses, &callback);
5144
5145 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
5146 conn = InternetConnectA(ses, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT,
5147 NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0xdeadbeef);
5148 ok(conn != NULL, "InternetConnect failed with error %u\n", GetLastError());
5149 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
5150
5151 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
5152 req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
5153 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
5154 0xdeadbeef);
5155 ok(req != NULL, "HttpOpenRequest failed\n");
5156 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
5157
5158 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_STRENGTH_STRONG
5159 |SECURITY_FLAG_IGNORE_REVOCATION|_SECURITY_FLAG_CERT_REV_FAILED|_SECURITY_FLAG_CERT_INVALID_CA, 0);
5160 test_http_version(req);
5161
5162 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
5163 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
5164 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION); /* IE11 calls it, it probably reconnects. */
5165 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED); /* IE11 */
5166 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER); /* IE11 */
5167 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER); /* IE11 */
5168 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
5169 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
5170 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
5171 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
5172 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
5173 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
5174
5175 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
5176 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
5177
5178 WaitForSingleObject(hCompleteEvent, INFINITE);
5179 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
5180
5181 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER, 2);
5182 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER, 2);
5183 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
5184 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
5185 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
5186 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
5187 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
5188 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
5189 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
5190 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
5191
5192 test_request_flags(req, 0);
5193 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_STRENGTH_STRONG
5194 |SECURITY_FLAG_IGNORE_REVOCATION|_SECURITY_FLAG_CERT_REV_FAILED|_SECURITY_FLAG_CERT_INVALID_CA, 0);
5195
5196 res = InternetReadFile(req, buf, sizeof(buf), &size);
5197 ok(res, "InternetReadFile failed: %u\n", GetLastError());
5198 ok(size, "size = 0\n");
5199
5200 close_async_handle(ses, hCompleteEvent, 2);
5201
5202 CloseHandle(hCompleteEvent);
5203
5204 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
5205 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
5206 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
5207 }
5208
5209 static void test_secure_connection(void)
5210 {
5211 static const WCHAR gizmo5[] = {'G','i','z','m','o','5',0};
5212 static const WCHAR testsite[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
5213 static const WCHAR get[] = {'G','E','T',0};
5214 static const WCHAR testpage[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
5215 HINTERNET ses, con, req;
5216 DWORD size, flags;
5217 INTERNET_CERTIFICATE_INFOA *certificate_structA = NULL;
5218 INTERNET_CERTIFICATE_INFOW *certificate_structW = NULL;
5219 BOOL ret;
5220
5221 ses = InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
5222 ok(ses != NULL, "InternetOpen failed\n");
5223
5224 con = InternetConnectA(ses, "test.winehq.org",
5225 INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL,
5226 INTERNET_SERVICE_HTTP, 0, 0);
5227 ok(con != NULL, "InternetConnect failed\n");
5228
5229 req = HttpOpenRequestA(con, "GET", "/tests/hello.html", NULL, NULL, NULL,
5230 INTERNET_FLAG_SECURE, 0);
5231 ok(req != NULL, "HttpOpenRequest failed\n");
5232
5233 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
5234 ok(ret || broken(GetLastError() == ERROR_INTERNET_CANNOT_CONNECT),
5235 "HttpSendRequest failed: %d\n", GetLastError());
5236 if (!ret)
5237 {
5238 win_skip("Cannot connect to https.\n");
5239 goto done;
5240 }
5241
5242 size = sizeof(flags);
5243 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
5244 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
5245 ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set\n");
5246
5247 test_cert_struct(req, &test_winehq_org_cert);
5248
5249 /* Querying the same option through InternetQueryOptionW still results in
5250 * ASCII strings being returned.
5251 */
5252 size = 0;
5253 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
5254 NULL, &size);
5255 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
5256 ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size);
5257 certificate_structW = HeapAlloc(GetProcessHeap(), 0, size);
5258 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
5259 certificate_structW, &size);
5260 certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW;
5261 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
5262 if (ret)
5263 {
5264 ok(certificate_structA->lpszSubjectInfo &&
5265 strlen(certificate_structA->lpszSubjectInfo) > 1,
5266 "expected a non-empty subject name\n");
5267 ok(certificate_structA->lpszIssuerInfo &&
5268 strlen(certificate_structA->lpszIssuerInfo) > 1,
5269 "expected a non-empty issuer name\n");
5270 ok(!certificate_structA->lpszSignatureAlgName,
5271 "unexpected signature algorithm name\n");
5272 ok(!certificate_structA->lpszEncryptionAlgName,
5273 "unexpected encryption algorithm name\n");
5274 ok(!certificate_structA->lpszProtocolName,
5275 "unexpected protocol name\n");
5276 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
5277 release_cert_info(certificate_structA);
5278 }
5279 HeapFree(GetProcessHeap(), 0, certificate_structW);
5280
5281 InternetCloseHandle(req);
5282 InternetCloseHandle(con);
5283 InternetCloseHandle(ses);
5284
5285 /* Repeating the tests with the W functions has the same result: */
5286 ses = InternetOpenW(gizmo5, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
5287 ok(ses != NULL, "InternetOpen failed\n");
5288
5289 con = InternetConnectW(ses, testsite,
5290 INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL,
5291 INTERNET_SERVICE_HTTP, 0, 0);
5292 ok(con != NULL, "InternetConnect failed\n");
5293
5294 req = HttpOpenRequestW(con, get, testpage, NULL, NULL, NULL,
5295 INTERNET_FLAG_SECURE|INTERNET_FLAG_RELOAD, 0);
5296 ok(req != NULL, "HttpOpenRequest failed\n");
5297
5298 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
5299 ok(ret, "HttpSendRequest failed: %d\n", GetLastError());
5300
5301 size = sizeof(flags);
5302 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
5303 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
5304 ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set, got %x\n", flags);
5305
5306 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
5307 NULL, &size);
5308 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
5309 ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %d\n", size);
5310 certificate_structA = HeapAlloc(GetProcessHeap(), 0, size);
5311 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
5312 certificate_structA, &size);
5313 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
5314 if (ret)
5315 {
5316 ok(certificate_structA->lpszSubjectInfo &&
5317 strlen(certificate_structA->lpszSubjectInfo) > 1,
5318 "expected a non-empty subject name\n");
5319 ok(certificate_structA->lpszIssuerInfo &&
5320 strlen(certificate_structA->lpszIssuerInfo) > 1,
5321 "expected a non-empty issuer name\n");
5322 ok(!certificate_structA->lpszSignatureAlgName,
5323 "unexpected signature algorithm name\n");
5324 ok(!certificate_structA->lpszEncryptionAlgName,
5325 "unexpected encryption algorithm name\n");
5326 ok(!certificate_structA->lpszProtocolName,
5327 "unexpected protocol name\n");
5328 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
5329 release_cert_info(certificate_structA);
5330 }
5331 HeapFree(GetProcessHeap(), 0, certificate_structA);
5332
5333 /* Again, querying the same option through InternetQueryOptionW still
5334 * results in ASCII strings being returned.
5335 */
5336 size = 0;
5337 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
5338 NULL, &size);
5339 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
5340 ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size);
5341 certificate_structW = HeapAlloc(GetProcessHeap(), 0, size);
5342 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
5343 certificate_structW, &size);
5344 certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW;
5345 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
5346 if (ret)
5347 {
5348 ok(certificate_structA->lpszSubjectInfo &&
5349 strlen(certificate_structA->lpszSubjectInfo) > 1,
5350 "expected a non-empty subject name\n");
5351 ok(certificate_structA->lpszIssuerInfo &&
5352 strlen(certificate_structA->lpszIssuerInfo) > 1,
5353 "expected a non-empty issuer name\n");
5354 ok(!certificate_structA->lpszSignatureAlgName,
5355 "unexpected signature algorithm name\n");
5356 ok(!certificate_structA->lpszEncryptionAlgName,
5357 "unexpected encryption algorithm name\n");
5358 ok(!certificate_structA->lpszProtocolName,
5359 "unexpected protocol name\n");
5360 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
5361 release_cert_info(certificate_structA);
5362 }
5363 HeapFree(GetProcessHeap(), 0, certificate_structW);
5364
5365 done:
5366 InternetCloseHandle(req);
5367 InternetCloseHandle(con);
5368 InternetCloseHandle(ses);
5369 }
5370
5371 static void test_user_agent_header(void)
5372 {
5373 HINTERNET ses, con, req;
5374 DWORD size, err;
5375 char buffer[64];
5376 BOOL ret;
5377
5378 ses = InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
5379 ok(ses != NULL, "InternetOpen failed\n");
5380
5381 con = InternetConnectA(ses, "test.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
5382 ok(con != NULL, "InternetConnect failed\n");
5383
5384 req = HttpOpenRequestA(con, "GET", "/tests/hello.html", "HTTP/1.0", NULL, NULL, 0, 0);
5385 ok(req != NULL, "HttpOpenRequest failed\n");
5386
5387 size = sizeof(buffer);
5388 ret = HttpQueryInfoA(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
5389 err = GetLastError();
5390 ok(!ret, "HttpQueryInfo succeeded\n");
5391 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
5392
5393 ret = HttpAddRequestHeadersA(req, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
5394 ok(ret, "HttpAddRequestHeaders succeeded\n");
5395
5396 size = sizeof(buffer);
5397 ret = HttpQueryInfoA(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
5398 err = GetLastError();
5399 ok(ret, "HttpQueryInfo failed\n");
5400
5401 InternetCloseHandle(req);
5402
5403 req = HttpOpenRequestA(con, "GET", "/", "HTTP/1.0", NULL, NULL, 0, 0);
5404 ok(req != NULL, "HttpOpenRequest failed\n");
5405
5406 size = sizeof(buffer);
5407 ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
5408 err = GetLastError();
5409 ok(!ret, "HttpQueryInfo succeeded\n");
5410 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
5411
5412 ret = HttpAddRequestHeadersA(req, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
5413 ok(ret, "HttpAddRequestHeaders failed\n");
5414
5415 buffer[0] = 0;
5416 size = sizeof(buffer);
5417 ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
5418 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
5419 ok(!strcmp(buffer, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer);
5420
5421 InternetCloseHandle(req);
5422 InternetCloseHandle(con);
5423 InternetCloseHandle(ses);
5424 }
5425
5426 static void test_bogus_accept_types_array(void)
5427 {
5428 HINTERNET ses, con, req;
5429 static const char *types[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL };
5430 DWORD size, error;
5431 char buffer[32];
5432 BOOL ret;
5433
5434 ses = InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT, "", "", 0);
5435 con = InternetConnectA(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
5436 req = HttpOpenRequestA(con, "POST", "/post/post_action.php", "HTTP/1.0", "", types, INTERNET_FLAG_FORMS_SUBMIT, 0);
5437
5438 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
5439
5440 buffer[0] = 0;
5441 size = sizeof(buffer);
5442 SetLastError(0xdeadbeef);
5443 ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
5444 error = GetLastError();
5445 ok(!ret || broken(ret), "HttpQueryInfo succeeded\n");
5446 if (!ret) ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error);
5447 ok(broken(!strcmp(buffer, ", */*, %p, , , */*")) /* IE6 */ ||
5448 broken(!strcmp(buffer, "*/*, %p, */*")) /* IE7/8 */ ||
5449 !strcmp(buffer, ""), "got '%s' expected ''\n", buffer);
5450
5451 InternetCloseHandle(req);
5452 InternetCloseHandle(con);
5453 InternetCloseHandle(ses);
5454 }
5455
5456 struct context
5457 {
5458 HANDLE event;
5459 HINTERNET req;
5460 };
5461
5462 static void WINAPI cb(HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID info, DWORD size)
5463 {
5464 INTERNET_ASYNC_RESULT *result = info;
5465 struct context *ctx = (struct context *)context;
5466
5467 trace("%p 0x%08lx %u %p 0x%08x\n", handle, context, status, info, size);
5468
5469 switch(status) {
5470 case INTERNET_STATUS_REQUEST_COMPLETE:
5471 trace("request handle: 0x%08lx\n", result->dwResult);
5472 ctx->req = (HINTERNET)result->dwResult;
5473 SetEvent(ctx->event);
5474 break;
5475 case INTERNET_STATUS_HANDLE_CLOSING: {
5476 DWORD type = INTERNET_HANDLE_TYPE_CONNECT_HTTP, size = sizeof(type);
5477
5478 if (InternetQueryOptionA(handle, INTERNET_OPTION_HANDLE_TYPE, &type, &size))
5479 ok(type != INTERNET_HANDLE_TYPE_CONNECT_HTTP, "unexpected callback\n");
5480 SetEvent(ctx->event);
5481 break;
5482 }
5483 case INTERNET_STATUS_NAME_RESOLVED:
5484 case INTERNET_STATUS_CONNECTING_TO_SERVER:
5485 case INTERNET_STATUS_CONNECTED_TO_SERVER: {
5486 char *str = info;
5487 ok(str[0] && str[1], "Got string: %s\n", str);
5488 ok(size == strlen(str)+1, "unexpected size %u\n", size);
5489 }
5490 }
5491 }
5492
5493 static void test_open_url_async(void)
5494 {
5495 BOOL ret;
5496 HINTERNET ses, req;
5497 DWORD size, error;
5498 struct context ctx;
5499 ULONG type;
5500
5501 /* Collect all existing persistent connections */
5502 ret = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
5503 ok(ret, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5504
5505 /*
5506 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
5507 * other versions never do. They also hang of following tests. We disable it for everything older
5508 * than IE7.
5509 */
5510 if(!pInternetGetSecurityInfoByURLA) {
5511 win_skip("Skipping async open on too old wininet version.\n");
5512 return;
5513 }
5514
5515 ctx.req = NULL;
5516 ctx.event = CreateEventA(NULL, TRUE, FALSE, "Z:_home_hans_jaman-installer.exe_ev1");
5517
5518 ses = InternetOpenA("AdvancedInstaller", 0, NULL, NULL, INTERNET_FLAG_ASYNC);
5519 ok(ses != NULL, "InternetOpen failed\n");
5520
5521 SetLastError(0xdeadbeef);
5522 ret = InternetSetOptionA(NULL, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR));
5523 error = GetLastError();
5524 ok(!ret, "InternetSetOptionA succeeded\n");
5525 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error);
5526
5527 ret = InternetSetOptionA(ses, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR));
5528 error = GetLastError();
5529 ok(!ret, "InternetSetOptionA failed\n");
5530 ok(error == ERROR_INTERNET_OPTION_NOT_SETTABLE, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error);
5531
5532 pInternetSetStatusCallbackW(ses, cb);
5533 ResetEvent(ctx.event);
5534
5535 req = InternetOpenUrlA(ses, "http://test.winehq.org", NULL, 0, 0, (DWORD_PTR)&ctx);
5536 ok(!req && GetLastError() == ERROR_IO_PENDING, "InternetOpenUrl failed\n");
5537
5538 WaitForSingleObject(ctx.event, INFINITE);
5539
5540 type = 0;
5541 size = sizeof(type);
5542 ret = InternetQueryOptionA(ctx.req, INTERNET_OPTION_HANDLE_TYPE, &type, &size);
5543 ok(ret, "InternetQueryOption failed: %u\n", GetLastError());
5544 ok(type == INTERNET_HANDLE_TYPE_HTTP_REQUEST,
5545 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type);
5546
5547 size = 0;
5548 ret = HttpQueryInfoA(ctx.req, HTTP_QUERY_RAW_HEADERS_CRLF, NULL, &size, NULL);
5549 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "HttpQueryInfo failed\n");
5550 ok(size > 0, "expected size > 0\n");
5551
5552 ResetEvent(ctx.event);
5553 InternetCloseHandle(ctx.req);
5554 WaitForSingleObject(ctx.event, INFINITE);
5555
5556 InternetCloseHandle(ses);
5557 CloseHandle(ctx.event);
5558 }
5559
5560 enum api
5561 {
5562 internet_connect = 1,
5563 http_open_request,
5564 http_send_request_ex,
5565 internet_writefile,
5566 http_end_request,
5567 internet_close_handle
5568 };
5569
5570 struct notification
5571 {
5572 enum api function; /* api responsible for notification */
5573 unsigned int status; /* status received */
5574 BOOL async; /* delivered from another thread? */
5575 BOOL todo;
5576 BOOL optional;
5577 };
5578
5579 struct info
5580 {
5581 enum api function;
5582 const struct notification *test;
5583 unsigned int count;
5584 unsigned int index;
5585 HANDLE wait;
5586 DWORD thread;
5587 unsigned int line;
5588 DWORD expect_result;
5589 BOOL is_aborted;
5590 };
5591
5592 static CRITICAL_SECTION notification_cs;
5593
5594 static void CALLBACK check_notification( HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID buffer, DWORD buflen )
5595 {
5596 BOOL status_ok, function_ok;
5597 struct info *info = (struct info *)context;
5598 unsigned int i;
5599
5600 EnterCriticalSection( &notification_cs );
5601
5602 if(info->is_aborted) {
5603 LeaveCriticalSection(&notification_cs);
5604 return;
5605 }
5606
5607 if (status == INTERNET_STATUS_HANDLE_CREATED)
5608 {
5609 DWORD size = sizeof(struct info *);
5610 HttpQueryInfoA( handle, INTERNET_OPTION_CONTEXT_VALUE, &info, &size, 0 );
5611 }else if(status == INTERNET_STATUS_REQUEST_COMPLETE) {
5612 INTERNET_ASYNC_RESULT *ar = (INTERNET_ASYNC_RESULT*)buffer;
5613
5614 ok(buflen == sizeof(*ar), "unexpected buflen = %d\n", buflen);
5615 if(info->expect_result == ERROR_SUCCESS) {
5616 ok(ar->dwResult == 1, "ar->dwResult = %ld, expected 1\n", ar->dwResult);
5617 }else {
5618 ok(!ar->dwResult, "ar->dwResult = %ld, expected 1\n", ar->dwResult);
5619 ok(ar->dwError == info->expect_result, "ar->dwError = %d, expected %d\n", ar->dwError, info->expect_result);
5620 }
5621 }
5622
5623 i = info->index;
5624 if (i >= info->count)
5625 {
5626 LeaveCriticalSection( &notification_cs );
5627 return;
5628 }
5629
5630 while (info->test[i].status != status &&
5631 (info->test[i].optional || info->test[i].todo) &&
5632 i < info->count - 1 &&
5633 info->test[i].function == info->test[i + 1].function)
5634 {
5635 i++;
5636 }
5637
5638 status_ok = (info->test[i].status == status);
5639 function_ok = (info->test[i].function == info->function);
5640
5641 if (!info->test[i].todo)
5642 {
5643 ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status );
5644 ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
5645
5646 if (info->test[i].async)
5647 ok(info->thread != GetCurrentThreadId(), "%u: expected thread %u got %u\n",
5648 info->line, info->thread, GetCurrentThreadId());
5649 }
5650 else
5651 {
5652 todo_wine ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status );
5653 if (status_ok)
5654 todo_wine ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
5655 }
5656 if (i == info->count - 1 || info->test[i].function != info->test[i + 1].function) SetEvent( info->wait );
5657 info->index = i+1;
5658
5659 LeaveCriticalSection( &notification_cs );
5660 }
5661
5662 static void setup_test( struct info *info, enum api function, unsigned int line, DWORD expect_result )
5663 {
5664 info->function = function;
5665 info->line = line;
5666 info->expect_result = expect_result;
5667 }
5668
5669 struct notification_data
5670 {
5671 const struct notification *test;
5672 const unsigned int count;
5673 const char *method;
5674 const char *host;
5675 const char *path;
5676 const char *data;
5677 BOOL expect_conn_failure;
5678 };
5679
5680 static const struct notification async_send_request_ex_test[] =
5681 {
5682 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5683 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5684 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5685 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, TRUE, FALSE, TRUE },
5686 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE, FALSE, TRUE },
5687 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, TRUE, FALSE, TRUE },
5688 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, TRUE },
5689 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, TRUE },
5690 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, TRUE },
5691 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, TRUE },
5692 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5693 { internet_writefile, INTERNET_STATUS_SENDING_REQUEST, FALSE },
5694 { internet_writefile, INTERNET_STATUS_REQUEST_SENT, FALSE },
5695 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, TRUE },
5696 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, TRUE },
5697 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5698 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, FALSE, FALSE, TRUE },
5699 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, FALSE, FALSE, TRUE },
5700 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, },
5701 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }
5702 };
5703
5704 static const struct notification async_send_request_ex_test2[] =
5705 {
5706 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5707 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5708 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5709 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, TRUE, FALSE, TRUE },
5710 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE, FALSE, TRUE },
5711 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, TRUE, FALSE, TRUE },
5712 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, TRUE, TRUE },
5713 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, TRUE, TRUE },
5714 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, TRUE },
5715 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, TRUE },
5716 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5717 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, TRUE },
5718 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, TRUE },
5719 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5720 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, FALSE, FALSE, TRUE },
5721 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, FALSE, FALSE, TRUE },
5722 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, },
5723 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }
5724 };
5725
5726 static const struct notification async_send_request_ex_resolve_failure_test[] =
5727 {
5728 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5729 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, FALSE },
5730 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5731 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE },
5732 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5733 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5734 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5735 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, FALSE, FALSE, TRUE },
5736 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, FALSE, FALSE, TRUE },
5737 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, },
5738 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, FALSE, }
5739 };
5740
5741 static const struct notification async_send_request_ex_chunked_test[] =
5742 {
5743 { internet_connect, INTERNET_STATUS_HANDLE_CREATED },
5744 { http_open_request, INTERNET_STATUS_HANDLE_CREATED },
5745 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, TRUE, FALSE, TRUE },
5746 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, TRUE, FALSE, TRUE },
5747 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, TRUE, FALSE, TRUE },
5748 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, TRUE, FALSE, TRUE },
5749 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, TRUE },
5750 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, TRUE },
5751 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, TRUE },
5752 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, TRUE },
5753 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5754 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, TRUE },
5755 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, TRUE },
5756 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, TRUE },
5757 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION },
5758 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED },
5759 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING },
5760 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING }
5761 };
5762
5763 static const struct notification_data notification_data[] = {
5764 {
5765 async_send_request_ex_chunked_test,
5766 sizeof(async_send_request_ex_chunked_test)/sizeof(async_send_request_ex_chunked_test[0]),
5767 "GET",
5768 "test.winehq.org",
5769 "tests/data.php"
5770 },
5771 {
5772 async_send_request_ex_test,
5773 sizeof(async_send_request_ex_test)/sizeof(async_send_request_ex_test[0]),
5774 "POST",
5775 "test.winehq.org",
5776 "tests/post.php",
5777 "Public ID=codeweavers"
5778 },
5779 {
5780 async_send_request_ex_test2,
5781 sizeof(async_send_request_ex_test)/sizeof(async_send_request_ex_test[0]),
5782 "POST",
5783 "test.winehq.org",
5784 "tests/post.php"
5785 },
5786 {
5787 async_send_request_ex_resolve_failure_test,
5788 sizeof(async_send_request_ex_resolve_failure_test)/sizeof(async_send_request_ex_resolve_failure_test[0]),
5789 "GET",
5790 "brokenhost",
5791 "index.html",
5792 NULL,
5793 TRUE
5794 }
5795 };
5796
5797 static void test_async_HttpSendRequestEx(const struct notification_data *nd)
5798 {
5799 BOOL ret;
5800 HINTERNET ses, req, con;
5801 struct info info;
5802 DWORD size, written, error;
5803 INTERNET_BUFFERSA b;
5804 static const char *accept[2] = {"*/*", NULL};
5805 char buffer[32];
5806
5807 trace("Async HttpSendRequestEx test (%s %s)\n", nd->method, nd->host);
5808
5809 InitializeCriticalSection( &notification_cs );
5810
5811 info.test = nd->test;
5812 info.count = nd->count;
5813 info.index = 0;
5814 info.wait = CreateEventW( NULL, FALSE, FALSE, NULL );
5815 info.thread = GetCurrentThreadId();
5816 info.is_aborted = FALSE;
5817
5818 ses = InternetOpenA( "winetest", 0, NULL, NULL, INTERNET_FLAG_ASYNC );
5819 ok( ses != NULL, "InternetOpen failed\n" );
5820
5821 pInternetSetStatusCallbackA( ses, check_notification );
5822
5823 setup_test( &info, internet_connect, __LINE__, ERROR_SUCCESS );
5824 con = InternetConnectA( ses, nd->host, 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, (DWORD_PTR)&info );
5825 ok( con != NULL, "InternetConnect failed %u\n", GetLastError() );
5826
5827 WaitForSingleObject( info.wait, 10000 );
5828
5829 setup_test( &info, http_open_request, __LINE__, ERROR_SUCCESS );
5830 req = HttpOpenRequestA( con, nd->method, nd->path, NULL, NULL, accept, 0, (DWORD_PTR)&info );
5831 ok( req != NULL, "HttpOpenRequest failed %u\n", GetLastError() );
5832
5833 WaitForSingleObject( info.wait, 10000 );
5834
5835 if(nd->data) {
5836 memset( &b, 0, sizeof(INTERNET_BUFFERSA) );
5837 b.dwStructSize = sizeof(INTERNET_BUFFERSA);
5838 b.lpcszHeader = "Content-Type: application/x-www-form-urlencoded";
5839 b.dwHeadersLength = strlen( b.lpcszHeader );
5840 b.dwBufferTotal = nd->data ? strlen( nd->data ) : 0;
5841 }
5842
5843 setup_test( &info, http_send_request_ex, __LINE__,
5844 nd->expect_conn_failure ? ERROR_INTERNET_NAME_NOT_RESOLVED : ERROR_SUCCESS );
5845 ret = HttpSendRequestExA( req, nd->data ? &b : NULL, NULL, 0x28, 0 );
5846 ok( !ret && GetLastError() == ERROR_IO_PENDING, "HttpSendRequestExA failed %d %u\n", ret, GetLastError() );
5847
5848 error = WaitForSingleObject( info.wait, 10000 );
5849 if(error != WAIT_OBJECT_0) {
5850 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error);
5851 info.is_aborted = TRUE;
5852 goto abort;
5853 }
5854
5855 size = sizeof(buffer);
5856 SetLastError( 0xdeadbeef );
5857 ret = HttpQueryInfoA( req, HTTP_QUERY_CONTENT_ENCODING, buffer, &size, 0 );
5858 error = GetLastError();
5859 ok( !ret, "HttpQueryInfoA failed %u\n", GetLastError() );
5860 if(nd->expect_conn_failure) {
5861 ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error );
5862 }else {
5863 todo_wine
5864 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_STATE,
5865 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error );
5866 }
5867
5868 if (nd->data)
5869 {
5870 written = 0;
5871 size = strlen( nd->data );
5872 setup_test( &info, internet_writefile, __LINE__, ERROR_SUCCESS );
5873 ret = InternetWriteFile( req, nd->data, size, &written );
5874 ok( ret, "InternetWriteFile failed %u\n", GetLastError() );
5875 ok( written == size, "expected %u got %u\n", written, size );
5876
5877 WaitForSingleObject( info.wait, 10000 );
5878
5879 SetLastError( 0xdeadbeef );
5880 ret = HttpEndRequestA( req, (void *)nd->data, 0x28, 0 );
5881 error = GetLastError();
5882 ok( !ret, "HttpEndRequestA succeeded\n" );
5883 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error );
5884 }
5885
5886 SetLastError( 0xdeadbeef );
5887 setup_test( &info, http_end_request, __LINE__,
5888 nd->expect_conn_failure ? ERROR_INTERNET_OPERATION_CANCELLED : ERROR_SUCCESS);
5889 ret = HttpEndRequestA( req, NULL, 0x28, 0 );
5890 error = GetLastError();
5891 ok( !ret, "HttpEndRequestA succeeded\n" );
5892 ok( error == ERROR_IO_PENDING, "expected ERROR_IO_PENDING got %u\n", error );
5893
5894 WaitForSingleObject( info.wait, 10000 );
5895
5896 setup_test( &info, internet_close_handle, __LINE__, ERROR_SUCCESS );
5897 abort:
5898 InternetCloseHandle( req );
5899 InternetCloseHandle( con );
5900 InternetCloseHandle( ses );
5901
5902 WaitForSingleObject( info.wait, 10000 );
5903 Sleep(100);
5904 CloseHandle( info.wait );
5905 }
5906
5907 static HINTERNET closetest_session, closetest_req, closetest_conn;
5908 static BOOL closetest_closed;
5909
5910 static void WINAPI closetest_callback(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus,
5911 LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
5912 {
5913 DWORD len, type;
5914 BOOL res;
5915
5916 trace("closetest_callback %p: %d\n", hInternet, dwInternetStatus);
5917
5918 ok(hInternet == closetest_session || hInternet == closetest_conn || hInternet == closetest_req,
5919 "Unexpected hInternet %p\n", hInternet);
5920 if(!closetest_closed)
5921 return;
5922
5923 len = sizeof(type);
5924 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_HANDLE_TYPE, &type, &len);
5925 ok(!res && GetLastError() == ERROR_INVALID_HANDLE,
5926 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5927 closetest_req, res, GetLastError());
5928 }
5929
5930 static void test_InternetCloseHandle(void)
5931 {
5932 DWORD len, flags;
5933 BOOL res;
5934
5935 closetest_session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
5936 ok(closetest_session != NULL,"InternetOpen failed with error %u\n", GetLastError());
5937
5938 pInternetSetStatusCallbackA(closetest_session, closetest_callback);
5939
5940 closetest_conn = InternetConnectA(closetest_session, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER,
5941 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
5942 ok(closetest_conn != NULL,"InternetConnect failed with error %u\n", GetLastError());
5943
5944 closetest_req = HttpOpenRequestA(closetest_conn, "GET", "winegecko.php", NULL, NULL, NULL,
5945 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
5946
5947 res = HttpSendRequestA(closetest_req, NULL, -1, NULL, 0);
5948 ok(!res && (GetLastError() == ERROR_IO_PENDING),
5949 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
5950
5951 test_request_flags(closetest_req, INTERNET_REQFLAG_NO_HEADERS);
5952
5953 res = InternetCloseHandle(closetest_session);
5954 ok(res, "InternetCloseHandle failed: %u\n", GetLastError());
5955 closetest_closed = TRUE;
5956 trace("Closed session handle\n");
5957
5958 res = InternetCloseHandle(closetest_conn);
5959 ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(conn) failed: %x %u\n",
5960 res, GetLastError());
5961
5962 res = InternetCloseHandle(closetest_req);
5963 ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(req) failed: %x %u\n",
5964 res, GetLastError());
5965
5966 len = sizeof(flags);
5967 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &len);
5968 ok(!res && GetLastError() == ERROR_INVALID_HANDLE,
5969 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5970 closetest_req, res, GetLastError());
5971 }
5972
5973 static void test_connection_failure(void)
5974 {
5975 HINTERNET session, connect, request;
5976 DWORD error;
5977 BOOL ret;
5978
5979 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
5980 ok(session != NULL, "failed to get session handle\n");
5981
5982 connect = InternetConnectA(session, "localhost", 1, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
5983 ok(connect != NULL, "failed to get connection handle\n");
5984
5985 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, 0, 0);
5986 ok(request != NULL, "failed to get request handle\n");
5987
5988 SetLastError(0xdeadbeef);
5989 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
5990 error = GetLastError();
5991 ok(!ret, "unexpected success\n");
5992 ok(error == ERROR_INTERNET_CANNOT_CONNECT, "wrong error %u\n", error);
5993
5994 InternetCloseHandle(request);
5995 InternetCloseHandle(connect);
5996 InternetCloseHandle(session);
5997 }
5998
5999 static void test_default_service_port(void)
6000 {
6001 HINTERNET session, connect, request;
6002 DWORD error;
6003 BOOL ret;
6004
6005 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
6006 ok(session != NULL, "InternetOpen failed\n");
6007
6008 connect = InternetConnectA(session, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL,
6009 INTERNET_SERVICE_HTTP, 0, 0);
6010 ok(connect != NULL, "InternetConnect failed\n");
6011
6012 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0);
6013 ok(request != NULL, "HttpOpenRequest failed\n");
6014
6015 SetLastError(0xdeadbeef);
6016 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
6017 error = GetLastError();
6018 ok(!ret, "HttpSendRequest succeeded\n");
6019 ok(error == ERROR_INTERNET_SECURITY_CHANNEL_ERROR || error == ERROR_INTERNET_CANNOT_CONNECT,
6020 "got %u\n", error);
6021
6022 InternetCloseHandle(request);
6023 InternetCloseHandle(connect);
6024 InternetCloseHandle(session);
6025 }
6026
6027 static void init_status_tests(void)
6028 {
6029 memset(expect, 0, sizeof(expect));
6030 memset(optional, 0, sizeof(optional));
6031 memset(wine_allow, 0, sizeof(wine_allow));
6032 memset(notified, 0, sizeof(notified));
6033 memset(status_string, 0, sizeof(status_string));
6034
6035 #define STATUS_STRING(status) status_string[status] = #status
6036 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME);
6037 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED);
6038 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER);
6039 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER);
6040 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST);
6041 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT);
6042 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE);
6043 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED);
6044 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED);
6045 STATUS_STRING(INTERNET_STATUS_PREFETCH);
6046 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION);
6047 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED);
6048 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED);
6049 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING);
6050 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY);
6051 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE);
6052 STATUS_STRING(INTERNET_STATUS_REDIRECT);
6053 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE);
6054 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED);
6055 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE);
6056 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT);
6057 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED);
6058 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED);
6059 STATUS_STRING(INTERNET_STATUS_P3P_HEADER);
6060 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF);
6061 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY);
6062 #undef STATUS_STRING
6063 }
6064
6065 static void WINAPI header_cb( HINTERNET handle, DWORD_PTR ctx, DWORD status, LPVOID info, DWORD len )
6066 {
6067 if (status == INTERNET_STATUS_REQUEST_COMPLETE) SetEvent( (HANDLE)ctx );
6068 }
6069
6070 static void test_concurrent_header_access(void)
6071 {
6072 HINTERNET ses, con, req;
6073 DWORD index, len, err;
6074 BOOL ret;
6075 char buf[128];
6076 HANDLE wait = CreateEventW( NULL, FALSE, FALSE, NULL );
6077
6078 ses = InternetOpenA( "winetest", 0, NULL, NULL, INTERNET_FLAG_ASYNC );
6079 ok( ses != NULL, "InternetOpenA failed\n" );
6080
6081 con = InternetConnectA( ses, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
6082 INTERNET_SERVICE_HTTP, 0, 0 );
6083 ok( con != NULL, "InternetConnectA failed %u\n", GetLastError() );
6084
6085 req = HttpOpenRequestA( con, NULL, "/", NULL, NULL, NULL, 0, (DWORD_PTR)wait );
6086 ok( req != NULL, "HttpOpenRequestA failed %u\n", GetLastError() );
6087
6088 pInternetSetStatusCallbackA( req, header_cb );
6089
6090 SetLastError( 0xdeadbeef );
6091 ret = HttpSendRequestA( req, NULL, 0, NULL, 0 );
6092 err = GetLastError();
6093 ok( !ret, "HttpSendRequestA succeeded\n" );
6094 ok( err == ERROR_IO_PENDING, "got %u\n", ERROR_IO_PENDING );
6095
6096 ret = HttpAddRequestHeadersA( req, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD );
6097 ok( ret, "HttpAddRequestHeadersA failed %u\n", GetLastError() );
6098
6099 index = 0;
6100 len = sizeof(buf);
6101 ret = HttpQueryInfoA( req, HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
6102 buf, &len, &index );
6103 ok( ret, "HttpQueryInfoA failed %u\n", GetLastError() );
6104 ok( strstr( buf, "winetest: winetest" ) != NULL, "header missing\n" );
6105
6106 WaitForSingleObject( wait, 5000 );
6107
6108 InternetCloseHandle( req );
6109 InternetCloseHandle( con );
6110 InternetCloseHandle( ses );
6111 CloseHandle( wait );
6112 }
6113
6114 START_TEST(http)
6115 {
6116 HMODULE hdll;
6117 hdll = GetModuleHandleA("wininet.dll");
6118
6119 if(!GetProcAddress(hdll, "InternetGetCookieExW")) {
6120 win_skip("Too old IE (older than 6.0)\n");
6121 return;
6122 }
6123
6124 pInternetSetStatusCallbackA = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackA");
6125 pInternetSetStatusCallbackW = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackW");
6126 pInternetGetSecurityInfoByURLA = (void*)GetProcAddress(hdll, "InternetGetSecurityInfoByURLA");
6127
6128 init_status_tests();
6129 test_InternetCloseHandle();
6130 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[0]);
6131 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[1]);
6132 InternetReadFile_test(0, &test_data[1]);
6133 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[2]);
6134 test_security_flags();
6135 InternetReadFile_test(0, &test_data[2]);
6136 InternetReadFileExA_test(INTERNET_FLAG_ASYNC);
6137 test_open_url_async();
6138 test_async_HttpSendRequestEx(&notification_data[0]);
6139 test_async_HttpSendRequestEx(&notification_data[1]);
6140 test_async_HttpSendRequestEx(&notification_data[2]);
6141 test_async_HttpSendRequestEx(&notification_data[3]);
6142 InternetOpenRequest_test();
6143 test_http_cache();
6144 InternetLockRequestFile_test();
6145 InternetOpenUrlA_test();
6146 HttpHeaders_test();
6147 test_http_connection();
6148 test_secure_connection();
6149 test_user_agent_header();
6150 test_bogus_accept_types_array();
6151 InternetReadFile_chunked_test();
6152 HttpSendRequestEx_test();
6153 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[3]);
6154 test_connection_failure();
6155 test_default_service_port();
6156 test_concurrent_header_access();
6157 }