wininet: Reading past end-of-file in chunked mode returns success.
[wine/multimedia.git] / dlls / wininet / tests / http.c
blobffb5fdfd559972b10e8874c7f07ef63fc7df336f
1 /*
2 * Wininet - HTTP tests
4 * Copyright 2002 Aric Stewart
5 * Copyright 2004 Mike McCormack
6 * Copyright 2005 Hans Leidekker
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <stdarg.h>
24 #include <stdio.h>
25 #include <stdlib.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "wininet.h"
30 #include "winineti.h"
31 #include "winsock2.h"
33 #include "wine/test.h"
35 #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, FALSE)
192 #define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)
193 static void _test_status_code(unsigned line, HINTERNET req, DWORD excode, BOOL is_todo)
195 DWORD code, size, index;
196 char exbuf[10], bufa[10];
197 WCHAR bufw[10];
198 BOOL res;
200 code = 0xdeadbeef;
201 size = sizeof(code);
202 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, NULL);
203 ok_(__FILE__,line)(res, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
204 if (is_todo)
205 todo_wine ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
206 else
207 ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
208 ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
210 code = 0xdeadbeef;
211 index = 0;
212 size = sizeof(code);
213 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index);
214 ok_(__FILE__,line)(res, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
215 if (is_todo)
216 todo_wine ok_(__FILE__,line)(code == excode, "code = %d, expected %d\n", code, excode);
217 else
218 ok_(__FILE__,line)(!index, "index = %d, expected 0\n", code);
219 ok_(__FILE__,line)(size == sizeof(code), "size = %u\n", size);
221 sprintf(exbuf, "%u", excode);
223 size = sizeof(bufa);
224 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, bufa, &size, NULL);
225 ok_(__FILE__,line)(res, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
226 if (is_todo)
227 todo_wine ok_(__FILE__,line)(!strcmp(bufa, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
228 else
229 ok_(__FILE__,line)(!strcmp(bufa, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
230 ok_(__FILE__,line)(size == strlen(exbuf), "unexpected size %d for \"%s\"\n", size, exbuf);
232 size = 0;
233 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE, NULL, &size, NULL);
234 ok_(__FILE__,line)(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
235 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
236 ok_(__FILE__,line)(size == strlen(exbuf)+1, "unexpected size %d for \"%s\"\n", size, exbuf);
238 size = sizeof(bufw);
239 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL);
240 ok_(__FILE__,line)(res, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
241 if (is_todo)
242 todo_wine ok_(__FILE__,line)(!strcmp_wa(bufw, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
243 else
244 ok_(__FILE__,line)(!strcmp_wa(bufw, exbuf), "unexpected status code %s, expected %s\n", bufa, exbuf);
245 ok_(__FILE__,line)(size == strlen(exbuf)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
247 size = 0;
248 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, bufw, &size, NULL);
249 ok_(__FILE__,line)(!res && GetLastError() == ERROR_INSUFFICIENT_BUFFER,
250 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
251 ok_(__FILE__,line)(size == (strlen(exbuf)+1)*sizeof(WCHAR), "unexpected size %d for \"%s\"\n", size, exbuf);
253 if(0) {
254 size = sizeof(bufw);
255 res = HttpQueryInfoW(req, HTTP_QUERY_STATUS_CODE, NULL, &size, NULL);
256 ok(!res && GetLastError() == ERROR_INVALID_PARAMETER, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
257 ok(size == sizeof(bufw), "unexpected size %d\n", size);
260 code = 0xdeadbeef;
261 index = 1;
262 size = sizeof(code);
263 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &code, &size, &index);
264 ok_(__FILE__,line)(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
265 "[7] HttpQueryInfoA failed: %x(%d)\n", res, GetLastError());
267 code = 0xdeadbeef;
268 size = sizeof(code);
269 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_REQUEST_HEADERS, &code, &size, NULL);
270 ok_(__FILE__,line)(!res && GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST,
271 "[8] HttpQueryInfoA failed: %x(%d)\n", res, GetLastError());
274 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
275 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
276 static void _test_request_flags(unsigned line, HINTERNET req, DWORD exflags, BOOL is_todo)
278 DWORD flags, size;
279 BOOL res;
281 flags = 0xdeadbeef;
282 size = sizeof(flags);
283 res = InternetQueryOptionW(req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &size);
284 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
286 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
287 flags &= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED;
288 if(!is_todo)
289 ok_(__FILE__,line)(flags == exflags, "flags = %x, expected %x\n", flags, exflags);
290 else
291 todo_wine ok_(__FILE__,line)(flags == exflags, "flags = %x, expected %x\n", flags, exflags);
294 #define test_http_version(a) _test_http_version(__LINE__,a)
295 static void _test_http_version(unsigned line, HINTERNET req)
297 HTTP_VERSION_INFO v = {0xdeadbeef, 0xdeadbeef};
298 DWORD size;
299 BOOL res;
301 size = sizeof(v);
302 res = InternetQueryOptionW(req, INTERNET_OPTION_HTTP_VERSION, &v, &size);
303 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
304 ok_(__FILE__,line)(v.dwMajorVersion == 1, "dwMajorVersion = %d\n", v.dwMajorVersion);
305 ok_(__FILE__,line)(v.dwMinorVersion == 1, "dwMinorVersion = %d\n", v.dwMinorVersion);
308 static int close_handle_cnt;
310 static VOID WINAPI callback(
311 HINTERNET hInternet,
312 DWORD_PTR dwContext,
313 DWORD dwInternetStatus,
314 LPVOID lpvStatusInformation,
315 DWORD dwStatusInformationLength
318 CHECK_EXPECT(dwInternetStatus);
319 switch (dwInternetStatus)
321 case INTERNET_STATUS_RESOLVING_NAME:
322 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
323 GetCurrentThreadId(), hInternet, dwContext,
324 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
325 *(LPSTR)lpvStatusInformation = '\0';
326 break;
327 case INTERNET_STATUS_NAME_RESOLVED:
328 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
329 GetCurrentThreadId(), hInternet, dwContext,
330 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
331 *(LPSTR)lpvStatusInformation = '\0';
332 break;
333 case INTERNET_STATUS_CONNECTING_TO_SERVER:
334 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
335 GetCurrentThreadId(), hInternet, dwContext,
336 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
337 ok(dwStatusInformationLength == strlen(lpvStatusInformation)+1, "unexpected size %u\n",
338 dwStatusInformationLength);
339 *(LPSTR)lpvStatusInformation = '\0';
340 break;
341 case INTERNET_STATUS_CONNECTED_TO_SERVER:
342 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
343 GetCurrentThreadId(), hInternet, dwContext,
344 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
345 ok(dwStatusInformationLength == strlen(lpvStatusInformation)+1, "unexpected size %u\n",
346 dwStatusInformationLength);
347 *(LPSTR)lpvStatusInformation = '\0';
348 break;
349 case INTERNET_STATUS_SENDING_REQUEST:
350 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
351 GetCurrentThreadId(), hInternet, dwContext,
352 lpvStatusInformation,dwStatusInformationLength);
353 break;
354 case INTERNET_STATUS_REQUEST_SENT:
355 ok(dwStatusInformationLength == sizeof(DWORD),
356 "info length should be sizeof(DWORD) instead of %d\n",
357 dwStatusInformationLength);
358 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
359 GetCurrentThreadId(), hInternet, dwContext,
360 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
361 break;
362 case INTERNET_STATUS_RECEIVING_RESPONSE:
363 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
364 GetCurrentThreadId(), hInternet, dwContext,
365 lpvStatusInformation,dwStatusInformationLength);
366 break;
367 case INTERNET_STATUS_RESPONSE_RECEIVED:
368 ok(dwStatusInformationLength == sizeof(DWORD),
369 "info length should be sizeof(DWORD) instead of %d\n",
370 dwStatusInformationLength);
371 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
372 GetCurrentThreadId(), hInternet, dwContext,
373 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
374 break;
375 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
376 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
377 GetCurrentThreadId(), hInternet,dwContext,
378 lpvStatusInformation,dwStatusInformationLength);
379 break;
380 case INTERNET_STATUS_PREFETCH:
381 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
382 GetCurrentThreadId(), hInternet, dwContext,
383 lpvStatusInformation,dwStatusInformationLength);
384 break;
385 case INTERNET_STATUS_CLOSING_CONNECTION:
386 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
387 GetCurrentThreadId(), hInternet, dwContext,
388 lpvStatusInformation,dwStatusInformationLength);
389 break;
390 case INTERNET_STATUS_CONNECTION_CLOSED:
391 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
392 GetCurrentThreadId(), hInternet, dwContext,
393 lpvStatusInformation,dwStatusInformationLength);
394 break;
395 case INTERNET_STATUS_HANDLE_CREATED:
396 ok(dwStatusInformationLength == sizeof(HINTERNET),
397 "info length should be sizeof(HINTERNET) instead of %d\n",
398 dwStatusInformationLength);
399 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
400 GetCurrentThreadId(), hInternet, dwContext,
401 *(HINTERNET *)lpvStatusInformation,dwStatusInformationLength);
402 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
403 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
404 break;
405 case INTERNET_STATUS_HANDLE_CLOSING:
406 ok(dwStatusInformationLength == sizeof(HINTERNET),
407 "info length should be sizeof(HINTERNET) instead of %d\n",
408 dwStatusInformationLength);
409 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
410 GetCurrentThreadId(), hInternet, dwContext,
411 *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength);
412 if(!InterlockedDecrement(&close_handle_cnt))
413 SetEvent(hCompleteEvent);
414 break;
415 case INTERNET_STATUS_REQUEST_COMPLETE:
417 INTERNET_ASYNC_RESULT *iar = (INTERNET_ASYNC_RESULT *)lpvStatusInformation;
418 ok(dwStatusInformationLength == sizeof(INTERNET_ASYNC_RESULT),
419 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
420 dwStatusInformationLength);
421 ok(iar->dwResult == 1 || iar->dwResult == 0, "iar->dwResult = %ld\n", iar->dwResult);
422 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
423 GetCurrentThreadId(), hInternet, dwContext,
424 iar->dwResult,iar->dwError,dwStatusInformationLength);
425 req_error = iar->dwError;
426 if(!close_handle_cnt)
427 SetEvent(hCompleteEvent);
428 break;
430 case INTERNET_STATUS_REDIRECT:
431 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
432 GetCurrentThreadId(), hInternet, dwContext,
433 (LPCSTR)lpvStatusInformation, dwStatusInformationLength);
434 *(LPSTR)lpvStatusInformation = '\0';
435 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
436 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY);
437 break;
438 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
439 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
440 GetCurrentThreadId(), hInternet, dwContext,
441 lpvStatusInformation, dwStatusInformationLength);
442 break;
443 default:
444 trace("%04x:Callback %p 0x%lx %d %p %d\n",
445 GetCurrentThreadId(), hInternet, dwContext, dwInternetStatus,
446 lpvStatusInformation, dwStatusInformationLength);
450 static void close_async_handle(HINTERNET handle, HANDLE complete_event, int handle_cnt)
452 BOOL res;
454 close_handle_cnt = handle_cnt;
456 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
457 res = InternetCloseHandle(handle);
458 ok(res, "InternetCloseHandle failed: %u\n", GetLastError());
459 WaitForSingleObject(hCompleteEvent, INFINITE);
460 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING, handle_cnt);
463 static void InternetReadFile_test(int flags, const test_data_t *test)
465 char *post_data = NULL;
466 BOOL res, on_async = TRUE;
467 CHAR buffer[4000];
468 DWORD length, exlen = 0, post_len = 0;
469 const char *types[2] = { "*", NULL };
470 HINTERNET hi, hic = 0, hor = 0;
472 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
474 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags,test->url);
476 trace("InternetOpenA <--\n");
477 hi = InternetOpenA((test->flags & TESTF_COMPRESSED) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
478 INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
479 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
480 trace("InternetOpenA -->\n");
482 if (hi == 0x0) goto abort;
484 pInternetSetStatusCallbackA(hi,&callback);
486 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
488 trace("InternetConnectA <--\n");
489 hic=InternetConnectA(hi, test->host, INTERNET_INVALID_PORT_NUMBER,
490 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
491 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
492 trace("InternetConnectA -->\n");
494 if (hic == 0x0) goto abort;
496 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
497 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
499 trace("HttpOpenRequestA <--\n");
500 hor = HttpOpenRequestA(hic, test->post_data ? "POST" : "GET", test->path, NULL, NULL, types,
501 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
502 0xdeadbead);
503 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
505 * If the internet name can't be resolved we are probably behind
506 * a firewall or in some other way not directly connected to the
507 * Internet. Not enough reason to fail the test. Just ignore and
508 * abort.
510 } else {
511 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
513 trace("HttpOpenRequestA -->\n");
515 if (hor == 0x0) goto abort;
517 test_request_flags(hor, INTERNET_REQFLAG_NO_HEADERS);
519 length = sizeof(buffer);
520 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
521 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
522 ok(!strcmp(buffer, test->url), "Wrong URL %s, expected %s\n", buffer, test->url);
524 length = sizeof(buffer);
525 res = HttpQueryInfoA(hor, HTTP_QUERY_RAW_HEADERS, buffer, &length, 0x0);
526 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
527 ok(length == 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length);
528 ok(!strcmp(buffer, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer);
530 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
531 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
532 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
533 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT,2);
534 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED,2);
535 if (first_connection_to_test_url)
537 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
538 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
540 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
541 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
542 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, (test->flags & TESTF_REDIRECT) ? 2 : 1);
543 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, (test->flags & TESTF_REDIRECT) ? 2 : 1);
544 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, (test->flags & TESTF_REDIRECT) ? 2 : 1);
545 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, (test->flags & TESTF_REDIRECT) ? 2 : 1);
546 if(test->flags & TESTF_REDIRECT) {
547 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
548 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
550 SET_EXPECT(INTERNET_STATUS_REDIRECT);
551 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER);
552 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER);
553 if (flags & INTERNET_FLAG_ASYNC)
554 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
556 if(test->flags & TESTF_COMPRESSED) {
557 BOOL b = TRUE;
559 res = InternetSetOptionA(hor, INTERNET_OPTION_HTTP_DECODING, &b, sizeof(b));
560 ok(res || broken(!res && GetLastError() == ERROR_INTERNET_INVALID_OPTION),
561 "InternetSetOption failed: %u\n", GetLastError());
562 if(!res)
563 goto abort;
566 test_status_code(hor, 0);
568 trace("HttpSendRequestA -->\n");
569 if(test->post_data) {
570 post_len = strlen(test->post_data);
571 post_data = HeapAlloc(GetProcessHeap(), 0, post_len);
572 memcpy(post_data, test->post_data, post_len);
574 SetLastError(0xdeadbeef);
575 res = HttpSendRequestA(hor, test->headers, -1, post_data, post_len);
576 if (flags & INTERNET_FLAG_ASYNC)
577 ok(!res && (GetLastError() == ERROR_IO_PENDING),
578 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
579 else
580 ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED),
581 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
582 trace("HttpSendRequestA <--\n");
584 if (flags & INTERNET_FLAG_ASYNC) {
585 WaitForSingleObject(hCompleteEvent, INFINITE);
586 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
588 HeapFree(GetProcessHeap(), 0, post_data);
590 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
591 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED);
592 if (first_connection_to_test_url)
594 if (! proxy_active())
596 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
597 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
599 else
601 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
602 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
605 else
607 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
608 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
610 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, (test->flags & TESTF_REDIRECT) ? 2 : 1);
611 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, (test->flags & TESTF_REDIRECT) ? 2 : 1);
612 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, (test->flags & TESTF_REDIRECT) ? 2 : 1);
613 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, (test->flags & TESTF_REDIRECT) ? 2 : 1);
614 if(test->flags & TESTF_REDIRECT)
615 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
616 if (flags & INTERNET_FLAG_ASYNC)
617 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
618 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
619 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
620 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
622 test_request_flags(hor, 0);
624 length = 100;
625 res = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
626 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
628 length = sizeof(buffer)-1;
629 res = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0);
630 ok(res, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
631 buffer[length]=0;
633 length = sizeof(buffer);
634 res = InternetQueryOptionA(hor, INTERNET_OPTION_URL, buffer, &length);
635 ok(res, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
636 ok(!strcmp(buffer, test->redirected_url), "Wrong URL %s\n", buffer);
638 length = 16;
639 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
640 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res,buffer,GetLastError());
641 if(test->flags & TESTF_COMPRESSED)
642 ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
643 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res, GetLastError());
645 length = 100;
646 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
647 buffer[length]=0;
648 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res,buffer);
650 length = 100;
651 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_ENCODING,buffer,&length,0x0);
652 buffer[length]=0;
653 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res,buffer);
655 SetLastError(0xdeadbeef);
656 res = InternetReadFile(NULL, buffer, 100, &length);
657 ok(!res, "InternetReadFile should have failed\n");
658 ok(GetLastError() == ERROR_INVALID_HANDLE,
659 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
660 GetLastError());
662 length = 100;
663 trace("Entering Query loop\n");
665 while (TRUE)
667 if (flags & INTERNET_FLAG_ASYNC)
668 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
669 length = 0;
670 res = InternetQueryDataAvailable(hor,&length,0x0,0x0);
671 if (flags & INTERNET_FLAG_ASYNC)
673 if (res)
675 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
676 if(exlen) {
677 ok(length >= exlen, "length %u < exlen %u\n", length, exlen);
678 exlen = 0;
681 else if (GetLastError() == ERROR_IO_PENDING)
683 trace("PENDING\n");
684 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
685 if(!(test->flags & TESTF_CHUNKED))
686 ok(!length, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length);
687 WaitForSingleObject(hCompleteEvent, INFINITE);
688 exlen = length;
689 ok(exlen, "length = 0\n");
690 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
691 ok(req_error, "req_error = 0\n");
692 continue;
693 }else {
694 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
696 }else {
697 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
699 trace("LENGTH %d\n", length);
700 if(test->flags & TESTF_CHUNKED)
701 ok(length <= 8192, "length = %d, expected <= 8192\n", length);
702 if (length)
704 char *buffer;
705 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
707 res = InternetReadFile(hor,buffer,length,&length);
709 buffer[length]=0;
711 trace("ReadFile -> %s %i\n",res?"TRUE":"FALSE",length);
713 if(test->content)
714 ok(!strcmp(buffer, test->content), "buffer = '%s', expected '%s'\n", buffer, test->content);
715 HeapFree(GetProcessHeap(),0,buffer);
716 }else {
717 ok(!on_async, "Returned zero size in response to request complete\n");
718 break;
720 on_async = FALSE;
722 if(test->flags & TESTF_REDIRECT) {
723 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
724 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
726 abort:
727 trace("aborting\n");
728 close_async_handle(hi, hCompleteEvent, 2);
729 CloseHandle(hCompleteEvent);
730 first_connection_to_test_url = FALSE;
733 static void InternetReadFile_chunked_test(void)
735 BOOL res;
736 CHAR buffer[4000];
737 DWORD length, got;
738 const char *types[2] = { "*", NULL };
739 HINTERNET hi, hic = 0, hor = 0;
741 trace("Starting InternetReadFile chunked test\n");
743 trace("InternetOpenA <--\n");
744 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
745 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
746 trace("InternetOpenA -->\n");
748 if (hi == 0x0) goto abort;
750 trace("InternetConnectA <--\n");
751 hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER,
752 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
753 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
754 trace("InternetConnectA -->\n");
756 if (hic == 0x0) goto abort;
758 trace("HttpOpenRequestA <--\n");
759 hor = HttpOpenRequestA(hic, "GET", "/tests/chunked", NULL, NULL, types,
760 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
761 0xdeadbead);
762 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
764 * If the internet name can't be resolved we are probably behind
765 * a firewall or in some other way not directly connected to the
766 * Internet. Not enough reason to fail the test. Just ignore and
767 * abort.
769 } else {
770 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
772 trace("HttpOpenRequestA -->\n");
774 if (hor == 0x0) goto abort;
776 trace("HttpSendRequestA -->\n");
777 SetLastError(0xdeadbeef);
778 res = HttpSendRequestA(hor, "", -1, NULL, 0);
779 ok(res || (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED),
780 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
781 trace("HttpSendRequestA <--\n");
783 test_request_flags(hor, 0);
785 length = 100;
786 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
787 buffer[length]=0;
788 trace("Option CONTENT_TYPE -> %i %s\n",res,buffer);
790 SetLastError( 0xdeadbeef );
791 length = 100;
792 res = HttpQueryInfoA(hor,HTTP_QUERY_TRANSFER_ENCODING,buffer,&length,0x0);
793 buffer[length]=0;
794 trace("Option TRANSFER_ENCODING -> %i %s\n",res,buffer);
795 ok( res || ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND ),
796 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
797 ok( !strcmp( buffer, "chunked" ) || ( ! res && proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND ),
798 "Wrong transfer encoding '%s'\n", buffer );
800 SetLastError( 0xdeadbeef );
801 length = 16;
802 res = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
803 ok( !res, "Found CONTENT_LENGTH option '%s'\n", buffer );
804 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "Wrong error %u\n", GetLastError() );
806 length = 100;
807 trace("Entering Query loop\n");
809 while (TRUE)
811 res = InternetQueryDataAvailable(hor,&length,0x0,0x0);
812 ok(!(!res && length != 0),"InternetQueryDataAvailable failed with non-zero length\n");
813 ok(res, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
814 trace("got %u available\n",length);
815 if (length)
817 char *buffer = HeapAlloc(GetProcessHeap(),0,length+1);
819 res = InternetReadFile(hor,buffer,length,&got);
821 buffer[got]=0;
822 trace("ReadFile -> %i %i\n",res,got);
823 ok( length == got, "only got %u of %u available\n", got, length );
824 ok( buffer[got-1] == '\n', "received partial line '%s'\n", buffer );
826 HeapFree(GetProcessHeap(),0,buffer);
827 if (!got) break;
829 if (length == 0)
831 got = 0xdeadbeef;
832 res = InternetReadFile( hor, buffer, 1, &got );
833 ok( res, "InternetReadFile failed: %u\n", GetLastError() );
834 ok( !got, "got %u\n", got );
835 break;
838 abort:
839 trace("aborting\n");
840 if (hor != 0x0) {
841 res = InternetCloseHandle(hor);
842 ok (res, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
844 if (hi != 0x0) {
845 res = InternetCloseHandle(hi);
846 ok (res, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
850 static void InternetReadFileExA_test(int flags)
852 DWORD rc;
853 DWORD length;
854 const char *types[2] = { "*", NULL };
855 HINTERNET hi, hic = 0, hor = 0;
856 INTERNET_BUFFERSA inetbuffers;
858 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
860 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags);
862 trace("InternetOpenA <--\n");
863 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
864 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
865 trace("InternetOpenA -->\n");
867 if (hi == 0x0) goto abort;
869 pInternetSetStatusCallbackA(hi,&callback);
871 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
873 trace("InternetConnectA <--\n");
874 hic=InternetConnectA(hi, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER,
875 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
876 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
877 trace("InternetConnectA -->\n");
879 if (hic == 0x0) goto abort;
881 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
882 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
884 trace("HttpOpenRequestA <--\n");
885 hor = HttpOpenRequestA(hic, "GET", "/tests/redirect", NULL, NULL, types,
886 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RELOAD,
887 0xdeadbead);
888 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
890 * If the internet name can't be resolved we are probably behind
891 * a firewall or in some other way not directly connected to the
892 * Internet. Not enough reason to fail the test. Just ignore and
893 * abort.
895 } else {
896 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
898 trace("HttpOpenRequestA -->\n");
900 if (hor == 0x0) goto abort;
902 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
903 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
904 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
905 if (first_connection_to_test_url)
907 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
908 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
910 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT, 2);
911 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
912 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
913 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, 2);
914 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, 2);
915 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
916 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
917 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
918 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
919 SET_EXPECT(INTERNET_STATUS_REDIRECT);
920 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER);
921 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER);
922 if (flags & INTERNET_FLAG_ASYNC)
923 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
924 else
925 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
927 trace("HttpSendRequestA -->\n");
928 SetLastError(0xdeadbeef);
929 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
930 if (flags & INTERNET_FLAG_ASYNC)
931 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
932 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
933 else
934 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
935 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
936 trace("HttpSendRequestA <--\n");
938 if (!rc && (GetLastError() == ERROR_IO_PENDING)) {
939 WaitForSingleObject(hCompleteEvent, INFINITE);
940 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
943 if (first_connection_to_test_url)
945 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
946 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
948 else
950 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
951 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
953 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, 2);
954 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, 2);
955 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
956 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
957 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
958 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
959 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
960 if (flags & INTERNET_FLAG_ASYNC)
961 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
962 else
963 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
964 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
965 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
966 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
967 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
969 /* tests invalid dwStructSize */
970 inetbuffers.dwStructSize = sizeof(inetbuffers)+1;
971 inetbuffers.lpcszHeader = NULL;
972 inetbuffers.dwHeadersLength = 0;
973 inetbuffers.dwBufferLength = 10;
974 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10);
975 inetbuffers.dwOffsetHigh = 1234;
976 inetbuffers.dwOffsetLow = 5678;
977 rc = InternetReadFileExA(hor, &inetbuffers, 0, 0xdeadcafe);
978 ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
979 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
980 rc ? "TRUE" : "FALSE", GetLastError());
981 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
983 test_request_flags(hor, 0);
985 /* tests to see whether lpcszHeader is used - it isn't */
986 inetbuffers.dwStructSize = sizeof(inetbuffers);
987 inetbuffers.lpcszHeader = (LPCSTR)0xdeadbeef;
988 inetbuffers.dwHeadersLength = 255;
989 inetbuffers.dwBufferLength = 0;
990 inetbuffers.lpvBuffer = NULL;
991 inetbuffers.dwOffsetHigh = 1234;
992 inetbuffers.dwOffsetLow = 5678;
993 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
994 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
995 rc = InternetReadFileExA(hor, &inetbuffers, 0, 0xdeadcafe);
996 ok(rc, "InternetReadFileEx failed with error %u\n", GetLastError());
997 trace("read %i bytes\n", inetbuffers.dwBufferLength);
998 todo_wine
1000 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1001 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1004 rc = InternetReadFileExA(NULL, &inetbuffers, 0, 0xdeadcafe);
1005 ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE),
1006 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1007 rc ? "TRUE" : "FALSE", GetLastError());
1009 length = 0;
1010 trace("Entering Query loop\n");
1012 while (TRUE)
1014 inetbuffers.dwStructSize = sizeof(inetbuffers);
1015 inetbuffers.dwBufferLength = 1024;
1016 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1);
1017 inetbuffers.dwOffsetHigh = 1234;
1018 inetbuffers.dwOffsetLow = 5678;
1020 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE);
1021 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED);
1022 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
1023 rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe);
1024 if (!rc)
1026 if (GetLastError() == ERROR_IO_PENDING)
1028 trace("InternetReadFileEx -> PENDING\n");
1029 ok(flags & INTERNET_FLAG_ASYNC,
1030 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1031 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1032 WaitForSingleObject(hCompleteEvent, INFINITE);
1033 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1034 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1035 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
1037 else
1039 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1040 break;
1043 else
1045 trace("InternetReadFileEx -> SUCCEEDED\n");
1046 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1047 if (inetbuffers.dwBufferLength)
1049 todo_wine {
1050 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1051 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1054 else
1056 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1057 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1058 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1062 trace("read %i bytes\n", inetbuffers.dwBufferLength);
1063 ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
1065 ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678,
1066 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1067 inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
1069 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
1071 if (!inetbuffers.dwBufferLength)
1072 break;
1074 length += inetbuffers.dwBufferLength;
1076 ok(length > 0, "failed to read any of the document\n");
1077 trace("Finished. Read %d bytes\n", length);
1079 abort:
1080 close_async_handle(hi, hCompleteEvent, 2);
1081 CloseHandle(hCompleteEvent);
1082 first_connection_to_test_url = FALSE;
1085 static void InternetOpenUrlA_test(void)
1087 HINTERNET myhinternet, myhttp;
1088 char buffer[0x400];
1089 DWORD size, readbytes, totalbytes=0;
1090 BOOL ret;
1092 ret = DeleteUrlCacheEntryA(TEST_URL);
1093 ok(ret || GetLastError() == ERROR_FILE_NOT_FOUND,
1094 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret, GetLastError());
1096 myhinternet = InternetOpenA("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
1097 ok((myhinternet != 0), "InternetOpen failed, error %u\n",GetLastError());
1098 size = 0x400;
1099 ret = InternetCanonicalizeUrlA(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
1100 ok( ret, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1102 SetLastError(0);
1103 myhttp = InternetOpenUrlA(myhinternet, TEST_URL, 0, 0,
1104 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
1105 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1106 return; /* WinXP returns this when not connected to the net */
1107 ok((myhttp != 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1108 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
1109 ok( ret, "InternetReadFile failed, error %u\n",GetLastError());
1110 totalbytes += readbytes;
1111 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
1112 totalbytes += readbytes;
1113 trace("read 0x%08x bytes\n",totalbytes);
1115 InternetCloseHandle(myhttp);
1116 InternetCloseHandle(myhinternet);
1118 ret = DeleteUrlCacheEntryA(TEST_URL);
1119 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1122 static void HttpSendRequestEx_test(void)
1124 HINTERNET hSession;
1125 HINTERNET hConnect;
1126 HINTERNET hRequest;
1128 INTERNET_BUFFERSA BufferIn;
1129 DWORD dwBytesWritten, dwBytesRead, error;
1130 CHAR szBuffer[256];
1131 int i;
1132 BOOL ret;
1134 static char szPostData[] = "mode=Test";
1135 static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
1137 hSession = InternetOpenA("Wine Regression Test",
1138 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1139 ok( hSession != NULL ,"Unable to open Internet session\n");
1140 hConnect = InternetConnectA(hSession, "crossover.codeweavers.com",
1141 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1143 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
1144 hRequest = HttpOpenRequestA(hConnect, "POST", "/posttest.php",
1145 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1146 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1148 skip( "Network unreachable, skipping test\n" );
1149 goto done;
1151 ok( hRequest != NULL, "Failed to open request handle err %u\n", GetLastError());
1153 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1155 BufferIn.dwStructSize = sizeof(BufferIn);
1156 BufferIn.Next = (INTERNET_BUFFERSA*)0xdeadcab;
1157 BufferIn.lpcszHeader = szContentType;
1158 BufferIn.dwHeadersLength = sizeof(szContentType)-1;
1159 BufferIn.dwHeadersTotal = sizeof(szContentType)-1;
1160 BufferIn.lpvBuffer = szPostData;
1161 BufferIn.dwBufferLength = 3;
1162 BufferIn.dwBufferTotal = sizeof(szPostData)-1;
1163 BufferIn.dwOffsetLow = 0;
1164 BufferIn.dwOffsetHigh = 0;
1166 SetLastError(0xdeadbeef);
1167 ret = HttpSendRequestExA(hRequest, &BufferIn, NULL, 0 ,0);
1168 error = GetLastError();
1169 ok(ret, "HttpSendRequestEx Failed with error %u\n", error);
1170 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", error);
1172 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1174 for (i = 3; szPostData[i]; i++)
1175 ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten),
1176 "InternetWriteFile failed\n");
1178 test_request_flags(hRequest, INTERNET_REQFLAG_NO_HEADERS);
1180 ok(HttpEndRequestA(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
1182 test_request_flags(hRequest, 0);
1184 ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead),
1185 "Unable to read response\n");
1186 szBuffer[dwBytesRead] = 0;
1188 ok(dwBytesRead == 13,"Read %u bytes instead of 13\n",dwBytesRead);
1189 ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0 || broken(proxy_active()),"Got string %s\n",szBuffer);
1191 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1192 done:
1193 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1194 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1197 static void InternetOpenRequest_test(void)
1199 HINTERNET session, connect, request;
1200 static const char *types[] = { "*", "", NULL };
1201 static const WCHAR slash[] = {'/', 0}, any[] = {'*', 0}, empty[] = {0};
1202 static const WCHAR *typesW[] = { any, empty, NULL };
1203 BOOL ret;
1205 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1206 ok(session != NULL ,"Unable to open Internet session\n");
1208 connect = InternetConnectA(session, NULL, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1209 INTERNET_SERVICE_HTTP, 0, 0);
1210 ok(connect == NULL, "InternetConnectA should have failed\n");
1211 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1213 connect = InternetConnectA(session, "", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1214 INTERNET_SERVICE_HTTP, 0, 0);
1215 ok(connect == NULL, "InternetConnectA should have failed\n");
1216 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1218 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1219 INTERNET_SERVICE_HTTP, 0, 0);
1220 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1222 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1223 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1225 skip( "Network unreachable, skipping test\n" );
1226 goto done;
1228 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1230 ret = HttpSendRequestW(request, NULL, 0, NULL, 0);
1231 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1232 ok(InternetCloseHandle(request), "Close request handle failed\n");
1234 request = HttpOpenRequestW(connect, NULL, slash, NULL, NULL, typesW, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1235 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1237 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1238 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1239 ok(InternetCloseHandle(request), "Close request handle failed\n");
1241 done:
1242 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1243 ok(InternetCloseHandle(session), "Close session handle failed\n");
1246 static void test_cache_read(void)
1248 HINTERNET session, connection, req;
1249 FILETIME now, tomorrow, yesterday;
1250 BYTE content[1000], buf[2000];
1251 char file_path[MAX_PATH];
1252 ULARGE_INTEGER li;
1253 HANDLE file;
1254 DWORD size;
1255 unsigned i;
1256 BOOL res;
1258 static const char cache_only_url[] = "http://test.winehq.org/tests/cache-only";
1259 BYTE cache_headers[] = "HTTP/1.1 200 OK\r\n\r\n";
1261 trace("Testing cache read...\n");
1263 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
1265 for(i = 0; i < sizeof(content); i++)
1266 content[i] = '0' + (i%10);
1268 GetSystemTimeAsFileTime(&now);
1269 li.u.HighPart = now.dwHighDateTime;
1270 li.u.LowPart = now.dwLowDateTime;
1271 li.QuadPart += (LONGLONG)10000000 * 3600 * 24;
1272 tomorrow.dwHighDateTime = li.u.HighPart;
1273 tomorrow.dwLowDateTime = li.u.LowPart;
1274 li.QuadPart -= (LONGLONG)10000000 * 3600 * 24 * 2;
1275 yesterday.dwHighDateTime = li.u.HighPart;
1276 yesterday.dwLowDateTime = li.u.LowPart;
1278 res = CreateUrlCacheEntryA(cache_only_url, sizeof(content), "", file_path, 0);
1279 ok(res, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1281 file = CreateFileA(file_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
1282 ok(file != INVALID_HANDLE_VALUE, "CreateFile failed\n");
1284 WriteFile(file, content, sizeof(content), &size, NULL);
1285 CloseHandle(file);
1287 res = CommitUrlCacheEntryA(cache_only_url, file_path, tomorrow, yesterday, NORMAL_CACHE_ENTRY,
1288 cache_headers, sizeof(cache_headers)-1, "", 0);
1289 ok(res, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1291 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
1292 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
1294 pInternetSetStatusCallbackA(session, callback);
1296 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
1297 connection = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT,
1298 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
1299 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
1300 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
1302 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
1303 req = HttpOpenRequestA(connection, "GET", "/tests/cache-only", NULL, NULL, NULL, 0, 0xdeadbead);
1304 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
1305 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
1307 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER);
1308 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER);
1309 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST);
1310 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT);
1311 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE);
1312 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED);
1313 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
1315 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
1316 todo_wine
1317 ok(res, "HttpSendRequest failed: %u\n", GetLastError());
1319 if(res) {
1320 size = 0;
1321 res = InternetQueryDataAvailable(req, &size, 0, 0);
1322 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1323 ok(size == sizeof(content), "size = %u\n", size);
1325 size = sizeof(buf);
1326 res = InternetReadFile(req, buf, sizeof(buf), &size);
1327 ok(res, "InternetReadFile failed: %u\n", GetLastError());
1328 ok(size == sizeof(content), "size = %u\n", size);
1329 ok(!memcmp(content, buf, sizeof(content)), "unexpected content\n");
1332 close_async_handle(session, hCompleteEvent, 2);
1334 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
1335 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
1336 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
1337 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
1338 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
1339 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
1340 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
1342 res = DeleteUrlCacheEntryA(cache_only_url);
1343 ok(res, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1345 CloseHandle(hCompleteEvent);
1348 static void test_http_cache(void)
1350 HINTERNET session, connect, request;
1351 char file_name[MAX_PATH], url[INTERNET_MAX_URL_LENGTH];
1352 DWORD size, file_size;
1353 BYTE buf[100];
1354 HANDLE file;
1355 BOOL ret;
1357 static const char *types[] = { "*", "", NULL };
1359 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1360 ok(session != NULL ,"Unable to open Internet session\n");
1362 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1363 INTERNET_SERVICE_HTTP, 0, 0);
1364 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1366 request = HttpOpenRequestA(connect, NULL, "/tests/hello.html", NULL, NULL, types, INTERNET_FLAG_NEED_FILE, 0);
1367 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1369 skip( "Network unreachable, skipping test\n" );
1371 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1372 ok(InternetCloseHandle(session), "Close session handle failed\n");
1374 return;
1376 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1378 size = sizeof(url);
1379 ret = InternetQueryOptionA(request, INTERNET_OPTION_URL, url, &size);
1380 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1381 ok(!strcmp(url, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url);
1383 size = sizeof(file_name);
1384 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1385 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1386 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1387 ok(!size, "size = %d\n", size);
1389 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1390 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1392 size = sizeof(file_name);
1393 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1394 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1396 file = CreateFileA(file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
1397 FILE_ATTRIBUTE_NORMAL, NULL);
1398 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1399 file_size = GetFileSize(file, NULL);
1400 ok(file_size == 106, "file size = %u\n", file_size);
1402 size = sizeof(buf);
1403 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1404 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1405 ok(size == 100, "size = %u\n", size);
1407 file_size = GetFileSize(file, NULL);
1408 ok(file_size == 106, "file size = %u\n", file_size);
1409 CloseHandle(file);
1411 ret = DeleteFileA(file_name);
1412 ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
1414 ok(InternetCloseHandle(request), "Close request handle failed\n");
1416 file = CreateFileA(file_name, GENERIC_READ, 0, NULL, OPEN_EXISTING,
1417 FILE_ATTRIBUTE_NORMAL, NULL);
1418 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1419 CloseHandle(file);
1421 /* Send the same request, requiring it to be retrieved from the cache */
1422 request = HttpOpenRequestA(connect, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
1424 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1425 ok(ret, "HttpSendRequest failed\n");
1427 size = sizeof(buf);
1428 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1429 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1430 ok(size == 100, "size = %u\n", size);
1432 ok(InternetCloseHandle(request), "Close request handle failed\n");
1434 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1435 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1437 size = sizeof(file_name);
1438 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1439 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1440 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1441 ok(!size, "size = %d\n", size);
1443 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1444 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1446 size = sizeof(file_name);
1447 file_name[0] = 0;
1448 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1449 if (ret)
1451 file = CreateFileA(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1452 FILE_ATTRIBUTE_NORMAL, NULL);
1453 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1454 CloseHandle(file);
1456 else
1458 /* < IE8 */
1459 ok(file_name[0] == 0, "Didn't expect a file name\n");
1462 ok(InternetCloseHandle(request), "Close request handle failed\n");
1463 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1464 ok(InternetCloseHandle(session), "Close session handle failed\n");
1466 test_cache_read();
1469 static void InternetLockRequestFile_test(void)
1471 HINTERNET session, connect, request;
1472 char file_name[MAX_PATH];
1473 HANDLE lock, lock2;
1474 DWORD size;
1475 BOOL ret;
1477 static const char *types[] = { "*", "", NULL };
1479 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1480 ok(session != NULL ,"Unable to open Internet session\n");
1482 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1483 INTERNET_SERVICE_HTTP, 0, 0);
1484 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1486 request = HttpOpenRequestA(connect, NULL, "/tests/hello.html", NULL, NULL, types, INTERNET_FLAG_NEED_FILE|INTERNET_FLAG_RELOAD, 0);
1487 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1489 skip( "Network unreachable, skipping test\n" );
1491 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1492 ok(InternetCloseHandle(session), "Close session handle failed\n");
1494 return;
1496 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1498 size = sizeof(file_name);
1499 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1500 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1501 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1502 ok(!size, "size = %d\n", size);
1504 lock = NULL;
1505 ret = InternetLockRequestFile(request, &lock);
1506 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
1508 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
1509 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1511 size = sizeof(file_name);
1512 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1513 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1515 ret = InternetLockRequestFile(request, &lock);
1516 ok(ret, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
1517 ok(lock != NULL, "lock == NULL\n");
1519 ret = InternetLockRequestFile(request, &lock2);
1520 ok(ret, "InternetLockRequestFile returned: %x(%u)\n", ret, GetLastError());
1521 ok(lock == lock2, "lock != lock2\n");
1523 ret = InternetUnlockRequestFile(lock2);
1524 ok(ret, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1526 ret = DeleteFileA(file_name);
1527 ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
1529 ok(InternetCloseHandle(request), "Close request handle failed\n");
1531 ret = DeleteFileA(file_name);
1532 ok(!ret && GetLastError() == ERROR_SHARING_VIOLATION, "Deleting file returned %x(%u)\n", ret, GetLastError());
1534 ret = InternetUnlockRequestFile(lock);
1535 ok(ret, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1537 ret = DeleteFileA(file_name);
1538 ok(ret, "Deleting file returned %x(%u)\n", ret, GetLastError());
1541 static void HttpHeaders_test(void)
1543 HINTERNET hSession;
1544 HINTERNET hConnect;
1545 HINTERNET hRequest;
1546 CHAR buffer[256];
1547 WCHAR wbuffer[256];
1548 DWORD len = 256;
1549 DWORD oldlen;
1550 DWORD index = 0;
1551 BOOL ret;
1553 hSession = InternetOpenA("Wine Regression Test",
1554 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1555 ok( hSession != NULL ,"Unable to open Internet session\n");
1556 hConnect = InternetConnectA(hSession, "crossover.codeweavers.com",
1557 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1559 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
1560 hRequest = HttpOpenRequestA(hConnect, "POST", "/posttest.php",
1561 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1562 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1564 skip( "Network unreachable, skipping test\n" );
1565 goto done;
1567 ok( hRequest != NULL, "Failed to open request handle\n");
1569 index = 0;
1570 len = sizeof(buffer);
1571 strcpy(buffer,"Warning");
1572 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1573 buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
1575 ok(HttpAddRequestHeadersA(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
1576 "Failed to add new header\n");
1578 index = 0;
1579 len = sizeof(buffer);
1580 strcpy(buffer,"Warning");
1581 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1582 buffer,&len,&index),"Unable to query header\n");
1583 ok(index == 1, "Index was not incremented\n");
1584 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1585 ok(len == 5, "Invalid length (exp. 5, got %d)\n", len);
1586 ok((len < sizeof(buffer)) && (buffer[len] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1587 len = sizeof(buffer);
1588 strcpy(buffer,"Warning");
1589 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1590 buffer,&len,&index)==0,"Second Index Should Not Exist\n");
1592 index = 0;
1593 len = 5; /* could store the string but not the NULL terminator */
1594 strcpy(buffer,"Warning");
1595 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1596 buffer,&len,&index) == FALSE,"Query succeeded on a too small buffer\n");
1597 ok(strcmp(buffer,"Warning")==0, "incorrect string was returned(%s)\n",buffer); /* string not touched */
1598 ok(len == 6, "Invalid length (exp. 6, got %d)\n", len); /* unlike success, the length includes the NULL-terminator */
1600 /* a call with NULL will fail but will return the length */
1601 index = 0;
1602 len = sizeof(buffer);
1603 SetLastError(0xdeadbeef);
1604 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1605 NULL,&len,&index) == FALSE,"Query worked\n");
1606 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1607 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1608 ok(index == 0, "Index was incremented\n");
1610 /* even for a len that is too small */
1611 index = 0;
1612 len = 15;
1613 SetLastError(0xdeadbeef);
1614 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1615 NULL,&len,&index) == FALSE,"Query worked\n");
1616 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1617 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1618 ok(index == 0, "Index was incremented\n");
1620 index = 0;
1621 len = 0;
1622 SetLastError(0xdeadbeef);
1623 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1624 NULL,&len,&index) == FALSE,"Query worked\n");
1625 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1626 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1627 ok(index == 0, "Index was incremented\n");
1628 oldlen = len; /* bytes; at least long enough to hold buffer & nul */
1631 /* a working query */
1632 index = 0;
1633 len = sizeof(buffer);
1634 memset(buffer, 'x', sizeof(buffer));
1635 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1636 buffer,&len,&index),"Unable to query header\n");
1637 ok(len + sizeof(CHAR) <= oldlen, "Result longer than advertised\n");
1638 ok((len < sizeof(buffer)-sizeof(CHAR)) && (buffer[len/sizeof(CHAR)] == 0),"No NUL at end\n");
1639 ok(len == strlen(buffer) * sizeof(CHAR), "Length wrong\n");
1640 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1641 ok(strncmp(buffer, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1642 ok(strcmp(buffer + strlen(buffer) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1643 ok(index == 0, "Index was incremented\n");
1645 /* Like above two tests, but for W version */
1647 index = 0;
1648 len = 0;
1649 SetLastError(0xdeadbeef);
1650 ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1651 NULL,&len,&index) == FALSE,"Query worked\n");
1652 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1653 ok(len > 80, "Invalid length (exp. more than 80, got %d)\n", len);
1654 ok(index == 0, "Index was incremented\n");
1655 oldlen = len; /* bytes; at least long enough to hold buffer & nul */
1657 /* a working query */
1658 index = 0;
1659 len = sizeof(wbuffer);
1660 memset(wbuffer, 'x', sizeof(wbuffer));
1661 ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1662 wbuffer,&len,&index),"Unable to query header\n");
1663 ok(len + sizeof(WCHAR) <= oldlen, "Result longer than advertised\n");
1664 ok(len == lstrlenW(wbuffer) * sizeof(WCHAR), "Length wrong\n");
1665 ok((len < sizeof(wbuffer)-sizeof(WCHAR)) && (wbuffer[len/sizeof(WCHAR)] == 0),"No NUL at end\n");
1666 ok(index == 0, "Index was incremented\n");
1668 /* end of W version tests */
1670 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1671 index = 0;
1672 len = sizeof(buffer);
1673 memset(buffer, 'x', sizeof(buffer));
1674 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF,
1675 buffer,&len,&index) == TRUE,"Query failed\n");
1676 ok(len == 2, "Expected 2, got %d\n", len);
1677 ok(strcmp(buffer, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer);
1678 ok(index == 0, "Index was incremented\n");
1680 ok(HttpAddRequestHeadersA(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
1681 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1683 index = 0;
1684 len = sizeof(buffer);
1685 strcpy(buffer,"Warning");
1686 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1687 buffer,&len,&index),"Unable to query header\n");
1688 ok(index == 1, "Index was not incremented\n");
1689 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1690 len = sizeof(buffer);
1691 strcpy(buffer,"Warning");
1692 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1693 buffer,&len,&index),"Failed to get second header\n");
1694 ok(index == 2, "Index was not incremented\n");
1695 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1696 len = sizeof(buffer);
1697 strcpy(buffer,"Warning");
1698 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1699 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1701 ok(HttpAddRequestHeadersA(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1703 index = 0;
1704 len = sizeof(buffer);
1705 strcpy(buffer,"Warning");
1706 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1707 buffer,&len,&index),"Unable to query header\n");
1708 ok(index == 1, "Index was not incremented\n");
1709 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1710 len = sizeof(buffer);
1711 strcpy(buffer,"Warning");
1712 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1713 buffer,&len,&index),"Failed to get second header\n");
1714 ok(index == 2, "Index was not incremented\n");
1715 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1716 len = sizeof(buffer);
1717 strcpy(buffer,"Warning");
1718 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1719 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1721 ok(HttpAddRequestHeadersA(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1723 index = 0;
1724 len = sizeof(buffer);
1725 strcpy(buffer,"Warning");
1726 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1727 buffer,&len,&index),"Unable to query header\n");
1728 ok(index == 1, "Index was not incremented\n");
1729 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1730 len = sizeof(buffer);
1731 strcpy(buffer,"Warning");
1732 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1733 buffer,&len,&index),"Failed to get second header\n");
1734 ok(index == 2, "Index was not incremented\n");
1735 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1736 len = sizeof(buffer);
1737 strcpy(buffer,"Warning");
1738 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1739 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1741 ok(HttpAddRequestHeadersA(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1743 index = 0;
1744 len = sizeof(buffer);
1745 strcpy(buffer,"Warning");
1746 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1747 buffer,&len,&index),"Unable to query header\n");
1748 ok(index == 1, "Index was not incremented\n");
1749 ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer);
1750 len = sizeof(buffer);
1751 strcpy(buffer,"Warning");
1752 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1753 ok(index == 2, "Index was not incremented\n");
1754 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1755 len = sizeof(buffer);
1756 strcpy(buffer,"Warning");
1757 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1759 ok(HttpAddRequestHeadersA(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1761 index = 0;
1762 len = sizeof(buffer);
1763 strcpy(buffer,"Warning");
1764 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1765 ok(index == 1, "Index was not incremented\n");
1766 ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer);
1767 len = sizeof(buffer);
1768 strcpy(buffer,"Warning");
1769 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1770 ok(index == 2, "Index was not incremented\n");
1771 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1772 len = sizeof(buffer);
1773 strcpy(buffer,"Warning");
1774 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1776 ok(HttpAddRequestHeadersA(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1778 index = 0;
1779 len = sizeof(buffer);
1780 strcpy(buffer,"Warning");
1781 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1782 ok(index == 1, "Index was not incremented\n");
1783 ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer);
1784 len = sizeof(buffer);
1785 strcpy(buffer,"Warning");
1786 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1787 ok(index == 2, "Index was not incremented\n");
1788 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1789 len = sizeof(buffer);
1790 strcpy(buffer,"Warning");
1791 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1793 ok(HttpAddRequestHeadersA(hRequest,"Warning:test7",-1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE), "HTTP_ADDREQ_FLAG_ADD with HTTP_ADDREQ_FLAG_REPALCE Did not work\n");
1795 index = 0;
1796 len = sizeof(buffer);
1797 strcpy(buffer,"Warning");
1798 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1799 ok(index == 1, "Index was not incremented\n");
1800 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1801 len = sizeof(buffer);
1802 strcpy(buffer,"Warning");
1803 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1804 ok(index == 2, "Index was not incremented\n");
1805 ok(strcmp(buffer,"test7")==0, "incorrect string was returned(%s)\n",buffer);
1806 len = sizeof(buffer);
1807 strcpy(buffer,"Warning");
1808 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1810 /* Ensure that blank headers are ignored and don't cause a failure */
1811 ok(HttpAddRequestHeadersA(hRequest,"\r\nBlankTest:value\r\n\r\n",-1, HTTP_ADDREQ_FLAG_ADD_IF_NEW), "Failed to add header with blank entries in list\n");
1813 index = 0;
1814 len = sizeof(buffer);
1815 strcpy(buffer,"BlankTest");
1816 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1817 ok(index == 1, "Index was not incremented\n");
1818 ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
1820 /* Ensure that malformed header separators are ignored and don't cause a failure */
1821 ok(HttpAddRequestHeadersA(hRequest,"\r\rMalformedTest:value\n\nMalformedTestTwo: value2\rMalformedTestThree: value3\n\n\r\r\n",-1, HTTP_ADDREQ_FLAG_ADD|HTTP_ADDREQ_FLAG_REPLACE),
1822 "Failed to add header with malformed entries in list\n");
1824 index = 0;
1825 len = sizeof(buffer);
1826 strcpy(buffer,"MalformedTest");
1827 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1828 ok(index == 1, "Index was not incremented\n");
1829 ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
1830 index = 0;
1831 len = sizeof(buffer);
1832 strcpy(buffer,"MalformedTestTwo");
1833 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1834 ok(index == 1, "Index was not incremented\n");
1835 ok(strcmp(buffer,"value2")==0, "incorrect string was returned(%s)\n",buffer);
1836 index = 0;
1837 len = sizeof(buffer);
1838 strcpy(buffer,"MalformedTestThree");
1839 ok(HttpQueryInfoA(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1840 ok(index == 1, "Index was not incremented\n");
1841 ok(strcmp(buffer,"value3")==0, "incorrect string was returned(%s)\n",buffer);
1843 ret = HttpAddRequestHeadersA(hRequest, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD);
1844 ok(ret, "unable to add header %u\n", GetLastError());
1846 index = 0;
1847 buffer[0] = 0;
1848 len = sizeof(buffer);
1849 ret = HttpQueryInfoA(hRequest, HTTP_QUERY_AUTHORIZATION|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &len, &index);
1850 ok(ret, "unable to query header %u\n", GetLastError());
1851 ok(index == 1, "index was not incremented\n");
1852 ok(!strcmp(buffer, "Basic"), "incorrect string was returned (%s)\n", buffer);
1854 ret = HttpAddRequestHeadersA(hRequest, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE);
1855 ok(ret, "unable to remove header %u\n", GetLastError());
1857 index = 0;
1858 len = sizeof(buffer);
1859 SetLastError(0xdeadbeef);
1860 ok(!HttpQueryInfoA(hRequest, HTTP_QUERY_AUTHORIZATION|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &len, &index),
1861 "header still present\n");
1862 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "got %u\n", GetLastError());
1864 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1865 done:
1866 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1867 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1870 static const char garbagemsg[] =
1871 "Garbage: Header\r\n";
1873 static const char contmsg[] =
1874 "HTTP/1.1 100 Continue\r\n";
1876 static const char expandcontmsg[] =
1877 "HTTP/1.1 100 Continue\r\n"
1878 "Server: winecontinue\r\n"
1879 "Tag: something witty\r\n"
1880 "\r\n";
1882 static const char okmsg[] =
1883 "HTTP/1.1 200 OK\r\n"
1884 "Server: winetest\r\n"
1885 "\r\n";
1887 static const char okmsg2[] =
1888 "HTTP/1.1 200 OK\r\n"
1889 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1890 "Server: winetest\r\n"
1891 "Content-Length: 0\r\n"
1892 "Set-Cookie: one\r\n"
1893 "Set-Cookie: two\r\n"
1894 "\r\n";
1896 static const char notokmsg[] =
1897 "HTTP/1.1 400 Bad Request\r\n"
1898 "Server: winetest\r\n"
1899 "\r\n";
1901 static const char noauthmsg[] =
1902 "HTTP/1.1 401 Unauthorized\r\n"
1903 "Server: winetest\r\n"
1904 "Connection: close\r\n"
1905 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1906 "\r\n";
1908 static const char noauthmsg2[] =
1909 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
1910 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
1911 "\0d`0|6\n"
1912 "Server: winetest\r\n";
1914 static const char proxymsg[] =
1915 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1916 "Server: winetest\r\n"
1917 "Proxy-Connection: close\r\n"
1918 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1919 "\r\n";
1921 static const char page1[] =
1922 "<HTML>\r\n"
1923 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1924 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1925 "</HTML>\r\n\r\n";
1927 static const char ok_with_length[] =
1928 "HTTP/1.1 200 OK\r\n"
1929 "Connection: Keep-Alive\r\n"
1930 "Content-Length: 23\r\n\r\n"
1931 "abc\r\nHTTP/1.1 211 OK\r\n\r\n";
1933 static const char ok_with_length2[] =
1934 "HTTP/1.1 210 OK\r\n"
1935 "Connection: Keep-Alive\r\n"
1936 "Content-Length: 24\r\n\r\n"
1937 "abc\r\nHTTP/1.1 211 OK\r\n\r\n";
1939 struct server_info {
1940 HANDLE hEvent;
1941 int port;
1944 static int test_cache_gzip;
1945 static const char *send_buffer;
1947 static DWORD CALLBACK server_thread(LPVOID param)
1949 struct server_info *si = param;
1950 int r, c, i, on, count = 0;
1951 SOCKET s;
1952 struct sockaddr_in sa;
1953 char buffer[0x100];
1954 WSADATA wsaData;
1955 int last_request = 0;
1956 char host_header[22];
1957 static int test_b = 0;
1958 static int test_no_cache = 0;
1960 WSAStartup(MAKEWORD(1,1), &wsaData);
1962 s = socket(AF_INET, SOCK_STREAM, 0);
1963 if (s == INVALID_SOCKET)
1964 return 1;
1966 on = 1;
1967 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof on);
1969 memset(&sa, 0, sizeof sa);
1970 sa.sin_family = AF_INET;
1971 sa.sin_port = htons(si->port);
1972 sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
1974 r = bind(s, (struct sockaddr*) &sa, sizeof sa);
1975 if (r<0)
1976 return 1;
1978 listen(s, 0);
1980 SetEvent(si->hEvent);
1982 sprintf(host_header, "Host: localhost:%d", si->port);
1986 c = accept(s, NULL, NULL);
1988 memset(buffer, 0, sizeof buffer);
1989 for(i=0; i<(sizeof buffer-1); i++)
1991 r = recv(c, &buffer[i], 1, 0);
1992 if (r != 1)
1993 break;
1994 if (i<4) continue;
1995 if (buffer[i-2] == '\n' && buffer[i] == '\n' &&
1996 buffer[i-3] == '\r' && buffer[i-1] == '\r')
1997 break;
1999 if (strstr(buffer, "GET /test1"))
2001 if (!strstr(buffer, "Content-Length: 0"))
2003 send(c, okmsg, sizeof okmsg-1, 0);
2004 send(c, page1, sizeof page1-1, 0);
2006 else
2007 send(c, notokmsg, sizeof notokmsg-1, 0);
2009 if (strstr(buffer, "/test2"))
2011 if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2013 send(c, okmsg, sizeof okmsg-1, 0);
2014 send(c, page1, sizeof page1-1, 0);
2016 else
2017 send(c, proxymsg, sizeof proxymsg-1, 0);
2019 if (strstr(buffer, "/test3"))
2021 if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
2022 send(c, okmsg, sizeof okmsg-1, 0);
2023 else
2024 send(c, noauthmsg, sizeof noauthmsg-1, 0);
2026 if (strstr(buffer, "/test4"))
2028 if (strstr(buffer, "Connection: Close"))
2029 send(c, okmsg, sizeof okmsg-1, 0);
2030 else
2031 send(c, notokmsg, sizeof notokmsg-1, 0);
2033 if (strstr(buffer, "POST /test5") ||
2034 strstr(buffer, "RPC_IN_DATA /test5") ||
2035 strstr(buffer, "RPC_OUT_DATA /test5"))
2037 if (strstr(buffer, "Content-Length: 0"))
2039 send(c, okmsg, sizeof okmsg-1, 0);
2040 send(c, page1, sizeof page1-1, 0);
2042 else
2043 send(c, notokmsg, sizeof notokmsg-1, 0);
2045 if (strstr(buffer, "GET /test6"))
2047 send(c, contmsg, sizeof contmsg-1, 0);
2048 send(c, contmsg, sizeof contmsg-1, 0);
2049 send(c, okmsg, sizeof okmsg-1, 0);
2050 send(c, page1, sizeof page1-1, 0);
2052 if (strstr(buffer, "POST /test7"))
2054 if (strstr(buffer, "Content-Length: 100"))
2056 send(c, okmsg, sizeof okmsg-1, 0);
2057 send(c, page1, sizeof page1-1, 0);
2059 else
2060 send(c, notokmsg, sizeof notokmsg-1, 0);
2062 if (strstr(buffer, "/test8"))
2064 if (!strstr(buffer, "Connection: Close") &&
2065 strstr(buffer, "Connection: Keep-Alive") &&
2066 !strstr(buffer, "Cache-Control: no-cache") &&
2067 !strstr(buffer, "Pragma: no-cache") &&
2068 strstr(buffer, host_header))
2069 send(c, okmsg, sizeof okmsg-1, 0);
2070 else
2071 send(c, notokmsg, sizeof notokmsg-1, 0);
2073 if (strstr(buffer, "/test9"))
2075 if (!strstr(buffer, "Connection: Close") &&
2076 !strstr(buffer, "Connection: Keep-Alive") &&
2077 !strstr(buffer, "Cache-Control: no-cache") &&
2078 !strstr(buffer, "Pragma: no-cache") &&
2079 strstr(buffer, host_header))
2080 send(c, okmsg, sizeof okmsg-1, 0);
2081 else
2082 send(c, notokmsg, sizeof notokmsg-1, 0);
2084 if (strstr(buffer, "/testA"))
2086 if (!strstr(buffer, "Connection: Close") &&
2087 !strstr(buffer, "Connection: Keep-Alive") &&
2088 (strstr(buffer, "Cache-Control: no-cache") ||
2089 strstr(buffer, "Pragma: no-cache")) &&
2090 strstr(buffer, host_header))
2091 send(c, okmsg, sizeof okmsg-1, 0);
2092 else
2093 send(c, notokmsg, sizeof notokmsg-1, 0);
2095 if (!test_b && strstr(buffer, "/testB HTTP/1.1"))
2097 test_b = 1;
2098 send(c, okmsg, sizeof okmsg-1, 0);
2099 recvfrom(c, buffer, sizeof buffer, 0, NULL, NULL);
2100 send(c, okmsg, sizeof okmsg-1, 0);
2102 if (strstr(buffer, "/testC"))
2104 if (strstr(buffer, "Cookie: cookie=biscuit"))
2105 send(c, okmsg, sizeof okmsg-1, 0);
2106 else
2107 send(c, notokmsg, sizeof notokmsg-1, 0);
2109 if (strstr(buffer, "/testD"))
2111 send(c, okmsg2, sizeof okmsg2-1, 0);
2113 if (strstr(buffer, "/testE"))
2115 send(c, noauthmsg2, sizeof noauthmsg2-1, 0);
2117 if (strstr(buffer, "GET /quit"))
2119 send(c, okmsg, sizeof okmsg-1, 0);
2120 send(c, page1, sizeof page1-1, 0);
2121 last_request = 1;
2123 if (strstr(buffer, "GET /testF"))
2125 send(c, expandcontmsg, sizeof expandcontmsg-1, 0);
2126 send(c, garbagemsg, sizeof garbagemsg-1, 0);
2127 send(c, contmsg, sizeof contmsg-1, 0);
2128 send(c, garbagemsg, sizeof garbagemsg-1, 0);
2129 send(c, okmsg, sizeof okmsg-1, 0);
2130 send(c, page1, sizeof page1-1, 0);
2132 if (strstr(buffer, "GET /testG"))
2134 send(c, page1, sizeof page1-1, 0);
2137 if (strstr(buffer, "GET /testJ"))
2139 if (count == 0)
2141 count++;
2142 send(c, ok_with_length, sizeof(ok_with_length)-1, 0);
2144 else
2146 send(c, ok_with_length2, sizeof(ok_with_length2)-1, 0);
2147 count = 0;
2151 if (strstr(buffer, "GET /test_no_content"))
2153 static const char nocontentmsg[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2154 send(c, nocontentmsg, sizeof(nocontentmsg)-1, 0);
2156 if (strstr(buffer, "GET /test_conn_close"))
2158 static const char conn_close_response[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2159 send(c, conn_close_response, sizeof(conn_close_response)-1, 0);
2160 WaitForSingleObject(conn_close_event, INFINITE);
2161 trace("closing connection\n");
2163 if (strstr(buffer, "GET /test_cache_control_no_cache"))
2165 static const char no_cache_response[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2166 if(!test_no_cache++)
2167 send(c, no_cache_response, sizeof(no_cache_response)-1, 0);
2168 else
2169 send(c, okmsg, sizeof(okmsg)-1, 0);
2171 if (strstr(buffer, "GET /test_cache_control_no_store"))
2173 static const char no_cache_response[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2174 send(c, no_cache_response, sizeof(no_cache_response)-1, 0);
2176 if (strstr(buffer, "GET /test_cache_gzip"))
2178 static const char gzip_response[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2179 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2180 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2181 if(!test_cache_gzip++)
2182 send(c, gzip_response, sizeof(gzip_response), 0);
2183 else
2184 send(c, notokmsg, sizeof(notokmsg)-1, 0);
2186 if (strstr(buffer, "GET /send_from_buffer"))
2187 send(c, send_buffer, strlen(send_buffer), 0);
2188 if (strstr(buffer, "/test_cache_control_verb"))
2190 if (!memcmp(buffer, "GET ", sizeof("GET ")-1) &&
2191 !strstr(buffer, "Cache-Control: no-cache\r\n")) send(c, okmsg, sizeof(okmsg)-1, 0);
2192 else if (strstr(buffer, "Cache-Control: no-cache\r\n")) send(c, okmsg, sizeof(okmsg)-1, 0);
2193 send(c, notokmsg, sizeof(notokmsg)-1, 0);
2195 if (strstr(buffer, "GET /test_premature_disconnect"))
2196 trace("closing connection\n");
2198 shutdown(c, 2);
2199 closesocket(c);
2200 } while (!last_request);
2202 closesocket(s);
2204 return 0;
2207 static void test_basic_request(int port, const char *verb, const char *url)
2209 HINTERNET hi, hc, hr;
2210 DWORD r, count;
2211 char buffer[0x100];
2213 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2214 ok(hi != NULL, "open failed\n");
2216 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2217 ok(hc != NULL, "connect failed\n");
2219 hr = HttpOpenRequestA(hc, verb, url, NULL, NULL, NULL, 0, 0);
2220 ok(hr != NULL, "HttpOpenRequest failed\n");
2222 r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
2223 ok(r, "HttpSendRequest failed\n");
2225 count = 0;
2226 memset(buffer, 0, sizeof buffer);
2227 SetLastError(0xdeadbeef);
2228 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
2229 ok(r, "InternetReadFile failed %u\n", GetLastError());
2230 ok(count == sizeof page1 - 1, "count was wrong\n");
2231 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong, got: %s\n", buffer);
2233 InternetCloseHandle(hr);
2234 InternetCloseHandle(hc);
2235 InternetCloseHandle(hi);
2238 static void test_last_error(int port)
2240 HINTERNET hi, hc, hr;
2241 DWORD error;
2242 BOOL r;
2244 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2245 ok(hi != NULL, "open failed\n");
2247 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2248 ok(hc != NULL, "connect failed\n");
2250 hr = HttpOpenRequestA(hc, NULL, "/test1", NULL, NULL, NULL, 0, 0);
2251 ok(hr != NULL, "HttpOpenRequest failed\n");
2253 SetLastError(0xdeadbeef);
2254 r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
2255 error = GetLastError();
2256 ok(r, "HttpSendRequest failed\n");
2257 ok(error == ERROR_SUCCESS || broken(error != ERROR_SUCCESS), "expected ERROR_SUCCESS, got %u\n", error);
2259 InternetCloseHandle(hr);
2260 InternetCloseHandle(hc);
2261 InternetCloseHandle(hi);
2264 static void test_proxy_indirect(int port)
2266 HINTERNET hi, hc, hr;
2267 DWORD r, sz;
2268 char buffer[0x40];
2270 hi = InternetOpenA(NULL, 0, NULL, NULL, 0);
2271 ok(hi != NULL, "open failed\n");
2273 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2274 ok(hc != NULL, "connect failed\n");
2276 hr = HttpOpenRequestA(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
2277 ok(hr != NULL, "HttpOpenRequest failed\n");
2279 r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
2280 ok(r, "HttpSendRequest failed %u\n", GetLastError());
2282 sz = sizeof buffer;
2283 r = HttpQueryInfoA(hr, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL);
2284 ok(r || GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo failed: %d\n", GetLastError());
2285 if (!r)
2287 skip("missing proxy header, not testing remaining proxy headers\n");
2288 goto out;
2290 ok(!strcmp(buffer, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2292 test_status_code(hr, 407);
2293 test_request_flags(hr, 0);
2295 sz = sizeof buffer;
2296 r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL);
2297 ok(r, "HttpQueryInfo failed\n");
2298 ok(!strcmp(buffer, "Proxy Authentication Required"), "proxy text wrong\n");
2300 sz = sizeof buffer;
2301 r = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &sz, NULL);
2302 ok(r, "HttpQueryInfo failed\n");
2303 ok(!strcmp(buffer, "HTTP/1.1"), "http version wrong\n");
2305 sz = sizeof buffer;
2306 r = HttpQueryInfoA(hr, HTTP_QUERY_SERVER, buffer, &sz, NULL);
2307 ok(r, "HttpQueryInfo failed\n");
2308 ok(!strcmp(buffer, "winetest"), "http server wrong\n");
2310 sz = sizeof buffer;
2311 r = HttpQueryInfoA(hr, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL);
2312 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo should fail\n");
2313 ok(r == FALSE, "HttpQueryInfo failed\n");
2315 out:
2316 InternetCloseHandle(hr);
2317 InternetCloseHandle(hc);
2318 InternetCloseHandle(hi);
2321 static void test_proxy_direct(int port)
2323 HINTERNET hi, hc, hr;
2324 DWORD r, sz, error;
2325 char buffer[0x40], *url;
2326 WCHAR bufferW[0x40];
2327 static CHAR username[] = "mike",
2328 password[] = "1101",
2329 useragent[] = "winetest",
2330 url_fmt[] = "http://test.winehq.org:%u/test2";
2331 static WCHAR usernameW[] = {'m','i','k','e',0},
2332 passwordW[] = {'1','1','0','1',0},
2333 useragentW[] = {'w','i','n','e','t','e','s','t',0};
2335 /* specify proxy type without the proxy and bypass */
2336 SetLastError(0xdeadbeef);
2337 hi = InternetOpenW(NULL, INTERNET_OPEN_TYPE_PROXY, NULL, NULL, 0);
2338 error = GetLastError();
2339 ok(error == ERROR_INVALID_PARAMETER ||
2340 broken(error == ERROR_SUCCESS) /* WinXPProSP2 */, "got %u\n", error);
2341 ok(hi == NULL || broken(!!hi) /* WinXPProSP2 */, "open should have failed\n");
2343 sprintf(buffer, "localhost:%d\n", port);
2344 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0);
2345 ok(hi != NULL, "open failed\n");
2347 /* try connect without authorization */
2348 hc = InternetConnectA(hi, "test.winehq.org", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2349 ok(hc != NULL, "connect failed\n");
2351 hr = HttpOpenRequestA(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
2352 ok(hr != NULL, "HttpOpenRequest failed\n");
2354 sz = 0;
2355 SetLastError(0xdeadbeef);
2356 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, NULL, &sz);
2357 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2358 ok(!r, "unexpected success\n");
2359 ok(sz == 1, "got %u\n", sz);
2361 sz = 0;
2362 SetLastError(0xdeadbeef);
2363 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, NULL, &sz);
2364 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2365 ok(!r, "unexpected success\n");
2366 ok(sz == 1, "got %u\n", sz);
2368 sz = sizeof(buffer);
2369 SetLastError(0xdeadbeef);
2370 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz);
2371 ok(r, "unexpected failure %u\n", GetLastError());
2372 ok(!sz, "got %u\n", sz);
2374 sz = sizeof(buffer);
2375 SetLastError(0xdeadbeef);
2376 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2377 ok(r, "unexpected failure %u\n", GetLastError());
2378 ok(!sz, "got %u\n", sz);
2380 sz = 0;
2381 SetLastError(0xdeadbeef);
2382 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, NULL, &sz);
2383 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2384 ok(!r, "unexpected success\n");
2385 ok(sz == 1, "got %u\n", sz);
2387 sz = 0;
2388 SetLastError(0xdeadbeef);
2389 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, NULL, &sz);
2390 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2391 ok(!r, "unexpected success\n");
2392 ok(sz == 1, "got %u\n", sz);
2394 sz = sizeof(buffer);
2395 SetLastError(0xdeadbeef);
2396 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz);
2397 ok(r, "unexpected failure %u\n", GetLastError());
2398 ok(!sz, "got %u\n", sz);
2400 sz = sizeof(buffer);
2401 SetLastError(0xdeadbeef);
2402 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz);
2403 ok(r, "unexpected failure %u\n", GetLastError());
2404 ok(!sz, "got %u\n", sz);
2406 sz = 0;
2407 SetLastError(0xdeadbeef);
2408 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, NULL, &sz);
2409 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2410 ok(!r, "unexpected success\n");
2411 ok(sz == 34, "got %u\n", sz);
2413 sz = sizeof(buffer);
2414 SetLastError(0xdeadbeef);
2415 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz);
2416 ok(r, "unexpected failure %u\n", GetLastError());
2417 ok(sz == 33, "got %u\n", sz);
2419 r = HttpSendRequestW(hr, NULL, 0, NULL, 0);
2420 ok(r || broken(!r), "HttpSendRequest failed %u\n", GetLastError());
2421 if (!r)
2423 win_skip("skipping proxy tests on broken wininet\n");
2424 goto done;
2427 test_status_code(hr, 407);
2429 /* set the user + password then try again */
2430 r = InternetSetOptionA(hi, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2431 ok(!r, "unexpected success\n");
2433 r = InternetSetOptionA(hc, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2434 ok(r, "failed to set user\n");
2436 r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, username, 4);
2437 ok(r, "failed to set user\n");
2439 buffer[0] = 0;
2440 sz = 3;
2441 SetLastError(0xdeadbeef);
2442 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2443 ok(!r, "unexpected failure %u\n", GetLastError());
2444 ok(!buffer[0], "got %s\n", buffer);
2445 ok(sz == strlen(username) + 1, "got %u\n", sz);
2447 buffer[0] = 0;
2448 sz = 0;
2449 SetLastError(0xdeadbeef);
2450 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2451 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2452 ok(!r, "unexpected success\n");
2453 ok(sz == strlen(username) + 1, "got %u\n", sz);
2455 bufferW[0] = 0;
2456 sz = 0;
2457 SetLastError(0xdeadbeef);
2458 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_USERNAME, bufferW, &sz);
2459 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2460 ok(!r, "unexpected success\n");
2461 ok(sz == (lstrlenW(usernameW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2463 buffer[0] = 0;
2464 sz = sizeof(buffer);
2465 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2466 ok(r, "failed to get username\n");
2467 ok(!strcmp(buffer, username), "got %s\n", buffer);
2468 ok(sz == strlen(username), "got %u\n", sz);
2470 buffer[0] = 0;
2471 sz = sizeof(bufferW);
2472 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_USERNAME, bufferW, &sz);
2473 ok(r, "failed to get username\n");
2474 ok(!lstrcmpW(bufferW, usernameW), "wrong username\n");
2475 ok(sz == lstrlenW(usernameW), "got %u\n", sz);
2477 r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, username, 1);
2478 ok(r, "failed to set user\n");
2480 buffer[0] = 0;
2481 sz = sizeof(buffer);
2482 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_USERNAME, buffer, &sz);
2483 ok(r, "failed to get username\n");
2484 ok(!strcmp(buffer, username), "got %s\n", buffer);
2485 ok(sz == strlen(username), "got %u\n", sz);
2487 r = InternetSetOptionA(hi, INTERNET_OPTION_USER_AGENT, useragent, 1);
2488 ok(r, "failed to set useragent\n");
2490 buffer[0] = 0;
2491 sz = 0;
2492 SetLastError(0xdeadbeef);
2493 r = InternetQueryOptionA(hi, INTERNET_OPTION_USER_AGENT, buffer, &sz);
2494 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2495 ok(!r, "unexpected success\n");
2496 ok(sz == strlen(useragent) + 1, "got %u\n", sz);
2498 buffer[0] = 0;
2499 sz = sizeof(buffer);
2500 r = InternetQueryOptionA(hi, INTERNET_OPTION_USER_AGENT, buffer, &sz);
2501 ok(r, "failed to get user agent\n");
2502 ok(!strcmp(buffer, useragent), "got %s\n", buffer);
2503 ok(sz == strlen(useragent), "got %u\n", sz);
2505 bufferW[0] = 0;
2506 sz = 0;
2507 SetLastError(0xdeadbeef);
2508 r = InternetQueryOptionW(hi, INTERNET_OPTION_USER_AGENT, bufferW, &sz);
2509 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2510 ok(!r, "unexpected success\n");
2511 ok(sz == (lstrlenW(useragentW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2513 bufferW[0] = 0;
2514 sz = sizeof(bufferW);
2515 r = InternetQueryOptionW(hi, INTERNET_OPTION_USER_AGENT, bufferW, &sz);
2516 ok(r, "failed to get user agent\n");
2517 ok(!lstrcmpW(bufferW, useragentW), "wrong user agent\n");
2518 ok(sz == lstrlenW(useragentW), "got %u\n", sz);
2520 r = InternetSetOptionA(hr, INTERNET_OPTION_USERNAME, username, 1);
2521 ok(r, "failed to set user\n");
2523 buffer[0] = 0;
2524 sz = 0;
2525 SetLastError(0xdeadbeef);
2526 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz);
2527 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2528 ok(!r, "unexpected success\n");
2529 ok(sz == strlen(username) + 1, "got %u\n", sz);
2531 buffer[0] = 0;
2532 sz = sizeof(buffer);
2533 r = InternetQueryOptionA(hr, INTERNET_OPTION_USERNAME, buffer, &sz);
2534 ok(r, "failed to get user\n");
2535 ok(!strcmp(buffer, username), "got %s\n", buffer);
2536 ok(sz == strlen(username), "got %u\n", sz);
2538 bufferW[0] = 0;
2539 sz = 0;
2540 SetLastError(0xdeadbeef);
2541 r = InternetQueryOptionW(hr, INTERNET_OPTION_USERNAME, bufferW, &sz);
2542 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2543 ok(!r, "unexpected success\n");
2544 ok(sz == (lstrlenW(usernameW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2546 bufferW[0] = 0;
2547 sz = sizeof(bufferW);
2548 r = InternetQueryOptionW(hr, INTERNET_OPTION_USERNAME, bufferW, &sz);
2549 ok(r, "failed to get user\n");
2550 ok(!lstrcmpW(bufferW, usernameW), "wrong user\n");
2551 ok(sz == lstrlenW(usernameW), "got %u\n", sz);
2553 r = InternetSetOptionA(hr, INTERNET_OPTION_PASSWORD, password, 1);
2554 ok(r, "failed to set password\n");
2556 buffer[0] = 0;
2557 sz = 0;
2558 SetLastError(0xdeadbeef);
2559 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz);
2560 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2561 ok(!r, "unexpected success\n");
2562 ok(sz == strlen(password) + 1, "got %u\n", sz);
2564 buffer[0] = 0;
2565 sz = sizeof(buffer);
2566 r = InternetQueryOptionA(hr, INTERNET_OPTION_PASSWORD, buffer, &sz);
2567 ok(r, "failed to get password\n");
2568 ok(!strcmp(buffer, password), "got %s\n", buffer);
2569 ok(sz == strlen(password), "got %u\n", sz);
2571 bufferW[0] = 0;
2572 sz = 0;
2573 SetLastError(0xdeadbeef);
2574 r = InternetQueryOptionW(hr, INTERNET_OPTION_PASSWORD, bufferW, &sz);
2575 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2576 ok(!r, "unexpected success\n");
2577 ok(sz == (lstrlenW(passwordW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2579 bufferW[0] = 0;
2580 sz = sizeof(bufferW);
2581 r = InternetQueryOptionW(hr, INTERNET_OPTION_PASSWORD, bufferW, &sz);
2582 ok(r, "failed to get password\n");
2583 ok(!lstrcmpW(bufferW, passwordW), "wrong password\n");
2584 ok(sz == lstrlenW(passwordW), "got %u\n", sz);
2586 url = HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt) + 11);
2587 sprintf(url, url_fmt, port);
2588 buffer[0] = 0;
2589 sz = 0;
2590 SetLastError(0xdeadbeef);
2591 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz);
2592 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2593 ok(!r, "unexpected success\n");
2594 ok(sz == strlen(url) + 1, "got %u\n", sz);
2596 buffer[0] = 0;
2597 sz = sizeof(buffer);
2598 r = InternetQueryOptionA(hr, INTERNET_OPTION_URL, buffer, &sz);
2599 ok(r, "failed to get url\n");
2600 ok(!strcmp(buffer, url), "got %s\n", buffer);
2601 ok(sz == strlen(url), "got %u\n", sz);
2603 bufferW[0] = 0;
2604 sz = 0;
2605 SetLastError(0xdeadbeef);
2606 r = InternetQueryOptionW(hr, INTERNET_OPTION_URL, bufferW, &sz);
2607 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2608 ok(!r, "unexpected success\n");
2609 ok(sz == (strlen(url) + 1) * sizeof(WCHAR), "got %u\n", sz);
2611 bufferW[0] = 0;
2612 sz = sizeof(bufferW);
2613 r = InternetQueryOptionW(hr, INTERNET_OPTION_URL, bufferW, &sz);
2614 ok(r, "failed to get url\n");
2615 ok(!strcmp_wa(bufferW, url), "wrong url\n");
2616 ok(sz == strlen(url), "got %u\n", sz);
2617 HeapFree(GetProcessHeap(), 0, url);
2619 r = InternetSetOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, password, 4);
2620 ok(r, "failed to set password\n");
2622 buffer[0] = 0;
2623 sz = 0;
2624 SetLastError(0xdeadbeef);
2625 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz);
2626 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2627 ok(!r, "unexpected success\n");
2628 ok(sz == strlen(password) + 1, "got %u\n", sz);
2630 buffer[0] = 0;
2631 sz = sizeof(buffer);
2632 r = InternetQueryOptionA(hr, INTERNET_OPTION_PROXY_PASSWORD, buffer, &sz);
2633 ok(r, "failed to get password\n");
2634 ok(!strcmp(buffer, password), "got %s\n", buffer);
2635 ok(sz == strlen(password), "got %u\n", sz);
2637 bufferW[0] = 0;
2638 sz = 0;
2639 SetLastError(0xdeadbeef);
2640 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_PASSWORD, bufferW, &sz);
2641 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %u\n", GetLastError());
2642 ok(!r, "unexpected success\n");
2643 ok(sz == (lstrlenW(passwordW) + 1) * sizeof(WCHAR), "got %u\n", sz);
2645 bufferW[0] = 0;
2646 sz = sizeof(bufferW);
2647 r = InternetQueryOptionW(hr, INTERNET_OPTION_PROXY_PASSWORD, bufferW, &sz);
2648 ok(r, "failed to get password\n");
2649 ok(!lstrcmpW(bufferW, passwordW), "wrong password\n");
2650 ok(sz == lstrlenW(passwordW), "got %u\n", sz);
2652 r = HttpSendRequestW(hr, NULL, 0, NULL, 0);
2653 if (!r)
2655 win_skip("skipping proxy tests on broken wininet\n");
2656 goto done;
2658 ok(r, "HttpSendRequest failed %u\n", GetLastError());
2659 sz = sizeof buffer;
2660 r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
2661 ok(r, "HttpQueryInfo failed\n");
2662 ok(!strcmp(buffer, "200"), "proxy code wrong\n");
2664 done:
2665 InternetCloseHandle(hr);
2666 InternetCloseHandle(hc);
2667 InternetCloseHandle(hi);
2670 static void test_header_handling_order(int port)
2672 static char authorization[] = "Authorization: Basic dXNlcjpwd2Q=";
2673 static char connection[] = "Connection: Close";
2675 static const char *types[2] = { "*", NULL };
2676 HINTERNET session, connect, request;
2677 DWORD size, status;
2678 BOOL ret;
2680 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2681 ok(session != NULL, "InternetOpen failed\n");
2683 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2684 ok(connect != NULL, "InternetConnect failed\n");
2686 request = HttpOpenRequestA(connect, NULL, "/test3", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2687 ok(request != NULL, "HttpOpenRequest failed\n");
2689 ret = HttpAddRequestHeadersA(request, authorization, ~0u, HTTP_ADDREQ_FLAG_ADD);
2690 ok(ret, "HttpAddRequestHeaders failed\n");
2692 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
2693 ok(ret, "HttpSendRequest failed\n");
2695 test_status_code(request, 200);
2696 test_request_flags(request, 0);
2698 InternetCloseHandle(request);
2700 request = HttpOpenRequestA(connect, NULL, "/test4", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2701 ok(request != NULL, "HttpOpenRequest failed\n");
2703 ret = HttpSendRequestA(request, connection, ~0u, NULL, 0);
2704 ok(ret, "HttpSendRequest failed\n");
2706 status = 0;
2707 size = sizeof(status);
2708 ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2709 ok(ret, "HttpQueryInfo failed\n");
2710 ok(status == 200 || status == 400 /* IE6 */, "got status %u, expected 200 or 400\n", status);
2712 InternetCloseHandle(request);
2714 request = HttpOpenRequestA(connect, "POST", "/test7", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2715 ok(request != NULL, "HttpOpenRequest failed\n");
2717 ret = HttpAddRequestHeadersA(request, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
2718 ok(ret, "HttpAddRequestHeaders failed\n");
2720 ret = HttpSendRequestA(request, connection, ~0u, NULL, 0);
2721 ok(ret, "HttpSendRequest failed\n");
2723 status = 0;
2724 size = sizeof(status);
2725 ret = HttpQueryInfoA( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2726 ok(ret, "HttpQueryInfo failed\n");
2727 ok(status == 200 || status == 400 /* IE6 */, "got status %u, expected 200 or 400\n", status);
2729 InternetCloseHandle(request);
2730 InternetCloseHandle(connect);
2731 InternetCloseHandle(session);
2734 static void test_connection_header(int port)
2736 HINTERNET ses, con, req;
2737 BOOL ret;
2739 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2740 ok(ses != NULL, "InternetOpen failed\n");
2742 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2743 ok(con != NULL, "InternetConnect failed\n");
2745 req = HttpOpenRequestA(con, NULL, "/test8", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2746 ok(req != NULL, "HttpOpenRequest failed\n");
2748 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2749 ok(ret, "HttpSendRequest failed\n");
2751 test_status_code(req, 200);
2753 InternetCloseHandle(req);
2755 req = HttpOpenRequestA(con, NULL, "/test9", NULL, NULL, NULL, 0, 0);
2756 ok(req != NULL, "HttpOpenRequest failed\n");
2758 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2759 ok(ret, "HttpSendRequest failed\n");
2761 test_status_code(req, 200);
2763 InternetCloseHandle(req);
2765 req = HttpOpenRequestA(con, NULL, "/test9", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
2766 ok(req != NULL, "HttpOpenRequest failed\n");
2768 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2769 ok(ret, "HttpSendRequest failed\n");
2771 test_status_code(req, 200);
2773 InternetCloseHandle(req);
2775 req = HttpOpenRequestA(con, "POST", "/testA", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
2776 ok(req != NULL, "HttpOpenRequest failed\n");
2778 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2779 ok(ret, "HttpSendRequest failed\n");
2781 test_status_code(req, 200);
2783 InternetCloseHandle(req);
2784 InternetCloseHandle(con);
2785 InternetCloseHandle(ses);
2788 static void test_http1_1(int port)
2790 HINTERNET ses, con, req;
2791 BOOL ret;
2793 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2794 ok(ses != NULL, "InternetOpen failed\n");
2796 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2797 ok(con != NULL, "InternetConnect failed\n");
2799 req = HttpOpenRequestA(con, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2800 ok(req != NULL, "HttpOpenRequest failed\n");
2802 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2803 if (ret)
2805 InternetCloseHandle(req);
2807 req = HttpOpenRequestA(con, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2808 ok(req != NULL, "HttpOpenRequest failed\n");
2810 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
2811 ok(ret, "HttpSendRequest failed\n");
2814 InternetCloseHandle(req);
2815 InternetCloseHandle(con);
2816 InternetCloseHandle(ses);
2819 static void test_connection_closing(int port)
2821 HINTERNET session, connection, req;
2822 DWORD res;
2824 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
2826 session = InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
2827 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
2829 pInternetSetStatusCallbackA(session, callback);
2831 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2832 connection = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
2833 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
2834 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2836 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2837 req = HttpOpenRequestA(connection, "GET", "/testJ", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0xdeadbeaf);
2838 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
2839 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2841 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
2842 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
2843 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
2844 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
2845 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
2846 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
2847 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
2848 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
2849 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION);
2850 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED);
2851 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2853 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
2854 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2855 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2856 WaitForSingleObject(hCompleteEvent, INFINITE);
2857 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2859 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
2860 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
2861 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
2862 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
2863 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
2864 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
2865 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
2866 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
2867 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
2868 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
2869 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
2871 test_status_code(req, 200);
2873 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
2874 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
2875 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
2876 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
2877 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
2878 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
2879 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
2880 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
2881 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2883 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
2884 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2885 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2886 WaitForSingleObject(hCompleteEvent, INFINITE);
2887 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2889 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
2890 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
2891 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
2892 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
2893 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
2894 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
2895 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
2896 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
2897 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
2899 test_status_code(req, 210);
2901 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
2902 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
2903 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
2904 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
2905 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
2906 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
2907 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
2908 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
2909 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION);
2910 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED);
2911 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2913 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
2914 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2915 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2916 WaitForSingleObject(hCompleteEvent, INFINITE);
2917 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2919 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
2920 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
2921 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
2922 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
2923 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
2924 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
2925 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
2926 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
2927 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
2928 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
2929 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
2931 test_status_code(req, 200);
2933 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION);
2934 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED);
2936 close_async_handle(session, hCompleteEvent, 2);
2937 CloseHandle(hCompleteEvent);
2941 static void test_no_content(int port)
2943 HINTERNET session, connection, req;
2944 DWORD res;
2946 trace("Testing 204 no content response...\n");
2948 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
2950 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
2951 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
2953 pInternetSetStatusCallbackA(session, callback);
2955 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2956 connection = InternetConnectA(session, "localhost", port,
2957 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
2958 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
2959 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2961 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2962 req = HttpOpenRequestA(connection, "GET", "/test_no_content", NULL, NULL, NULL,
2963 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
2964 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
2965 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2967 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
2968 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
2969 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
2970 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
2971 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
2972 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
2973 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
2974 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
2975 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
2976 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2978 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
2979 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2980 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2981 WaitForSingleObject(hCompleteEvent, INFINITE);
2982 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2984 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
2985 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
2986 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
2987 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
2988 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
2989 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
2990 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
2991 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
2992 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
2993 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
2995 close_async_handle(session, hCompleteEvent, 2);
2996 CloseHandle(hCompleteEvent);
2999 static void test_conn_close(int port)
3001 HINTERNET session, connection, req;
3002 DWORD res, avail, size;
3003 BYTE buf[1024];
3005 trace("Testing connection close connection...\n");
3007 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
3008 conn_close_event = CreateEventW(NULL, FALSE, FALSE, NULL);
3010 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
3011 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
3013 pInternetSetStatusCallbackA(session, callback);
3015 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3016 connection = InternetConnectA(session, "localhost", port,
3017 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
3018 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
3019 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3021 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
3022 req = HttpOpenRequestA(connection, "GET", "/test_conn_close", NULL, NULL, NULL,
3023 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
3024 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
3025 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
3027 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
3028 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
3029 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
3030 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
3031 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
3032 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
3033 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
3034 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3036 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
3037 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3038 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3039 WaitForSingleObject(hCompleteEvent, INFINITE);
3040 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3042 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
3043 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
3044 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
3045 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
3046 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
3047 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
3048 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
3049 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3051 avail = 0;
3052 res = InternetQueryDataAvailable(req, &avail, 0, 0);
3053 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3054 ok(avail != 0, "avail = 0\n");
3056 size = 0;
3057 res = InternetReadFile(req, buf, avail, &size);
3058 ok(res, "InternetReadFile failed: %u\n", GetLastError());
3060 res = InternetQueryDataAvailable(req, &avail, 0, 0);
3061 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3062 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3063 ok(!avail, "avail = %u, expected 0\n", avail);
3065 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
3066 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
3067 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
3068 SetEvent(conn_close_event);
3069 WaitForSingleObject(hCompleteEvent, INFINITE);
3070 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
3071 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
3072 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
3073 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
3075 close_async_handle(session, hCompleteEvent, 2);
3076 CloseHandle(hCompleteEvent);
3079 static void test_no_cache(int port)
3081 static const char cache_control_no_cache[] = "/test_cache_control_no_cache";
3082 static const char cache_control_no_store[] = "/test_cache_control_no_store";
3083 static const char cache_url_fmt[] = "http://localhost:%d%s";
3085 char cache_url[256], buf[256];
3086 HINTERNET ses, con, req;
3087 DWORD read, size;
3088 BOOL ret;
3090 trace("Testing no-cache header\n");
3092 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3093 ok(ses != NULL,"InternetOpen failed with error %u\n", GetLastError());
3095 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3096 ok(con != NULL, "InternetConnect failed with error %u\n", GetLastError());
3098 req = HttpOpenRequestA(con, NULL, cache_control_no_cache, NULL, NULL, NULL, 0, 0);
3099 ok(req != NULL, "HttpOpenRequest failed\n");
3101 sprintf(cache_url, cache_url_fmt, port, cache_control_no_cache);
3102 DeleteUrlCacheEntryA(cache_url);
3104 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3105 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3106 size = 0;
3107 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
3108 size += read;
3109 ok(size == 12, "read %d bytes of data\n", size);
3110 InternetCloseHandle(req);
3112 req = HttpOpenRequestA(con, NULL, cache_control_no_cache, NULL, NULL, NULL, 0, 0);
3113 ok(req != NULL, "HttpOpenRequest failed\n");
3115 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3116 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3117 size = 0;
3118 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
3119 size += read;
3120 ok(size == 0, "read %d bytes of data\n", size);
3121 InternetCloseHandle(req);
3122 DeleteUrlCacheEntryA(cache_url);
3124 req = HttpOpenRequestA(con, NULL, cache_control_no_store, NULL, NULL, NULL, 0, 0);
3125 ok(req != NULL, "HttpOpenRequest failed\n");
3127 sprintf(cache_url, cache_url_fmt, port, cache_control_no_store);
3128 DeleteUrlCacheEntryA(cache_url);
3130 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3131 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3132 size = 0;
3133 while(InternetReadFile(req, buf, sizeof(buf), &read) && read)
3134 size += read;
3135 ok(size == 12, "read %d bytes of data\n", size);
3136 InternetCloseHandle(req);
3138 ret = DeleteUrlCacheEntryA(cache_url);
3139 ok(!ret && GetLastError()==ERROR_FILE_NOT_FOUND, "cache entry should not exist\n");
3141 InternetCloseHandle(con);
3142 InternetCloseHandle(ses);
3145 static void test_cache_read_gzipped(int port)
3147 static const char cache_url_fmt[] = "http://localhost:%d%s";
3148 static const char get_gzip[] = "/test_cache_gzip";
3149 static const char content[] = "gzip test\n";
3150 static const char text_html[] = "text/html";
3151 static const char raw_header[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3153 HINTERNET ses, con, req;
3154 DWORD read, size;
3155 char cache_url[256], buf[256];
3156 BOOL ret;
3158 trace("Testing reading compressed content from cache\n");
3160 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3161 ok(ses != NULL,"InternetOpen failed with error %u\n", GetLastError());
3163 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3164 ok(con != NULL, "InternetConnect failed with error %u\n", GetLastError());
3166 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, 0, 0);
3167 ok(req != NULL, "HttpOpenRequest failed\n");
3169 ret = TRUE;
3170 ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
3171 if(!ret && GetLastError()==ERROR_INTERNET_INVALID_OPTION) {
3172 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3173 InternetCloseHandle(req);
3174 InternetCloseHandle(con);
3175 InternetCloseHandle(ses);
3176 return;
3178 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3180 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3181 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3182 size = 0;
3183 while(InternetReadFile(req, buf+size, sizeof(buf)-size, &read) && read)
3184 size += read;
3185 ok(size == 10, "read %d bytes of data\n", size);
3186 buf[size] = 0;
3187 ok(!strncmp(buf, content, size), "incorrect page content: %s\n", buf);
3189 size = sizeof(buf)-1;
3190 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_TYPE, buf, &size, 0);
3191 ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3192 buf[size] = 0;
3193 ok(!strncmp(text_html, buf, size), "buf = %s\n", buf);
3195 size = sizeof(buf)-1;
3196 ret = HttpQueryInfoA(req, HTTP_QUERY_RAW_HEADERS_CRLF, buf, &size, 0);
3197 ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3198 buf[size] = 0;
3199 ok(!strncmp(raw_header, buf, size), "buf = %s\n", buf);
3200 InternetCloseHandle(req);
3202 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
3203 ok(req != NULL, "HttpOpenRequest failed\n");
3205 ret = TRUE;
3206 ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
3207 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3209 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3210 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3211 size = 0;
3212 while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read)
3213 size += read;
3214 todo_wine ok(size == 10, "read %d bytes of data\n", size);
3215 buf[size] = 0;
3216 ok(!strncmp(buf, content, size), "incorrect page content: %s\n", buf);
3218 size = sizeof(buf);
3219 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
3220 ok(!ret && GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND,
3221 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3222 ret, GetLastError());
3224 size = sizeof(buf)-1;
3225 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_TYPE, buf, &size, 0);
3226 todo_wine ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3227 buf[size] = 0;
3228 todo_wine ok(!strncmp(text_html, buf, size), "buf = %s\n", buf);
3229 InternetCloseHandle(req);
3231 /* Decompression doesn't work while reading from cache */
3232 test_cache_gzip = 0;
3233 sprintf(cache_url, cache_url_fmt, port, get_gzip);
3234 DeleteUrlCacheEntryA(cache_url);
3236 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, 0, 0);
3237 ok(req != NULL, "HttpOpenRequest failed\n");
3239 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3240 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3241 size = 0;
3242 while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read)
3243 size += read;
3244 ok(size == 31, "read %d bytes of data\n", size);
3245 InternetCloseHandle(req);
3247 req = HttpOpenRequestA(con, NULL, get_gzip, NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
3248 ok(req != NULL, "HttpOpenRequest failed\n");
3250 ret = TRUE;
3251 ret = InternetSetOptionA(req, INTERNET_OPTION_HTTP_DECODING, &ret, sizeof(ret));
3252 ok(ret, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3254 ret = HttpSendRequestA(req, "Accept-Encoding: gzip", -1, NULL, 0);
3255 ok(ret, "HttpSendRequest failed with error %u\n", GetLastError());
3256 size = 0;
3257 while(InternetReadFile(req, buf+size, sizeof(buf)-1-size, &read) && read)
3258 size += read;
3259 todo_wine ok(size == 31, "read %d bytes of data\n", size);
3261 size = sizeof(buf);
3262 ret = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
3263 todo_wine ok(ret, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3264 InternetCloseHandle(req);
3266 InternetCloseHandle(con);
3267 InternetCloseHandle(ses);
3269 DeleteUrlCacheEntryA(cache_url);
3272 static void test_HttpSendRequestW(int port)
3274 static const WCHAR header[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3275 HINTERNET ses, con, req;
3276 DWORD error;
3277 BOOL ret;
3279 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
3280 ok(ses != NULL, "InternetOpen failed\n");
3282 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3283 ok(con != NULL, "InternetConnect failed\n");
3285 req = HttpOpenRequestA(con, NULL, "/test1", NULL, NULL, NULL, 0, 0);
3286 ok(req != NULL, "HttpOpenRequest failed\n");
3288 SetLastError(0xdeadbeef);
3289 ret = HttpSendRequestW(req, header, ~0u, NULL, 0);
3290 error = GetLastError();
3291 ok(!ret, "HttpSendRequestW succeeded\n");
3292 ok(error == ERROR_IO_PENDING ||
3293 broken(error == ERROR_HTTP_HEADER_NOT_FOUND) || /* IE6 */
3294 broken(error == ERROR_INVALID_PARAMETER), /* IE5 */
3295 "got %u expected ERROR_IO_PENDING\n", error);
3297 InternetCloseHandle(req);
3298 InternetCloseHandle(con);
3299 InternetCloseHandle(ses);
3302 static void test_cookie_header(int port)
3304 HINTERNET ses, con, req;
3305 DWORD size, error;
3306 BOOL ret;
3307 char buffer[64];
3309 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3310 ok(ses != NULL, "InternetOpen failed\n");
3312 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3313 ok(con != NULL, "InternetConnect failed\n");
3315 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3317 req = HttpOpenRequestA(con, NULL, "/testC", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3318 ok(req != NULL, "HttpOpenRequest failed\n");
3320 buffer[0] = 0;
3321 size = sizeof(buffer);
3322 SetLastError(0xdeadbeef);
3323 ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3324 error = GetLastError();
3325 ok(!ret, "HttpQueryInfo succeeded\n");
3326 ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error);
3328 ret = HttpAddRequestHeadersA(req, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD);
3329 ok(ret, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3331 buffer[0] = 0;
3332 size = sizeof(buffer);
3333 ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3334 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
3335 ok(!strcmp(buffer, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer);
3337 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
3338 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
3340 test_status_code(req, 200);
3342 buffer[0] = 0;
3343 size = sizeof(buffer);
3344 ret = HttpQueryInfoA(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3345 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
3346 ok(!strcmp(buffer, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer);
3348 InternetCloseHandle(req);
3349 InternetCloseHandle(con);
3350 InternetCloseHandle(ses);
3353 static void test_basic_authentication(int port)
3355 HINTERNET session, connect, request;
3356 BOOL ret;
3358 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3359 ok(session != NULL, "InternetOpen failed\n");
3361 connect = InternetConnectA(session, "localhost", port, "user", "pwd", INTERNET_SERVICE_HTTP, 0, 0);
3362 ok(connect != NULL, "InternetConnect failed\n");
3364 request = HttpOpenRequestA(connect, NULL, "/test3", NULL, NULL, NULL, 0, 0);
3365 ok(request != NULL, "HttpOpenRequest failed\n");
3367 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
3368 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
3370 test_status_code(request, 200);
3371 test_request_flags(request, 0);
3373 InternetCloseHandle(request);
3374 InternetCloseHandle(connect);
3375 InternetCloseHandle(session);
3378 static void test_premature_disconnect(int port)
3380 HINTERNET session, connect, request;
3381 DWORD err;
3382 BOOL ret;
3384 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3385 ok(session != NULL, "InternetOpen failed\n");
3387 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3388 ok(connect != NULL, "InternetConnect failed\n");
3390 request = HttpOpenRequestA(connect, NULL, "/premature_disconnect", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
3391 ok(request != NULL, "HttpOpenRequest failed\n");
3393 SetLastError(0xdeadbeef);
3394 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
3395 err = GetLastError();
3396 todo_wine ok(!ret, "HttpSendRequest succeeded\n");
3397 todo_wine ok(err == ERROR_HTTP_INVALID_SERVER_RESPONSE, "got %u\n", err);
3399 InternetCloseHandle(request);
3400 InternetCloseHandle(connect);
3401 InternetCloseHandle(session);
3404 static void test_invalid_response_headers(int port)
3406 HINTERNET session, connect, request;
3407 DWORD size;
3408 BOOL ret;
3409 char buffer[256];
3411 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3412 ok(session != NULL, "InternetOpen failed\n");
3414 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3415 ok(connect != NULL, "InternetConnect failed\n");
3417 request = HttpOpenRequestA(connect, NULL, "/testE", NULL, NULL, NULL, 0, 0);
3418 ok(request != NULL, "HttpOpenRequest failed\n");
3420 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
3421 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
3423 test_status_code(request, 401);
3424 test_request_flags(request, 0);
3426 buffer[0] = 0;
3427 size = sizeof(buffer);
3428 ret = HttpQueryInfoA( request, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
3429 ok(ret, "HttpQueryInfo failed\n");
3430 ok(!strcmp(buffer, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
3431 "headers wrong \"%s\"\n", buffer);
3433 buffer[0] = 0;
3434 size = sizeof(buffer);
3435 ret = HttpQueryInfoA( request, HTTP_QUERY_SERVER, buffer, &size, NULL);
3436 ok(ret, "HttpQueryInfo failed\n");
3437 ok(!strcmp(buffer, "winetest"), "server wrong \"%s\"\n", buffer);
3439 InternetCloseHandle(request);
3440 InternetCloseHandle(connect);
3441 InternetCloseHandle(session);
3444 static void test_response_without_headers(int port)
3446 HINTERNET hi, hc, hr;
3447 DWORD r, count, size;
3448 char buffer[1024];
3450 SetLastError(0xdeadbeef);
3451 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3452 ok(hi != NULL, "open failed %u\n", GetLastError());
3454 SetLastError(0xdeadbeef);
3455 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3456 ok(hc != NULL, "connect failed %u\n", GetLastError());
3458 SetLastError(0xdeadbeef);
3459 hr = HttpOpenRequestA(hc, NULL, "/testG", NULL, NULL, NULL, 0, 0);
3460 ok(hr != NULL, "HttpOpenRequest failed %u\n", GetLastError());
3462 test_request_flags(hr, INTERNET_REQFLAG_NO_HEADERS);
3464 SetLastError(0xdeadbeef);
3465 r = HttpSendRequestA(hr, NULL, 0, NULL, 0);
3466 ok(r, "HttpSendRequest failed %u\n", GetLastError());
3468 test_request_flags_todo(hr, INTERNET_REQFLAG_NO_HEADERS);
3470 count = 0;
3471 memset(buffer, 0, sizeof buffer);
3472 SetLastError(0xdeadbeef);
3473 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
3474 ok(r, "InternetReadFile failed %u\n", GetLastError());
3475 todo_wine ok(count == sizeof page1 - 1, "count was wrong\n");
3476 todo_wine ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
3478 test_status_code(hr, 200);
3479 test_request_flags_todo(hr, INTERNET_REQFLAG_NO_HEADERS);
3481 buffer[0] = 0;
3482 size = sizeof(buffer);
3483 SetLastError(0xdeadbeef);
3484 r = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, NULL );
3485 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
3486 ok(!strcmp(buffer, "OK"), "expected OK got: \"%s\"\n", buffer);
3488 buffer[0] = 0;
3489 size = sizeof(buffer);
3490 SetLastError(0xdeadbeef);
3491 r = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &size, NULL);
3492 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
3493 ok(!strcmp(buffer, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer);
3495 buffer[0] = 0;
3496 size = sizeof(buffer);
3497 SetLastError(0xdeadbeef);
3498 r = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
3499 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
3500 ok(!strcmp(buffer, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer);
3502 InternetCloseHandle(hr);
3503 InternetCloseHandle(hc);
3504 InternetCloseHandle(hi);
3507 static void test_HttpQueryInfo(int port)
3509 HINTERNET hi, hc, hr;
3510 DWORD size, index;
3511 char buffer[1024];
3512 BOOL ret;
3514 hi = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3515 ok(hi != NULL, "InternetOpen failed\n");
3517 hc = InternetConnectA(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3518 ok(hc != NULL, "InternetConnect failed\n");
3520 hr = HttpOpenRequestA(hc, NULL, "/testD", NULL, NULL, NULL, 0, 0);
3521 ok(hr != NULL, "HttpOpenRequest failed\n");
3523 size = sizeof(buffer);
3524 ret = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
3525 ok(!ret && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo failed %u\n", GetLastError());
3527 ret = HttpSendRequestA(hr, NULL, 0, NULL, 0);
3528 ok(ret, "HttpSendRequest failed\n");
3530 index = 0;
3531 size = sizeof(buffer);
3532 ret = HttpQueryInfoA(hr, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &index);
3533 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3534 ok(index == 1, "expected 1 got %u\n", index);
3536 index = 0;
3537 size = sizeof(buffer);
3538 ret = HttpQueryInfoA(hr, HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME, buffer, &size, &index);
3539 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3540 ok(index == 1, "expected 1 got %u\n", index);
3542 index = 0;
3543 size = sizeof(buffer);
3544 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
3545 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3546 ok(index == 0, "expected 0 got %u\n", index);
3548 size = sizeof(buffer);
3549 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
3550 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3551 ok(index == 0, "expected 0 got %u\n", index);
3553 index = 0xdeadbeef; /* invalid start index */
3554 size = sizeof(buffer);
3555 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
3556 todo_wine ok(!ret, "HttpQueryInfo should have failed\n");
3557 todo_wine ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND,
3558 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
3560 index = 0;
3561 size = sizeof(buffer);
3562 ret = HttpQueryInfoA(hr, HTTP_QUERY_RAW_HEADERS_CRLF, buffer, &size, &index);
3563 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3564 ok(index == 0, "expected 0 got %u\n", index);
3566 size = sizeof(buffer);
3567 ret = HttpQueryInfoA(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
3568 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3569 ok(index == 0, "expected 0 got %u\n", index);
3571 size = sizeof(buffer);
3572 ret = HttpQueryInfoA(hr, HTTP_QUERY_VERSION, buffer, &size, &index);
3573 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3574 ok(index == 0, "expected 0 got %u\n", index);
3576 test_status_code(hr, 200);
3578 index = 0xdeadbeef;
3579 size = sizeof(buffer);
3580 ret = HttpQueryInfoA(hr, HTTP_QUERY_FORWARDED, buffer, &size, &index);
3581 ok(!ret, "HttpQueryInfo succeeded\n");
3582 ok(index == 0xdeadbeef, "expected 0xdeadbeef got %u\n", index);
3584 index = 0;
3585 size = sizeof(buffer);
3586 ret = HttpQueryInfoA(hr, HTTP_QUERY_SERVER, buffer, &size, &index);
3587 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3588 ok(index == 1, "expected 1 got %u\n", index);
3590 index = 0;
3591 size = sizeof(buffer);
3592 strcpy(buffer, "Server");
3593 ret = HttpQueryInfoA(hr, HTTP_QUERY_CUSTOM, buffer, &size, &index);
3594 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3595 ok(index == 1, "expected 1 got %u\n", index);
3597 index = 0;
3598 size = sizeof(buffer);
3599 ret = HttpQueryInfoA(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
3600 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3601 ok(index == 1, "expected 1 got %u\n", index);
3603 size = sizeof(buffer);
3604 ret = HttpQueryInfoA(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
3605 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
3606 ok(index == 2, "expected 2 got %u\n", index);
3608 InternetCloseHandle(hr);
3609 InternetCloseHandle(hc);
3610 InternetCloseHandle(hi);
3613 static void test_options(int port)
3615 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi;
3616 HINTERNET ses, con, req;
3617 DWORD size, error;
3618 DWORD_PTR ctx;
3619 BOOL ret;
3621 ses = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3622 ok(ses != NULL, "InternetOpen failed\n");
3624 SetLastError(0xdeadbeef);
3625 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, 0);
3626 error = GetLastError();
3627 ok(!ret, "InternetSetOption succeeded\n");
3628 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3630 SetLastError(0xdeadbeef);
3631 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, sizeof(ctx));
3632 ok(!ret, "InternetSetOption succeeded\n");
3633 error = GetLastError();
3634 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3636 SetLastError(0xdeadbeef);
3637 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, 0);
3638 ok(!ret, "InternetSetOption succeeded\n");
3639 error = GetLastError();
3640 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3642 ctx = 1;
3643 ret = InternetSetOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
3644 ok(ret, "InternetSetOption failed %u\n", GetLastError());
3646 SetLastError(0xdeadbeef);
3647 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, NULL);
3648 error = GetLastError();
3649 ok(!ret, "InternetQueryOption succeeded\n");
3650 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3652 SetLastError(0xdeadbeef);
3653 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, NULL);
3654 error = GetLastError();
3655 ok(!ret, "InternetQueryOption succeeded\n");
3656 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3658 size = 0;
3659 SetLastError(0xdeadbeef);
3660 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, &size);
3661 error = GetLastError();
3662 ok(!ret, "InternetQueryOption succeeded\n");
3663 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
3665 size = sizeof(ctx);
3666 SetLastError(0xdeadbeef);
3667 ret = InternetQueryOptionA(NULL, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3668 error = GetLastError();
3669 ok(!ret, "InternetQueryOption succeeded\n");
3670 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error);
3672 ctx = 0xdeadbeef;
3673 size = sizeof(ctx);
3674 ret = InternetQueryOptionA(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3675 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3676 ok(ctx == 1, "expected 1 got %lu\n", ctx);
3678 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3679 ok(con != NULL, "InternetConnect failed\n");
3681 ctx = 0xdeadbeef;
3682 size = sizeof(ctx);
3683 ret = InternetQueryOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3684 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3685 ok(ctx == 0, "expected 0 got %lu\n", ctx);
3687 ctx = 2;
3688 ret = InternetSetOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
3689 ok(ret, "InternetSetOption failed %u\n", GetLastError());
3691 ctx = 0xdeadbeef;
3692 size = sizeof(ctx);
3693 ret = InternetQueryOptionA(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3694 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3695 ok(ctx == 2, "expected 2 got %lu\n", ctx);
3697 req = HttpOpenRequestA(con, NULL, "/test1", NULL, NULL, NULL, 0, 0);
3698 ok(req != NULL, "HttpOpenRequest failed\n");
3700 ctx = 0xdeadbeef;
3701 size = sizeof(ctx);
3702 ret = InternetQueryOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3703 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3704 ok(ctx == 0, "expected 0 got %lu\n", ctx);
3706 ctx = 3;
3707 ret = InternetSetOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
3708 ok(ret, "InternetSetOption failed %u\n", GetLastError());
3710 ctx = 0xdeadbeef;
3711 size = sizeof(ctx);
3712 ret = InternetQueryOptionA(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
3713 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3714 ok(ctx == 3, "expected 3 got %lu\n", ctx);
3716 size = sizeof(idsi);
3717 ret = InternetQueryOptionA(req, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO, &idsi, &size);
3718 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
3720 size = 0;
3721 SetLastError(0xdeadbeef);
3722 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, NULL, &size);
3723 error = GetLastError();
3724 ok(!ret, "InternetQueryOption succeeded\n");
3725 ok(error == ERROR_INTERNET_INVALID_OPERATION, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error);
3727 /* INTERNET_OPTION_PROXY */
3728 SetLastError(0xdeadbeef);
3729 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, NULL);
3730 error = GetLastError();
3731 ok(!ret, "InternetQueryOption succeeded\n");
3732 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3734 SetLastError(0xdeadbeef);
3735 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, &ctx, NULL);
3736 error = GetLastError();
3737 ok(!ret, "InternetQueryOption succeeded\n");
3738 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
3740 size = 0;
3741 SetLastError(0xdeadbeef);
3742 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, &size);
3743 error = GetLastError();
3744 ok(!ret, "InternetQueryOption succeeded\n");
3745 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
3746 ok(size >= sizeof(INTERNET_PROXY_INFOA), "expected size to be greater or equal to the struct size\n");
3748 InternetCloseHandle(req);
3749 InternetCloseHandle(con);
3750 InternetCloseHandle(ses);
3753 typedef struct {
3754 const char *response_text;
3755 int status_code;
3756 const char *status_text;
3757 const char *raw_headers;
3758 } http_status_test_t;
3760 static const http_status_test_t http_status_tests[] = {
3762 "HTTP/1.1 200 OK\r\n"
3763 "Content-Length: 1\r\n"
3764 "\r\nx",
3765 200,
3766 "OK"
3769 "HTTP/1.1 404 Fail\r\n"
3770 "Content-Length: 1\r\n"
3771 "\r\nx",
3772 404,
3773 "Fail"
3776 "HTTP/1.1 200\r\n"
3777 "Content-Length: 1\r\n"
3778 "\r\nx",
3779 200,
3783 "HTTP/1.1 410 \r\n"
3784 "Content-Length: 1\r\n"
3785 "\r\nx",
3786 410,
3791 static void test_http_status(int port)
3793 HINTERNET ses, con, req;
3794 char buf[1000];
3795 DWORD i, size;
3796 BOOL res;
3798 for(i=0; i < sizeof(http_status_tests)/sizeof(*http_status_tests); i++) {
3799 send_buffer = http_status_tests[i].response_text;
3801 ses = InternetOpenA(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3802 ok(ses != NULL, "InternetOpen failed\n");
3804 con = InternetConnectA(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3805 ok(con != NULL, "InternetConnect failed\n");
3807 req = HttpOpenRequestA(con, NULL, "/send_from_buffer", NULL, NULL, NULL, 0, 0);
3808 ok(req != NULL, "HttpOpenRequest failed\n");
3810 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
3811 ok(res, "HttpSendRequest failed\n");
3813 test_status_code(req, http_status_tests[i].status_code);
3815 size = sizeof(buf);
3816 res = HttpQueryInfoA(req, HTTP_QUERY_STATUS_TEXT, buf, &size, NULL);
3817 ok(res, "HttpQueryInfo failed: %u\n", GetLastError());
3818 ok(!strcmp(buf, http_status_tests[i].status_text), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
3819 i, buf, http_status_tests[i].status_text);
3821 InternetCloseHandle(req);
3822 InternetCloseHandle(con);
3823 InternetCloseHandle(ses);
3827 static void test_cache_control_verb(int port)
3829 HINTERNET session, connect, request;
3830 BOOL ret;
3832 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
3833 ok(session != NULL, "InternetOpen failed\n");
3835 connect = InternetConnectA(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3836 ok(connect != NULL, "InternetConnect failed\n");
3838 request = HttpOpenRequestA(connect, "RPC_OUT_DATA", "/test_cache_control_verb", NULL, NULL, NULL,
3839 INTERNET_FLAG_NO_CACHE_WRITE, 0);
3840 ok(request != NULL, "HttpOpenRequest failed\n");
3841 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
3842 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
3843 test_status_code(request, 200);
3845 request = HttpOpenRequestA(connect, "POST", "/test_cache_control_verb", NULL, NULL, NULL,
3846 INTERNET_FLAG_NO_CACHE_WRITE, 0);
3847 ok(request != NULL, "HttpOpenRequest failed\n");
3848 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
3849 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
3850 test_status_code(request, 200);
3852 request = HttpOpenRequestA(connect, "HEAD", "/test_cache_control_verb", NULL, NULL, NULL,
3853 INTERNET_FLAG_NO_CACHE_WRITE, 0);
3854 ok(request != NULL, "HttpOpenRequest failed\n");
3855 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
3856 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
3857 test_status_code(request, 200);
3859 request = HttpOpenRequestA(connect, "GET", "/test_cache_control_verb", NULL, NULL, NULL,
3860 INTERNET_FLAG_NO_CACHE_WRITE, 0);
3861 ok(request != NULL, "HttpOpenRequest failed\n");
3862 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
3863 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
3864 test_status_code(request, 200);
3866 InternetCloseHandle(request);
3867 InternetCloseHandle(connect);
3868 InternetCloseHandle(session);
3871 static void test_http_connection(void)
3873 struct server_info si;
3874 HANDLE hThread;
3875 DWORD id = 0, r;
3877 si.hEvent = CreateEventW(NULL, 0, 0, NULL);
3878 si.port = 7531;
3880 hThread = CreateThread(NULL, 0, server_thread, (LPVOID) &si, 0, &id);
3881 ok( hThread != NULL, "create thread failed\n");
3883 r = WaitForSingleObject(si.hEvent, 10000);
3884 ok (r == WAIT_OBJECT_0, "failed to start wininet test server\n");
3885 if (r != WAIT_OBJECT_0)
3886 return;
3888 test_basic_request(si.port, "GET", "/test1");
3889 test_proxy_indirect(si.port);
3890 test_proxy_direct(si.port);
3891 test_header_handling_order(si.port);
3892 test_basic_request(si.port, "POST", "/test5");
3893 test_basic_request(si.port, "RPC_IN_DATA", "/test5");
3894 test_basic_request(si.port, "RPC_OUT_DATA", "/test5");
3895 test_basic_request(si.port, "GET", "/test6");
3896 test_basic_request(si.port, "GET", "/testF");
3897 test_connection_header(si.port);
3898 test_http1_1(si.port);
3899 test_cookie_header(si.port);
3900 test_basic_authentication(si.port);
3901 test_invalid_response_headers(si.port);
3902 test_response_without_headers(si.port);
3903 test_HttpQueryInfo(si.port);
3904 test_HttpSendRequestW(si.port);
3905 test_last_error(si.port);
3906 test_options(si.port);
3907 test_no_content(si.port);
3908 test_conn_close(si.port);
3909 test_no_cache(si.port);
3910 test_cache_read_gzipped(si.port);
3911 test_http_status(si.port);
3912 test_premature_disconnect(si.port);
3913 test_connection_closing(si.port);
3914 test_cache_control_verb(si.port);
3916 /* send the basic request again to shutdown the server thread */
3917 test_basic_request(si.port, "GET", "/quit");
3919 r = WaitForSingleObject(hThread, 3000);
3920 ok( r == WAIT_OBJECT_0, "thread wait failed\n");
3921 CloseHandle(hThread);
3924 static void release_cert_info(INTERNET_CERTIFICATE_INFOA *info)
3926 LocalFree(info->lpszSubjectInfo);
3927 LocalFree(info->lpszIssuerInfo);
3928 LocalFree(info->lpszProtocolName);
3929 LocalFree(info->lpszSignatureAlgName);
3930 LocalFree(info->lpszEncryptionAlgName);
3933 typedef struct {
3934 const char *ex_subject;
3935 const char *ex_issuer;
3936 } cert_struct_test_t;
3938 static const cert_struct_test_t test_winehq_org_cert = {
3939 "0mJuv1t-1CFypQkyTZwfvjHHBAbnUndG\r\n"
3940 "GT98380011\r\n"
3941 "See www.rapidssl.com/resources/cps (c)13\r\n"
3942 "Domain Control Validated - RapidSSL(R)\r\n"
3943 "*.winehq.org",
3945 "US\r\n"
3946 "\"GeoTrust, Inc.\"\r\n"
3947 "RapidSSL CA"
3950 static const cert_struct_test_t test_winehq_com_cert = {
3951 "US\r\n"
3952 "Minnesota\r\n"
3953 "Saint Paul\r\n"
3954 "WineHQ\r\n"
3955 "test.winehq.com\r\n"
3956 "webmaster@winehq.org",
3958 "US\r\n"
3959 "Minnesota\r\n"
3960 "WineHQ\r\n"
3961 "test.winehq.com\r\n"
3962 "webmaster@winehq.org"
3965 static void test_cert_struct(HINTERNET req, const cert_struct_test_t *test)
3967 INTERNET_CERTIFICATE_INFOA info;
3968 DWORD size;
3969 BOOL res;
3971 memset(&info, 0x5, sizeof(info));
3973 size = sizeof(info);
3974 res = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, &info, &size);
3975 ok(res, "InternetQueryOption failed: %u\n", GetLastError());
3976 ok(size == sizeof(info), "size = %u\n", size);
3978 ok(!strcmp(info.lpszSubjectInfo, test->ex_subject), "lpszSubjectInfo = %s\n", info.lpszSubjectInfo);
3979 ok(!strcmp(info.lpszIssuerInfo, test->ex_issuer), "lpszIssuerInfo = %s\n", info.lpszIssuerInfo);
3980 ok(!info.lpszSignatureAlgName, "lpszSignatureAlgName = %s\n", info.lpszSignatureAlgName);
3981 ok(!info.lpszEncryptionAlgName, "lpszEncryptionAlgName = %s\n", info.lpszEncryptionAlgName);
3982 ok(!info.lpszProtocolName, "lpszProtocolName = %s\n", info.lpszProtocolName);
3983 ok(info.dwKeySize == 128, "dwKeySize = %u\n", info.dwKeySize);
3985 release_cert_info(&info);
3988 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
3989 static void _test_security_info(unsigned line, const char *urlc, DWORD error, DWORD ex_flags)
3991 char url[INTERNET_MAX_URL_LENGTH];
3992 const CERT_CHAIN_CONTEXT *chain;
3993 DWORD flags;
3994 BOOL res;
3996 if(!pInternetGetSecurityInfoByURLA) {
3997 win_skip("pInternetGetSecurityInfoByURLA not available\n");
3998 return;
4001 strcpy(url, urlc);
4002 chain = (void*)0xdeadbeef;
4003 flags = 0xdeadbeef;
4004 res = pInternetGetSecurityInfoByURLA(url, &chain, &flags);
4005 if(error == ERROR_SUCCESS) {
4006 ok_(__FILE__,line)(res, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
4007 ok_(__FILE__,line)(chain != NULL, "chain = NULL\n");
4008 ok_(__FILE__,line)(flags == ex_flags, "flags = %x\n", flags);
4009 CertFreeCertificateChain(chain);
4010 }else {
4011 ok_(__FILE__,line)(!res && GetLastError() == error,
4012 "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res, GetLastError(), error);
4016 #define test_secflags_option(a,b) _test_secflags_option(__LINE__,a,b)
4017 static void _test_secflags_option(unsigned line, HINTERNET req, DWORD ex_flags)
4019 DWORD flags, size;
4020 BOOL res;
4022 flags = 0xdeadbeef;
4023 size = sizeof(flags);
4024 res = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
4025 ok_(__FILE__,line)(res, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4026 ok_(__FILE__,line)(flags == ex_flags, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n", flags, ex_flags);
4028 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
4029 flags = 0xdeadbeef;
4030 size = sizeof(flags);
4031 res = InternetQueryOptionW(req, 98, &flags, &size);
4032 ok_(__FILE__,line)(res, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
4033 ok_(__FILE__,line)(flags == ex_flags, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n", flags, ex_flags);
4036 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
4037 static void _set_secflags(unsigned line, HINTERNET req, BOOL use_undoc, DWORD flags)
4039 BOOL res;
4041 res = InternetSetOptionW(req, use_undoc ? 99 : INTERNET_OPTION_SECURITY_FLAGS, &flags, sizeof(flags));
4042 ok_(__FILE__,line)(res, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4045 static void test_security_flags(void)
4047 HINTERNET ses, conn, req;
4048 DWORD size, flags;
4049 char buf[100];
4050 BOOL res;
4052 trace("Testing security flags...\n");
4054 hCompleteEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
4056 ses = InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
4057 ok(ses != NULL, "InternetOpen failed\n");
4059 pInternetSetStatusCallbackA(ses, &callback);
4061 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4062 conn = InternetConnectA(ses, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT,
4063 NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0xdeadbeef);
4064 ok(conn != NULL, "InternetConnect failed with error %u\n", GetLastError());
4065 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4067 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4068 req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
4069 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
4070 0xdeadbeef);
4071 ok(req != NULL, "HttpOpenRequest failed\n");
4072 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4074 flags = 0xdeadbeef;
4075 size = sizeof(flags);
4076 res = InternetQueryOptionW(req, 98, &flags, &size);
4077 if(!res && GetLastError() == ERROR_INVALID_PARAMETER) {
4078 win_skip("Incomplete security flags support, skipping\n");
4080 close_async_handle(ses, hCompleteEvent, 2);
4081 CloseHandle(hCompleteEvent);
4082 return;
4085 test_secflags_option(req, 0);
4086 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4088 set_secflags(req, TRUE, SECURITY_FLAG_IGNORE_REVOCATION);
4089 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION);
4091 set_secflags(req, TRUE, SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
4092 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
4094 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
4095 test_secflags_option(req, SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID);
4097 flags = SECURITY_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_SECURE;
4098 res = InternetSetOptionW(req, 99, &flags, sizeof(flags));
4099 ok(!res && GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE, "InternetSetOption(99) failed: %u\n", GetLastError());
4101 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME);
4102 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED);
4103 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4104 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4105 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
4106 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
4107 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
4108 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
4109 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4110 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
4111 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4113 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4114 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4116 WaitForSingleObject(hCompleteEvent, INFINITE);
4117 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
4119 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
4120 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
4121 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
4122 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
4123 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
4124 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
4125 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
4126 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
4127 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4128 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
4129 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4131 test_request_flags(req, 0);
4132 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4133 |SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_CERT_CN_INVALID|SECURITY_FLAG_STRENGTH_STRONG);
4135 res = InternetReadFile(req, buf, sizeof(buf), &size);
4136 ok(res, "InternetReadFile failed: %u\n", GetLastError());
4137 ok(size, "size = 0\n");
4139 /* Collect all existing persistent connections */
4140 res = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
4141 ok(res, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4143 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4144 req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
4145 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
4146 0xdeadbeef);
4147 ok(req != NULL, "HttpOpenRequest failed\n");
4148 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4150 flags = INTERNET_ERROR_MASK_COMBINED_SEC_CERT|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY;
4151 res = InternetSetOptionA(req, INTERNET_OPTION_ERROR_MASK, (void*)&flags, sizeof(flags));
4152 ok(res, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
4154 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4155 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4156 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
4157 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
4158 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4159 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4160 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
4162 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4163 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4165 WaitForSingleObject(hCompleteEvent, INFINITE);
4166 ok(req_error == ERROR_INTERNET_SEC_CERT_REV_FAILED || broken(req_error == ERROR_INTERNET_SEC_CERT_ERRORS),
4167 "req_error = %d\n", req_error);
4169 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
4170 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
4171 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
4172 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
4173 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4174 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4175 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
4177 if(req_error != ERROR_INTERNET_SEC_CERT_REV_FAILED) {
4178 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error);
4180 close_async_handle(ses, hCompleteEvent, 3);
4181 CloseHandle(hCompleteEvent);
4182 return;
4185 size = sizeof(buf);
4186 res = HttpQueryInfoA(req, HTTP_QUERY_CONTENT_ENCODING, buf, &size, 0);
4187 ok(!res && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
4189 test_request_flags(req, 8);
4190 test_secflags_option(req, 0x800000);
4192 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_REVOCATION);
4193 test_secflags_option(req, 0x800000|SECURITY_FLAG_IGNORE_REVOCATION);
4195 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4196 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4197 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
4198 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
4199 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4200 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4201 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
4203 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4204 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4206 WaitForSingleObject(hCompleteEvent, INFINITE);
4207 ok(req_error == ERROR_INTERNET_SEC_CERT_ERRORS, "req_error = %d\n", req_error);
4209 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
4210 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
4211 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
4212 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
4213 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4214 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4215 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
4217 test_request_flags(req, INTERNET_REQFLAG_NO_HEADERS);
4218 test_secflags_option(req, SECURITY_FLAG_IGNORE_REVOCATION|0x1800000);
4219 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4221 set_secflags(req, FALSE, SECURITY_FLAG_IGNORE_UNKNOWN_CA);
4222 test_secflags_option(req, 0x1800000|SECURITY_FLAG_IGNORE_REVOCATION|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4223 |SECURITY_FLAG_IGNORE_REVOCATION);
4224 test_http_version(req);
4226 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4227 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4228 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
4229 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
4230 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
4231 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
4232 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4233 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4234 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY);
4236 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4237 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4239 WaitForSingleObject(hCompleteEvent, INFINITE);
4240 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
4242 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
4243 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
4244 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
4245 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
4246 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
4247 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
4248 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4249 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4250 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY);
4252 test_request_flags(req, 0);
4253 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_REVOCATION
4254 |SECURITY_FLAG_STRENGTH_STRONG|0x1800000);
4256 test_cert_struct(req, &test_winehq_com_cert);
4257 test_security_info("https://test.winehq.com/data/some_file.html?q", 0, 0x1800000);
4259 res = InternetReadFile(req, buf, sizeof(buf), &size);
4260 ok(res, "InternetReadFile failed: %u\n", GetLastError());
4261 ok(size, "size = 0\n");
4263 close_async_handle(ses, hCompleteEvent, 3);
4265 /* Collect all existing persistent connections */
4266 res = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
4267 ok(res, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4269 /* Make another request, without setting security flags */
4271 ses = InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
4272 ok(ses != NULL, "InternetOpen failed\n");
4274 pInternetSetStatusCallbackA(ses, &callback);
4276 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4277 conn = InternetConnectA(ses, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT,
4278 NULL, NULL, INTERNET_SERVICE_HTTP, INTERNET_FLAG_SECURE, 0xdeadbeef);
4279 ok(conn != NULL, "InternetConnect failed with error %u\n", GetLastError());
4280 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4282 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
4283 req = HttpOpenRequestA(conn, "GET", "/tests/hello.html", NULL, NULL, NULL,
4284 INTERNET_FLAG_SECURE|INTERNET_FLAG_KEEP_CONNECTION|INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
4285 0xdeadbeef);
4286 ok(req != NULL, "HttpOpenRequest failed\n");
4287 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
4289 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_STRENGTH_STRONG
4290 |SECURITY_FLAG_IGNORE_REVOCATION|0x1800000);
4291 test_http_version(req);
4293 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
4294 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
4295 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
4296 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
4297 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
4298 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
4299 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
4300 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
4302 res = HttpSendRequestA(req, NULL, 0, NULL, 0);
4303 ok(!res && GetLastError() == ERROR_IO_PENDING, "HttpSendRequest failed: %u\n", GetLastError());
4305 WaitForSingleObject(hCompleteEvent, INFINITE);
4306 ok(req_error == ERROR_SUCCESS, "req_error = %d\n", req_error);
4308 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
4309 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
4310 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
4311 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
4312 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
4313 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
4314 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
4315 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
4317 test_request_flags(req, 0);
4318 test_secflags_option(req, SECURITY_FLAG_SECURE|SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_STRENGTH_STRONG
4319 |SECURITY_FLAG_IGNORE_REVOCATION|0x1800000);
4321 res = InternetReadFile(req, buf, sizeof(buf), &size);
4322 ok(res, "InternetReadFile failed: %u\n", GetLastError());
4323 ok(size, "size = 0\n");
4325 close_async_handle(ses, hCompleteEvent, 2);
4327 CloseHandle(hCompleteEvent);
4329 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4330 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4331 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND, 0);
4334 static void test_secure_connection(void)
4336 static const WCHAR gizmo5[] = {'G','i','z','m','o','5',0};
4337 static const WCHAR testsite[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
4338 static const WCHAR get[] = {'G','E','T',0};
4339 static const WCHAR testpage[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
4340 HINTERNET ses, con, req;
4341 DWORD size, flags;
4342 INTERNET_CERTIFICATE_INFOA *certificate_structA = NULL;
4343 INTERNET_CERTIFICATE_INFOW *certificate_structW = NULL;
4344 BOOL ret;
4346 ses = InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
4347 ok(ses != NULL, "InternetOpen failed\n");
4349 con = InternetConnectA(ses, "test.winehq.org",
4350 INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL,
4351 INTERNET_SERVICE_HTTP, 0, 0);
4352 ok(con != NULL, "InternetConnect failed\n");
4354 req = HttpOpenRequestA(con, "GET", "/tests/hello.html", NULL, NULL, NULL,
4355 INTERNET_FLAG_SECURE, 0);
4356 ok(req != NULL, "HttpOpenRequest failed\n");
4358 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
4359 ok(ret, "HttpSendRequest failed: %d\n", GetLastError());
4361 size = sizeof(flags);
4362 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
4363 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
4364 ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set\n");
4366 test_cert_struct(req, &test_winehq_org_cert);
4368 /* Querying the same option through InternetQueryOptionW still results in
4369 * ASCII strings being returned.
4371 size = 0;
4372 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
4373 NULL, &size);
4374 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
4375 ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size);
4376 certificate_structW = HeapAlloc(GetProcessHeap(), 0, size);
4377 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
4378 certificate_structW, &size);
4379 certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW;
4380 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
4381 if (ret)
4383 ok(certificate_structA->lpszSubjectInfo &&
4384 strlen(certificate_structA->lpszSubjectInfo) > 1,
4385 "expected a non-empty subject name\n");
4386 ok(certificate_structA->lpszIssuerInfo &&
4387 strlen(certificate_structA->lpszIssuerInfo) > 1,
4388 "expected a non-empty issuer name\n");
4389 ok(!certificate_structA->lpszSignatureAlgName,
4390 "unexpected signature algorithm name\n");
4391 ok(!certificate_structA->lpszEncryptionAlgName,
4392 "unexpected encryption algorithm name\n");
4393 ok(!certificate_structA->lpszProtocolName,
4394 "unexpected protocol name\n");
4395 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
4396 release_cert_info(certificate_structA);
4398 HeapFree(GetProcessHeap(), 0, certificate_structW);
4400 InternetCloseHandle(req);
4401 InternetCloseHandle(con);
4402 InternetCloseHandle(ses);
4404 /* Repeating the tests with the W functions has the same result: */
4405 ses = InternetOpenW(gizmo5, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
4406 ok(ses != NULL, "InternetOpen failed\n");
4408 con = InternetConnectW(ses, testsite,
4409 INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL,
4410 INTERNET_SERVICE_HTTP, 0, 0);
4411 ok(con != NULL, "InternetConnect failed\n");
4413 req = HttpOpenRequestW(con, get, testpage, NULL, NULL, NULL,
4414 INTERNET_FLAG_SECURE|INTERNET_FLAG_RELOAD, 0);
4415 ok(req != NULL, "HttpOpenRequest failed\n");
4417 ret = HttpSendRequestA(req, NULL, 0, NULL, 0);
4418 ok(ret, "HttpSendRequest failed: %d\n", GetLastError());
4420 size = sizeof(flags);
4421 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
4422 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
4423 ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set, got %x\n", flags);
4425 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
4426 NULL, &size);
4427 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
4428 ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %d\n", size);
4429 certificate_structA = HeapAlloc(GetProcessHeap(), 0, size);
4430 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
4431 certificate_structA, &size);
4432 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
4433 if (ret)
4435 ok(certificate_structA->lpszSubjectInfo &&
4436 strlen(certificate_structA->lpszSubjectInfo) > 1,
4437 "expected a non-empty subject name\n");
4438 ok(certificate_structA->lpszIssuerInfo &&
4439 strlen(certificate_structA->lpszIssuerInfo) > 1,
4440 "expected a non-empty issuer name\n");
4441 ok(!certificate_structA->lpszSignatureAlgName,
4442 "unexpected signature algorithm name\n");
4443 ok(!certificate_structA->lpszEncryptionAlgName,
4444 "unexpected encryption algorithm name\n");
4445 ok(!certificate_structA->lpszProtocolName,
4446 "unexpected protocol name\n");
4447 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
4448 release_cert_info(certificate_structA);
4450 HeapFree(GetProcessHeap(), 0, certificate_structA);
4452 /* Again, querying the same option through InternetQueryOptionW still
4453 * results in ASCII strings being returned.
4455 size = 0;
4456 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
4457 NULL, &size);
4458 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
4459 ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size);
4460 certificate_structW = HeapAlloc(GetProcessHeap(), 0, size);
4461 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
4462 certificate_structW, &size);
4463 certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW;
4464 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
4465 if (ret)
4467 ok(certificate_structA->lpszSubjectInfo &&
4468 strlen(certificate_structA->lpszSubjectInfo) > 1,
4469 "expected a non-empty subject name\n");
4470 ok(certificate_structA->lpszIssuerInfo &&
4471 strlen(certificate_structA->lpszIssuerInfo) > 1,
4472 "expected a non-empty issuer name\n");
4473 ok(!certificate_structA->lpszSignatureAlgName,
4474 "unexpected signature algorithm name\n");
4475 ok(!certificate_structA->lpszEncryptionAlgName,
4476 "unexpected encryption algorithm name\n");
4477 ok(!certificate_structA->lpszProtocolName,
4478 "unexpected protocol name\n");
4479 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
4480 release_cert_info(certificate_structA);
4482 HeapFree(GetProcessHeap(), 0, certificate_structW);
4484 InternetCloseHandle(req);
4485 InternetCloseHandle(con);
4486 InternetCloseHandle(ses);
4489 static void test_user_agent_header(void)
4491 HINTERNET ses, con, req;
4492 DWORD size, err;
4493 char buffer[64];
4494 BOOL ret;
4496 ses = InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
4497 ok(ses != NULL, "InternetOpen failed\n");
4499 con = InternetConnectA(ses, "test.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4500 ok(con != NULL, "InternetConnect failed\n");
4502 req = HttpOpenRequestA(con, "GET", "/tests/hello.html", "HTTP/1.0", NULL, NULL, 0, 0);
4503 ok(req != NULL, "HttpOpenRequest failed\n");
4505 size = sizeof(buffer);
4506 ret = HttpQueryInfoA(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4507 err = GetLastError();
4508 ok(!ret, "HttpQueryInfo succeeded\n");
4509 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
4511 ret = HttpAddRequestHeadersA(req, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
4512 ok(ret, "HttpAddRequestHeaders succeeded\n");
4514 size = sizeof(buffer);
4515 ret = HttpQueryInfoA(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4516 err = GetLastError();
4517 ok(ret, "HttpQueryInfo failed\n");
4518 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
4520 InternetCloseHandle(req);
4522 req = HttpOpenRequestA(con, "GET", "/", "HTTP/1.0", NULL, NULL, 0, 0);
4523 ok(req != NULL, "HttpOpenRequest failed\n");
4525 size = sizeof(buffer);
4526 ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4527 err = GetLastError();
4528 ok(!ret, "HttpQueryInfo succeeded\n");
4529 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
4531 ret = HttpAddRequestHeadersA(req, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
4532 ok(ret, "HttpAddRequestHeaders failed\n");
4534 buffer[0] = 0;
4535 size = sizeof(buffer);
4536 ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4537 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
4538 ok(!strcmp(buffer, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer);
4540 InternetCloseHandle(req);
4541 InternetCloseHandle(con);
4542 InternetCloseHandle(ses);
4545 static void test_bogus_accept_types_array(void)
4547 HINTERNET ses, con, req;
4548 static const char *types[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL };
4549 DWORD size, error;
4550 char buffer[32];
4551 BOOL ret;
4553 ses = InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT, "", "", 0);
4554 con = InternetConnectA(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
4555 req = HttpOpenRequestA(con, "POST", "/post/post_action.php", "HTTP/1.0", "", types, INTERNET_FLAG_FORMS_SUBMIT, 0);
4557 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
4559 buffer[0] = 0;
4560 size = sizeof(buffer);
4561 SetLastError(0xdeadbeef);
4562 ret = HttpQueryInfoA(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
4563 error = GetLastError();
4564 ok(!ret || broken(ret), "HttpQueryInfo succeeded\n");
4565 if (!ret) ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error);
4566 ok(broken(!strcmp(buffer, ", */*, %p, , , */*")) /* IE6 */ ||
4567 broken(!strcmp(buffer, "*/*, %p, */*")) /* IE7/8 */ ||
4568 !strcmp(buffer, ""), "got '%s' expected ''\n", buffer);
4570 InternetCloseHandle(req);
4571 InternetCloseHandle(con);
4572 InternetCloseHandle(ses);
4575 struct context
4577 HANDLE event;
4578 HINTERNET req;
4581 static void WINAPI cb(HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID info, DWORD size)
4583 INTERNET_ASYNC_RESULT *result = info;
4584 struct context *ctx = (struct context *)context;
4586 trace("%p 0x%08lx %u %p 0x%08x\n", handle, context, status, info, size);
4588 switch(status) {
4589 case INTERNET_STATUS_REQUEST_COMPLETE:
4590 trace("request handle: 0x%08lx\n", result->dwResult);
4591 ctx->req = (HINTERNET)result->dwResult;
4592 SetEvent(ctx->event);
4593 break;
4594 case INTERNET_STATUS_HANDLE_CLOSING: {
4595 DWORD type = INTERNET_HANDLE_TYPE_CONNECT_HTTP, size = sizeof(type);
4597 if (InternetQueryOptionA(handle, INTERNET_OPTION_HANDLE_TYPE, &type, &size))
4598 ok(type != INTERNET_HANDLE_TYPE_CONNECT_HTTP, "unexpected callback\n");
4599 SetEvent(ctx->event);
4600 break;
4602 case INTERNET_STATUS_NAME_RESOLVED:
4603 case INTERNET_STATUS_CONNECTING_TO_SERVER:
4604 case INTERNET_STATUS_CONNECTED_TO_SERVER: {
4605 char *str = info;
4606 ok(str[0] && str[1], "Got string: %s\n", str);
4607 ok(size == strlen(str)+1, "unexpected size %u\n", size);
4612 static void test_open_url_async(void)
4614 BOOL ret;
4615 HINTERNET ses, req;
4616 DWORD size, error;
4617 struct context ctx;
4618 ULONG type;
4620 /* Collect all existing persistent connections */
4621 ret = InternetSetOptionA(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0);
4622 ok(ret, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4625 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
4626 * other versions never do. They also hang of following tests. We disable it for everything older
4627 * than IE7.
4629 if(!pInternetGetSecurityInfoByURLA) {
4630 win_skip("Skipping async open on too old wininet version.\n");
4631 return;
4634 ctx.req = NULL;
4635 ctx.event = CreateEventA(NULL, TRUE, FALSE, "Z:_home_hans_jaman-installer.exe_ev1");
4637 ses = InternetOpenA("AdvancedInstaller", 0, NULL, NULL, INTERNET_FLAG_ASYNC);
4638 ok(ses != NULL, "InternetOpen failed\n");
4640 SetLastError(0xdeadbeef);
4641 ret = InternetSetOptionA(NULL, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR));
4642 error = GetLastError();
4643 ok(!ret, "InternetSetOptionA succeeded\n");
4644 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error);
4646 ret = InternetSetOptionA(ses, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR));
4647 error = GetLastError();
4648 ok(!ret, "InternetSetOptionA failed\n");
4649 ok(error == ERROR_INTERNET_OPTION_NOT_SETTABLE, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error);
4651 pInternetSetStatusCallbackW(ses, cb);
4652 ResetEvent(ctx.event);
4654 req = InternetOpenUrlA(ses, "http://test.winehq.org", NULL, 0, 0, (DWORD_PTR)&ctx);
4655 ok(!req && GetLastError() == ERROR_IO_PENDING, "InternetOpenUrl failed\n");
4657 WaitForSingleObject(ctx.event, INFINITE);
4659 type = 0;
4660 size = sizeof(type);
4661 ret = InternetQueryOptionA(ctx.req, INTERNET_OPTION_HANDLE_TYPE, &type, &size);
4662 ok(ret, "InternetQueryOption failed: %u\n", GetLastError());
4663 ok(type == INTERNET_HANDLE_TYPE_HTTP_REQUEST,
4664 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type);
4666 size = 0;
4667 ret = HttpQueryInfoA(ctx.req, HTTP_QUERY_RAW_HEADERS_CRLF, NULL, &size, NULL);
4668 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "HttpQueryInfo failed\n");
4669 ok(size > 0, "expected size > 0\n");
4671 ResetEvent(ctx.event);
4672 InternetCloseHandle(ctx.req);
4673 WaitForSingleObject(ctx.event, INFINITE);
4675 InternetCloseHandle(ses);
4676 CloseHandle(ctx.event);
4679 enum api
4681 internet_connect = 1,
4682 http_open_request,
4683 http_send_request_ex,
4684 internet_writefile,
4685 http_end_request,
4686 internet_close_handle
4689 struct notification
4691 enum api function; /* api responsible for notification */
4692 unsigned int status; /* status received */
4693 int async; /* delivered from another thread? */
4694 int todo;
4695 int optional;
4698 struct info
4700 enum api function;
4701 const struct notification *test;
4702 unsigned int count;
4703 unsigned int index;
4704 HANDLE wait;
4705 DWORD thread;
4706 unsigned int line;
4707 DWORD expect_result;
4708 BOOL is_aborted;
4711 static CRITICAL_SECTION notification_cs;
4713 static void CALLBACK check_notification( HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID buffer, DWORD buflen )
4715 BOOL status_ok, function_ok;
4716 struct info *info = (struct info *)context;
4717 unsigned int i;
4719 EnterCriticalSection( &notification_cs );
4721 if(info->is_aborted) {
4722 LeaveCriticalSection(&notification_cs);
4723 return;
4726 if (status == INTERNET_STATUS_HANDLE_CREATED)
4728 DWORD size = sizeof(struct info *);
4729 HttpQueryInfoA( handle, INTERNET_OPTION_CONTEXT_VALUE, &info, &size, 0 );
4730 }else if(status == INTERNET_STATUS_REQUEST_COMPLETE) {
4731 INTERNET_ASYNC_RESULT *ar = (INTERNET_ASYNC_RESULT*)buffer;
4733 ok(buflen == sizeof(*ar), "unexpected buflen = %d\n", buflen);
4734 if(info->expect_result == ERROR_SUCCESS) {
4735 ok(ar->dwResult == 1, "ar->dwResult = %ld, expected 1\n", ar->dwResult);
4736 }else {
4737 ok(!ar->dwResult, "ar->dwResult = %ld, expected 1\n", ar->dwResult);
4738 ok(ar->dwError == info->expect_result, "ar->dwError = %d, expected %d\n", ar->dwError, info->expect_result);
4742 i = info->index;
4743 if (i >= info->count)
4745 LeaveCriticalSection( &notification_cs );
4746 return;
4749 while (info->test[i].status != status &&
4750 (info->test[i].optional || info->test[i].todo) &&
4751 i < info->count - 1 &&
4752 info->test[i].function == info->test[i + 1].function)
4754 i++;
4757 status_ok = (info->test[i].status == status);
4758 function_ok = (info->test[i].function == info->function);
4760 if (!info->test[i].todo)
4762 ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status );
4763 ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
4765 if (info->test[i].async)
4766 ok(info->thread != GetCurrentThreadId(), "%u: expected thread %u got %u\n",
4767 info->line, info->thread, GetCurrentThreadId());
4769 else
4771 todo_wine ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status );
4772 if (status_ok)
4773 todo_wine ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
4775 if (i == info->count - 1 || info->test[i].function != info->test[i + 1].function) SetEvent( info->wait );
4776 info->index = i+1;
4778 LeaveCriticalSection( &notification_cs );
4781 static void setup_test( struct info *info, enum api function, unsigned int line, DWORD expect_result )
4783 info->function = function;
4784 info->line = line;
4785 info->expect_result = expect_result;
4788 struct notification_data
4790 const struct notification *test;
4791 const unsigned int count;
4792 const char *method;
4793 const char *host;
4794 const char *path;
4795 const char *data;
4796 BOOL expect_conn_failure;
4799 static const struct notification async_send_request_ex_test[] =
4801 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, 0 },
4802 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, 0 },
4803 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
4804 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, 1, 0, 1 },
4805 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, 1, 0, 1 },
4806 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, 1, 0, 1 },
4807 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, 1 },
4808 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, 1 },
4809 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, 1 },
4810 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, 1 },
4811 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
4812 { internet_writefile, INTERNET_STATUS_SENDING_REQUEST, 0 },
4813 { internet_writefile, INTERNET_STATUS_REQUEST_SENT, 0 },
4814 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, 1 },
4815 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, 1 },
4816 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
4817 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, 0, 0, 1 },
4818 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, 0, 0, 1 },
4819 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, },
4820 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, }
4823 static const struct notification async_send_request_ex_test2[] =
4825 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, 0 },
4826 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, 0 },
4827 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
4828 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, 1, 0, 1 },
4829 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, 1, 0, 1 },
4830 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, 1, 0, 1 },
4831 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, 1, 1 },
4832 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, 1, 1 },
4833 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, 1 },
4834 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, 1 },
4835 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
4836 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, 1 },
4837 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, 1 },
4838 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
4839 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, 0, 0, 1 },
4840 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, 0, 0, 1 },
4841 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, },
4842 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, }
4845 static const struct notification async_send_request_ex_resolve_failure_test[] =
4847 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, 0 },
4848 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, 0 },
4849 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
4850 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, 1 },
4851 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
4852 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
4853 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
4854 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, 0, 0, 1 },
4855 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, 0, 0, 1 },
4856 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, },
4857 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, }
4860 static const struct notification async_send_request_ex_chunked_test[] =
4862 { internet_connect, INTERNET_STATUS_HANDLE_CREATED },
4863 { http_open_request, INTERNET_STATUS_HANDLE_CREATED },
4864 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
4865 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, 1, 0, 1 },
4866 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, 1, 0, 1 },
4867 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, 1, 0, 1 },
4868 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, 1 },
4869 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, 1 },
4870 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, 1 },
4871 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, 1 },
4872 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
4873 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, 1 },
4874 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, 1 },
4875 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
4876 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION },
4877 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED },
4878 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING },
4879 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING }
4882 static const struct notification_data notification_data[] = {
4884 async_send_request_ex_chunked_test,
4885 sizeof(async_send_request_ex_chunked_test)/sizeof(async_send_request_ex_chunked_test[0]),
4886 "GET",
4887 "test.winehq.org",
4888 "tests/data.php"
4891 async_send_request_ex_test,
4892 sizeof(async_send_request_ex_test)/sizeof(async_send_request_ex_test[0]),
4893 "POST",
4894 "test.winehq.org",
4895 "tests/posttest.php",
4896 "Public ID=codeweavers"
4899 async_send_request_ex_test2,
4900 sizeof(async_send_request_ex_test)/sizeof(async_send_request_ex_test[0]),
4901 "POST",
4902 "test.winehq.org",
4903 "tests/posttest.php"
4906 async_send_request_ex_resolve_failure_test,
4907 sizeof(async_send_request_ex_resolve_failure_test)/sizeof(async_send_request_ex_resolve_failure_test[0]),
4908 "GET",
4909 "brokenhost",
4910 "index.html",
4911 NULL,
4912 TRUE
4916 static void test_async_HttpSendRequestEx(const struct notification_data *nd)
4918 BOOL ret;
4919 HINTERNET ses, req, con;
4920 struct info info;
4921 DWORD size, written, error;
4922 INTERNET_BUFFERSA b;
4923 static const char *accept[2] = {"*/*", NULL};
4924 char buffer[32];
4926 trace("Async HttpSendRequestEx test (%s %s)\n", nd->method, nd->host);
4928 InitializeCriticalSection( &notification_cs );
4930 info.test = nd->test;
4931 info.count = nd->count;
4932 info.index = 0;
4933 info.wait = CreateEventW( NULL, FALSE, FALSE, NULL );
4934 info.thread = GetCurrentThreadId();
4935 info.is_aborted = FALSE;
4937 ses = InternetOpenA( "winetest", 0, NULL, NULL, INTERNET_FLAG_ASYNC );
4938 ok( ses != NULL, "InternetOpen failed\n" );
4940 pInternetSetStatusCallbackA( ses, check_notification );
4942 setup_test( &info, internet_connect, __LINE__, ERROR_SUCCESS );
4943 con = InternetConnectA( ses, nd->host, 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, (DWORD_PTR)&info );
4944 ok( con != NULL, "InternetConnect failed %u\n", GetLastError() );
4946 WaitForSingleObject( info.wait, 10000 );
4948 setup_test( &info, http_open_request, __LINE__, ERROR_SUCCESS );
4949 req = HttpOpenRequestA( con, nd->method, nd->path, NULL, NULL, accept, 0, (DWORD_PTR)&info );
4950 ok( req != NULL, "HttpOpenRequest failed %u\n", GetLastError() );
4952 WaitForSingleObject( info.wait, 10000 );
4954 if(nd->data) {
4955 memset( &b, 0, sizeof(INTERNET_BUFFERSA) );
4956 b.dwStructSize = sizeof(INTERNET_BUFFERSA);
4957 b.lpcszHeader = "Content-Type: application/x-www-form-urlencoded";
4958 b.dwHeadersLength = strlen( b.lpcszHeader );
4959 b.dwBufferTotal = nd->data ? strlen( nd->data ) : 0;
4962 setup_test( &info, http_send_request_ex, __LINE__,
4963 nd->expect_conn_failure ? ERROR_INTERNET_NAME_NOT_RESOLVED : ERROR_SUCCESS );
4964 ret = HttpSendRequestExA( req, nd->data ? &b : NULL, NULL, 0x28, 0 );
4965 ok( !ret && GetLastError() == ERROR_IO_PENDING, "HttpSendRequestExA failed %d %u\n", ret, GetLastError() );
4967 error = WaitForSingleObject( info.wait, 10000 );
4968 if(error != WAIT_OBJECT_0) {
4969 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error);
4970 info.is_aborted = TRUE;
4971 goto abort;
4974 size = sizeof(buffer);
4975 SetLastError( 0xdeadbeef );
4976 ret = HttpQueryInfoA( req, HTTP_QUERY_CONTENT_ENCODING, buffer, &size, 0 );
4977 error = GetLastError();
4978 ok( !ret, "HttpQueryInfoA failed %u\n", GetLastError() );
4979 if(nd->expect_conn_failure) {
4980 ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error );
4981 }else {
4982 todo_wine
4983 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_STATE,
4984 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error );
4987 if (nd->data)
4989 written = 0;
4990 size = strlen( nd->data );
4991 setup_test( &info, internet_writefile, __LINE__, ERROR_SUCCESS );
4992 ret = InternetWriteFile( req, nd->data, size, &written );
4993 ok( ret, "InternetWriteFile failed %u\n", GetLastError() );
4994 ok( written == size, "expected %u got %u\n", written, size );
4996 WaitForSingleObject( info.wait, 10000 );
4998 SetLastError( 0xdeadbeef );
4999 ret = HttpEndRequestA( req, (void *)nd->data, 0x28, 0 );
5000 error = GetLastError();
5001 ok( !ret, "HttpEndRequestA succeeded\n" );
5002 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error );
5005 SetLastError( 0xdeadbeef );
5006 setup_test( &info, http_end_request, __LINE__,
5007 nd->expect_conn_failure ? ERROR_INTERNET_OPERATION_CANCELLED : ERROR_SUCCESS);
5008 ret = HttpEndRequestA( req, NULL, 0x28, 0 );
5009 error = GetLastError();
5010 ok( !ret, "HttpEndRequestA succeeded\n" );
5011 ok( error == ERROR_IO_PENDING, "expected ERROR_IO_PENDING got %u\n", error );
5013 WaitForSingleObject( info.wait, 10000 );
5015 setup_test( &info, internet_close_handle, __LINE__, ERROR_SUCCESS );
5016 abort:
5017 InternetCloseHandle( req );
5018 InternetCloseHandle( con );
5019 InternetCloseHandle( ses );
5021 WaitForSingleObject( info.wait, 10000 );
5022 Sleep(100);
5023 CloseHandle( info.wait );
5026 static HINTERNET closetest_session, closetest_req, closetest_conn;
5027 static BOOL closetest_closed;
5029 static void WINAPI closetest_callback(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus,
5030 LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
5032 DWORD len, type;
5033 BOOL res;
5035 trace("closetest_callback %p: %d\n", hInternet, dwInternetStatus);
5037 ok(hInternet == closetest_session || hInternet == closetest_conn || hInternet == closetest_req,
5038 "Unexpected hInternet %p\n", hInternet);
5039 if(!closetest_closed)
5040 return;
5042 len = sizeof(type);
5043 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_HANDLE_TYPE, &type, &len);
5044 ok(!res && GetLastError() == ERROR_INVALID_HANDLE,
5045 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5046 closetest_req, res, GetLastError());
5049 static void test_InternetCloseHandle(void)
5051 DWORD len, flags;
5052 BOOL res;
5054 closetest_session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
5055 ok(closetest_session != NULL,"InternetOpen failed with error %u\n", GetLastError());
5057 pInternetSetStatusCallbackA(closetest_session, closetest_callback);
5059 closetest_conn = InternetConnectA(closetest_session, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER,
5060 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
5061 ok(closetest_conn != NULL,"InternetConnect failed with error %u\n", GetLastError());
5063 closetest_req = HttpOpenRequestA(closetest_conn, "GET", "winegecko.php", NULL, NULL, NULL,
5064 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
5066 res = HttpSendRequestA(closetest_req, NULL, -1, NULL, 0);
5067 ok(!res && (GetLastError() == ERROR_IO_PENDING),
5068 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
5070 test_request_flags(closetest_req, INTERNET_REQFLAG_NO_HEADERS);
5072 res = InternetCloseHandle(closetest_session);
5073 ok(res, "InternetCloseHandle failed: %u\n", GetLastError());
5074 closetest_closed = TRUE;
5075 trace("Closed session handle\n");
5077 res = InternetCloseHandle(closetest_conn);
5078 ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(conn) failed: %x %u\n",
5079 res, GetLastError());
5081 res = InternetCloseHandle(closetest_req);
5082 ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(req) failed: %x %u\n",
5083 res, GetLastError());
5085 len = sizeof(flags);
5086 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &len);
5087 ok(!res && GetLastError() == ERROR_INVALID_HANDLE,
5088 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5089 closetest_req, res, GetLastError());
5092 static void test_connection_failure(void)
5094 HINTERNET session, connect, request;
5095 DWORD error;
5096 BOOL ret;
5098 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
5099 ok(session != NULL, "failed to get session handle\n");
5101 connect = InternetConnectA(session, "localhost", 1, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
5102 ok(connect != NULL, "failed to get connection handle\n");
5104 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, 0, 0);
5105 ok(request != NULL, "failed to get request handle\n");
5107 SetLastError(0xdeadbeef);
5108 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
5109 error = GetLastError();
5110 ok(!ret, "unexpected success\n");
5111 ok(error == ERROR_INTERNET_CANNOT_CONNECT, "wrong error %u\n", error);
5113 InternetCloseHandle(request);
5114 InternetCloseHandle(connect);
5115 InternetCloseHandle(session);
5118 static void test_default_service_port(void)
5120 HINTERNET session, connect, request;
5121 DWORD error;
5122 BOOL ret;
5124 session = InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
5125 ok(session != NULL, "InternetOpen failed\n");
5127 connect = InternetConnectA(session, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER, NULL, NULL,
5128 INTERNET_SERVICE_HTTP, 0, 0);
5129 ok(connect != NULL, "InternetConnect failed\n");
5131 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0);
5132 ok(request != NULL, "HttpOpenRequest failed\n");
5134 SetLastError(0xdeadbeef);
5135 ret = HttpSendRequestA(request, NULL, 0, NULL, 0);
5136 error = GetLastError();
5137 ok(!ret, "HttpSendRequest succeeded\n");
5138 ok(error == ERROR_INTERNET_SECURITY_CHANNEL_ERROR || error == ERROR_INTERNET_CANNOT_CONNECT,
5139 "got %u\n", error);
5141 InternetCloseHandle(request);
5142 InternetCloseHandle(connect);
5143 InternetCloseHandle(session);
5146 static void init_status_tests(void)
5148 memset(expect, 0, sizeof(expect));
5149 memset(optional, 0, sizeof(optional));
5150 memset(wine_allow, 0, sizeof(wine_allow));
5151 memset(notified, 0, sizeof(notified));
5152 memset(status_string, 0, sizeof(status_string));
5154 #define STATUS_STRING(status) status_string[status] = #status
5155 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME);
5156 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED);
5157 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER);
5158 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER);
5159 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST);
5160 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT);
5161 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE);
5162 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED);
5163 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED);
5164 STATUS_STRING(INTERNET_STATUS_PREFETCH);
5165 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION);
5166 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED);
5167 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED);
5168 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING);
5169 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY);
5170 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE);
5171 STATUS_STRING(INTERNET_STATUS_REDIRECT);
5172 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE);
5173 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED);
5174 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE);
5175 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT);
5176 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED);
5177 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED);
5178 STATUS_STRING(INTERNET_STATUS_P3P_HEADER);
5179 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF);
5180 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY);
5181 #undef STATUS_STRING
5184 START_TEST(http)
5186 HMODULE hdll;
5187 hdll = GetModuleHandleA("wininet.dll");
5189 if(!GetProcAddress(hdll, "InternetGetCookieExW")) {
5190 win_skip("Too old IE (older than 6.0)\n");
5191 return;
5194 pInternetSetStatusCallbackA = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackA");
5195 pInternetSetStatusCallbackW = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackW");
5196 pInternetGetSecurityInfoByURLA = (void*)GetProcAddress(hdll, "InternetGetSecurityInfoByURLA");
5198 init_status_tests();
5199 test_InternetCloseHandle();
5200 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[0]);
5201 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[1]);
5202 InternetReadFile_test(0, &test_data[1]);
5203 first_connection_to_test_url = TRUE;
5204 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[2]);
5205 test_security_flags();
5206 InternetReadFile_test(0, &test_data[2]);
5207 InternetReadFileExA_test(INTERNET_FLAG_ASYNC);
5208 test_open_url_async();
5209 test_async_HttpSendRequestEx(&notification_data[0]);
5210 test_async_HttpSendRequestEx(&notification_data[1]);
5211 test_async_HttpSendRequestEx(&notification_data[2]);
5212 test_async_HttpSendRequestEx(&notification_data[3]);
5213 InternetOpenRequest_test();
5214 test_http_cache();
5215 InternetLockRequestFile_test();
5216 InternetOpenUrlA_test();
5217 HttpHeaders_test();
5218 test_http_connection();
5219 test_secure_connection();
5220 test_user_agent_header();
5221 test_bogus_accept_types_array();
5222 InternetReadFile_chunked_test();
5223 HttpSendRequestEx_test();
5224 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[3]);
5225 test_connection_failure();
5226 test_default_service_port();