wininet: Only accept proxy and proxy bypass if type is INTERNET_OPEN_TYPE_PROXY.
[wine.git] / dlls / wininet / tests / http.c
blobbc3505f3f00b96aecc0e916a64fe6f9a4f9d93ef
1 /*
2 * Wininet - HTTP tests
4 * Copyright 2002 Aric Stewart
5 * Copyright 2004 Mike McCormack
6 * Copyright 2005 Hans Leidekker
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wininet.h"
30 #include "winineti.h"
31 #include "winsock.h"
33 #include "wine/test.h"
35 #define TEST_URL "http://test.winehq.org/tests/hello.html"
37 static BOOL first_connection_to_test_url = TRUE;
39 /* Adapted from dlls/urlmon/tests/protocol.c */
41 #define SET_EXPECT2(status, num) \
42 expect[status] = num
44 #define SET_EXPECT(status) \
45 SET_EXPECT2(status, 1)
47 #define SET_OPTIONAL2(status, num) \
48 optional[status] = num
50 #define SET_OPTIONAL(status) \
51 SET_OPTIONAL2(status, 1)
53 /* SET_WINE_ALLOW's should be used with an appropriate
54 * todo_wine CHECK_NOTIFIED at a later point in the code */
55 #define SET_WINE_ALLOW2(status, num) \
56 wine_allow[status] = num
58 #define SET_WINE_ALLOW(status) \
59 SET_WINE_ALLOW2(status, 1)
61 #define CHECK_EXPECT(status) \
62 do { \
63 if (!expect[status] && !optional[status] && wine_allow[status]) \
64 { \
65 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
66 status < MAX_INTERNET_STATUS && status_string[status] ? \
67 status_string[status] : "unknown"); \
68 wine_allow[status]--; \
69 } \
70 else \
71 { \
72 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
73 status < MAX_INTERNET_STATUS && status_string[status] ? \
74 status_string[status] : "unknown"); \
75 if (expect[status]) expect[status]--; \
76 else optional[status]--; \
77 } \
78 notified[status]++; \
79 }while(0)
81 /* CLEAR_NOTIFIED used in cases when notification behavior
82 * differs between Windows versions */
83 #define CLEAR_NOTIFIED(status) \
84 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
86 #define CHECK_NOTIFIED2(status, num) \
87 do { \
88 ok(notified[status] + optional[status] == (num), \
89 "expected status %d (%s) %d times, received %d times\n", \
90 status, status < MAX_INTERNET_STATUS && status_string[status] ? \
91 status_string[status] : "unknown", (num), notified[status]); \
92 CLEAR_NOTIFIED(status); \
93 }while(0)
95 #define CHECK_NOTIFIED(status) \
96 CHECK_NOTIFIED2(status, 1)
98 #define CHECK_NOT_NOTIFIED(status) \
99 CHECK_NOTIFIED2(status, 0)
101 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
102 static int expect[MAX_INTERNET_STATUS], optional[MAX_INTERNET_STATUS],
103 wine_allow[MAX_INTERNET_STATUS], notified[MAX_INTERNET_STATUS];
104 static const char *status_string[MAX_INTERNET_STATUS];
106 static HANDLE hCompleteEvent, conn_close_event;
107 static DWORD req_error;
109 #define TESTF_REDIRECT 0x01
110 #define TESTF_COMPRESSED 0x02
111 #define TESTF_CHUNKED 0x04
113 typedef struct {
114 const char *url;
115 const char *redirected_url;
116 const char *host;
117 const char *path;
118 const char *headers;
119 DWORD flags;
120 const char *post_data;
121 const char *content;
122 } test_data_t;
124 static const test_data_t test_data[] = {
126 "http://test.winehq.org/tests/data.php",
127 "http://test.winehq.org/tests/data.php",
128 "test.winehq.org",
129 "/tests/data.php",
131 TESTF_CHUNKED
134 "http://test.winehq.org/tests/redirect",
135 "http://test.winehq.org/tests/hello.html",
136 "test.winehq.org",
137 "/tests/redirect",
139 TESTF_REDIRECT
142 "http://www.codeweavers.com/",
143 "http://www.codeweavers.com/",
144 "www.codeweavers.com",
146 "Accept-Encoding: gzip, deflate",
147 TESTF_COMPRESSED
150 "http://test.winehq.org/tests/post.php",
151 "http://test.winehq.org/tests/post.php",
152 "test.winehq.org",
153 "/tests/post.php",
154 "Content-Type: application/x-www-form-urlencoded",
156 "mode=Test",
157 "mode => Test\n"
161 static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackA)(HINTERNET ,INTERNET_STATUS_CALLBACK);
162 static INTERNET_STATUS_CALLBACK (WINAPI *pInternetSetStatusCallbackW)(HINTERNET ,INTERNET_STATUS_CALLBACK);
163 static BOOL (WINAPI *pInternetGetSecurityInfoByURLA)(LPSTR,PCCERT_CHAIN_CONTEXT*,DWORD*);
165 static int strcmp_wa(LPCWSTR strw, const char *stra)
167 WCHAR buf[512];
168 MultiByteToWideChar(CP_ACP, 0, stra, -1, buf, sizeof(buf)/sizeof(WCHAR));
169 return lstrcmpW(strw, buf);
172 static BOOL proxy_active(void)
174 HKEY internet_settings;
175 DWORD proxy_enable;
176 DWORD size;
178 if (RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
179 0, KEY_QUERY_VALUE, &internet_settings) != ERROR_SUCCESS)
180 return FALSE;
182 size = sizeof(DWORD);
183 if (RegQueryValueExA(internet_settings, "ProxyEnable", NULL, NULL, (LPBYTE) &proxy_enable, &size) != ERROR_SUCCESS)
184 proxy_enable = 0;
186 RegCloseKey(internet_settings);
188 return proxy_enable != 0;
191 #define test_status_code(a,b) _test_status_code(__LINE__,a,b)
192 static void _test_status_code(unsigned line, HINTERNET req, DWORD excode)
194 DWORD code, size, index;
195 char exbuf[10], bufa[10];
196 WCHAR bufw[10];
197 BOOL res;
199 code = 0xdeadbeef;
200 size = sizeof(code);
201 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, NULL);
202 ok_(__FILE__,line)(res, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
203 ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
204 ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
206 code = 0xdeadbeef;
207 index = 0;
208 size = sizeof(code);
209 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index);
210 ok_(__FILE__,line)(res, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
211 ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
212 ok_(__FILE__,line)(!index, "index = %d, expected 0\n", code);
213 ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
215 sprintf(exbuf, "%u", excode);
217 size = sizeof(bufa);
218 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, bufa, &size, NULL);
219 ok_(__FILE__,line)(res, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
220 ok_(__FILE__,line)(!strcmp(bufa, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
221 ok_(__FILE__,line)(size == strlen(exbuf), "unexpected size %d for \"%s\"\n", size, exbuf);
223 size = 0;
224 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, NULL, &size, NULL);
225 ok_(__FILE__,line)(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
226 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
227 ok_(__FILE__,line)(size == strlen(exbuf)+1, "unexpected size %d for \"%s\"\n", size, exbuf);
229 size = sizeof(bufw);
230 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL);
231 ok_(__FILE__,line)(res, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
232 ok_(__FILE__,line)(!strcmp_wa(bufw, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
233 ok_(__FILE__,line)(size == strlen(exbuf)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
235 size = 0;
236 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL);
237 ok_(__FILE__,line)(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
238 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
239 ok_(__FILE__,line)(size == (strlen(exbuf)+1)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
241 if(0) {
242 size = sizeof(bufw);
243 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, NULL, &size, NULL);
244 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
245 ok(size == sizeof(bufw), "unexpected size %d\n", size);
248 code = 0xdeadbeef;
249 index = 1;
250 size = sizeof(code);
251 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index);
252 ok_(__FILE__,line)(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
253 "[7] HttpQueryInfoA failed: %x(%d)\n", res, GetLastError());
255 code = 0xdeadbeef;
256 size = sizeof(code);
257 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_REQUEST_HEADERS, &code, &size, NULL);
258 ok_(__FILE__,line)(!res && GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST,
259 "[8] HttpQueryInfoA failed: %x(%d)\n", res, GetLastError());
262 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
263 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
264 static void _test_request_flags(unsigned line, HINTERNET req, DWORD exflags, BOOL is_todo)
266 DWORD flags, size;
267 BOOL res;
269 flags = 0xdeadbeef;
270 size = sizeof(flags);
271 res = InternetQueryOptionW(req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &size);
272 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
274 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
275 flags &= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED;
276 if(!is_todo)
277 ok_(__FILE__,line)(flags == exflags, "flags = %x, expected %x\n", flags, exflags);
278 else
279 todo_wine ok_(__FILE__,line)(flags == exflags, "flags = %x, expected %x\n", flags, exflags);
282 #define test_http_version(a) _test_http_version(__LINE__,a)
283 static void _test_http_version(unsigned line, HINTERNET req)
285 HTTP_VERSION_INFO v = {0xdeadbeef, 0xdeadbeef};
286 DWORD size;
287 BOOL res;
289 size = sizeof(v);
290 res = InternetQueryOptionW(req, INTERNET_OPTION_HTTP_VERSION, &v, &size);
291 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
292 ok_(__FILE__,line)(v.dwMajorVersion == 1, "dwMajorVersion = %d\n", v.dwMajorVersion);
293 ok_(__FILE__,line)(v.dwMinorVersion == 1, "dwMinorVersion = %d\n", v.dwMinorVersion);
296 static int close_handle_cnt;
298 static VOID WINAPI callback(
299 HINTERNET hInternet,
300 DWORD_PTR dwContext,
301 DWORD dwInternetStatus,
302 LPVOID lpvStatusInformation,
303 DWORD dwStatusInformationLength
306 CHECK_EXPECT(dwInternetStatus);
307 switch (dwInternetStatus)
309 case INTERNET_STATUS_RESOLVING_NAME:
310 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
311 GetCurrentThreadId(), hInternet, dwContext,
312 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
313 *(LPSTR)lpvStatusInformation = '\0';
314 break;
315 case INTERNET_STATUS_NAME_RESOLVED:
316 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
317 GetCurrentThreadId(), hInternet, dwContext,
318 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
319 *(LPSTR)lpvStatusInformation = '\0';
320 break;
321 case INTERNET_STATUS_CONNECTING_TO_SERVER:
322 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
323 GetCurrentThreadId(), hInternet, dwContext,
324 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
325 ok(dwStatusInformationLength == strlen(lpvStatusInformation)+1, "unexpected size %u\n",
326 dwStatusInformationLength);
327 *(LPSTR)lpvStatusInformation = '\0';
328 break;
329 case INTERNET_STATUS_CONNECTED_TO_SERVER:
330 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
331 GetCurrentThreadId(), hInternet, dwContext,
332 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
333 ok(dwStatusInformationLength == strlen(lpvStatusInformation)+1, "unexpected size %u\n",
334 dwStatusInformationLength);
335 *(LPSTR)lpvStatusInformation = '\0';
336 break;
337 case INTERNET_STATUS_SENDING_REQUEST:
338 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
339 GetCurrentThreadId(), hInternet, dwContext,
340 lpvStatusInformation,dwStatusInformationLength);
341 break;
342 case INTERNET_STATUS_REQUEST_SENT:
343 ok(dwStatusInformationLength == sizeof(DWORD),
344 "info length should be sizeof(DWORD) instead of %d\n",
345 dwStatusInformationLength);
346 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
347 GetCurrentThreadId(), hInternet, dwContext,
348 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
349 break;
350 case INTERNET_STATUS_RECEIVING_RESPONSE:
351 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
352 GetCurrentThreadId(), hInternet, dwContext,
353 lpvStatusInformation,dwStatusInformationLength);
354 break;
355 case INTERNET_STATUS_RESPONSE_RECEIVED:
356 ok(dwStatusInformationLength == sizeof(DWORD),
357 "info length should be sizeof(DWORD) instead of %d\n",
358 dwStatusInformationLength);
359 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
360 GetCurrentThreadId(), hInternet, dwContext,
361 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
362 break;
363 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
364 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
365 GetCurrentThreadId(), hInternet,dwContext,
366 lpvStatusInformation,dwStatusInformationLength);
367 break;
368 case INTERNET_STATUS_PREFETCH:
369 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
370 GetCurrentThreadId(), hInternet, dwContext,
371 lpvStatusInformation,dwStatusInformationLength);
372 break;
373 case INTERNET_STATUS_CLOSING_CONNECTION:
374 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
375 GetCurrentThreadId(), hInternet, dwContext,
376 lpvStatusInformation,dwStatusInformationLength);
377 break;
378 case INTERNET_STATUS_CONNECTION_CLOSED:
379 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
380 GetCurrentThreadId(), hInternet, dwContext,
381 lpvStatusInformation,dwStatusInformationLength);
382 break;
383 case INTERNET_STATUS_HANDLE_CREATED:
384 ok(dwStatusInformationLength == sizeof(HINTERNET),
385 "info length should be sizeof(HINTERNET) instead of %d\n",
386 dwStatusInformationLength);
387 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
388 GetCurrentThreadId(), hInternet, dwContext,
389 *(HINTERNET *)lpvStatusInformation,dwStatusInformationLength);
390 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
391 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
392 break;
393 case INTERNET_STATUS_HANDLE_CLOSING:
394 ok(dwStatusInformationLength == sizeof(HINTERNET),
395 "info length should be sizeof(HINTERNET) instead of %d\n",
396 dwStatusInformationLength);
397 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
398 GetCurrentThreadId(), hInternet, dwContext,
399 *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength);
400 if(!InterlockedDecrement(&close_handle_cnt))
401 SetEvent(hCompleteEvent);
402 break;
403 case INTERNET_STATUS_REQUEST_COMPLETE:
405 INTERNET_ASYNC_RESULT *iar = (INTERNET_ASYNC_RESULT *)lpvStatusInformation;
406 ok(dwStatusInformationLength == sizeof(INTERNET_ASYNC_RESULT),
407 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
408 dwStatusInformationLength);
409 ok(iar->dwResult == 1 || iar->dwResult == 0, "iar->dwResult = %ld\n", iar->dwResult);
410 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
411 GetCurrentThreadId(), hInternet, dwContext,
412 iar->dwResult,iar->dwError,dwStatusInformationLength);
413 req_error = iar->dwError;
414 if(!close_handle_cnt)
415 SetEvent(hCompleteEvent);
416 break;
418 case INTERNET_STATUS_REDIRECT:
419 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
420 GetCurrentThreadId(), hInternet, dwContext,
421 (LPCSTR)lpvStatusInformation, dwStatusInformationLength);
422 *(LPSTR)lpvStatusInformation = '\0';
423 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
424 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
425 break;
426 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
427 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
428 GetCurrentThreadId(), hInternet, dwContext,
429 lpvStatusInformation, dwStatusInformationLength);
430 break;
431 default:
432 trace("%04x:Callback %p 0x%lx %d %p %d\n",
433 GetCurrentThreadId(), hInternet, dwContext, dwInternetStatus,
434 lpvStatusInformation, dwStatusInformationLength);
438 static void close_async_handle(HINTERNET handle, HANDLE complete_event, int handle_cnt)
440 BOOL res;
442 close_handle_cnt = handle_cnt;
444 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
445 res = InternetCloseHandle(handle);
446 ok(res, "InternetCloseHandle failed: %u\n", GetLastError());
447 WaitForSingleObject(hCompleteEvent, INFINITE);
448 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
451 static void InternetReadFile_test(int flags, const test_data_t *test)
453 char *post_data = NULL;
454 BOOL res, on_async = TRUE;
455 CHAR buffer[4000];
456 DWORD length, exlen = 0, post_len = 0;
457 const char *types[2] = { "*", NULL };
458 HINTERNET hi, hic = 0, hor = 0;
460 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
462 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags,test->url);
464 trace("InternetOpenA <--\n");
465 hi = InternetOpenA((test->flags & TESTF_COMPRESSED) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
466 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
467 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
468 trace("InternetOpenA -->\n");
470 if (hi == 0x0) goto abort;
472 pInternetSetStatusCallbackA(hi,&callback);
474 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
476 trace("InternetConnectA <--\n");
477 hic=InternetConnectA(hi, test->host, INTERNET_INVALID_PORT_NUMBER,
478 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
479 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
480 trace("InternetConnectA -->\n");
482 if (hic == 0x0) goto abort;
484 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
485 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
487 trace("HttpOpenRequestA <--\n");
488 hor = HttpOpenRequestA(hic, test->post_data ? "POST" : "GET", test->path, NULL, NULL, types,
489 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
490 0xdeadbead);
491 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
493 * If the internet name can't be resolved we are probably behind
494 * a firewall or in some other way not directly connected to the
495 * Internet. Not enough reason to fail the test. Just ignore and
496 * abort.
498 } else {
499 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
501 trace("HttpOpenRequestA -->\n");
503 if (hor == 0x0) goto abort;
505 test_request_flags(hor, INTERNET_REQFLAG_NO_HEADERS);
507 length = sizeof(buffer);
508 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
509 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
510 ok(!strcmp(buffer, test->url), "Wrong URL %s, expected %s\n", buffer, test->url);
512 length = sizeof(buffer);
513 res = HttpQueryInfoA(hor, HTTP_QUERY_RAW_HEADERS, buffer, &length, 0x0);
514 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
515 ok(length == 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length);
516 ok(!strcmp(buffer, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer);
518 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
519 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
520 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
521 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT,2);
522 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED,2);
523 if (first_connection_to_test_url)
525 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
526 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
528 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
529 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
530 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, (test->flags & TESTF_REDIRECT) ? 2 : 1);
531 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, (test->flags & TESTF_REDIRECT) ? 2 : 1);
532 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, (test->flags & TESTF_REDIRECT) ? 2 : 1);
533 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, (test->flags & TESTF_REDIRECT) ? 2 : 1);
534 if(test->flags & TESTF_REDIRECT) {
535 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
536 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
538 SET_EXPECT(INTERNET_STATUS_REDIRECT);
539 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER);
540 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER);
541 if (flags & INTERNET_FLAG_ASYNC)
542 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
544 if(test->flags & TESTF_COMPRESSED) {
545 BOOL b = TRUE;
547 res = InternetSetOption(hor, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b));
548 ok(res || broken(!res && GetLastError() == ERROR_INTERNET_INVALID_OPTION),
549 "InternetSetOption failed: %u\n", GetLastError());
550 if(!res)
551 goto abort;
554 test_status_code(hor, 0);
556 trace("HttpSendRequestA -->\n");
557 if(test->post_data) {
558 post_len = strlen(test->post_data);
559 post_data = HeapAlloc(GetProcessHeap(), 0, post_len);
560 memcpy(post_data, test->post_data, post_len);
562 SetLastError(0xdeadbeef);
563 res = HttpSendRequestA(hor, test->headers, -1, post_data, post_len);
564 if (flags & INTERNET_FLAG_ASYNC)
565 ok(!res && (GetLastError() == ERROR_IO_PENDING),
566 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
567 else
568 ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED),
569 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
570 trace("HttpSendRequestA <--\n");
572 if (flags & INTERNET_FLAG_ASYNC) {
573 WaitForSingleObject(hCompleteEvent, INFINITE);
574 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
576 HeapFree(GetProcessHeap(), 0, post_data);
578 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
579 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED);
580 if (first_connection_to_test_url)
582 if (! proxy_active())
584 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
585 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
587 else
589 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
590 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
593 else
595 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
596 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
598 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, (test->flags & TESTF_REDIRECT) ? 2 : 1);
599 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, (test->flags & TESTF_REDIRECT) ? 2 : 1);
600 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, (test->flags & TESTF_REDIRECT) ? 2 : 1);
601 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, (test->flags & TESTF_REDIRECT) ? 2 : 1);
602 if(test->flags & TESTF_REDIRECT)
603 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
604 if (flags & INTERNET_FLAG_ASYNC)
605 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
606 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
607 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
608 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
610 test_request_flags(hor, 0);
612 length = 100;
613 res = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
614 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
616 length = sizeof(buffer);
617 res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0);
618 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
619 buffer[length]=0;
621 length = sizeof(buffer);
622 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
623 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
624 ok(!strcmp(buffer, test->redirected_url), "Wrong URL %s\n", buffer);
626 length = 16;
627 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
628 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res,buffer,GetLastError());
629 if(test->flags & TESTF_COMPRESSED)
630 ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
631 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res, GetLastError());
633 length = 100;
634 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
635 buffer[length]=0;
636 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res,buffer);
638 length = 100;
639 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_ENCODING,buffer,&length,0x0);
640 buffer[length]=0;
641 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res,buffer);
643 SetLastError(0xdeadbeef);
644 res = InternetReadFile(NULL, buffer, 100, &length);
645 ok(!res, "InternetReadFile should have failed\n");
646 ok(GetLastError() == ERROR_INVALID_HANDLE,
647 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
648 GetLastError());
650 length = 100;
651 trace("Entering Query loop\n");
653 while (TRUE)
655 if (flags & INTERNET_FLAG_ASYNC)
656 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
657 length = 0;
658 res = InternetQueryDataAvailable(hor,&length,0x0,0x0);
659 if (flags & INTERNET_FLAG_ASYNC)
661 if (res)
663 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
664 if(exlen) {
665 ok(length >= exlen, "length %u < exlen %u\n", length, exlen);
666 exlen = 0;
669 else if (GetLastError() == ERROR_IO_PENDING)
671 trace("PENDING\n");
672 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
673 if(!(test->flags & TESTF_CHUNKED))
674 ok(!length, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length);
675 WaitForSingleObject(hCompleteEvent, INFINITE);
676 exlen = length;
677 ok(exlen, "length = 0\n");
678 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
679 ok(req_error, "req_error = 0\n");
680 continue;
681 }else {
682 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
684 }else {
685 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
687 trace("LENGTH %d\n", length);
688 if(test->flags & TESTF_CHUNKED)
689 ok(length <= 8192, "length = %d, expected <= 8192\n", length);
690 if (length)
692 char *buffer;
693 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
695 res = InternetReadFile(hor,buffer,length,&length);
697 buffer[length]=0;
699 trace("ReadFile -> %s %i\n",res?"TRUE":"FALSE",length);
701 if(test->content)
702 ok(!strcmp(buffer, test->content), "buffer = '%s', expected '%s'\n", buffer, test->content);
703 HeapFree(GetProcessHeap(),0,buffer);
704 }else {
705 ok(!on_async, "Returned zero size in response to request complete\n");
706 break;
708 on_async = FALSE;
710 if(test->flags & TESTF_REDIRECT) {
711 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
712 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
714 abort:
715 trace("aborting\n");
716 close_async_handle(hi, hCompleteEvent, 2);
717 CloseHandle(hCompleteEvent);
718 first_connection_to_test_url = FALSE;
721 static void InternetReadFile_chunked_test(void)
723 BOOL res;
724 CHAR buffer[4000];
725 DWORD length;
726 const char *types[2] = { "*", NULL };
727 HINTERNET hi, hic = 0, hor = 0;
729 trace("Starting InternetReadFile chunked test\n");
731 trace("InternetOpenA <--\n");
732 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
733 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
734 trace("InternetOpenA -->\n");
736 if (hi == 0x0) goto abort;
738 trace("InternetConnectA <--\n");
739 hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER,
740 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
741 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
742 trace("InternetConnectA -->\n");
744 if (hic == 0x0) goto abort;
746 trace("HttpOpenRequestA <--\n");
747 hor = HttpOpenRequestA(hic, "GET", "/tests/chunked", NULL, NULL, types,
748 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
749 0xdeadbead);
750 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
752 * If the internet name can't be resolved we are probably behind
753 * a firewall or in some other way not directly connected to the
754 * Internet. Not enough reason to fail the test. Just ignore and
755 * abort.
757 } else {
758 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
760 trace("HttpOpenRequestA -->\n");
762 if (hor == 0x0) goto abort;
764 trace("HttpSendRequestA -->\n");
765 SetLastError(0xdeadbeef);
766 res = HttpSendRequestA(hor, "", -1, NULL, 0);
767 ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED),
768 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
769 trace("HttpSendRequestA <--\n");
771 test_request_flags(hor, 0);
773 length = 100;
774 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
775 buffer[length]=0;
776 trace("Option CONTENT_TYPE -> %i %s\n",res,buffer);
778 SetLastError( 0xdeadbeef );
779 length = 100;
780 res = HttpQueryInfoA(hor,HTTP_QUERY_TRANSFER_ENCODING,buffer,&length,0x0);
781 buffer[length]=0;
782 trace("Option TRANSFER_ENCODING -> %i %s\n",res,buffer);
783 ok( res || ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND ),
784 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
785 ok( !strcmp( buffer, "chunked" ) || ( ! res && proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND ),
786 "Wrong transfer encoding '%s'\n", buffer );
788 SetLastError( 0xdeadbeef );
789 length = 16;
790 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
791 ok( !res, "Found CONTENT_LENGTH option '%s'\n", buffer );
792 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "Wrong error %u\n", GetLastError() );
794 length = 100;
795 trace("Entering Query loop\n");
797 while (TRUE)
799 res = InternetQueryDataAvailable(hor,&length,0x0,0x0);
800 ok(!(!res && length != 0),"InternetQueryDataAvailable failed with non-zero length\n");
801 ok(res, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
802 trace("got %u available\n",length);
803 if (length)
805 DWORD got;
806 char *buffer = HeapAlloc(GetProcessHeap(),0,length+1);
808 res = InternetReadFile(hor,buffer,length,&got);
810 buffer[got]=0;
811 trace("ReadFile -> %i %i\n",res,got);
812 ok( length == got, "only got %u of %u available\n", got, length );
813 ok( buffer[got-1] == '\n', "received partial line '%s'\n", buffer );
815 HeapFree(GetProcessHeap(),0,buffer);
816 if (!got) break;
818 if (length == 0)
819 break;
821 abort:
822 trace("aborting\n");
823 if (hor != 0x0) {
824 res = InternetCloseHandle(hor);
825 ok (res, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
827 if (hi != 0x0) {
828 res = InternetCloseHandle(hi);
829 ok (res, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
833 static void InternetReadFileExA_test(int flags)
835 DWORD rc;
836 DWORD length;
837 const char *types[2] = { "*", NULL };
838 HINTERNET hi, hic = 0, hor = 0;
839 INTERNET_BUFFERS inetbuffers;
841 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
843 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags);
845 trace("InternetOpenA <--\n");
846 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
847 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
848 trace("InternetOpenA -->\n");
850 if (hi == 0x0) goto abort;
852 pInternetSetStatusCallbackA(hi,&callback);
854 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
856 trace("InternetConnectA <--\n");
857 hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER,
858 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
859 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
860 trace("InternetConnectA -->\n");
862 if (hic == 0x0) goto abort;
864 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
865 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
867 trace("HttpOpenRequestA <--\n");
868 hor = HttpOpenRequestA(hic, "GET", "/tests/redirect", NULL, NULL, types,
869 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
870 0xdeadbead);
871 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
873 * If the internet name can't be resolved we are probably behind
874 * a firewall or in some other way not directly connected to the
875 * Internet. Not enough reason to fail the test. Just ignore and
876 * abort.
878 } else {
879 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
881 trace("HttpOpenRequestA -->\n");
883 if (hor == 0x0) goto abort;
885 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
886 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
887 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
888 if (first_connection_to_test_url)
890 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
891 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
893 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT, 2);
894 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
895 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
896 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, 2);
897 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, 2);
898 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
899 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
900 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
901 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
902 SET_EXPECT(INTERNET_STATUS_REDIRECT);
903 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER);
904 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER);
905 if (flags & INTERNET_FLAG_ASYNC)
906 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
907 else
908 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
910 trace("HttpSendRequestA -->\n");
911 SetLastError(0xdeadbeef);
912 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
913 if (flags & INTERNET_FLAG_ASYNC)
914 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
915 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
916 else
917 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
918 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
919 trace("HttpSendRequestA <--\n");
921 if (!rc && (GetLastError() == ERROR_IO_PENDING)) {
922 WaitForSingleObject(hCompleteEvent, INFINITE);
923 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
926 if (first_connection_to_test_url)
928 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
929 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
931 else
933 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
934 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
936 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, 2);
937 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, 2);
938 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
939 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
940 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
941 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
942 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
943 if (flags & INTERNET_FLAG_ASYNC)
944 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
945 else
946 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
947 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
948 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
949 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
950 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
952 /* tests invalid dwStructSize */
953 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS)+1;
954 inetbuffers.lpcszHeader = NULL;
955 inetbuffers.dwHeadersLength = 0;
956 inetbuffers.dwBufferLength = 10;
957 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10);
958 inetbuffers.dwOffsetHigh = 1234;
959 inetbuffers.dwOffsetLow = 5678;
960 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
961 ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
962 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
963 rc ? "TRUE" : "FALSE", GetLastError());
964 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
966 test_request_flags(hor, 0);
968 /* tests to see whether lpcszHeader is used - it isn't */
969 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
970 inetbuffers.lpcszHeader = (LPCTSTR)0xdeadbeef;
971 inetbuffers.dwHeadersLength = 255;
972 inetbuffers.dwBufferLength = 0;
973 inetbuffers.lpvBuffer = NULL;
974 inetbuffers.dwOffsetHigh = 1234;
975 inetbuffers.dwOffsetLow = 5678;
976 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
977 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
978 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
979 ok(rc, "InternetReadFileEx failed with error %u\n", GetLastError());
980 trace("read %i bytes\n", inetbuffers.dwBufferLength);
981 todo_wine
983 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
984 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
987 rc = InternetReadFileEx(NULL, &inetbuffers, 0, 0xdeadcafe);
988 ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE),
989 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
990 rc ? "TRUE" : "FALSE", GetLastError());
992 length = 0;
993 trace("Entering Query loop\n");
995 while (TRUE)
997 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
998 inetbuffers.dwBufferLength = 1024;
999 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1);
1000 inetbuffers.dwOffsetHigh = 1234;
1001 inetbuffers.dwOffsetLow = 5678;
1003 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE);
1004 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED);
1005 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
1006 rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe);
1007 if (!rc)
1009 if (GetLastError() == ERROR_IO_PENDING)
1011 trace("InternetReadFileEx -> PENDING\n");
1012 ok(flags & INTERNET_FLAG_ASYNC,
1013 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1014 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1015 WaitForSingleObject(hCompleteEvent, INFINITE);
1016 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1017 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1018 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
1020 else
1022 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1023 break;
1026 else
1028 trace("InternetReadFileEx -> SUCCEEDED\n");
1029 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1030 if (inetbuffers.dwBufferLength)
1032 todo_wine {
1033 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1034 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1037 else
1039 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1040 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1041 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1045 trace("read %i bytes\n", inetbuffers.dwBufferLength);
1046 ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
1048 ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678,
1049 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1050 inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
1052 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
1054 if (!inetbuffers.dwBufferLength)
1055 break;
1057 length += inetbuffers.dwBufferLength;
1059 ok(length > 0, "failed to read any of the document\n");
1060 trace("Finished. Read %d bytes\n", length);
1062 abort:
1063 close_async_handle(hi, hCompleteEvent, 2);
1064 CloseHandle(hCompleteEvent);
1065 first_connection_to_test_url = FALSE;
1068 static void InternetOpenUrlA_test(void)
1070 HINTERNET myhinternet, myhttp;
1071 char buffer[0x400];
1072 DWORD size, readbytes, totalbytes=0;
1073 BOOL ret;
1075 ret = DeleteUrlCacheEntry(TEST_URL);
1076 ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND,
1077 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret, GetLastError());
1079 myhinternet = InternetOpen("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
1080 ok((myhinternet != 0), "InternetOpen failed, error %u\n",GetLastError());
1081 size = 0x400;
1082 ret = InternetCanonicalizeUrl(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
1083 ok( ret, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1085 SetLastError(0);
1086 myhttp = InternetOpenUrl(myhinternet, TEST_URL, 0, 0,
1087 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
1088 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1089 return; /* WinXP returns this when not connected to the net */
1090 ok((myhttp != 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1091 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
1092 ok( ret, "InternetReadFile failed, error %u\n",GetLastError());
1093 totalbytes += readbytes;
1094 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
1095 totalbytes += readbytes;
1096 trace("read 0x%08x bytes\n",totalbytes);
1098 InternetCloseHandle(myhttp);
1099 InternetCloseHandle(myhinternet);
1101 ret = DeleteUrlCacheEntry(TEST_URL);
1102 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1105 static void HttpSendRequestEx_test(void)
1107 HINTERNET hSession;
1108 HINTERNET hConnect;
1109 HINTERNET hRequest;
1111 INTERNET_BUFFERS BufferIn;
1112 DWORD dwBytesWritten, dwBytesRead, error;
1113 CHAR szBuffer[256];
1114 int i;
1115 BOOL ret;
1117 static char szPostData[] = "mode=Test";
1118 static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
1120 hSession = InternetOpen("Wine Regression Test",
1121 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1122 ok( hSession != NULL ,"Unable to open Internet session\n");
1123 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
1124 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1126 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
1127 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
1128 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1129 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1131 skip( "Network unreachable, skipping test\n" );
1132 goto done;
1134 ok( hRequest != NULL, "Failed to open request handle err %u\n", GetLastError());
1136 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1138 BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS);
1139 BufferIn.Next = (LPINTERNET_BUFFERS)0xdeadcab;
1140 BufferIn.lpcszHeader = szContentType;
1141 BufferIn.dwHeadersLength = sizeof(szContentType)-1;
1142 BufferIn.dwHeadersTotal = sizeof(szContentType)-1;
1143 BufferIn.lpvBuffer = szPostData;
1144 BufferIn.dwBufferLength = 3;
1145 BufferIn.dwBufferTotal = sizeof(szPostData)-1;
1146 BufferIn.dwOffsetLow = 0;
1147 BufferIn.dwOffsetHigh = 0;
1149 SetLastError(0xdeadbeef);
1150 ret = HttpSendRequestEx(hRequest, &BufferIn, NULL, 0 ,0);
1151 error = GetLastError();
1152 ok(ret, "HttpSendRequestEx Failed with error %u\n", error);
1153 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", error);
1155 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1157 for (i = 3; szPostData[i]; i++)
1158 ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten),
1159 "InternetWriteFile failed\n");
1161 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1163 ok(HttpEndRequest(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
1165 test_request_flags(hRequest, 0);
1167 ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead),
1168 "Unable to read response\n");
1169 szBuffer[dwBytesRead] = 0;
1171 ok(dwBytesRead == 13,"Read %u bytes instead of 13\n",dwBytesRead);
1172 ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0 || broken(proxy_active()),"Got string %s\n",szBuffer);
1174 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1175 done:
1176 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1177 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1180 static void InternetOpenRequest_test(void)
1182 HINTERNET session, connect, request;
1183 static const char *types[] = { "*", "", NULL };
1184 static const WCHAR slash[] = {'/', 0}, any[] = {'*', 0}, empty[] = {0};
1185 static const WCHAR *typesW[] = { any, empty, NULL };
1186 BOOL ret;
1188 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1189 ok(session != NULL ,"Unable to open Internet session\n");
1191 connect = InternetConnectA(session, NULL, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1192 INTERNET_SERVICE_HTTP, 0, 0);
1193 ok(connect == NULL, "InternetConnectA should have failed\n");
1194 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1196 connect = InternetConnectA(session, "", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1197 INTERNET_SERVICE_HTTP, 0, 0);
1198 ok(connect == NULL, "InternetConnectA should have failed\n");
1199 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1201 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1202 INTERNET_SERVICE_HTTP, 0, 0);
1203 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1205 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1206 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1208 skip( "Network unreachable, skipping test\n" );
1209 goto done;
1211 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1213 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1214 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1215 ok(InternetCloseHandle(request), "Close request handle failed\n");
1217 request = HttpOpenRequestW(connect, NULL, slash, NULL, NULL, typesW, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1218 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1220 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1221 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1222 ok(InternetCloseHandle(request), "Close request handle failed\n");
1224 done:
1225 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1226 ok(InternetCloseHandle(session), "Close session handle failed\n");
1229 static void test_cache_read(void)
1231 HINTERNET session, connection, req;
1232 FILETIME now, tomorrow, yesterday;
1233 BYTE content[1000], buf[2000];
1234 char file_path[MAX_PATH];
1235 ULARGE_INTEGER li;
1236 HANDLE file;
1237 DWORD size;
1238 unsigned i;
1239 BOOL res;
1241 static const char cache_only_url[] = "http://test.winehq.org/tests/cache-only";
1242 BYTE cache_headers[] = "HTTP/1.1 200 OK\r\n\r\n";
1244 trace("Testing cache read...\n");
1246 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
1248 for(i = 0; i < sizeof(content); i++)
1249 content[i] = '0' + (i%10);
1251 GetSystemTimeAsFileTime(&now);
1252 li.u.HighPart = now.dwHighDateTime;
1253 li.u.LowPart = now.dwLowDateTime;
1254 li.QuadPart += (LONGLONG)10000000 * 3600 * 24;
1255 tomorrow.dwHighDateTime = li.u.HighPart;
1256 tomorrow.dwLowDateTime = li.u.LowPart;
1257 li.QuadPart -= (LONGLONG)10000000 * 3600 * 24 * 2;
1258 yesterday.dwHighDateTime = li.u.HighPart;
1259 yesterday.dwLowDateTime = li.u.LowPart;
1261 res = CreateUrlCacheEntryA(cache_only_url, sizeof(content), "", file_path, 0);
1262 ok(res, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1264 file = CreateFileA(file_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1265 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
1267 WriteFile(file, content, sizeof(content), &size, NULL);
1268 CloseHandle(file);
1270 res = CommitUrlCacheEntryA(cache_only_url, file_path, tomorrow, yesterday, NORMAL_CACHE_ENTRY,
1271 cache_headers, sizeof(cache_headers)-1, "", 0);
1272 ok(res, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1274 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
1275 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
1277 pInternetSetStatusCallbackA(session, callback);
1279 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
1280 connection = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT,
1281 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
1282 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
1283 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
1285 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
1286 req = HttpOpenRequestA(connection, "GET", "/tests/cache-only", NULL, NULL, NULL, 0, 0xdeadbead);
1287 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
1288 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
1290 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER);
1291 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER);
1292 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST);
1293 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT);
1294 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE);
1295 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED);
1296 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
1298 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
1299 todo_wine
1300 ok(res, "HttpSendRequest failed: %u\n", GetLastError());
1302 if(res) {
1303 size = 0;
1304 res = InternetQueryDataAvailable(req, &size, 0, 0);
1305 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1306 ok(size == sizeof(content), "size = %u\n", size);
1308 size = sizeof(buf);
1309 res = InternetReadFile(req, buf, sizeof(buf), &size);
1310 ok(res, "InternetReadFile failed: %u\n", GetLastError());
1311 ok(size == sizeof(content), "size = %u\n", size);
1312 ok(!memcmp(content, buf, sizeof(content)), "unexpected content\n");
1315 close_async_handle(session, hCompleteEvent, 2);
1317 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
1318 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
1319 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
1320 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
1321 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1322 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1323 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1325 res = DeleteUrlCacheEntryA(cache_only_url);
1326 ok(res, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1328 CloseHandle(hCompleteEvent);
1331 static void test_http_cache(void)
1333 HINTERNET session, connect, request;
1334 char file_name[MAX_PATH], url[INTERNET_MAX_URL_LENGTH];
1335 DWORD size, file_size;
1336 BYTE buf[100];
1337 HANDLE file;
1338 BOOL ret;
1340 static const char *types[] = { "*", "", NULL };
1342 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1343 ok(session != NULL ,"Unable to open Internet session\n");
1345 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1346 INTERNET_SERVICE_HTTP, 0, 0);
1347 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1349 request = HttpOpenRequestA(connect, NULL, "/tests/hello.html", NULL, NULL, types, INTERNET_FLAG_NEED_FILE, 0);
1350 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1352 skip( "Network unreachable, skipping test\n" );
1354 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1355 ok(InternetCloseHandle(session), "Close session handle failed\n");
1357 return;
1359 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1361 size = sizeof(url);
1362 ret = InternetQueryOptionA(request, INTERNET_OPTION_URL, url, &size);
1363 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1364 ok(!strcmp(url, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url);
1366 size = sizeof(file_name);
1367 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1368 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1369 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1370 ok(!size, "size = %d\n", size);
1372 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1373 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1375 size = sizeof(file_name);
1376 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1377 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1379 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
1380 FILE_ATTRIBUTE_NORMAL, NULL);
1381 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1382 file_size = GetFileSize(file, NULL);
1383 ok(file_size == 106, "file size = %u\n", file_size);
1385 size = sizeof(buf);
1386 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1387 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1388 ok(size == 100, "size = %u\n", size);
1390 file_size = GetFileSize(file, NULL);
1391 ok(file_size == 106, "file size = %u\n", file_size);
1392 CloseHandle(file);
1394 ok(InternetCloseHandle(request), "Close request handle failed\n");
1396 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1397 FILE_ATTRIBUTE_NORMAL, NULL);
1398 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1399 CloseHandle(file);
1401 /* Send the same request, requiring it to be retrieved from the cache */
1402 request = HttpOpenRequest(connect, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
1404 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1405 ok(ret, "HttpSendRequest failed\n");
1407 size = sizeof(buf);
1408 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1409 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1410 ok(size == 100, "size = %u\n", size);
1412 ok(InternetCloseHandle(request), "Close request handle failed\n");
1414 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1415 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1417 size = sizeof(file_name);
1418 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1419 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1420 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1421 ok(!size, "size = %d\n", size);
1423 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1424 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1426 size = sizeof(file_name);
1427 file_name[0] = 0;
1428 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1429 if (ret)
1431 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1432 FILE_ATTRIBUTE_NORMAL, NULL);
1433 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1434 CloseHandle(file);
1436 else
1438 /* < IE8 */
1439 ok(file_name[0] == 0, "Didn't expect a file name\n");
1442 ok(InternetCloseHandle(request), "Close request handle failed\n");
1443 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1444 ok(InternetCloseHandle(session), "Close session handle failed\n");
1446 test_cache_read();
1449 static void HttpHeaders_test(void)
1451 HINTERNET hSession;
1452 HINTERNET hConnect;
1453 HINTERNET hRequest;
1454 CHAR buffer[256];
1455 WCHAR wbuffer[256];
1456 DWORD len = 256;
1457 DWORD oldlen;
1458 DWORD index = 0;
1460 hSession = InternetOpen("Wine Regression Test",
1461 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1462 ok( hSession != NULL ,"Unable to open Internet session\n");
1463 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
1464 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1466 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
1467 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
1468 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1469 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1471 skip( "Network unreachable, skipping test\n" );
1472 goto done;
1474 ok( hRequest != NULL, "Failed to open request handle\n");
1476 index = 0;
1477 len = sizeof(buffer);
1478 strcpy(buffer,"Warning");
1479 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1480 buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
1482 ok(HttpAddRequestHeaders(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
1483 "Failed to add new header\n");
1485 index = 0;
1486 len = sizeof(buffer);
1487 strcpy(buffer,"Warning");
1488 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1489 buffer,&len,&index),"Unable to query header\n");
1490 ok(index == 1, "Index was not incremented\n");
1491 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1492 ok(len == 5, "Invalid length (exp. 5, got %d)\n", len);
1493 ok((len < sizeof(buffer)) && (buffer[len] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1494 len = sizeof(buffer);
1495 strcpy(buffer,"Warning");
1496 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1497 buffer,&len,&index)==0,"Second Index Should Not Exist\n");
1499 index = 0;
1500 len = 5; /* could store the string but not the NULL terminator */
1501 strcpy(buffer,"Warning");
1502 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1503 buffer,&len,&index) == FALSE,"Query succeeded on a too small buffer\n");
1504 ok(strcmp(buffer,"Warning")==0, "incorrect string was returned(%s)\n",buffer); /* string not touched */
1505 ok(len == 6, "Invalid length (exp. 6, got %d)\n", len); /* unlike success, the length includes the NULL-terminator */
1507 /* a call with NULL will fail but will return the length */
1508 index = 0;
1509 len = sizeof(buffer);
1510 SetLastError(0xdeadbeef);
1511 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1512 NULL,&len,&index) == FALSE,"Query worked\n");
1513 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1514 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1515 ok(index == 0, "Index was incremented\n");
1517 /* even for a len that is too small */
1518 index = 0;
1519 len = 15;
1520 SetLastError(0xdeadbeef);
1521 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1522 NULL,&len,&index) == FALSE,"Query worked\n");
1523 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1524 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1525 ok(index == 0, "Index was incremented\n");
1527 index = 0;
1528 len = 0;
1529 SetLastError(0xdeadbeef);
1530 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1531 NULL,&len,&index) == FALSE,"Query worked\n");
1532 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1533 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1534 ok(index == 0, "Index was incremented\n");
1535 oldlen = len; /* bytes; at least long enough to hold buffer & nul */
1538 /* a working query */
1539 index = 0;
1540 len = sizeof(buffer);
1541 memset(buffer, 'x', sizeof(buffer));
1542 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1543 buffer,&len,&index),"Unable to query header\n");
1544 ok(len + sizeof(CHAR) <= oldlen, "Result longer than advertised\n");
1545 ok((len < sizeof(buffer)-sizeof(CHAR)) && (buffer[len/sizeof(CHAR)] == 0),"No NUL at end\n");
1546 ok(len == strlen(buffer) * sizeof(CHAR), "Length wrong\n");
1547 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1548 ok(strncmp(buffer, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1549 ok(strcmp(buffer + strlen(buffer) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1550 ok(index == 0, "Index was incremented\n");
1552 /* Like above two tests, but for W version */
1554 index = 0;
1555 len = 0;
1556 SetLastError(0xdeadbeef);
1557 ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1558 NULL,&len,&index) == FALSE,"Query worked\n");
1559 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1560 ok(len > 80, "Invalid length (exp. more than 80, got %d)\n", len);
1561 ok(index == 0, "Index was incremented\n");
1562 oldlen = len; /* bytes; at least long enough to hold buffer & nul */
1564 /* a working query */
1565 index = 0;
1566 len = sizeof(wbuffer);
1567 memset(wbuffer, 'x', sizeof(wbuffer));
1568 ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1569 wbuffer,&len,&index),"Unable to query header\n");
1570 ok(len + sizeof(WCHAR) <= oldlen, "Result longer than advertised\n");
1571 ok(len == lstrlenW(wbuffer) * sizeof(WCHAR), "Length wrong\n");
1572 ok((len < sizeof(wbuffer)-sizeof(WCHAR)) && (wbuffer[len/sizeof(WCHAR)] == 0),"No NUL at end\n");
1573 ok(index == 0, "Index was incremented\n");
1575 /* end of W version tests */
1577 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1578 index = 0;
1579 len = sizeof(buffer);
1580 memset(buffer, 'x', sizeof(buffer));
1581 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF,
1582 buffer,&len,&index) == TRUE,"Query failed\n");
1583 ok(len == 2, "Expected 2, got %d\n", len);
1584 ok(strcmp(buffer, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer);
1585 ok(index == 0, "Index was incremented\n");
1587 ok(HttpAddRequestHeaders(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
1588 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1590 index = 0;
1591 len = sizeof(buffer);
1592 strcpy(buffer,"Warning");
1593 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1594 buffer,&len,&index),"Unable to query header\n");
1595 ok(index == 1, "Index was not incremented\n");
1596 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1597 len = sizeof(buffer);
1598 strcpy(buffer,"Warning");
1599 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1600 buffer,&len,&index),"Failed to get second header\n");
1601 ok(index == 2, "Index was not incremented\n");
1602 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1603 len = sizeof(buffer);
1604 strcpy(buffer,"Warning");
1605 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1606 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1608 ok(HttpAddRequestHeaders(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1610 index = 0;
1611 len = sizeof(buffer);
1612 strcpy(buffer,"Warning");
1613 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1614 buffer,&len,&index),"Unable to query header\n");
1615 ok(index == 1, "Index was not incremented\n");
1616 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1617 len = sizeof(buffer);
1618 strcpy(buffer,"Warning");
1619 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1620 buffer,&len,&index),"Failed to get second header\n");
1621 ok(index == 2, "Index was not incremented\n");
1622 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1623 len = sizeof(buffer);
1624 strcpy(buffer,"Warning");
1625 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1626 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1628 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1630 index = 0;
1631 len = sizeof(buffer);
1632 strcpy(buffer,"Warning");
1633 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1634 buffer,&len,&index),"Unable to query header\n");
1635 ok(index == 1, "Index was not incremented\n");
1636 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1637 len = sizeof(buffer);
1638 strcpy(buffer,"Warning");
1639 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1640 buffer,&len,&index),"Failed to get second header\n");
1641 ok(index == 2, "Index was not incremented\n");
1642 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1643 len = sizeof(buffer);
1644 strcpy(buffer,"Warning");
1645 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1646 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1648 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1650 index = 0;
1651 len = sizeof(buffer);
1652 strcpy(buffer,"Warning");
1653 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1654 buffer,&len,&index),"Unable to query header\n");
1655 ok(index == 1, "Index was not incremented\n");
1656 ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer);
1657 len = sizeof(buffer);
1658 strcpy(buffer,"Warning");
1659 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1660 ok(index == 2, "Index was not incremented\n");
1661 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1662 len = sizeof(buffer);
1663 strcpy(buffer,"Warning");
1664 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1666 ok(HttpAddRequestHeaders(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1668 index = 0;
1669 len = sizeof(buffer);
1670 strcpy(buffer,"Warning");
1671 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1672 ok(index == 1, "Index was not incremented\n");
1673 ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer);
1674 len = sizeof(buffer);
1675 strcpy(buffer,"Warning");
1676 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1677 ok(index == 2, "Index was not incremented\n");
1678 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1679 len = sizeof(buffer);
1680 strcpy(buffer,"Warning");
1681 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1683 ok(HttpAddRequestHeaders(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1685 index = 0;
1686 len = sizeof(buffer);
1687 strcpy(buffer,"Warning");
1688 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1689 ok(index == 1, "Index was not incremented\n");
1690 ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer);
1691 len = sizeof(buffer);
1692 strcpy(buffer,"Warning");
1693 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1694 ok(index == 2, "Index was not incremented\n");
1695 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1696 len = sizeof(buffer);
1697 strcpy(buffer,"Warning");
1698 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1700 ok(HttpAddRequestHeaders(hRequest,"Warning:test7",-1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE), "HTTP_ADDREQ_FLAG_ADD with HTTP_ADDREQ_FLAG_REPALCE Did not work\n");
1702 index = 0;
1703 len = sizeof(buffer);
1704 strcpy(buffer,"Warning");
1705 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1706 ok(index == 1, "Index was not incremented\n");
1707 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1708 len = sizeof(buffer);
1709 strcpy(buffer,"Warning");
1710 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1711 ok(index == 2, "Index was not incremented\n");
1712 ok(strcmp(buffer,"test7")==0, "incorrect string was returned(%s)\n",buffer);
1713 len = sizeof(buffer);
1714 strcpy(buffer,"Warning");
1715 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1717 /* Ensure that blank headers are ignored and don't cause a failure */
1718 ok(HttpAddRequestHeaders(hRequest,"\r\nBlankTest:value\r\n\r\n",-1, HTTP_ADDREQ_FLAG_ADD_IF_NEW), "Failed to add header with blank entries in list\n");
1720 index = 0;
1721 len = sizeof(buffer);
1722 strcpy(buffer,"BlankTest");
1723 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1724 ok(index == 1, "Index was not incremented\n");
1725 ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
1727 /* Ensure that malformed header separators are ignored and don't cause a failure */
1728 ok(HttpAddRequestHeaders(hRequest,"\r\rMalformedTest:value\n\nMalformedTestTwo: value2\rMalformedTestThree: value3\n\n\r\r\n",-1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE),
1729 "Failed to add header with malformed entries in list\n");
1731 index = 0;
1732 len = sizeof(buffer);
1733 strcpy(buffer,"MalformedTest");
1734 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1735 ok(index == 1, "Index was not incremented\n");
1736 ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
1737 index = 0;
1738 len = sizeof(buffer);
1739 strcpy(buffer,"MalformedTestTwo");
1740 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1741 ok(index == 1, "Index was not incremented\n");
1742 ok(strcmp(buffer,"value2")==0, "incorrect string was returned(%s)\n",buffer);
1743 index = 0;
1744 len = sizeof(buffer);
1745 strcpy(buffer,"MalformedTestThree");
1746 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1747 ok(index == 1, "Index was not incremented\n");
1748 ok(strcmp(buffer,"value3")==0, "incorrect string was returned(%s)\n",buffer);
1750 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1751 done:
1752 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1753 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1756 static const char garbagemsg[] =
1757 "Garbage: Header\r\n";
1759 static const char contmsg[] =
1760 "HTTP/1.1 100 Continue\r\n";
1762 static const char expandcontmsg[] =
1763 "HTTP/1.1 100 Continue\r\n"
1764 "Server: winecontinue\r\n"
1765 "Tag: something witty\r\n"
1766 "\r\n";
1768 static const char okmsg[] =
1769 "HTTP/1.1 200 OK\r\n"
1770 "Server: winetest\r\n"
1771 "\r\n";
1773 static const char okmsg2[] =
1774 "HTTP/1.1 200 OK\r\n"
1775 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1776 "Server: winetest\r\n"
1777 "Content-Length: 0\r\n"
1778 "Set-Cookie: one\r\n"
1779 "Set-Cookie: two\r\n"
1780 "\r\n";
1782 static const char notokmsg[] =
1783 "HTTP/1.1 400 Bad Request\r\n"
1784 "Server: winetest\r\n"
1785 "\r\n";
1787 static const char noauthmsg[] =
1788 "HTTP/1.1 401 Unauthorized\r\n"
1789 "Server: winetest\r\n"
1790 "Connection: close\r\n"
1791 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1792 "\r\n";
1794 static const char noauthmsg2[] =
1795 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
1796 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
1797 "\0d`0|6\n"
1798 "Server: winetest\r\n";
1800 static const char proxymsg[] =
1801 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1802 "Server: winetest\r\n"
1803 "Proxy-Connection: close\r\n"
1804 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1805 "\r\n";
1807 static const char page1[] =
1808 "<HTML>\r\n"
1809 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1810 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1811 "</HTML>\r\n\r\n";
1813 struct server_info {
1814 HANDLE hEvent;
1815 int port;
1818 static int test_cache_gzip;
1820 static DWORD CALLBACK server_thread(LPVOID param)
1822 struct server_info *si = param;
1823 int r, c, i, on;
1824 SOCKET s;
1825 struct sockaddr_in sa;
1826 char buffer[0x100];
1827 WSADATA wsaData;
1828 int last_request = 0;
1829 char host_header[22];
1830 static int test_b = 0;
1831 static int test_no_cache = 0;
1833 WSAStartup(MAKEWORD(1,1), &wsaData);
1835 s = socket(AF_INET, SOCK_STREAM, 0);
1836 if (s == INVALID_SOCKET)
1837 return 1;
1839 on = 1;
1840 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof on);
1842 memset(&sa, 0, sizeof sa);
1843 sa.sin_family = AF_INET;
1844 sa.sin_port = htons(si->port);
1845 sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
1847 r = bind(s, (struct sockaddr*) &sa, sizeof sa);
1848 if (r<0)
1849 return 1;
1851 listen(s, 0);
1853 SetEvent(si->hEvent);
1855 sprintf(host_header, "Host: localhost:%d", si->port);
1859 c = accept(s, NULL, NULL);
1861 memset(buffer, 0, sizeof buffer);
1862 for(i=0; i<(sizeof buffer-1); i++)
1864 r = recv(c, &buffer[i], 1, 0);
1865 if (r != 1)
1866 break;
1867 if (i<4) continue;
1868 if (buffer[i-2] == '\n' && buffer[i] == '\n' &&
1869 buffer[i-3] == '\r' && buffer[i-1] == '\r')
1870 break;
1872 if (strstr(buffer, "GET /test1"))
1874 if (!strstr(buffer, "Content-Length: 0"))
1876 send(c, okmsg, sizeof okmsg-1, 0);
1877 send(c, page1, sizeof page1-1, 0);
1879 else
1880 send(c, notokmsg, sizeof notokmsg-1, 0);
1882 if (strstr(buffer, "/test2"))
1884 if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx"))
1886 send(c, okmsg, sizeof okmsg-1, 0);
1887 send(c, page1, sizeof page1-1, 0);
1889 else
1890 send(c, proxymsg, sizeof proxymsg-1, 0);
1892 if (strstr(buffer, "/test3"))
1894 if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
1895 send(c, okmsg, sizeof okmsg-1, 0);
1896 else
1897 send(c, noauthmsg, sizeof noauthmsg-1, 0);
1899 if (strstr(buffer, "/test4"))
1901 if (strstr(buffer, "Connection: Close"))
1902 send(c, okmsg, sizeof okmsg-1, 0);
1903 else
1904 send(c, notokmsg, sizeof notokmsg-1, 0);
1906 if (strstr(buffer, "POST /test5") ||
1907 strstr(buffer, "RPC_IN_DATA /test5") ||
1908 strstr(buffer, "RPC_OUT_DATA /test5"))
1910 if (strstr(buffer, "Content-Length: 0"))
1912 send(c, okmsg, sizeof okmsg-1, 0);
1913 send(c, page1, sizeof page1-1, 0);
1915 else
1916 send(c, notokmsg, sizeof notokmsg-1, 0);
1918 if (strstr(buffer, "GET /test6"))
1920 send(c, contmsg, sizeof contmsg-1, 0);
1921 send(c, contmsg, sizeof contmsg-1, 0);
1922 send(c, okmsg, sizeof okmsg-1, 0);
1923 send(c, page1, sizeof page1-1, 0);
1925 if (strstr(buffer, "POST /test7"))
1927 if (strstr(buffer, "Content-Length: 100"))
1929 send(c, okmsg, sizeof okmsg-1, 0);
1930 send(c, page1, sizeof page1-1, 0);
1932 else
1933 send(c, notokmsg, sizeof notokmsg-1, 0);
1935 if (strstr(buffer, "/test8"))
1937 if (!strstr(buffer, "Connection: Close") &&
1938 strstr(buffer, "Connection: Keep-Alive") &&
1939 !strstr(buffer, "Cache-Control: no-cache") &&
1940 !strstr(buffer, "Pragma: no-cache") &&
1941 strstr(buffer, host_header))
1942 send(c, okmsg, sizeof okmsg-1, 0);
1943 else
1944 send(c, notokmsg, sizeof notokmsg-1, 0);
1946 if (strstr(buffer, "/test9"))
1948 if (!strstr(buffer, "Connection: Close") &&
1949 !strstr(buffer, "Connection: Keep-Alive") &&
1950 !strstr(buffer, "Cache-Control: no-cache") &&
1951 !strstr(buffer, "Pragma: no-cache") &&
1952 strstr(buffer, host_header))
1953 send(c, okmsg, sizeof okmsg-1, 0);
1954 else
1955 send(c, notokmsg, sizeof notokmsg-1, 0);
1957 if (strstr(buffer, "/testA"))
1959 if (!strstr(buffer, "Connection: Close") &&
1960 !strstr(buffer, "Connection: Keep-Alive") &&
1961 (strstr(buffer, "Cache-Control: no-cache") ||
1962 strstr(buffer, "Pragma: no-cache")) &&
1963 strstr(buffer, host_header))
1964 send(c, okmsg, sizeof okmsg-1, 0);
1965 else
1966 send(c, notokmsg, sizeof notokmsg-1, 0);
1968 if (!test_b && strstr(buffer, "/testB HTTP/1.1"))
1970 test_b = 1;
1971 send(c, okmsg, sizeof okmsg-1, 0);
1972 recvfrom(c, buffer, sizeof buffer, 0, NULL, NULL);
1973 send(c, okmsg, sizeof okmsg-1, 0);
1975 if (strstr(buffer, "/testC"))
1977 if (strstr(buffer, "Cookie: cookie=biscuit"))
1978 send(c, okmsg, sizeof okmsg-1, 0);
1979 else
1980 send(c, notokmsg, sizeof notokmsg-1, 0);
1982 if (strstr(buffer, "/testD"))
1984 send(c, okmsg2, sizeof okmsg2-1, 0);
1986 if (strstr(buffer, "/testE"))
1988 send(c, noauthmsg2, sizeof noauthmsg2-1, 0);
1990 if (strstr(buffer, "GET /quit"))
1992 send(c, okmsg, sizeof okmsg-1, 0);
1993 send(c, page1, sizeof page1-1, 0);
1994 last_request = 1;
1996 if (strstr(buffer, "GET /testF"))
1998 send(c, expandcontmsg, sizeof expandcontmsg-1, 0);
1999 send(c, garbagemsg, sizeof garbagemsg-1, 0);
2000 send(c, contmsg, sizeof contmsg-1, 0);
2001 send(c, garbagemsg, sizeof garbagemsg-1, 0);
2002 send(c, okmsg, sizeof okmsg-1, 0);
2003 send(c, page1, sizeof page1-1, 0);
2005 if (strstr(buffer, "GET /testG"))
2007 send(c, page1, sizeof page1-1, 0);
2009 if (strstr(buffer, "GET /test_no_content"))
2011 static const char nocontentmsg[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2012 send(c, nocontentmsg, sizeof(nocontentmsg)-1, 0);
2014 if (strstr(buffer, "GET /test_conn_close"))
2016 static const char conn_close_response[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2017 send(c, conn_close_response, sizeof(conn_close_response)-1, 0);
2018 WaitForSingleObject(conn_close_event, INFINITE);
2019 trace("closing connection\n");
2021 if (strstr(buffer, "GET /test_cache_control_no_cache"))
2023 static const char no_cache_response[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2024 if(!test_no_cache++)
2025 send(c, no_cache_response, sizeof(no_cache_response)-1, 0);
2026 else
2027 send(c, okmsg, sizeof(okmsg)-1, 0);
2029 if (strstr(buffer, "GET /test_cache_control_no_store"))
2031 static const char no_cache_response[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2032 send(c, no_cache_response, sizeof(no_cache_response)-1, 0);
2034 if (strstr(buffer, "GET /test_cache_gzip"))
2036 static const char gzip_response[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2037 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2038 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2039 if(!test_cache_gzip++)
2040 send(c, gzip_response, sizeof(gzip_response), 0);
2041 else
2042 send(c, notokmsg, sizeof(notokmsg)-1, 0);
2044 if (strstr(buffer, "GET /test_premature_disconnect"))
2045 trace("closing connection\n");
2047 shutdown(c, 2);
2048 closesocket(c);
2049 } while (!last_request);
2051 closesocket(s);
2053 return 0;
2056 static void test_basic_request(int port, const char *verb, const char *url)
2058 HINTERNET hi, hc, hr;
2059 DWORD r, count;
2060 char buffer[0x100];
2062 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2063 ok(hi != NULL, "open failed\n");
2065 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2066 ok(hc != NULL, "connect failed\n");
2068 hr = HttpOpenRequest(hc, verb, url, NULL, NULL, NULL, 0, 0);
2069 ok(hr != NULL, "HttpOpenRequest failed\n");
2071 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
2072 ok(r, "HttpSendRequest failed\n");
2074 count = 0;
2075 memset(buffer, 0, sizeof buffer);
2076 SetLastError(0xdeadbeef);
2077 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
2078 ok(r, "InternetReadFile failed %u\n", GetLastError());
2079 ok(count == sizeof page1 - 1, "count was wrong\n");
2080 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong, got: %s\n", buffer);
2082 InternetCloseHandle(hr);
2083 InternetCloseHandle(hc);
2084 InternetCloseHandle(hi);
2087 static void test_last_error(int port)
2089 HINTERNET hi, hc, hr;
2090 DWORD error;
2091 BOOL r;
2093 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2094 ok(hi != NULL, "open failed\n");
2096 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2097 ok(hc != NULL, "connect failed\n");
2099 hr = HttpOpenRequest(hc, NULL, "/test1", NULL, NULL, NULL, 0, 0);
2100 ok(hr != NULL, "HttpOpenRequest failed\n");
2102 SetLastError(0xdeadbeef);
2103 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
2104 error = GetLastError();
2105 ok(r, "HttpSendRequest failed\n");
2106 ok(error == ERROR_SUCCESS || broken(error != ERROR_SUCCESS), "expected ERROR_SUCCESS, got %u\n", error);
2108 InternetCloseHandle(hr);
2109 InternetCloseHandle(hc);
2110 InternetCloseHandle(hi);
2113 static void test_proxy_indirect(int port)
2115 HINTERNET hi, hc, hr;
2116 DWORD r, sz;
2117 char buffer[0x40];
2119 hi = InternetOpen(NULL, 0, NULL, NULL, 0);
2120 ok(hi != NULL, "open failed\n");
2122 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2123 ok(hc != NULL, "connect failed\n");
2125 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
2126 ok(hr != NULL, "HttpOpenRequest failed\n");
2128 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
2129 ok(r, "HttpSendRequest failed %u\n", GetLastError());
2131 sz = sizeof buffer;
2132 r = HttpQueryInfo(hr, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL);
2133 ok(r || GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo failed: %d\n", GetLastError());
2134 if (!r)
2136 skip("missing proxy header, not testing remaining proxy headers\n");
2137 goto out;
2139 ok(!strcmp(buffer, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2141 test_status_code(hr, 407);
2142 test_request_flags(hr, 0);
2144 sz = sizeof buffer;
2145 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL);
2146 ok(r, "HttpQueryInfo failed\n");
2147 ok(!strcmp(buffer, "Proxy Authentication Required"), "proxy text wrong\n");
2149 sz = sizeof buffer;
2150 r = HttpQueryInfo(hr, HTTP_QUERY_VERSION, buffer, &sz, NULL);
2151 ok(r, "HttpQueryInfo failed\n");
2152 ok(!strcmp(buffer, "HTTP/1.1"), "http version wrong\n");
2154 sz = sizeof buffer;
2155 r = HttpQueryInfo(hr, HTTP_QUERY_SERVER, buffer, &sz, NULL);
2156 ok(r, "HttpQueryInfo failed\n");
2157 ok(!strcmp(buffer, "winetest"), "http server wrong\n");
2159 sz = sizeof buffer;
2160 r = HttpQueryInfo(hr, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL);
2161 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo should fail\n");
2162 ok(r == FALSE, "HttpQueryInfo failed\n");
2164 out:
2165 InternetCloseHandle(hr);
2166 InternetCloseHandle(hc);
2167 InternetCloseHandle(hi);
2170 static void test_proxy_direct(int port)
2172 HINTERNET hi, hc, hr;
2173 DWORD r, sz, error;
2174 char buffer[0x40], *url;
2175 WCHAR bufferW[0x40];
2176 static CHAR username[] = "mike",
2177 password[] = "1101",
2178 useragent[] = "winetest",
2179 url_fmt[] = "http://test.winehq.org:%u/test2";
2180 static WCHAR usernameW[] = {'m','i','k','e',0},
2181 passwordW[] = {'1','1','0','1',0},
2182 useragentW[] = {'w','i','n','e','t','e','s','t',0};
2184 /* specify proxy type without the proxy and bypass */
2185 SetLastError(0xdeadbeef);
2186 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_PROXY, NULL, NULL, 0);
2187 error = GetLastError();
2188 ok(error == ERROR_INVALID_PARAMETER ||
2189 broken(error == ERROR_SUCCESS) /* WinXPProSP2 */, "got %u\n", error);
2190 ok(hi == NULL || broken(!!hi) /* WinXPProSP2 */, "open should have failed\n");
2192 sprintf(buffer, "localhost:%d\n", port);
2193 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0);
2194 ok(hi != NULL, "open failed\n");
2196 /* try connect without authorization */
2197 hc = InternetConnect(hi, "test.winehq.org", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2198 ok(hc != NULL, "connect failed\n");
2200 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
2201 ok(hr != NULL, "HttpOpenRequest failed\n");
2203 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
2204 ok(r || broken(!r), "HttpSendRequest failed %u\n", GetLastError());
2205 if (!r)
2207 win_skip("skipping proxy tests on broken wininet\n");
2208 goto done;
2211 test_status_code(hr, 407);
2213 /* set the user + password then try again */
2214 r = InternetSetOption(hi, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2215 ok(!r, "unexpected success\n");
2217 r = InternetSetOption(hc, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2218 ok(r, "failed to set user\n");
2220 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2221 ok(r, "failed to set user\n");
2223 buffer[0] = 0;
2224 sz = 0;
2225 SetLastError(0xdeadbeef);
2226 r = InternetQueryOption(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2227 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2228 ok(!r, "unexpected success\n");
2229 ok(sz == strlen(username) + 1, "got %u\n", sz);
2231 bufferW[0] = 0;
2232 sz = 0;
2233 SetLastError(0xdeadbeef);
2234 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_USERNAME, bufferW, &sz);
2235 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2236 ok(!r, "unexpected success\n");
2237 ok(sz == (lstrlenW(usernameW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2239 buffer[0] = 0;
2240 sz = sizeof(buffer);
2241 r = InternetQueryOption(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2242 ok(r, "failed to get username\n");
2243 ok(!strcmp(buffer, username), "got %s\n", buffer);
2244 ok(sz == strlen(username), "got %u\n", sz);
2246 buffer[0] = 0;
2247 sz = sizeof(bufferW);
2248 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_USERNAME, bufferW, &sz);
2249 ok(r, "failed to get username\n");
2250 ok(!lstrcmpW(bufferW, usernameW), "wrong username\n");
2251 ok(sz == lstrlenW(usernameW), "got %u\n", sz);
2253 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_USERNAME, username, 1);
2254 ok(r, "failed to set user\n");
2256 buffer[0] = 0;
2257 sz = sizeof(buffer);
2258 r = InternetQueryOption(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2259 ok(r, "failed to get username\n");
2260 ok(!strcmp(buffer, username), "got %s\n", buffer);
2261 ok(sz == strlen(username), "got %u\n", sz);
2263 r = InternetSetOption(hi, INTERNET_OPTION_USER_AGENT, useragent, 1);
2264 ok(r, "failed to set useragent\n");
2266 buffer[0] = 0;
2267 sz = 0;
2268 SetLastError(0xdeadbeef);
2269 r = InternetQueryOption(hi, INTERNET_OPTION_USER_AGENT, buffer, &sz);
2270 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2271 ok(!r, "unexpected success\n");
2272 ok(sz == strlen(useragent) + 1, "got %u\n", sz);
2274 buffer[0] = 0;
2275 sz = sizeof(buffer);
2276 r = InternetQueryOption(hi, INTERNET_OPTION_USER_AGENT, buffer, &sz);
2277 ok(r, "failed to get user agent\n");
2278 ok(!strcmp(buffer, useragent), "got %s\n", buffer);
2279 ok(sz == strlen(useragent), "got %u\n", sz);
2281 bufferW[0] = 0;
2282 sz = 0;
2283 SetLastError(0xdeadbeef);
2284 r = InternetQueryOptionW(hi, INTERNET_OPTION_USER_AGENT, bufferW, &sz);
2285 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2286 ok(!r, "unexpected success\n");
2287 ok(sz == (lstrlenW(useragentW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2289 bufferW[0] = 0;
2290 sz = sizeof(bufferW);
2291 r = InternetQueryOptionW(hi, INTERNET_OPTION_USER_AGENT, bufferW, &sz);
2292 ok(r, "failed to get user agent\n");
2293 ok(!lstrcmpW(bufferW, useragentW), "wrong user agent\n");
2294 ok(sz == lstrlenW(useragentW), "got %u\n", sz);
2296 r = InternetSetOption(hr, INTERNET_OPTION_USERNAME, username, 1);
2297 ok(r, "failed to set user\n");
2299 buffer[0] = 0;
2300 sz = 0;
2301 SetLastError(0xdeadbeef);
2302 r = InternetQueryOption(hr, INTERNET_OPTION_USERNAME, buffer, &sz);
2303 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2304 ok(!r, "unexpected success\n");
2305 ok(sz == strlen(username) + 1, "got %u\n", sz);
2307 buffer[0] = 0;
2308 sz = sizeof(buffer);
2309 r = InternetQueryOption(hr, INTERNET_OPTION_USERNAME, buffer, &sz);
2310 ok(r, "failed to get user\n");
2311 ok(!strcmp(buffer, username), "got %s\n", buffer);
2312 ok(sz == strlen(username), "got %u\n", sz);
2314 bufferW[0] = 0;
2315 sz = 0;
2316 SetLastError(0xdeadbeef);
2317 r = InternetQueryOptionW(hr, INTERNET_OPTION_USERNAME, bufferW, &sz);
2318 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2319 ok(!r, "unexpected success\n");
2320 ok(sz == (lstrlenW(usernameW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2322 bufferW[0] = 0;
2323 sz = sizeof(bufferW);
2324 r = InternetQueryOptionW(hr, INTERNET_OPTION_USERNAME, bufferW, &sz);
2325 ok(r, "failed to get user\n");
2326 ok(!lstrcmpW(bufferW, usernameW), "wrong user\n");
2327 ok(sz == lstrlenW(usernameW), "got %u\n", sz);
2329 r = InternetSetOption(hr, INTERNET_OPTION_PASSWORD, password, 1);
2330 ok(r, "failed to set password\n");
2332 buffer[0] = 0;
2333 sz = 0;
2334 SetLastError(0xdeadbeef);
2335 r = InternetQueryOption(hr, INTERNET_OPTION_PASSWORD, buffer, &sz);
2336 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2337 ok(!r, "unexpected success\n");
2338 ok(sz == strlen(password) + 1, "got %u\n", sz);
2340 buffer[0] = 0;
2341 sz = sizeof(buffer);
2342 r = InternetQueryOption(hr, INTERNET_OPTION_PASSWORD, buffer, &sz);
2343 ok(r, "failed to get password\n");
2344 ok(!strcmp(buffer, password), "got %s\n", buffer);
2345 ok(sz == strlen(password), "got %u\n", sz);
2347 bufferW[0] = 0;
2348 sz = 0;
2349 SetLastError(0xdeadbeef);
2350 r = InternetQueryOptionW(hr, INTERNET_OPTION_PASSWORD, bufferW, &sz);
2351 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2352 ok(!r, "unexpected success\n");
2353 ok(sz == (lstrlenW(passwordW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2355 bufferW[0] = 0;
2356 sz = sizeof(bufferW);
2357 r = InternetQueryOptionW(hr, INTERNET_OPTION_PASSWORD, bufferW, &sz);
2358 ok(r, "failed to get password\n");
2359 ok(!lstrcmpW(bufferW, passwordW), "wrong password\n");
2360 ok(sz == lstrlenW(passwordW), "got %u\n", sz);
2362 url = HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt) + 11);
2363 sprintf(url, url_fmt, port);
2364 buffer[0] = 0;
2365 sz = 0;
2366 SetLastError(0xdeadbeef);
2367 r = InternetQueryOption(hr, INTERNET_OPTION_URL, buffer, &sz);
2368 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2369 ok(!r, "unexpected success\n");
2370 ok(sz == strlen(url) + 1, "got %u\n", sz);
2372 buffer[0] = 0;
2373 sz = sizeof(buffer);
2374 r = InternetQueryOption(hr, INTERNET_OPTION_URL, buffer, &sz);
2375 ok(r, "failed to get url\n");
2376 ok(!strcmp(buffer, url), "got %s\n", buffer);
2377 ok(sz == strlen(url), "got %u\n", sz);
2379 bufferW[0] = 0;
2380 sz = 0;
2381 SetLastError(0xdeadbeef);
2382 r = InternetQueryOptionW(hr, INTERNET_OPTION_URL, bufferW, &sz);
2383 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2384 ok(!r, "unexpected success\n");
2385 ok(sz == (strlen(url) + 1) * sizeof(WCHAR), "got %u\n", sz);
2387 bufferW[0] = 0;
2388 sz = sizeof(bufferW);
2389 r = InternetQueryOptionW(hr, INTERNET_OPTION_URL, bufferW, &sz);
2390 ok(r, "failed to get url\n");
2391 ok(!strcmp_wa(bufferW, url), "wrong url\n");
2392 ok(sz == strlen(url), "got %u\n", sz);
2393 HeapFree(GetProcessHeap(), 0, url);
2395 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_PASSWORD, password, 4);
2396 ok(r, "failed to set password\n");
2398 buffer[0] = 0;
2399 sz = 0;
2400 SetLastError(0xdeadbeef);
2401 r = InternetQueryOption(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz);
2402 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2403 ok(!r, "unexpected success\n");
2404 ok(sz == strlen(password) + 1, "got %u\n", sz);
2406 buffer[0] = 0;
2407 sz = sizeof(buffer);
2408 r = InternetQueryOption(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz);
2409 ok(r, "failed to get password\n");
2410 ok(!strcmp(buffer, password), "got %s\n", buffer);
2411 ok(sz == strlen(password), "got %u\n", sz);
2413 bufferW[0] = 0;
2414 sz = 0;
2415 SetLastError(0xdeadbeef);
2416 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_PASSWORD, bufferW, &sz);
2417 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2418 ok(!r, "unexpected success\n");
2419 ok(sz == (lstrlenW(passwordW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2421 bufferW[0] = 0;
2422 sz = sizeof(bufferW);
2423 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_PASSWORD, bufferW, &sz);
2424 ok(r, "failed to get password\n");
2425 ok(!lstrcmpW(bufferW, passwordW), "wrong password\n");
2426 ok(sz == lstrlenW(passwordW), "got %u\n", sz);
2428 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
2429 ok(r, "HttpSendRequest failed %u\n", GetLastError());
2430 sz = sizeof buffer;
2431 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
2432 ok(r, "HttpQueryInfo failed\n");
2433 ok(!strcmp(buffer, "200"), "proxy code wrong\n");
2435 done:
2436 InternetCloseHandle(hr);
2437 InternetCloseHandle(hc);
2438 InternetCloseHandle(hi);
2441 static void test_header_handling_order(int port)
2443 static char authorization[] = "Authorization: Basic dXNlcjpwd2Q=";
2444 static char connection[] = "Connection: Close";
2446 static const char *types[2] = { "*", NULL };
2447 HINTERNET session, connect, request;
2448 DWORD size, status;
2449 BOOL ret;
2451 session = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2452 ok(session != NULL, "InternetOpen failed\n");
2454 connect = InternetConnect(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2455 ok(connect != NULL, "InternetConnect failed\n");
2457 request = HttpOpenRequest(connect, NULL, "/test3", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2458 ok(request != NULL, "HttpOpenRequest failed\n");
2460 ret = HttpAddRequestHeaders(request, authorization, ~0u, HTTP_ADDREQ_FLAG_ADD);
2461 ok(ret, "HttpAddRequestHeaders failed\n");
2463 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
2464 ok(ret, "HttpSendRequest failed\n");
2466 test_status_code(request, 200);
2467 test_request_flags(request, 0);
2469 InternetCloseHandle(request);
2471 request = HttpOpenRequest(connect, NULL, "/test4", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2472 ok(request != NULL, "HttpOpenRequest failed\n");
2474 ret = HttpSendRequest(request, connection, ~0u, NULL, 0);
2475 ok(ret, "HttpSendRequest failed\n");
2477 status = 0;
2478 size = sizeof(status);
2479 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2480 ok(ret, "HttpQueryInfo failed\n");
2481 ok(status == 200 || status == 400 /* IE6 */, "got status %u, expected 200 or 400\n", status);
2483 InternetCloseHandle(request);
2485 request = HttpOpenRequest(connect, "POST", "/test7", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2486 ok(request != NULL, "HttpOpenRequest failed\n");
2488 ret = HttpAddRequestHeaders(request, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
2489 ok(ret, "HttpAddRequestHeaders failed\n");
2491 ret = HttpSendRequest(request, connection, ~0u, NULL, 0);
2492 ok(ret, "HttpSendRequest failed\n");
2494 status = 0;
2495 size = sizeof(status);
2496 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2497 ok(ret, "HttpQueryInfo failed\n");
2498 ok(status == 200 || status == 400 /* IE6 */, "got status %u, expected 200 or 400\n", status);
2500 InternetCloseHandle(request);
2501 InternetCloseHandle(connect);
2502 InternetCloseHandle(session);
2505 static void test_connection_header(int port)
2507 HINTERNET ses, con, req;
2508 BOOL ret;
2510 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2511 ok(ses != NULL, "InternetOpen failed\n");
2513 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2514 ok(con != NULL, "InternetConnect failed\n");
2516 req = HttpOpenRequest(con, NULL, "/test8", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2517 ok(req != NULL, "HttpOpenRequest failed\n");
2519 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2520 ok(ret, "HttpSendRequest failed\n");
2522 test_status_code(req, 200);
2524 InternetCloseHandle(req);
2526 req = HttpOpenRequest(con, NULL, "/test9", NULL, NULL, NULL, 0, 0);
2527 ok(req != NULL, "HttpOpenRequest failed\n");
2529 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2530 ok(ret, "HttpSendRequest failed\n");
2532 test_status_code(req, 200);
2534 InternetCloseHandle(req);
2536 req = HttpOpenRequest(con, NULL, "/test9", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
2537 ok(req != NULL, "HttpOpenRequest failed\n");
2539 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2540 ok(ret, "HttpSendRequest failed\n");
2542 test_status_code(req, 200);
2544 InternetCloseHandle(req);
2546 req = HttpOpenRequest(con, "POST", "/testA", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
2547 ok(req != NULL, "HttpOpenRequest failed\n");
2549 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2550 ok(ret, "HttpSendRequest failed\n");
2552 test_status_code(req, 200);
2554 InternetCloseHandle(req);
2555 InternetCloseHandle(con);
2556 InternetCloseHandle(ses);
2559 static void test_http1_1(int port)
2561 HINTERNET ses, con, req;
2562 BOOL ret;
2564 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2565 ok(ses != NULL, "InternetOpen failed\n");
2567 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2568 ok(con != NULL, "InternetConnect failed\n");
2570 req = HttpOpenRequest(con, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2571 ok(req != NULL, "HttpOpenRequest failed\n");
2573 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2574 if (ret)
2576 InternetCloseHandle(req);
2578 req = HttpOpenRequest(con, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2579 ok(req != NULL, "HttpOpenRequest failed\n");
2581 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2582 ok(ret, "HttpSendRequest failed\n");
2585 InternetCloseHandle(req);
2586 InternetCloseHandle(con);
2587 InternetCloseHandle(ses);
2590 static void test_no_content(int port)
2592 HINTERNET session, connection, req;
2593 DWORD res;
2595 trace("Testing 204 no content response...\n");
2597 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
2599 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
2600 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
2602 pInternetSetStatusCallbackA(session, callback);
2604 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2605 connection = InternetConnectA(session, "localhost", port,
2606 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
2607 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
2608 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2610 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2611 req = HttpOpenRequestA(connection, "GET", "/test_no_content", NULL, NULL, NULL,
2612 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
2613 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
2614 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2616 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
2617 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
2618 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
2619 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
2620 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
2621 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
2622 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
2623 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
2624 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
2625 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2627 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
2628 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2629 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2630 WaitForSingleObject(hCompleteEvent, INFINITE);
2631 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2633 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
2634 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
2635 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
2636 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
2637 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
2638 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
2639 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
2640 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
2641 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
2642 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
2644 close_async_handle(session, hCompleteEvent, 2);
2645 CloseHandle(hCompleteEvent);
2648 static void test_conn_close(int port)
2650 HINTERNET session, connection, req;
2651 DWORD res, avail, size;
2652 BYTE buf[1024];
2654 trace("Testing connection close connection...\n");
2656 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
2657 conn_close_event = CreateEvent(NULL, FALSE, FALSE, NULL);
2659 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
2660 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
2662 pInternetSetStatusCallbackA(session, callback);
2664 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2665 connection = InternetConnectA(session, "localhost", port,
2666 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
2667 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
2668 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2670 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2671 req = HttpOpenRequestA(connection, "GET", "/test_conn_close", NULL, NULL, NULL,
2672 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
2673 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
2674 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2676 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
2677 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
2678 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
2679 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
2680 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
2681 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
2682 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
2683 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2685 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
2686 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2687 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2688 WaitForSingleObject(hCompleteEvent, INFINITE);
2689 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2691 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
2692 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
2693 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
2694 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
2695 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
2696 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
2697 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
2698 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
2700 avail = 0;
2701 res = InternetQueryDataAvailable(req, &avail, 0, 0);
2702 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
2703 ok(avail != 0, "avail = 0\n");
2705 size = 0;
2706 res = InternetReadFile(req, buf, avail, &size);
2707 ok(res, "InternetReadFile failed: %u\n", GetLastError());
2709 res = InternetQueryDataAvailable(req, &avail, 0, 0);
2710 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2711 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2712 ok(!avail, "avail = %u, expected 0\n", avail);
2714 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
2715 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
2716 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2717 SetEvent(conn_close_event);
2718 WaitForSingleObject(hCompleteEvent, INFINITE);
2719 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2720 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
2721 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
2722 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
2724 close_async_handle(session, hCompleteEvent, 2);
2725 CloseHandle(hCompleteEvent);
2728 static void test_no_cache(int port)
2730 static const char cache_control_no_cache[] = "/test_cache_control_no_cache";
2731 static const char cache_control_no_store[] = "/test_cache_control_no_store";
2732 static const char cache_url_fmt[] = "http://localhost:%d%s";
2734 char cache_url[256], buf[256];
2735 HINTERNET ses, con, req;
2736 DWORD read, size;
2737 BOOL ret;
2739 trace("Testing no-cache header\n");
2741 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2742 ok(ses != NULL,"InternetOpen failed with error %u\n", GetLastError());
2744 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2745 ok(con != NULL, "InternetConnect failed with error %u\n", GetLastError());
2747 req = HttpOpenRequest(con, NULL, cache_control_no_cache, NULL, NULL, NULL, 0, 0);
2748 ok(req != NULL, "HttpOpenRequest failed\n");
2750 sprintf(cache_url, cache_url_fmt, port, cache_control_no_cache);
2751 DeleteUrlCacheEntry(cache_url);
2753 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2754 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
2755 size = 0;
2756 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
2757 size += read;
2758 ok(size == 12, "read %d bytes of data\n", size);
2759 InternetCloseHandle(req);
2761 req = HttpOpenRequest(con, NULL, cache_control_no_cache, NULL, NULL, NULL, 0, 0);
2762 ok(req != NULL, "HttpOpenRequest failed\n");
2764 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2765 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
2766 size = 0;
2767 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
2768 size += read;
2769 ok(size == 0, "read %d bytes of data\n", size);
2770 InternetCloseHandle(req);
2771 DeleteUrlCacheEntry(cache_url);
2773 req = HttpOpenRequest(con, NULL, cache_control_no_store, NULL, NULL, NULL, 0, 0);
2774 ok(req != NULL, "HttpOpenRequest failed\n");
2776 sprintf(cache_url, cache_url_fmt, port, cache_control_no_store);
2777 DeleteUrlCacheEntry(cache_url);
2779 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2780 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
2781 size = 0;
2782 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
2783 size += read;
2784 ok(size == 12, "read %d bytes of data\n", size);
2785 InternetCloseHandle(req);
2787 ret = DeleteUrlCacheEntry(cache_url);
2788 ok(!ret && GetLastError()==ERROR_FILE_NOT_FOUND, "cache entry should not exist\n");
2790 InternetCloseHandle(con);
2791 InternetCloseHandle(ses);
2794 static void test_cache_read_gzipped(int port)
2796 static const char cache_url_fmt[] = "http://localhost:%d%s";
2797 static const char get_gzip[] = "/test_cache_gzip";
2798 static const char content[] = "gzip test\n";
2799 static const char text_html[] = "text/html";
2800 static const char raw_header[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
2802 HINTERNET ses, con, req;
2803 DWORD read, size;
2804 char cache_url[256], buf[256];
2805 BOOL ret;
2807 trace("Testing reading compressed content from cache\n");
2809 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2810 ok(ses != NULL,"InternetOpen failed with error %u\n", GetLastError());
2812 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2813 ok(con != NULL, "InternetConnect failed with error %u\n", GetLastError());
2815 req = HttpOpenRequest(con, NULL, get_gzip, NULL, NULL, NULL, 0, 0);
2816 ok(req != NULL, "HttpOpenRequest failed\n");
2818 ret = TRUE;
2819 ret = InternetSetOption(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
2820 if(!ret && GetLastError()==ERROR_INTERNET_INVALID_OPTION) {
2821 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
2822 InternetCloseHandle(req);
2823 InternetCloseHandle(con);
2824 InternetCloseHandle(ses);
2825 return;
2827 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
2829 ret = HttpSendRequest(req, "Accept-Encoding: gzip", -1, NULL, 0);
2830 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
2831 size = 0;
2832 while(InternetReadFile(req, buf+size, sizeof(buf)-size, &read) && read)
2833 size += read;
2834 ok(size == 10, "read %d bytes of data\n", size);
2835 buf[size] = 0;
2836 ok(!strncmp(buf, content, size), "incorrect page content: %s\n", buf);
2838 size = sizeof(buf);
2839 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_TYPE, buf, &size, 0);
2840 ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
2841 buf[size] = 0;
2842 ok(!strncmp(text_html, buf, size), "buf = %s\n", buf);
2844 size = sizeof(buf);
2845 ret = HttpQueryInfoA(req, HTTP_QUERY_RAW_HEADERS_CRLF, buf, &size, 0);
2846 ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
2847 buf[size] = 0;
2848 ok(!strncmp(raw_header, buf, size), "buf = %s\n", buf);
2849 InternetCloseHandle(req);
2851 req = HttpOpenRequest(con, NULL, get_gzip, NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
2852 ok(req != NULL, "HttpOpenRequest failed\n");
2854 ret = TRUE;
2855 ret = InternetSetOption(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
2856 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
2858 ret = HttpSendRequest(req, "Accept-Encoding: gzip", -1, NULL, 0);
2859 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
2860 size = 0;
2861 while(InternetReadFile(req, buf+size, sizeof(buf)-size, &read) && read)
2862 size += read;
2863 todo_wine ok(size == 10, "read %d bytes of data\n", size);
2864 buf[size] = 0;
2865 ok(!strncmp(buf, content, size), "incorrect page content: %s\n", buf);
2867 size = sizeof(buf);
2868 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
2869 ok(!ret && GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND,
2870 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
2871 ret, GetLastError());
2873 size = sizeof(buf);
2874 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_TYPE, buf, &size, 0);
2875 todo_wine ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
2876 buf[size] = 0;
2877 todo_wine ok(!strncmp(text_html, buf, size), "buf = %s\n", buf);
2878 InternetCloseHandle(req);
2880 /* Decompression doesn't work while reading from cache */
2881 test_cache_gzip = 0;
2882 sprintf(cache_url, cache_url_fmt, port, get_gzip);
2883 DeleteUrlCacheEntry(cache_url);
2885 req = HttpOpenRequest(con, NULL, get_gzip, NULL, NULL, NULL, 0, 0);
2886 ok(req != NULL, "HttpOpenRequest failed\n");
2888 ret = HttpSendRequest(req, "Accept-Encoding: gzip", -1, NULL, 0);
2889 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
2890 size = 0;
2891 while(InternetReadFile(req, buf+size, sizeof(buf)-size, &read) && read)
2892 size += read;
2893 ok(size == 31, "read %d bytes of data\n", size);
2894 InternetCloseHandle(req);
2896 req = HttpOpenRequest(con, NULL, get_gzip, NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
2897 ok(req != NULL, "HttpOpenRequest failed\n");
2899 ret = TRUE;
2900 ret = InternetSetOption(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
2901 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
2903 ret = HttpSendRequest(req, "Accept-Encoding: gzip", -1, NULL, 0);
2904 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
2905 size = 0;
2906 while(InternetReadFile(req, buf+size, sizeof(buf)-size, &read) && read)
2907 size += read;
2908 todo_wine ok(size == 31, "read %d bytes of data\n", size);
2910 size = sizeof(buf);
2911 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
2912 todo_wine ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
2913 InternetCloseHandle(req);
2915 InternetCloseHandle(con);
2916 InternetCloseHandle(ses);
2918 DeleteUrlCacheEntry(cache_url);
2921 static void test_HttpSendRequestW(int port)
2923 static const WCHAR header[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
2924 HINTERNET ses, con, req;
2925 DWORD error;
2926 BOOL ret;
2928 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
2929 ok(ses != NULL, "InternetOpen failed\n");
2931 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2932 ok(con != NULL, "InternetConnect failed\n");
2934 req = HttpOpenRequest(con, NULL, "/test1", NULL, NULL, NULL, 0, 0);
2935 ok(req != NULL, "HttpOpenRequest failed\n");
2937 SetLastError(0xdeadbeef);
2938 ret = HttpSendRequestW(req, header, ~0u, NULL, 0);
2939 error = GetLastError();
2940 ok(!ret, "HttpSendRequestW succeeded\n");
2941 ok(error == ERROR_IO_PENDING ||
2942 broken(error == ERROR_HTTP_HEADER_NOT_FOUND) || /* IE6 */
2943 broken(error == ERROR_INVALID_PARAMETER), /* IE5 */
2944 "got %u expected ERROR_IO_PENDING\n", error);
2946 InternetCloseHandle(req);
2947 InternetCloseHandle(con);
2948 InternetCloseHandle(ses);
2951 static void test_cookie_header(int port)
2953 HINTERNET ses, con, req;
2954 DWORD size, error;
2955 BOOL ret;
2956 char buffer[64];
2958 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2959 ok(ses != NULL, "InternetOpen failed\n");
2961 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2962 ok(con != NULL, "InternetConnect failed\n");
2964 InternetSetCookie("http://localhost", "cookie", "biscuit");
2966 req = HttpOpenRequest(con, NULL, "/testC", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2967 ok(req != NULL, "HttpOpenRequest failed\n");
2969 buffer[0] = 0;
2970 size = sizeof(buffer);
2971 SetLastError(0xdeadbeef);
2972 ret = HttpQueryInfo(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
2973 error = GetLastError();
2974 ok(!ret, "HttpQueryInfo succeeded\n");
2975 ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error);
2977 ret = HttpAddRequestHeaders(req, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD);
2978 ok(ret, "HttpAddRequestHeaders failed: %u\n", GetLastError());
2980 buffer[0] = 0;
2981 size = sizeof(buffer);
2982 ret = HttpQueryInfo(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
2983 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
2984 ok(!strcmp(buffer, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer);
2986 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2987 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
2989 test_status_code(req, 200);
2991 buffer[0] = 0;
2992 size = sizeof(buffer);
2993 ret = HttpQueryInfo(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
2994 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
2995 ok(!strcmp(buffer, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer);
2997 InternetCloseHandle(req);
2998 InternetCloseHandle(con);
2999 InternetCloseHandle(ses);
3002 static void test_basic_authentication(int port)
3004 HINTERNET session, connect, request;
3005 BOOL ret;
3007 session = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3008 ok(session != NULL, "InternetOpen failed\n");
3010 connect = InternetConnect(session, "localhost", port, "user", "pwd", INTERNET_SERVICE_HTTP, 0, 0);
3011 ok(connect != NULL, "InternetConnect failed\n");
3013 request = HttpOpenRequest(connect, NULL, "/test3", NULL, NULL, NULL, 0, 0);
3014 ok(request != NULL, "HttpOpenRequest failed\n");
3016 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
3017 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
3019 test_status_code(request, 200);
3020 test_request_flags(request, 0);
3022 InternetCloseHandle(request);
3023 InternetCloseHandle(connect);
3024 InternetCloseHandle(session);
3027 static void test_premature_disconnect(int port)
3029 HINTERNET session, connect, request;
3030 DWORD err;
3031 BOOL ret;
3033 session = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3034 ok(session != NULL, "InternetOpen failed\n");
3036 connect = InternetConnect(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3037 ok(connect != NULL, "InternetConnect failed\n");
3039 request = HttpOpenRequest(connect, NULL, "/premature_disconnect", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3040 ok(request != NULL, "HttpOpenRequest failed\n");
3042 SetLastError(0xdeadbeef);
3043 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
3044 err = GetLastError();
3045 todo_wine ok(!ret, "HttpSendRequest succeeded\n");
3046 todo_wine ok(err == ERROR_HTTP_INVALID_SERVER_RESPONSE, "got %u\n", err);
3048 InternetCloseHandle(request);
3049 InternetCloseHandle(connect);
3050 InternetCloseHandle(session);
3053 static void test_invalid_response_headers(int port)
3055 HINTERNET session, connect, request;
3056 DWORD size;
3057 BOOL ret;
3058 char buffer[256];
3060 session = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3061 ok(session != NULL, "InternetOpen failed\n");
3063 connect = InternetConnect(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3064 ok(connect != NULL, "InternetConnect failed\n");
3066 request = HttpOpenRequest(connect, NULL, "/testE", NULL, NULL, NULL, 0, 0);
3067 ok(request != NULL, "HttpOpenRequest failed\n");
3069 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
3070 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
3072 test_status_code(request, 401);
3073 test_request_flags(request, 0);
3075 buffer[0] = 0;
3076 size = sizeof(buffer);
3077 ret = HttpQueryInfo( request, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
3078 ok(ret, "HttpQueryInfo failed\n");
3079 ok(!strcmp(buffer, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
3080 "headers wrong \"%s\"\n", buffer);
3082 buffer[0] = 0;
3083 size = sizeof(buffer);
3084 ret = HttpQueryInfo( request, HTTP_QUERY_SERVER, buffer, &size, NULL);
3085 ok(ret, "HttpQueryInfo failed\n");
3086 ok(!strcmp(buffer, "winetest"), "server wrong \"%s\"\n", buffer);
3088 InternetCloseHandle(request);
3089 InternetCloseHandle(connect);
3090 InternetCloseHandle(session);
3093 static void test_response_without_headers(int port)
3095 HINTERNET hi, hc, hr;
3096 DWORD r, count, size;
3097 char buffer[1024];
3099 SetLastError(0xdeadbeef);
3100 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3101 ok(hi != NULL, "open failed %u\n", GetLastError());
3103 SetLastError(0xdeadbeef);
3104 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3105 ok(hc != NULL, "connect failed %u\n", GetLastError());
3107 SetLastError(0xdeadbeef);
3108 hr = HttpOpenRequest(hc, NULL, "/testG", NULL, NULL, NULL, 0, 0);
3109 ok(hr != NULL, "HttpOpenRequest failed %u\n", GetLastError());
3111 test_request_flags(hr, INTERNET_REQFLAG_NO_HEADERS);
3113 SetLastError(0xdeadbeef);
3114 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
3115 ok(r, "HttpSendRequest failed %u\n", GetLastError());
3117 test_request_flags_todo(hr, INTERNET_REQFLAG_NO_HEADERS);
3119 count = 0;
3120 memset(buffer, 0, sizeof buffer);
3121 SetLastError(0xdeadbeef);
3122 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
3123 ok(r, "InternetReadFile failed %u\n", GetLastError());
3124 todo_wine ok(count == sizeof page1 - 1, "count was wrong\n");
3125 todo_wine ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
3127 test_status_code(hr, 200);
3128 test_request_flags_todo(hr, INTERNET_REQFLAG_NO_HEADERS);
3130 buffer[0] = 0;
3131 size = sizeof(buffer);
3132 SetLastError(0xdeadbeef);
3133 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, NULL );
3134 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
3135 ok(!strcmp(buffer, "OK"), "expected OK got: \"%s\"\n", buffer);
3137 buffer[0] = 0;
3138 size = sizeof(buffer);
3139 SetLastError(0xdeadbeef);
3140 r = HttpQueryInfo(hr, HTTP_QUERY_VERSION, buffer, &size, NULL);
3141 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
3142 ok(!strcmp(buffer, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer);
3144 buffer[0] = 0;
3145 size = sizeof(buffer);
3146 SetLastError(0xdeadbeef);
3147 r = HttpQueryInfo(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
3148 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
3149 ok(!strcmp(buffer, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer);
3151 InternetCloseHandle(hr);
3152 InternetCloseHandle(hc);
3153 InternetCloseHandle(hi);
3156 static void test_HttpQueryInfo(int port)
3158 HINTERNET hi, hc, hr;
3159 DWORD size, index;
3160 char buffer[1024];
3161 BOOL ret;
3163 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3164 ok(hi != NULL, "InternetOpen failed\n");
3166 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3167 ok(hc != NULL, "InternetConnect failed\n");
3169 hr = HttpOpenRequest(hc, NULL, "/testD", NULL, NULL, NULL, 0, 0);
3170 ok(hr != NULL, "HttpOpenRequest failed\n");
3172 ret = HttpSendRequest(hr, NULL, 0, NULL, 0);
3173 ok(ret, "HttpSendRequest failed\n");
3175 index = 0;
3176 size = sizeof(buffer);
3177 ret = HttpQueryInfo(hr, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &index);
3178 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3179 ok(index == 1, "expected 1 got %u\n", index);
3181 index = 0;
3182 size = sizeof(buffer);
3183 ret = HttpQueryInfo(hr, HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME, buffer, &size, &index);
3184 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3185 ok(index == 1, "expected 1 got %u\n", index);
3187 index = 0;
3188 size = sizeof(buffer);
3189 ret = HttpQueryInfo(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
3190 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3191 ok(index == 0, "expected 0 got %u\n", index);
3193 size = sizeof(buffer);
3194 ret = HttpQueryInfo(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
3195 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3196 ok(index == 0, "expected 0 got %u\n", index);
3198 index = 0xdeadbeef; /* invalid start index */
3199 size = sizeof(buffer);
3200 ret = HttpQueryInfo(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
3201 todo_wine ok(!ret, "HttpQueryInfo should have failed\n");
3202 todo_wine ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
3203 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
3205 index = 0;
3206 size = sizeof(buffer);
3207 ret = HttpQueryInfo(hr, HTTP_QUERY_RAW_HEADERS_CRLF, buffer, &size, &index);
3208 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3209 ok(index == 0, "expected 0 got %u\n", index);
3211 size = sizeof(buffer);
3212 ret = HttpQueryInfo(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
3213 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3214 ok(index == 0, "expected 0 got %u\n", index);
3216 size = sizeof(buffer);
3217 ret = HttpQueryInfo(hr, HTTP_QUERY_VERSION, buffer, &size, &index);
3218 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3219 ok(index == 0, "expected 0 got %u\n", index);
3221 test_status_code(hr, 200);
3223 index = 0xdeadbeef;
3224 size = sizeof(buffer);
3225 ret = HttpQueryInfo(hr, HTTP_QUERY_FORWARDED, buffer, &size, &index);
3226 ok(!ret, "HttpQueryInfo succeeded\n");
3227 ok(index == 0xdeadbeef, "expected 0xdeadbeef got %u\n", index);
3229 index = 0;
3230 size = sizeof(buffer);
3231 ret = HttpQueryInfo(hr, HTTP_QUERY_SERVER, buffer, &size, &index);
3232 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3233 ok(index == 1, "expected 1 got %u\n", index);
3235 index = 0;
3236 size = sizeof(buffer);
3237 strcpy(buffer, "Server");
3238 ret = HttpQueryInfo(hr, HTTP_QUERY_CUSTOM, buffer, &size, &index);
3239 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3240 ok(index == 1, "expected 1 got %u\n", index);
3242 index = 0;
3243 size = sizeof(buffer);
3244 ret = HttpQueryInfo(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
3245 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3246 ok(index == 1, "expected 1 got %u\n", index);
3248 size = sizeof(buffer);
3249 ret = HttpQueryInfo(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
3250 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3251 ok(index == 2, "expected 2 got %u\n", index);
3253 InternetCloseHandle(hr);
3254 InternetCloseHandle(hc);
3255 InternetCloseHandle(hi);
3258 static void test_options(int port)
3260 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi;
3261 HINTERNET ses, con, req;
3262 DWORD size, error;
3263 DWORD_PTR ctx;
3264 BOOL ret;
3266 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3267 ok(ses != NULL, "InternetOpen failed\n");
3269 SetLastError(0xdeadbeef);
3270 ret = InternetSetOption(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, 0);
3271 error = GetLastError();
3272 ok(!ret, "InternetSetOption succeeded\n");
3273 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3275 SetLastError(0xdeadbeef);
3276 ret = InternetSetOption(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, sizeof(ctx));
3277 ok(!ret, "InternetSetOption succeeded\n");
3278 error = GetLastError();
3279 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3281 SetLastError(0xdeadbeef);
3282 ret = InternetSetOption(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, 0);
3283 ok(!ret, "InternetSetOption succeeded\n");
3284 error = GetLastError();
3285 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3287 ctx = 1;
3288 ret = InternetSetOption(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
3289 ok(ret, "InternetSetOption failed %u\n", GetLastError());
3291 SetLastError(0xdeadbeef);
3292 ret = InternetQueryOption(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, NULL);
3293 error = GetLastError();
3294 ok(!ret, "InternetQueryOption succeeded\n");
3295 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3297 SetLastError(0xdeadbeef);
3298 ret = InternetQueryOption(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, NULL);
3299 error = GetLastError();
3300 ok(!ret, "InternetQueryOption succeeded\n");
3301 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3303 size = 0;
3304 SetLastError(0xdeadbeef);
3305 ret = InternetQueryOption(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, &size);
3306 error = GetLastError();
3307 ok(!ret, "InternetQueryOption succeeded\n");
3308 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
3310 size = sizeof(ctx);
3311 SetLastError(0xdeadbeef);
3312 ret = InternetQueryOption(NULL, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3313 error = GetLastError();
3314 ok(!ret, "InternetQueryOption succeeded\n");
3315 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error);
3317 ctx = 0xdeadbeef;
3318 size = sizeof(ctx);
3319 ret = InternetQueryOption(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3320 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3321 ok(ctx == 1, "expected 1 got %lu\n", ctx);
3323 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3324 ok(con != NULL, "InternetConnect failed\n");
3326 ctx = 0xdeadbeef;
3327 size = sizeof(ctx);
3328 ret = InternetQueryOption(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3329 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3330 ok(ctx == 0, "expected 0 got %lu\n", ctx);
3332 ctx = 2;
3333 ret = InternetSetOption(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
3334 ok(ret, "InternetSetOption failed %u\n", GetLastError());
3336 ctx = 0xdeadbeef;
3337 size = sizeof(ctx);
3338 ret = InternetQueryOption(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3339 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3340 ok(ctx == 2, "expected 2 got %lu\n", ctx);
3342 req = HttpOpenRequest(con, NULL, "/test1", NULL, NULL, NULL, 0, 0);
3343 ok(req != NULL, "HttpOpenRequest failed\n");
3345 ctx = 0xdeadbeef;
3346 size = sizeof(ctx);
3347 ret = InternetQueryOption(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3348 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3349 ok(ctx == 0, "expected 0 got %lu\n", ctx);
3351 ctx = 3;
3352 ret = InternetSetOption(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
3353 ok(ret, "InternetSetOption failed %u\n", GetLastError());
3355 ctx = 0xdeadbeef;
3356 size = sizeof(ctx);
3357 ret = InternetQueryOption(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3358 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3359 ok(ctx == 3, "expected 3 got %lu\n", ctx);
3361 size = sizeof(idsi);
3362 ret = InternetQueryOption(req, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO, &idsi, &size);
3363 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3365 size = 0;
3366 SetLastError(0xdeadbeef);
3367 ret = InternetQueryOption(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, NULL, &size);
3368 error = GetLastError();
3369 ok(!ret, "InternetQueryOption succeeded\n");
3370 ok(error == ERROR_INTERNET_INVALID_OPERATION, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error);
3372 /* INTERNET_OPTION_PROXY */
3373 SetLastError(0xdeadbeef);
3374 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, NULL);
3375 error = GetLastError();
3376 ok(!ret, "InternetQueryOption succeeded\n");
3377 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3379 SetLastError(0xdeadbeef);
3380 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, &ctx, NULL);
3381 error = GetLastError();
3382 ok(!ret, "InternetQueryOption succeeded\n");
3383 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3385 size = 0;
3386 SetLastError(0xdeadbeef);
3387 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, &size);
3388 error = GetLastError();
3389 ok(!ret, "InternetQueryOption succeeded\n");
3390 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
3391 ok(size >= sizeof(INTERNET_PROXY_INFOA), "expected size to be greater or equal to the struct size\n");
3393 InternetCloseHandle(req);
3394 InternetCloseHandle(con);
3395 InternetCloseHandle(ses);
3398 static void test_http_connection(void)
3400 struct server_info si;
3401 HANDLE hThread;
3402 DWORD id = 0, r;
3404 si.hEvent = CreateEvent(NULL, 0, 0, NULL);
3405 si.port = 7531;
3407 hThread = CreateThread(NULL, 0, server_thread, (LPVOID) &si, 0, &id);
3408 ok( hThread != NULL, "create thread failed\n");
3410 r = WaitForSingleObject(si.hEvent, 10000);
3411 ok (r == WAIT_OBJECT_0, "failed to start wininet test server\n");
3412 if (r != WAIT_OBJECT_0)
3413 return;
3415 test_basic_request(si.port, "GET", "/test1");
3416 test_proxy_indirect(si.port);
3417 test_proxy_direct(si.port);
3418 test_header_handling_order(si.port);
3419 test_basic_request(si.port, "POST", "/test5");
3420 test_basic_request(si.port, "RPC_IN_DATA", "/test5");
3421 test_basic_request(si.port, "RPC_OUT_DATA", "/test5");
3422 test_basic_request(si.port, "GET", "/test6");
3423 test_basic_request(si.port, "GET", "/testF");
3424 test_connection_header(si.port);
3425 test_http1_1(si.port);
3426 test_cookie_header(si.port);
3427 test_basic_authentication(si.port);
3428 test_invalid_response_headers(si.port);
3429 test_response_without_headers(si.port);
3430 test_HttpQueryInfo(si.port);
3431 test_HttpSendRequestW(si.port);
3432 test_last_error(si.port);
3433 test_options(si.port);
3434 test_no_content(si.port);
3435 test_conn_close(si.port);
3436 test_no_cache(si.port);
3437 test_cache_read_gzipped(si.port);
3438 test_premature_disconnect(si.port);
3440 /* send the basic request again to shutdown the server thread */
3441 test_basic_request(si.port, "GET", "/quit");
3443 r = WaitForSingleObject(hThread, 3000);
3444 ok( r == WAIT_OBJECT_0, "thread wait failed\n");
3445 CloseHandle(hThread);
3448 static void release_cert_info(INTERNET_CERTIFICATE_INFOA *info)
3450 LocalFree(info->lpszSubjectInfo);
3451 LocalFree(info->lpszIssuerInfo);
3452 LocalFree(info->lpszProtocolName);
3453 LocalFree(info->lpszSignatureAlgName);
3454 LocalFree(info->lpszEncryptionAlgName);
3457 static void test_cert_struct(HINTERNET req)
3459 INTERNET_CERTIFICATE_INFOA info;
3460 DWORD size;
3461 BOOL res;
3463 static const char ex_subject[] =
3464 "US\r\n"
3465 "Minnesota\r\n"
3466 "Saint Paul\r\n"
3467 "WineHQ\r\n"
3468 "test.winehq.org\r\n"
3469 "webmaster@winehq.org";
3471 static const char ex_issuer[] =
3472 "US\r\n"
3473 "Minnesota\r\n"
3474 "WineHQ\r\n"
3475 "test.winehq.org\r\n"
3476 "webmaster@winehq.org";
3478 memset(&info, 0x5, sizeof(info));
3480 size = sizeof(info);
3481 res = InternetQueryOption(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, &info, &size);
3482 ok(res, "InternetQueryOption failed: %u\n", GetLastError());
3483 ok(size == sizeof(info), "size = %u\n", size);
3485 ok(!strcmp(info.lpszSubjectInfo, ex_subject), "lpszSubjectInfo = %s\n", info.lpszSubjectInfo);
3486 ok(!strcmp(info.lpszIssuerInfo, ex_issuer), "lpszIssuerInfo = %s\n", info.lpszIssuerInfo);
3487 ok(!info.lpszSignatureAlgName, "lpszSignatureAlgName = %s\n", info.lpszSignatureAlgName);
3488 ok(!info.lpszEncryptionAlgName, "lpszEncryptionAlgName = %s\n", info.lpszEncryptionAlgName);
3489 ok(!info.lpszProtocolName, "lpszProtocolName = %s\n", info.lpszProtocolName);
3490 ok(info.dwKeySize == 128, "dwKeySize = %u\n", info.dwKeySize);
3492 release_cert_info(&info);
3495 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
3496 static void _test_security_info(unsigned line, const char *urlc, DWORD error, DWORD ex_flags)
3498 char url[INTERNET_MAX_URL_LENGTH];
3499 const CERT_CHAIN_CONTEXT *chain;
3500 DWORD flags;
3501 BOOL res;
3503 if(!pInternetGetSecurityInfoByURLA) {
3504 win_skip("pInternetGetSecurityInfoByURLA not available\n");
3505 return;
3508 strcpy(url, urlc);
3509 chain = (void*)0xdeadbeef;
3510 flags = 0xdeadbeef;
3511 res = pInternetGetSecurityInfoByURLA(url, &chain, &flags);
3512 if(error == ERROR_SUCCESS) {
3513 ok_(__FILE__,line)(res, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
3514 ok_(__FILE__,line)(chain != NULL, "chain = NULL\n");
3515 ok_(__FILE__,line)(flags == ex_flags, "flags = %x\n", flags);
3516 CertFreeCertificateChain(chain);
3517 }else {
3518 ok_(__FILE__,line)(!res && GetLastError() == error,
3519 "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res, GetLastError(), error);
3523 #define test_secflags_option(a,b) _test_secflags_option(__LINE__,a,b)
3524 static void _test_secflags_option(unsigned line, HINTERNET req, DWORD ex_flags)
3526 DWORD flags, size;
3527 BOOL res;
3529 flags = 0xdeadbeef;
3530 size = sizeof(flags);
3531 res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
3532 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
3533 ok_(__FILE__,line)(flags == ex_flags, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n", flags, ex_flags);
3535 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
3536 flags = 0xdeadbeef;
3537 size = sizeof(flags);
3538 res = InternetQueryOptionW(req, 98, &flags, &size);
3539 ok_(__FILE__,line)(res, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
3540 ok_(__FILE__,line)(flags == ex_flags, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n", flags, ex_flags);
3543 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
3544 static void _set_secflags(unsigned line, HINTERNET req, BOOL use_undoc, DWORD flags)
3546 BOOL res;
3548 res = InternetSetOptionW(req, use_undoc ? 99 : INTERNET_OPTION_SECURITY_FLAGS, &flags, sizeof(flags));
3549 ok_(__FILE__,line)(res, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
3552 static void test_security_flags(void)
3554 HINTERNET ses, conn, req;
3555 DWORD size, flags;
3556 char buf[100];
3557 BOOL res;
3559 trace("Testing security flags...\n");
3561 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
3563 ses = InternetOpen("WineTest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
3564 ok(ses != NULL, "InternetOpen failed\n");
3566 pInternetSetStatusCallbackA(ses, &callback);
3568 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3569 conn = InternetConnectA(ses, "test.winehq.org", INTERNET_DEFAULT_HTTPS_PORT,
3570 NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0xdeadbeef);
3571 ok(conn != NULL, "InternetConnect failed with error %u\n", GetLastError());
3572 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3574 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3575 req = HttpOpenRequest(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
3576 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
3577 0xdeadbeef);
3578 ok(req != NULL, "HttpOpenRequest failed\n");
3579 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3581 flags = 0xdeadbeef;
3582 size = sizeof(flags);
3583 res = InternetQueryOptionW(req, 98, &flags, &size);
3584 if(!res && GetLastError() == ERROR_INVALID_PARAMETER) {
3585 win_skip("Incomplete security flags support, skipping\n");
3587 close_async_handle(ses, hCompleteEvent, 2);
3588 CloseHandle(hCompleteEvent);
3589 return;
3592 test_secflags_option(req, 0);
3593 test_security_info("https://test.winehq.org/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
3595 set_secflags(req, TRUE, SECURITY_FLAG_IGNORE_REVOCATION);
3596 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION);
3598 set_secflags(req, TRUE, SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
3599 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
3601 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
3602 test_secflags_option(req, SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
3604 flags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_SECURE;
3605 res = InternetSetOptionW(req, 99, &flags, sizeof(flags));
3606 ok(!res && GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE, "InternetSetOption(99) failed: %u\n", GetLastError());
3608 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
3609 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
3610 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3611 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3612 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3613 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3614 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3615 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3616 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3617 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3618 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3620 res = HttpSendRequest(req, NULL, 0, NULL, 0);
3621 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
3623 WaitForSingleObject(hCompleteEvent, INFINITE);
3624 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
3626 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
3627 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
3628 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3629 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3630 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3631 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3632 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3633 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3634 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3635 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3636 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3638 test_request_flags(req, 0);
3639 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA
3640 |SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_STRENGTH_STRONG);
3642 res = InternetReadFile(req, buf, sizeof(buf), &size);
3643 ok(res, "InternetReadFile failed: %u\n", GetLastError());
3644 ok(size, "size = 0\n");
3646 /* Collect all existing persistent connections */
3647 res = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
3648 ok(res, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
3650 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3651 req = HttpOpenRequest(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
3652 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
3653 0xdeadbeef);
3654 ok(req != NULL, "HttpOpenRequest failed\n");
3655 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3657 flags = INTERNET_ERROR_MASK_COMBINED_SEC_CERT|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY;
3658 res = InternetSetOption(req, INTERNET_OPTION_ERROR_MASK, (void*)&flags, sizeof(flags));
3659 ok(res, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
3661 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3662 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3663 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
3664 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
3665 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3666 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3667 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3669 res = HttpSendRequest(req, NULL, 0, NULL, 0);
3670 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
3672 WaitForSingleObject(hCompleteEvent, INFINITE);
3673 ok(req_error == ERROR_INTERNET_SEC_CERT_REV_FAILED || broken(req_error == ERROR_INTERNET_SEC_CERT_ERRORS),
3674 "req_error = %d\n", req_error);
3676 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3677 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3678 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3679 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3680 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3681 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3682 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3684 if(req_error != ERROR_INTERNET_SEC_CERT_REV_FAILED) {
3685 win_skip("Unexpected cert errors, skipping security flags tests\n");
3687 close_async_handle(ses, hCompleteEvent, 3);
3688 CloseHandle(hCompleteEvent);
3689 return;
3692 size = sizeof(buf);
3693 res = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
3694 ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
3696 test_request_flags(req, 8);
3697 test_secflags_option(req, 0x800000);
3699 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_REVOCATION);
3700 test_secflags_option(req, 0x800000|SECURITY_FLAG_IGNORE_REVOCATION);
3702 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3703 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3704 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
3705 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
3706 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3707 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3708 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3710 res = HttpSendRequest(req, NULL, 0, NULL, 0);
3711 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
3713 WaitForSingleObject(hCompleteEvent, INFINITE);
3714 ok(req_error == ERROR_INTERNET_SEC_CERT_ERRORS, "req_error = %d\n", req_error);
3716 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3717 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3718 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3719 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3720 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3721 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3722 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3724 test_request_flags(req, INTERNET_REQFLAG_NO_HEADERS);
3725 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION|0x1800000);
3726 test_security_info("https://test.winehq.org/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
3728 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
3729 test_secflags_option(req, 0x1800000|SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_UNKNOWN_CA
3730 |SECURITY_FLAG_IGNORE_REVOCATION);
3731 test_http_version(req);
3733 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3734 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3735 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3736 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3737 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3738 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3739 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3740 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3741 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
3743 res = HttpSendRequest(req, NULL, 0, NULL, 0);
3744 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
3746 WaitForSingleObject(hCompleteEvent, INFINITE);
3747 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
3749 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3750 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3751 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3752 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3753 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3754 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3755 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3756 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3757 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
3759 test_request_flags(req, 0);
3760 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION
3761 |SECURITY_FLAG_STRENGTH_STRONG|0x1800000);
3763 test_cert_struct(req);
3764 test_security_info("https://test.winehq.org/data/some_file.html?q", 0, 0x1800000);
3766 res = InternetReadFile(req, buf, sizeof(buf), &size);
3767 ok(res, "InternetReadFile failed: %u\n", GetLastError());
3768 ok(size, "size = 0\n");
3770 close_async_handle(ses, hCompleteEvent, 3);
3772 /* Collect all existing persistent connections */
3773 res = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
3774 ok(res, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
3776 /* Make another request, without setting security flags */
3778 ses = InternetOpen("WineTest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
3779 ok(ses != NULL, "InternetOpen failed\n");
3781 pInternetSetStatusCallbackA(ses, &callback);
3783 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3784 conn = InternetConnectA(ses, "test.winehq.org", INTERNET_DEFAULT_HTTPS_PORT,
3785 NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0xdeadbeef);
3786 ok(conn != NULL, "InternetConnect failed with error %u\n", GetLastError());
3787 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3789 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3790 req = HttpOpenRequest(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
3791 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
3792 0xdeadbeef);
3793 ok(req != NULL, "HttpOpenRequest failed\n");
3794 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3796 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_STRENGTH_STRONG
3797 |SECURITY_FLAG_IGNORE_REVOCATION|0x1800000);
3798 test_http_version(req);
3800 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3801 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3802 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3803 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3804 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3805 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3806 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3807 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3809 res = HttpSendRequest(req, NULL, 0, NULL, 0);
3810 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
3812 WaitForSingleObject(hCompleteEvent, INFINITE);
3813 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
3815 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3816 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3817 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3818 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3819 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3820 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3821 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3822 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3824 test_request_flags(req, 0);
3825 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_STRENGTH_STRONG
3826 |SECURITY_FLAG_IGNORE_REVOCATION|0x1800000);
3828 res = InternetReadFile(req, buf, sizeof(buf), &size);
3829 ok(res, "InternetReadFile failed: %u\n", GetLastError());
3830 ok(size, "size = 0\n");
3832 close_async_handle(ses, hCompleteEvent, 2);
3834 CloseHandle(hCompleteEvent);
3836 test_security_info("http://test.winehq.org/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
3837 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
3838 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
3841 static void test_secure_connection(void)
3843 static const WCHAR gizmo5[] = {'G','i','z','m','o','5',0};
3844 static const WCHAR testbot[] = {'t','e','s','t','b','o','t','.','w','i','n','e','h','q','.','o','r','g',0};
3845 static const WCHAR get[] = {'G','E','T',0};
3846 static const WCHAR slash[] = {'/',0};
3847 HINTERNET ses, con, req;
3848 DWORD size, flags;
3849 INTERNET_CERTIFICATE_INFOA *certificate_structA = NULL;
3850 INTERNET_CERTIFICATE_INFOW *certificate_structW = NULL;
3851 BOOL ret;
3853 ses = InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
3854 ok(ses != NULL, "InternetOpen failed\n");
3856 con = InternetConnect(ses, "testbot.winehq.org",
3857 INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL,
3858 INTERNET_SERVICE_HTTP, 0, 0);
3859 ok(con != NULL, "InternetConnect failed\n");
3861 req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL,
3862 INTERNET_FLAG_SECURE, 0);
3863 ok(req != NULL, "HttpOpenRequest failed\n");
3865 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
3866 ok(ret, "HttpSendRequest failed: %d\n", GetLastError());
3868 size = sizeof(flags);
3869 ret = InternetQueryOption(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
3870 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
3871 ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set\n");
3873 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3874 NULL, &size);
3875 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
3876 ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %d\n", size);
3877 certificate_structA = HeapAlloc(GetProcessHeap(), 0, size);
3878 ret = InternetQueryOption(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3879 certificate_structA, &size);
3880 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
3881 if (ret)
3883 ok(certificate_structA->lpszSubjectInfo &&
3884 strlen(certificate_structA->lpszSubjectInfo) > 1,
3885 "expected a non-empty subject name\n");
3886 ok(certificate_structA->lpszIssuerInfo &&
3887 strlen(certificate_structA->lpszIssuerInfo) > 1,
3888 "expected a non-empty issuer name\n");
3889 ok(!certificate_structA->lpszSignatureAlgName,
3890 "unexpected signature algorithm name\n");
3891 ok(!certificate_structA->lpszEncryptionAlgName,
3892 "unexpected encryption algorithm name\n");
3893 ok(!certificate_structA->lpszProtocolName,
3894 "unexpected protocol name\n");
3895 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
3896 release_cert_info(certificate_structA);
3898 HeapFree(GetProcessHeap(), 0, certificate_structA);
3900 /* Querying the same option through InternetQueryOptionW still results in
3901 * ASCII strings being returned.
3903 size = 0;
3904 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3905 NULL, &size);
3906 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
3907 ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size);
3908 certificate_structW = HeapAlloc(GetProcessHeap(), 0, size);
3909 ret = InternetQueryOption(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3910 certificate_structW, &size);
3911 certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW;
3912 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
3913 if (ret)
3915 ok(certificate_structA->lpszSubjectInfo &&
3916 strlen(certificate_structA->lpszSubjectInfo) > 1,
3917 "expected a non-empty subject name\n");
3918 ok(certificate_structA->lpszIssuerInfo &&
3919 strlen(certificate_structA->lpszIssuerInfo) > 1,
3920 "expected a non-empty issuer name\n");
3921 ok(!certificate_structA->lpszSignatureAlgName,
3922 "unexpected signature algorithm name\n");
3923 ok(!certificate_structA->lpszEncryptionAlgName,
3924 "unexpected encryption algorithm name\n");
3925 ok(!certificate_structA->lpszProtocolName,
3926 "unexpected protocol name\n");
3927 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
3928 release_cert_info(certificate_structA);
3930 HeapFree(GetProcessHeap(), 0, certificate_structW);
3932 InternetCloseHandle(req);
3933 InternetCloseHandle(con);
3934 InternetCloseHandle(ses);
3936 /* Repeating the tests with the W functions has the same result: */
3937 ses = InternetOpenW(gizmo5, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
3938 ok(ses != NULL, "InternetOpen failed\n");
3940 con = InternetConnectW(ses, testbot,
3941 INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL,
3942 INTERNET_SERVICE_HTTP, 0, 0);
3943 ok(con != NULL, "InternetConnect failed\n");
3945 req = HttpOpenRequestW(con, get, slash, NULL, NULL, NULL,
3946 INTERNET_FLAG_SECURE, 0);
3947 ok(req != NULL, "HttpOpenRequest failed\n");
3949 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
3950 ok(ret, "HttpSendRequest failed: %d\n", GetLastError());
3952 size = sizeof(flags);
3953 ret = InternetQueryOption(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
3954 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
3955 ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set\n");
3957 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3958 NULL, &size);
3959 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
3960 ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %d\n", size);
3961 certificate_structA = HeapAlloc(GetProcessHeap(), 0, size);
3962 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3963 certificate_structA, &size);
3964 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
3965 if (ret)
3967 ok(certificate_structA->lpszSubjectInfo &&
3968 strlen(certificate_structA->lpszSubjectInfo) > 1,
3969 "expected a non-empty subject name\n");
3970 ok(certificate_structA->lpszIssuerInfo &&
3971 strlen(certificate_structA->lpszIssuerInfo) > 1,
3972 "expected a non-empty issuer name\n");
3973 ok(!certificate_structA->lpszSignatureAlgName,
3974 "unexpected signature algorithm name\n");
3975 ok(!certificate_structA->lpszEncryptionAlgName,
3976 "unexpected encryption algorithm name\n");
3977 ok(!certificate_structA->lpszProtocolName,
3978 "unexpected protocol name\n");
3979 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
3980 release_cert_info(certificate_structA);
3982 HeapFree(GetProcessHeap(), 0, certificate_structA);
3984 /* Again, querying the same option through InternetQueryOptionW still
3985 * results in ASCII strings being returned.
3987 size = 0;
3988 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3989 NULL, &size);
3990 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
3991 ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size);
3992 certificate_structW = HeapAlloc(GetProcessHeap(), 0, size);
3993 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3994 certificate_structW, &size);
3995 certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW;
3996 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
3997 if (ret)
3999 ok(certificate_structA->lpszSubjectInfo &&
4000 strlen(certificate_structA->lpszSubjectInfo) > 1,
4001 "expected a non-empty subject name\n");
4002 ok(certificate_structA->lpszIssuerInfo &&
4003 strlen(certificate_structA->lpszIssuerInfo) > 1,
4004 "expected a non-empty issuer name\n");
4005 ok(!certificate_structA->lpszSignatureAlgName,
4006 "unexpected signature algorithm name\n");
4007 ok(!certificate_structA->lpszEncryptionAlgName,
4008 "unexpected encryption algorithm name\n");
4009 ok(!certificate_structA->lpszProtocolName,
4010 "unexpected protocol name\n");
4011 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
4012 release_cert_info(certificate_structA);
4014 HeapFree(GetProcessHeap(), 0, certificate_structW);
4016 InternetCloseHandle(req);
4017 InternetCloseHandle(con);
4018 InternetCloseHandle(ses);
4021 static void test_user_agent_header(void)
4023 HINTERNET ses, con, req;
4024 DWORD size, err;
4025 char buffer[64];
4026 BOOL ret;
4028 ses = InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
4029 ok(ses != NULL, "InternetOpen failed\n");
4031 con = InternetConnect(ses, "test.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4032 ok(con != NULL, "InternetConnect failed\n");
4034 req = HttpOpenRequest(con, "GET", "/tests/hello.html", "HTTP/1.0", NULL, NULL, 0, 0);
4035 ok(req != NULL, "HttpOpenRequest failed\n");
4037 size = sizeof(buffer);
4038 ret = HttpQueryInfo(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4039 err = GetLastError();
4040 ok(!ret, "HttpQueryInfo succeeded\n");
4041 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
4043 ret = HttpAddRequestHeaders(req, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
4044 ok(ret, "HttpAddRequestHeaders succeeded\n");
4046 size = sizeof(buffer);
4047 ret = HttpQueryInfo(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4048 err = GetLastError();
4049 ok(ret, "HttpQueryInfo failed\n");
4050 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
4052 InternetCloseHandle(req);
4054 req = HttpOpenRequest(con, "GET", "/", "HTTP/1.0", NULL, NULL, 0, 0);
4055 ok(req != NULL, "HttpOpenRequest failed\n");
4057 size = sizeof(buffer);
4058 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4059 err = GetLastError();
4060 ok(!ret, "HttpQueryInfo succeeded\n");
4061 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
4063 ret = HttpAddRequestHeaders(req, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
4064 ok(ret, "HttpAddRequestHeaders failed\n");
4066 buffer[0] = 0;
4067 size = sizeof(buffer);
4068 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4069 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
4070 ok(!strcmp(buffer, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer);
4072 InternetCloseHandle(req);
4073 InternetCloseHandle(con);
4074 InternetCloseHandle(ses);
4077 static void test_bogus_accept_types_array(void)
4079 HINTERNET ses, con, req;
4080 static const char *types[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL };
4081 DWORD size, error;
4082 char buffer[32];
4083 BOOL ret;
4085 ses = InternetOpen("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT, "", "", 0);
4086 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4087 req = HttpOpenRequest(con, "POST", "/post/post_action.php", "HTTP/1.0", "", types, INTERNET_FLAG_FORMS_SUBMIT, 0);
4089 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
4091 buffer[0] = 0;
4092 size = sizeof(buffer);
4093 SetLastError(0xdeadbeef);
4094 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4095 error = GetLastError();
4096 ok(!ret || broken(ret), "HttpQueryInfo succeeded\n");
4097 if (!ret) ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error);
4098 ok(broken(!strcmp(buffer, ", */*, %p, , , */*")) /* IE6 */ ||
4099 broken(!strcmp(buffer, "*/*, %p, */*")) /* IE7/8 */ ||
4100 !strcmp(buffer, ""), "got '%s' expected ''\n", buffer);
4102 InternetCloseHandle(req);
4103 InternetCloseHandle(con);
4104 InternetCloseHandle(ses);
4107 struct context
4109 HANDLE event;
4110 HINTERNET req;
4113 static void WINAPI cb(HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID info, DWORD size)
4115 INTERNET_ASYNC_RESULT *result = info;
4116 struct context *ctx = (struct context *)context;
4118 trace("%p 0x%08lx %u %p 0x%08x\n", handle, context, status, info, size);
4120 switch(status) {
4121 case INTERNET_STATUS_REQUEST_COMPLETE:
4122 trace("request handle: 0x%08lx\n", result->dwResult);
4123 ctx->req = (HINTERNET)result->dwResult;
4124 SetEvent(ctx->event);
4125 break;
4126 case INTERNET_STATUS_HANDLE_CLOSING: {
4127 DWORD type = INTERNET_HANDLE_TYPE_CONNECT_HTTP, size = sizeof(type);
4129 if (InternetQueryOption(handle, INTERNET_OPTION_HANDLE_TYPE, &type, &size))
4130 ok(type != INTERNET_HANDLE_TYPE_CONNECT_HTTP, "unexpected callback\n");
4131 SetEvent(ctx->event);
4132 break;
4134 case INTERNET_STATUS_NAME_RESOLVED:
4135 case INTERNET_STATUS_CONNECTING_TO_SERVER:
4136 case INTERNET_STATUS_CONNECTED_TO_SERVER: {
4137 char *str = info;
4138 ok(str[0] && str[1], "Got string: %s\n", str);
4139 ok(size == strlen(str)+1, "unexpected size %u\n", size);
4144 static void test_open_url_async(void)
4146 BOOL ret;
4147 HINTERNET ses, req;
4148 DWORD size, error;
4149 struct context ctx;
4150 ULONG type;
4152 /* Collect all existing persistent connections */
4153 ret = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
4154 ok(ret, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4157 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
4158 * other versions never do. They also hang of following tests. We disable it for everything older
4159 * than IE7.
4161 if(!pInternetGetSecurityInfoByURLA) {
4162 win_skip("Skipping async open on too old wininet version.\n");
4163 return;
4166 ctx.req = NULL;
4167 ctx.event = CreateEvent(NULL, TRUE, FALSE, "Z:_home_hans_jaman-installer.exe_ev1");
4169 ses = InternetOpen("AdvancedInstaller", 0, NULL, NULL, INTERNET_FLAG_ASYNC);
4170 ok(ses != NULL, "InternetOpen failed\n");
4172 SetLastError(0xdeadbeef);
4173 ret = InternetSetOptionA(NULL, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR));
4174 error = GetLastError();
4175 ok(!ret, "InternetSetOptionA succeeded\n");
4176 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error);
4178 ret = InternetSetOptionA(ses, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR));
4179 error = GetLastError();
4180 ok(!ret, "InternetSetOptionA failed\n");
4181 ok(error == ERROR_INTERNET_OPTION_NOT_SETTABLE, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error);
4183 pInternetSetStatusCallbackW(ses, cb);
4184 ResetEvent(ctx.event);
4186 req = InternetOpenUrl(ses, "http://test.winehq.org", NULL, 0, 0, (DWORD_PTR)&ctx);
4187 ok(!req && GetLastError() == ERROR_IO_PENDING, "InternetOpenUrl failed\n");
4189 WaitForSingleObject(ctx.event, INFINITE);
4191 type = 0;
4192 size = sizeof(type);
4193 ret = InternetQueryOption(ctx.req, INTERNET_OPTION_HANDLE_TYPE, &type, &size);
4194 ok(ret, "InternetQueryOption failed: %u\n", GetLastError());
4195 ok(type == INTERNET_HANDLE_TYPE_HTTP_REQUEST,
4196 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type);
4198 size = 0;
4199 ret = HttpQueryInfo(ctx.req, HTTP_QUERY_RAW_HEADERS_CRLF, NULL, &size, NULL);
4200 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "HttpQueryInfo failed\n");
4201 ok(size > 0, "expected size > 0\n");
4203 ResetEvent(ctx.event);
4204 InternetCloseHandle(ctx.req);
4205 WaitForSingleObject(ctx.event, INFINITE);
4207 InternetCloseHandle(ses);
4208 CloseHandle(ctx.event);
4211 enum api
4213 internet_connect = 1,
4214 http_open_request,
4215 http_send_request_ex,
4216 internet_writefile,
4217 http_end_request,
4218 internet_close_handle
4221 struct notification
4223 enum api function; /* api responsible for notification */
4224 unsigned int status; /* status received */
4225 int async; /* delivered from another thread? */
4226 int todo;
4227 int optional;
4230 struct info
4232 enum api function;
4233 const struct notification *test;
4234 unsigned int count;
4235 unsigned int index;
4236 HANDLE wait;
4237 DWORD thread;
4238 unsigned int line;
4239 DWORD expect_result;
4240 BOOL is_aborted;
4243 static CRITICAL_SECTION notification_cs;
4245 static void CALLBACK check_notification( HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID buffer, DWORD buflen )
4247 BOOL status_ok, function_ok;
4248 struct info *info = (struct info *)context;
4249 unsigned int i;
4251 EnterCriticalSection( &notification_cs );
4253 if(info->is_aborted) {
4254 LeaveCriticalSection(&notification_cs);
4255 return;
4258 if (status == INTERNET_STATUS_HANDLE_CREATED)
4260 DWORD size = sizeof(struct info *);
4261 HttpQueryInfoA( handle, INTERNET_OPTION_CONTEXT_VALUE, &info, &size, 0 );
4262 }else if(status == INTERNET_STATUS_REQUEST_COMPLETE) {
4263 INTERNET_ASYNC_RESULT *ar = (INTERNET_ASYNC_RESULT*)buffer;
4265 ok(buflen == sizeof(*ar), "unexpected buflen = %d\n", buflen);
4266 if(info->expect_result == ERROR_SUCCESS) {
4267 ok(ar->dwResult == 1, "ar->dwResult = %ld, expected 1\n", ar->dwResult);
4268 }else {
4269 ok(!ar->dwResult, "ar->dwResult = %ld, expected 1\n", ar->dwResult);
4270 ok(ar->dwError == info->expect_result, "ar->dwError = %d, expected %d\n", ar->dwError, info->expect_result);
4274 i = info->index;
4275 if (i >= info->count)
4277 LeaveCriticalSection( &notification_cs );
4278 return;
4281 while (info->test[i].status != status &&
4282 (info->test[i].optional || info->test[i].todo) &&
4283 i < info->count - 1 &&
4284 info->test[i].function == info->test[i + 1].function)
4286 i++;
4289 status_ok = (info->test[i].status == status);
4290 function_ok = (info->test[i].function == info->function);
4292 if (!info->test[i].todo)
4294 ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status );
4295 ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
4297 if (info->test[i].async)
4298 ok(info->thread != GetCurrentThreadId(), "%u: expected thread %u got %u\n",
4299 info->line, info->thread, GetCurrentThreadId());
4301 else
4303 todo_wine ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status );
4304 if (status_ok)
4305 todo_wine ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
4307 if (i == info->count - 1 || info->test[i].function != info->test[i + 1].function) SetEvent( info->wait );
4308 info->index = i+1;
4310 LeaveCriticalSection( &notification_cs );
4313 static void setup_test( struct info *info, enum api function, unsigned int line, DWORD expect_result )
4315 info->function = function;
4316 info->line = line;
4317 info->expect_result = expect_result;
4320 struct notification_data
4322 const struct notification *test;
4323 const unsigned int count;
4324 const char *method;
4325 const char *host;
4326 const char *path;
4327 const char *data;
4328 BOOL expect_conn_failure;
4331 static const struct notification async_send_request_ex_test[] =
4333 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, 0 },
4334 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, 0 },
4335 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
4336 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, 1, 0, 1 },
4337 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, 1, 0, 1 },
4338 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, 1, 0, 1 },
4339 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, 1 },
4340 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, 1 },
4341 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, 1 },
4342 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, 1 },
4343 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
4344 { internet_writefile, INTERNET_STATUS_SENDING_REQUEST, 0 },
4345 { internet_writefile, INTERNET_STATUS_REQUEST_SENT, 0 },
4346 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, 1 },
4347 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, 1 },
4348 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
4349 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, 0, 0, 1 },
4350 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, 0, 0, 1 },
4351 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, },
4352 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, }
4355 static const struct notification async_send_request_ex_test2[] =
4357 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, 0 },
4358 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, 0 },
4359 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
4360 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, 1, 0, 1 },
4361 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, 1, 0, 1 },
4362 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, 1, 0, 1 },
4363 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, 1, 1 },
4364 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, 1, 1 },
4365 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, 1 },
4366 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, 1 },
4367 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
4368 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, 1 },
4369 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, 1 },
4370 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
4371 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, 0, 0, 1 },
4372 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, 0, 0, 1 },
4373 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, },
4374 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, }
4377 static const struct notification async_send_request_ex_resolve_failure_test[] =
4379 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, 0 },
4380 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, 0 },
4381 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
4382 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, 1 },
4383 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
4384 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
4385 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
4386 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, 0, 0, 1 },
4387 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, 0, 0, 1 },
4388 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, },
4389 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, }
4392 static const struct notification_data notification_data[] = {
4394 async_send_request_ex_test,
4395 sizeof(async_send_request_ex_test)/sizeof(async_send_request_ex_test[0]),
4396 "POST",
4397 "test.winehq.org",
4398 "tests/posttest.php",
4399 "Public ID=codeweavers"
4402 async_send_request_ex_test2,
4403 sizeof(async_send_request_ex_test)/sizeof(async_send_request_ex_test[0]),
4404 "POST",
4405 "test.winehq.org",
4406 "tests/posttest.php"
4409 async_send_request_ex_resolve_failure_test,
4410 sizeof(async_send_request_ex_resolve_failure_test)/sizeof(async_send_request_ex_resolve_failure_test[0]),
4411 "GET",
4412 "brokenhost",
4413 "index.html",
4414 NULL,
4415 TRUE
4419 static void test_async_HttpSendRequestEx(const struct notification_data *nd)
4421 BOOL ret;
4422 HINTERNET ses, req, con;
4423 struct info info;
4424 DWORD size, written, error;
4425 INTERNET_BUFFERSA b;
4426 static const char *accept[2] = {"*/*", NULL};
4427 char buffer[32];
4429 trace("Async HttpSendRequestEx test (%s %s)\n", nd->method, nd->host);
4431 InitializeCriticalSection( &notification_cs );
4433 info.test = nd->test;
4434 info.count = nd->count;
4435 info.index = 0;
4436 info.wait = CreateEvent( NULL, FALSE, FALSE, NULL );
4437 info.thread = GetCurrentThreadId();
4438 info.is_aborted = FALSE;
4440 ses = InternetOpen( "winetest", 0, NULL, NULL, INTERNET_FLAG_ASYNC );
4441 ok( ses != NULL, "InternetOpen failed\n" );
4443 pInternetSetStatusCallbackA( ses, check_notification );
4445 setup_test( &info, internet_connect, __LINE__, ERROR_SUCCESS );
4446 con = InternetConnect( ses, nd->host, 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, (DWORD_PTR)&info );
4447 ok( con != NULL, "InternetConnect failed %u\n", GetLastError() );
4449 WaitForSingleObject( info.wait, 10000 );
4451 setup_test( &info, http_open_request, __LINE__, ERROR_SUCCESS );
4452 req = HttpOpenRequest( con, nd->method, nd->path, NULL, NULL, accept, 0, (DWORD_PTR)&info );
4453 ok( req != NULL, "HttpOpenRequest failed %u\n", GetLastError() );
4455 WaitForSingleObject( info.wait, 10000 );
4457 if(nd->data) {
4458 memset( &b, 0, sizeof(INTERNET_BUFFERSA) );
4459 b.dwStructSize = sizeof(INTERNET_BUFFERSA);
4460 b.lpcszHeader = "Content-Type: application/x-www-form-urlencoded";
4461 b.dwHeadersLength = strlen( b.lpcszHeader );
4462 b.dwBufferTotal = nd->data ? strlen( nd->data ) : 0;
4465 setup_test( &info, http_send_request_ex, __LINE__,
4466 nd->expect_conn_failure ? ERROR_INTERNET_NAME_NOT_RESOLVED : ERROR_SUCCESS );
4467 ret = HttpSendRequestExA( req, nd->data ? &b : NULL, NULL, 0x28, 0 );
4468 ok( !ret && GetLastError() == ERROR_IO_PENDING, "HttpSendRequestExA failed %d %u\n", ret, GetLastError() );
4470 error = WaitForSingleObject( info.wait, 10000 );
4471 if(error != WAIT_OBJECT_0) {
4472 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error);
4473 info.is_aborted = TRUE;
4474 goto abort;
4477 size = sizeof(buffer);
4478 SetLastError( 0xdeadbeef );
4479 ret = HttpQueryInfoA( req, HTTP_QUERY_CONTENT_ENCODING, buffer, &size, 0 );
4480 error = GetLastError();
4481 ok( !ret, "HttpQueryInfoA failed %u\n", GetLastError() );
4482 if(nd->expect_conn_failure) {
4483 ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error );
4484 }else {
4485 todo_wine
4486 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_STATE,
4487 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error );
4490 if (nd->data)
4492 written = 0;
4493 size = strlen( nd->data );
4494 setup_test( &info, internet_writefile, __LINE__, ERROR_SUCCESS );
4495 ret = InternetWriteFile( req, nd->data, size, &written );
4496 ok( ret, "InternetWriteFile failed %u\n", GetLastError() );
4497 ok( written == size, "expected %u got %u\n", written, size );
4499 WaitForSingleObject( info.wait, 10000 );
4501 SetLastError( 0xdeadbeef );
4502 ret = HttpEndRequestA( req, (void *)nd->data, 0x28, 0 );
4503 error = GetLastError();
4504 ok( !ret, "HttpEndRequestA succeeded\n" );
4505 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error );
4508 SetLastError( 0xdeadbeef );
4509 setup_test( &info, http_end_request, __LINE__,
4510 nd->expect_conn_failure ? ERROR_INTERNET_OPERATION_CANCELLED : ERROR_SUCCESS);
4511 ret = HttpEndRequestA( req, NULL, 0x28, 0 );
4512 error = GetLastError();
4513 ok( !ret, "HttpEndRequestA succeeded\n" );
4514 ok( error == ERROR_IO_PENDING, "expected ERROR_IO_PENDING got %u\n", error );
4516 WaitForSingleObject( info.wait, 10000 );
4518 setup_test( &info, internet_close_handle, __LINE__, ERROR_SUCCESS );
4519 abort:
4520 InternetCloseHandle( req );
4521 InternetCloseHandle( con );
4522 InternetCloseHandle( ses );
4524 WaitForSingleObject( info.wait, 10000 );
4525 Sleep(100);
4526 CloseHandle( info.wait );
4529 static HINTERNET closetest_session, closetest_req, closetest_conn;
4530 static BOOL closetest_closed;
4532 static void WINAPI closetest_callback(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus,
4533 LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
4535 DWORD len, type;
4536 BOOL res;
4538 trace("closetest_callback %p: %d\n", hInternet, dwInternetStatus);
4540 ok(hInternet == closetest_session || hInternet == closetest_conn || hInternet == closetest_req,
4541 "Unexpected hInternet %p\n", hInternet);
4542 if(!closetest_closed)
4543 return;
4545 len = sizeof(type);
4546 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_HANDLE_TYPE, &type, &len);
4547 ok(!res && GetLastError() == ERROR_INVALID_HANDLE,
4548 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
4549 closetest_req, res, GetLastError());
4552 static void test_InternetCloseHandle(void)
4554 DWORD len, flags;
4555 BOOL res;
4557 closetest_session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
4558 ok(closetest_session != NULL,"InternetOpen failed with error %u\n", GetLastError());
4560 pInternetSetStatusCallbackA(closetest_session, closetest_callback);
4562 closetest_conn = InternetConnectA(closetest_session, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER,
4563 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
4564 ok(closetest_conn != NULL,"InternetConnect failed with error %u\n", GetLastError());
4566 closetest_req = HttpOpenRequestA(closetest_conn, "GET", "winegecko.php", NULL, NULL, NULL,
4567 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
4569 res = HttpSendRequestA(closetest_req, NULL, -1, NULL, 0);
4570 ok(!res && (GetLastError() == ERROR_IO_PENDING),
4571 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
4573 test_request_flags(closetest_req, INTERNET_REQFLAG_NO_HEADERS);
4575 res = InternetCloseHandle(closetest_session);
4576 ok(res, "InternetCloseHandle failed: %u\n", GetLastError());
4577 closetest_closed = TRUE;
4578 trace("Closed session handle\n");
4580 res = InternetCloseHandle(closetest_conn);
4581 ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(conn) failed: %x %u\n",
4582 res, GetLastError());
4584 res = InternetCloseHandle(closetest_req);
4585 ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(req) failed: %x %u\n",
4586 res, GetLastError());
4588 len = sizeof(flags);
4589 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &len);
4590 ok(!res && GetLastError() == ERROR_INVALID_HANDLE,
4591 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
4592 closetest_req, res, GetLastError());
4595 static void test_connection_failure(void)
4597 HINTERNET session, connect, request;
4598 DWORD error;
4599 BOOL ret;
4601 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
4602 ok(session != NULL, "failed to get session handle\n");
4604 connect = InternetConnectA(session, "localhost", 1, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4605 ok(connect != NULL, "failed to get connection handle\n");
4607 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, 0, 0);
4608 ok(request != NULL, "failed to get request handle\n");
4610 SetLastError(0xdeadbeef);
4611 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
4612 error = GetLastError();
4613 ok(!ret, "unexpected success\n");
4614 ok(error == ERROR_INTERNET_CANNOT_CONNECT, "wrong error %u\n", error);
4616 InternetCloseHandle(request);
4617 InternetCloseHandle(connect);
4618 InternetCloseHandle(session);
4621 static void test_default_service_port(void)
4623 HINTERNET session, connect, request;
4624 DWORD error;
4625 BOOL ret;
4627 session = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
4628 ok(session != NULL, "InternetOpen failed\n");
4630 connect = InternetConnect(session, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL,
4631 INTERNET_SERVICE_HTTP, 0, 0);
4632 ok(connect != NULL, "InternetConnect failed\n");
4634 request = HttpOpenRequest(connect, NULL, "/", NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0);
4635 ok(request != NULL, "HttpOpenRequest failed\n");
4637 SetLastError(0xdeadbeef);
4638 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
4639 error = GetLastError();
4640 ok(!ret, "HttpSendRequest succeeded\n");
4641 ok(error == ERROR_INTERNET_SECURITY_CHANNEL_ERROR || error == ERROR_INTERNET_CANNOT_CONNECT,
4642 "got %u\n", error);
4644 InternetCloseHandle(request);
4645 InternetCloseHandle(connect);
4646 InternetCloseHandle(session);
4649 static void init_status_tests(void)
4651 memset(expect, 0, sizeof(expect));
4652 memset(optional, 0, sizeof(optional));
4653 memset(wine_allow, 0, sizeof(wine_allow));
4654 memset(notified, 0, sizeof(notified));
4655 memset(status_string, 0, sizeof(status_string));
4657 #define STATUS_STRING(status) status_string[status] = #status
4658 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME);
4659 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED);
4660 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER);
4661 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER);
4662 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST);
4663 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT);
4664 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE);
4665 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED);
4666 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED);
4667 STATUS_STRING(INTERNET_STATUS_PREFETCH);
4668 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION);
4669 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED);
4670 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED);
4671 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING);
4672 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY);
4673 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE);
4674 STATUS_STRING(INTERNET_STATUS_REDIRECT);
4675 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE);
4676 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED);
4677 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE);
4678 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT);
4679 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED);
4680 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED);
4681 STATUS_STRING(INTERNET_STATUS_P3P_HEADER);
4682 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF);
4683 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY);
4684 #undef STATUS_STRING
4687 START_TEST(http)
4689 HMODULE hdll;
4690 hdll = GetModuleHandleA("wininet.dll");
4692 if(!GetProcAddress(hdll, "InternetGetCookieExW")) {
4693 win_skip("Too old IE (older than 6.0)\n");
4694 return;
4697 pInternetSetStatusCallbackA = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackA");
4698 pInternetSetStatusCallbackW = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackW");
4699 pInternetGetSecurityInfoByURLA = (void*)GetProcAddress(hdll, "InternetGetSecurityInfoByURLA");
4701 init_status_tests();
4702 test_InternetCloseHandle();
4703 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[0]);
4704 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[1]);
4705 InternetReadFile_test(0, &test_data[1]);
4706 first_connection_to_test_url = TRUE;
4707 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[2]);
4708 test_security_flags();
4709 InternetReadFile_test(0, &test_data[2]);
4710 InternetReadFileExA_test(INTERNET_FLAG_ASYNC);
4711 test_open_url_async();
4712 test_async_HttpSendRequestEx(&notification_data[0]);
4713 test_async_HttpSendRequestEx(&notification_data[1]);
4714 test_async_HttpSendRequestEx(&notification_data[2]);
4715 InternetOpenRequest_test();
4716 test_http_cache();
4717 InternetOpenUrlA_test();
4718 HttpHeaders_test();
4719 test_http_connection();
4720 test_secure_connection();
4721 test_user_agent_header();
4722 test_bogus_accept_types_array();
4723 InternetReadFile_chunked_test();
4724 HttpSendRequestEx_test();
4725 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[3]);
4726 test_connection_failure();
4727 test_default_service_port();