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
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) \
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) \
63 if (!expect[status] && !optional[status] && wine_allow[status]) \
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]--; \
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]--; \
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) \
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); \
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
115 const char *redirected_url
;
120 const char *post_data
;
124 static const test_data_t test_data
[] = {
126 "http://test.winehq.org/tests/data.php",
127 "http://test.winehq.org/tests/data.php",
134 "http://test.winehq.org/tests/redirect",
135 "http://test.winehq.org/tests/hello.html",
142 "http://www.codeweavers.com/",
143 "http://www.codeweavers.com/",
144 "www.codeweavers.com",
146 "Accept-Encoding: gzip, deflate",
150 "http://test.winehq.org/tests/post.php",
151 "http://test.winehq.org/tests/post.php",
154 "Content-Type: application/x-www-form-urlencoded",
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
)
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
;
178 if (RegOpenKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
179 0, KEY_QUERY_VALUE
, &internet_settings
) != ERROR_SUCCESS
)
182 size
= sizeof(DWORD
);
183 if (RegQueryValueExA(internet_settings
, "ProxyEnable", NULL
, NULL
, (LPBYTE
) &proxy_enable
, &size
) != ERROR_SUCCESS
)
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];
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());
205 todo_wine
ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
207 ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
208 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
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());
216 todo_wine
ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
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
);
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());
227 todo_wine
ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
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
);
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
);
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());
242 todo_wine
ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
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
);
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
);
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
);
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());
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
)
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
;
289 ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
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};
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(
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';
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';
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';
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';
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
)
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
;
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
,
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
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
) {
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());
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");
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
);
601 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
602 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
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);
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());
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
);
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());
646 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
648 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res
,buffer
);
651 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_ENCODING
,buffer
,&length
,0x0);
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",
663 trace("Entering Query loop\n");
667 if (flags
& INTERNET_FLAG_ASYNC
)
668 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
670 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
671 if (flags
& INTERNET_FLAG_ASYNC
)
675 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
677 ok(length
>= exlen
, "length %u < exlen %u\n", length
, exlen
);
681 else if (GetLastError() == ERROR_IO_PENDING
)
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
);
689 ok(exlen
, "length = 0\n");
690 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
691 ok(req_error
, "req_error = 0\n");
694 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
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
);
705 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
707 res
= InternetReadFile(hor
,buffer
,length
,&length
);
711 trace("ReadFile -> %s %i\n",res
?"TRUE":"FALSE",length
);
714 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
715 HeapFree(GetProcessHeap(),0,buffer
);
717 ok(!on_async
, "Returned zero size in response to request complete\n");
722 if(test
->flags
& TESTF_REDIRECT
) {
723 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
724 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
728 close_async_handle(hi
, hCompleteEvent
, 2);
729 CloseHandle(hCompleteEvent
);
730 first_connection_to_test_url
= FALSE
;
733 static void InternetReadFile_chunked_test(void)
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
,
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
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);
786 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
788 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
790 SetLastError( 0xdeadbeef );
792 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
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 );
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() );
807 trace("Entering Query loop\n");
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
);
817 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
819 res
= InternetReadFile(hor
,buffer
,length
,&got
);
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
);
832 res
= InternetReadFile( hor
, buffer
, 1, &got
);
833 ok( res
, "InternetReadFile failed: %u\n", GetLastError() );
834 ok( !got
, "got %u\n", got
);
841 res
= InternetCloseHandle(hor
);
842 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
845 res
= InternetCloseHandle(hi
);
846 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
850 static void InternetReadFileExA_test(int flags
)
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
,
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
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
);
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");
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
);
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
);
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
);
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());
1010 trace("Entering Query loop\n");
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);
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
);
1039 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1045 trace("InternetReadFileEx -> SUCCEEDED\n");
1046 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1047 if (inetbuffers
.dwBufferLength
)
1050 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1051 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
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
)
1074 length
+= inetbuffers
.dwBufferLength
;
1076 ok(length
> 0, "failed to read any of the document\n");
1077 trace("Finished. Read %d bytes\n", length
);
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
;
1089 DWORD size
, readbytes
, totalbytes
=0;
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());
1099 ret
= InternetCanonicalizeUrlA(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1100 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
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)
1128 INTERNET_BUFFERSA BufferIn
;
1129 DWORD dwBytesWritten
, dwBytesRead
, error
;
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" );
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");
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
};
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" );
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");
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
];
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
);
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);
1317 ok(res
, "HttpSendRequest failed: %u\n", GetLastError());
1321 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
1322 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1323 ok(size
== sizeof(content
), "size = %u\n", size
);
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
;
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");
1376 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
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
);
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
);
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());
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");
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
);
1448 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
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());
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");
1469 static void InternetLockRequestFile_test(void)
1471 HINTERNET session
, connect
, request
;
1472 char file_name
[MAX_PATH
];
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");
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
);
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)
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" );
1567 ok( hRequest
!= NULL
, "Failed to open request handle\n");
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");
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");
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 */
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 */
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");
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 */
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 */
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 */
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 */
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");
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");
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");
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");
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");
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");
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");
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");
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");
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
);
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
);
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());
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());
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");
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"
1882 static const char okmsg
[] =
1883 "HTTP/1.1 200 OK\r\n"
1884 "Server: winetest\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"
1896 static const char notokmsg
[] =
1897 "HTTP/1.1 400 Bad Request\r\n"
1898 "Server: winetest\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"
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"
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"
1921 static const char page1
[] =
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"
1927 static const char ok_with_length
[] =
1928 "HTTP/1.1 200 OK\r\n"
1929 "Connection: Keep-Alive\r\n"
1930 "Content-Length: 18\r\n\r\n"
1931 "HTTP/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: 19\r\n\r\n"
1937 "HTTP/1.1 211 OK\r\n\r\n";
1939 struct server_info
{
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;
1952 struct sockaddr_in sa
;
1955 int last_request
= 0;
1956 char host_header
[22];
1957 static BOOL test_b
= FALSE
;
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
)
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
);
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);
1995 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
1996 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
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);
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);
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);
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);
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);
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);
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);
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);
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);
2093 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2095 if (!test_b
&& strstr(buffer
, "/testB HTTP/1.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);
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);
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"))
2142 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2146 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2150 if (strstr(buffer
, "GET /testH"))
2152 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2153 recvfrom(c
, buffer
, sizeof(buffer
), 0, NULL
, NULL
);
2154 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2157 if (strstr(buffer
, "GET /test_no_content"))
2159 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2160 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2162 if (strstr(buffer
, "GET /test_conn_close"))
2164 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2165 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
2166 WaitForSingleObject(conn_close_event
, INFINITE
);
2167 trace("closing connection\n");
2169 if (strstr(buffer
, "GET /test_cache_control_no_cache"))
2171 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2172 if(!test_no_cache
++)
2173 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2175 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2177 if (strstr(buffer
, "GET /test_cache_control_no_store"))
2179 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2180 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2182 if (strstr(buffer
, "GET /test_cache_gzip"))
2184 static const char gzip_response
[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2185 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2186 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2187 if(!test_cache_gzip
++)
2188 send(c
, gzip_response
, sizeof(gzip_response
), 0);
2190 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2192 if (strstr(buffer
, "GET /send_from_buffer"))
2193 send(c
, send_buffer
, strlen(send_buffer
), 0);
2194 if (strstr(buffer
, "/test_cache_control_verb"))
2196 if (!memcmp(buffer
, "GET ", sizeof("GET ")-1) &&
2197 !strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2198 else if (strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2199 else send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2201 if (strstr(buffer
, "GET /test_premature_disconnect"))
2202 trace("closing connection\n");
2206 } while (!last_request
);
2213 static void test_basic_request(int port
, const char *verb
, const char *url
)
2215 HINTERNET hi
, hc
, hr
;
2216 DWORD r
, count
, error
;
2219 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2220 ok(hi
!= NULL
, "open failed\n");
2222 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2223 ok(hc
!= NULL
, "connect failed\n");
2225 hr
= HttpOpenRequestA(hc
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
2226 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2228 SetLastError(0xdeadbeef);
2229 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2230 error
= GetLastError();
2231 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
2232 ok(r
, "HttpSendRequest failed\n");
2235 memset(buffer
, 0, sizeof buffer
);
2236 SetLastError(0xdeadbeef);
2237 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
2238 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2239 ok(count
== sizeof page1
- 1, "count was wrong\n");
2240 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2242 InternetCloseHandle(hr
);
2243 InternetCloseHandle(hc
);
2244 InternetCloseHandle(hi
);
2247 static void test_proxy_indirect(int port
)
2249 HINTERNET hi
, hc
, hr
;
2253 hi
= InternetOpenA(NULL
, 0, NULL
, NULL
, 0);
2254 ok(hi
!= NULL
, "open failed\n");
2256 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2257 ok(hc
!= NULL
, "connect failed\n");
2259 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2260 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2262 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2263 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2266 r
= HttpQueryInfoA(hr
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2267 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
2270 skip("missing proxy header, not testing remaining proxy headers\n");
2273 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2275 test_status_code(hr
, 407);
2276 test_request_flags(hr
, 0);
2279 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2280 ok(r
, "HttpQueryInfo failed\n");
2281 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2284 r
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2285 ok(r
, "HttpQueryInfo failed\n");
2286 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2289 r
= HttpQueryInfoA(hr
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2290 ok(r
, "HttpQueryInfo failed\n");
2291 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2294 r
= HttpQueryInfoA(hr
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2295 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2296 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2299 InternetCloseHandle(hr
);
2300 InternetCloseHandle(hc
);
2301 InternetCloseHandle(hi
);
2304 static void test_proxy_direct(int port
)
2306 HINTERNET hi
, hc
, hr
;
2308 char buffer
[0x40], *url
;
2309 WCHAR bufferW
[0x40];
2310 static const char url_fmt
[] = "http://test.winehq.org:%u/test2";
2311 static CHAR username
[] = "mike",
2312 password
[] = "1101",
2313 useragent
[] = "winetest";
2314 static const WCHAR usernameW
[] = {'m','i','k','e',0},
2315 passwordW
[] = {'1','1','0','1',0},
2316 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2318 /* specify proxy type without the proxy and bypass */
2319 SetLastError(0xdeadbeef);
2320 hi
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2321 error
= GetLastError();
2322 ok(error
== ERROR_INVALID_PARAMETER
||
2323 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %u\n", error
);
2324 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2326 sprintf(buffer
, "localhost:%d\n", port
);
2327 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2328 ok(hi
!= NULL
, "open failed\n");
2330 /* try connect without authorization */
2331 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2332 ok(hc
!= NULL
, "connect failed\n");
2334 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2335 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2338 SetLastError(0xdeadbeef);
2339 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
2340 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2341 ok(!r
, "unexpected success\n");
2342 ok(sz
== 1, "got %u\n", sz
);
2345 SetLastError(0xdeadbeef);
2346 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
2347 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2348 ok(!r
, "unexpected success\n");
2349 ok(sz
== 1, "got %u\n", sz
);
2351 sz
= sizeof(buffer
);
2352 SetLastError(0xdeadbeef);
2353 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2354 ok(r
, "unexpected failure %u\n", GetLastError());
2355 ok(!sz
, "got %u\n", sz
);
2357 sz
= sizeof(buffer
);
2358 SetLastError(0xdeadbeef);
2359 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2360 ok(r
, "unexpected failure %u\n", GetLastError());
2361 ok(!sz
, "got %u\n", sz
);
2364 SetLastError(0xdeadbeef);
2365 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
2366 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2367 ok(!r
, "unexpected success\n");
2368 ok(sz
== 1, "got %u\n", sz
);
2371 SetLastError(0xdeadbeef);
2372 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
2373 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2374 ok(!r
, "unexpected success\n");
2375 ok(sz
== 1, "got %u\n", sz
);
2377 sz
= sizeof(buffer
);
2378 SetLastError(0xdeadbeef);
2379 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2380 ok(r
, "unexpected failure %u\n", GetLastError());
2381 ok(!sz
, "got %u\n", sz
);
2383 sz
= sizeof(buffer
);
2384 SetLastError(0xdeadbeef);
2385 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2386 ok(r
, "unexpected failure %u\n", GetLastError());
2387 ok(!sz
, "got %u\n", sz
);
2390 SetLastError(0xdeadbeef);
2391 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
2392 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2393 ok(!r
, "unexpected success\n");
2394 ok(sz
== 34, "got %u\n", sz
);
2396 sz
= sizeof(buffer
);
2397 SetLastError(0xdeadbeef);
2398 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2399 ok(r
, "unexpected failure %u\n", GetLastError());
2400 ok(sz
== 33, "got %u\n", sz
);
2402 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2403 ok(r
|| broken(!r
), "HttpSendRequest failed %u\n", GetLastError());
2406 win_skip("skipping proxy tests on broken wininet\n");
2410 test_status_code(hr
, 407);
2412 /* set the user + password then try again */
2413 r
= InternetSetOptionA(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2414 ok(!r
, "unexpected success\n");
2416 r
= InternetSetOptionA(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2417 ok(r
, "failed to set user\n");
2419 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2420 ok(r
, "failed to set user\n");
2424 SetLastError(0xdeadbeef);
2425 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2426 ok(!r
, "unexpected failure %u\n", GetLastError());
2427 ok(!buffer
[0], "got %s\n", buffer
);
2428 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2432 SetLastError(0xdeadbeef);
2433 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2434 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2435 ok(!r
, "unexpected success\n");
2436 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2440 SetLastError(0xdeadbeef);
2441 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2442 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2443 ok(!r
, "unexpected success\n");
2444 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2447 sz
= sizeof(buffer
);
2448 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2449 ok(r
, "failed to get username\n");
2450 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2451 ok(sz
== strlen(username
), "got %u\n", sz
);
2454 sz
= sizeof(bufferW
);
2455 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2456 ok(r
, "failed to get username\n");
2457 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
2458 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2460 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
2461 ok(r
, "failed to set user\n");
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 r
= InternetSetOptionA(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
2471 ok(r
, "failed to set useragent\n");
2475 SetLastError(0xdeadbeef);
2476 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2477 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2478 ok(!r
, "unexpected success\n");
2479 ok(sz
== strlen(useragent
) + 1, "got %u\n", sz
);
2482 sz
= sizeof(buffer
);
2483 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2484 ok(r
, "failed to get user agent\n");
2485 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
2486 ok(sz
== strlen(useragent
), "got %u\n", sz
);
2490 SetLastError(0xdeadbeef);
2491 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2492 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2493 ok(!r
, "unexpected success\n");
2494 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2497 sz
= sizeof(bufferW
);
2498 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2499 ok(r
, "failed to get user agent\n");
2500 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
2501 ok(sz
== lstrlenW(useragentW
), "got %u\n", sz
);
2503 r
= InternetSetOptionA(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
2504 ok(r
, "failed to set user\n");
2508 SetLastError(0xdeadbeef);
2509 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2510 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2511 ok(!r
, "unexpected success\n");
2512 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2515 sz
= sizeof(buffer
);
2516 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2517 ok(r
, "failed to get user\n");
2518 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2519 ok(sz
== strlen(username
), "got %u\n", sz
);
2523 SetLastError(0xdeadbeef);
2524 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2525 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2526 ok(!r
, "unexpected success\n");
2527 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2530 sz
= sizeof(bufferW
);
2531 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2532 ok(r
, "failed to get user\n");
2533 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
2534 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2536 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
2537 ok(r
, "failed to set password\n");
2541 SetLastError(0xdeadbeef);
2542 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2543 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2544 ok(!r
, "unexpected success\n");
2545 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2548 sz
= sizeof(buffer
);
2549 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2550 ok(r
, "failed to get password\n");
2551 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2552 ok(sz
== strlen(password
), "got %u\n", sz
);
2556 SetLastError(0xdeadbeef);
2557 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2558 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2559 ok(!r
, "unexpected success\n");
2560 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2563 sz
= sizeof(bufferW
);
2564 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2565 ok(r
, "failed to get password\n");
2566 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2567 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2569 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
2570 sprintf(url
, url_fmt
, port
);
2573 SetLastError(0xdeadbeef);
2574 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2575 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2576 ok(!r
, "unexpected success\n");
2577 ok(sz
== strlen(url
) + 1, "got %u\n", sz
);
2580 sz
= sizeof(buffer
);
2581 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2582 ok(r
, "failed to get url\n");
2583 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
2584 ok(sz
== strlen(url
), "got %u\n", sz
);
2588 SetLastError(0xdeadbeef);
2589 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2590 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2591 ok(!r
, "unexpected success\n");
2592 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2595 sz
= sizeof(bufferW
);
2596 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2597 ok(r
, "failed to get url\n");
2598 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
2599 ok(sz
== strlen(url
), "got %u\n", sz
);
2600 HeapFree(GetProcessHeap(), 0, url
);
2602 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2603 ok(r
, "failed to set password\n");
2607 SetLastError(0xdeadbeef);
2608 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2609 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2610 ok(!r
, "unexpected success\n");
2611 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2614 sz
= sizeof(buffer
);
2615 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2616 ok(r
, "failed to get password\n");
2617 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2618 ok(sz
== strlen(password
), "got %u\n", sz
);
2622 SetLastError(0xdeadbeef);
2623 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2624 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2625 ok(!r
, "unexpected success\n");
2626 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2629 sz
= sizeof(bufferW
);
2630 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2631 ok(r
, "failed to get password\n");
2632 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2633 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2635 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2638 win_skip("skipping proxy tests on broken wininet\n");
2641 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2643 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2644 ok(r
, "HttpQueryInfo failed\n");
2645 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2648 InternetCloseHandle(hr
);
2649 InternetCloseHandle(hc
);
2650 InternetCloseHandle(hi
);
2653 static void test_header_handling_order(int port
)
2655 static const char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
2656 static const char connection
[] = "Connection: Close";
2657 static const char *types
[2] = { "*", NULL
};
2659 HINTERNET session
, connect
, request
;
2660 DWORD size
, status
, data_len
;
2663 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2664 ok(session
!= NULL
, "InternetOpen failed\n");
2666 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2667 ok(connect
!= NULL
, "InternetConnect failed\n");
2669 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2670 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2672 ret
= HttpAddRequestHeadersA(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
2673 ok(ret
, "HttpAddRequestHeaders failed\n");
2675 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
2676 ok(ret
, "HttpSendRequest failed\n");
2678 test_status_code(request
, 200);
2679 test_request_flags(request
, 0);
2681 InternetCloseHandle(request
);
2683 request
= HttpOpenRequestA(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2684 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2686 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2687 ok(ret
, "HttpSendRequest failed\n");
2690 size
= sizeof(status
);
2691 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2692 ok(ret
, "HttpQueryInfo failed\n");
2693 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2695 InternetCloseHandle(request
);
2696 InternetCloseHandle(connect
);
2698 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2699 ok(connect
!= NULL
, "InternetConnect failed\n");
2701 request
= HttpOpenRequestA(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2702 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2704 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2705 ok(ret
, "HttpAddRequestHeaders failed\n");
2707 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2708 ok(ret
, "HttpSendRequest failed\n");
2711 size
= sizeof(status
);
2712 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2713 ok(ret
, "HttpQueryInfo failed\n");
2714 ok(status
== 200, "got status %u, expected 200\n", status
);
2716 InternetCloseHandle(request
);
2717 InternetCloseHandle(connect
);
2719 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2720 ok(connect
!= NULL
, "InternetConnect failed\n");
2722 request
= HttpOpenRequestA(connect
, "POST", "/test7b", NULL
, NULL
, types
, 0, 0);
2723 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2725 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2726 ok(ret
, "HttpAddRequestHeaders failed\n");
2728 data_len
= sizeof(data
);
2729 memset(data
, 'a', sizeof(data
));
2730 ret
= HttpSendRequestA(request
, connection
, ~0u, data
, data_len
);
2731 ok(ret
, "HttpSendRequest failed\n");
2734 size
= sizeof(status
);
2735 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2736 ok(ret
, "HttpQueryInfo failed\n");
2737 ok(status
== 200, "got status %u, expected 200\n", status
);
2739 InternetCloseHandle(request
);
2740 InternetCloseHandle(connect
);
2741 InternetCloseHandle(session
);
2744 static void test_connection_header(int port
)
2746 HINTERNET ses
, con
, req
;
2749 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2750 ok(ses
!= NULL
, "InternetOpen failed\n");
2752 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2753 ok(con
!= NULL
, "InternetConnect failed\n");
2755 req
= HttpOpenRequestA(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 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
, 0, 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
, NULL
, "/test9", 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
);
2785 req
= HttpOpenRequestA(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2786 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2788 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2789 ok(ret
, "HttpSendRequest failed\n");
2791 test_status_code(req
, 200);
2793 InternetCloseHandle(req
);
2794 InternetCloseHandle(con
);
2795 InternetCloseHandle(ses
);
2798 static void test_http1_1(int port
)
2800 HINTERNET ses
, con
, req
;
2803 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2804 ok(ses
!= NULL
, "InternetOpen failed\n");
2806 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2807 ok(con
!= NULL
, "InternetConnect failed\n");
2809 req
= HttpOpenRequestA(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2810 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2812 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2815 InternetCloseHandle(req
);
2817 req
= HttpOpenRequestA(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2818 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2820 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2821 ok(ret
, "HttpSendRequest failed\n");
2824 InternetCloseHandle(req
);
2825 InternetCloseHandle(con
);
2826 InternetCloseHandle(ses
);
2829 static void test_connection_closing(int port
)
2831 HINTERNET session
, connection
, req
;
2834 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2836 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2837 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2839 pInternetSetStatusCallbackA(session
, callback
);
2841 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2842 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2843 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2844 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2846 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2847 req
= HttpOpenRequestA(connection
, "GET", "/testJ", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
2848 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2849 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2851 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2852 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2853 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2854 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2855 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2856 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2857 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2858 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2859 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
2860 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
2861 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2863 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2864 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2865 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2866 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2867 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2869 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2870 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2871 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2872 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2873 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2874 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2875 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2876 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2877 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2878 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2879 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2881 test_status_code(req
, 200);
2883 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2884 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2885 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2886 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2887 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2888 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2889 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2890 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2891 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2893 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2894 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2895 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2896 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2897 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2899 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2900 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2901 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2902 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2903 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2904 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2905 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2906 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2907 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2909 test_status_code(req
, 210);
2911 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2912 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2913 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2914 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2915 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2916 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2917 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2918 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2919 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
2920 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
2921 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2923 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2924 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2925 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2926 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2927 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2929 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2930 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2931 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2932 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2933 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2934 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2935 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2936 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2937 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2938 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2939 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2941 test_status_code(req
, 200);
2943 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
2944 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
2946 close_async_handle(session
, hCompleteEvent
, 2);
2947 CloseHandle(hCompleteEvent
);
2950 static void test_successive_HttpSendRequest(int port
)
2952 HINTERNET session
, connection
, req
;
2955 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2957 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2958 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2960 pInternetSetStatusCallbackA(session
, callback
);
2962 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2963 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2964 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2965 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2967 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2968 req
= HttpOpenRequestA(connection
, "GET", "/testH", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
2969 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2970 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2972 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2973 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2974 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2975 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2976 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2977 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2978 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2979 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2980 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2982 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2983 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2984 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2985 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2986 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2988 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2989 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2990 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2991 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2992 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2993 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2994 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2995 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2996 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2998 test_status_code(req
, 210);
3000 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3001 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3002 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3003 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3004 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3005 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3006 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3007 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3008 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3010 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3011 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3012 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3013 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3014 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3016 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3017 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3018 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3019 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3020 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3021 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3022 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3023 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3024 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3026 test_status_code(req
, 200);
3028 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3029 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3031 close_async_handle(session
, hCompleteEvent
, 2);
3032 CloseHandle(hCompleteEvent
);
3035 static void test_no_content(int port
)
3037 HINTERNET session
, connection
, req
;
3040 trace("Testing 204 no content response...\n");
3042 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3044 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3045 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3047 pInternetSetStatusCallbackA(session
, callback
);
3049 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3050 connection
= InternetConnectA(session
, "localhost", port
,
3051 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3052 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3053 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3055 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3056 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
3057 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3058 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3059 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3061 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3062 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3063 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3064 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3065 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3066 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3067 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3068 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3069 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3070 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3072 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3073 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3074 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3075 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3076 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3078 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3079 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3080 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3081 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3082 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3083 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3084 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3085 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3087 close_async_handle(session
, hCompleteEvent
, 2);
3088 CloseHandle(hCompleteEvent
);
3091 * The connection should be closed before closing handle. This is true for most
3092 * wininet versions (including Wine), but some old win2k versions fail to do that.
3094 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3095 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3098 static void test_conn_close(int port
)
3100 HINTERNET session
, connection
, req
;
3101 DWORD res
, avail
, size
;
3104 trace("Testing connection close connection...\n");
3106 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3107 conn_close_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3109 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3110 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3112 pInternetSetStatusCallbackA(session
, callback
);
3114 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3115 connection
= InternetConnectA(session
, "localhost", port
,
3116 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3117 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3118 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3120 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3121 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
3122 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3123 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3124 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3126 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3127 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3128 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3129 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3130 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3131 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3132 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3133 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3135 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3136 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3137 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3138 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3139 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3141 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3142 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3143 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3144 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3145 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3146 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3147 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3148 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3151 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3152 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3153 ok(avail
!= 0, "avail = 0\n");
3156 res
= InternetReadFile(req
, buf
, avail
, &size
);
3157 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3159 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3160 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3161 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3162 ok(!avail
, "avail = %u, expected 0\n", avail
);
3164 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3165 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3166 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3167 SetEvent(conn_close_event
);
3168 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3169 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3170 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3171 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3172 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3174 close_async_handle(session
, hCompleteEvent
, 2);
3175 CloseHandle(hCompleteEvent
);
3178 static void test_no_cache(int port
)
3180 static const char cache_control_no_cache
[] = "/test_cache_control_no_cache";
3181 static const char cache_control_no_store
[] = "/test_cache_control_no_store";
3182 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3184 char cache_url
[256], buf
[256];
3185 HINTERNET ses
, con
, req
;
3189 trace("Testing no-cache header\n");
3191 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3192 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3194 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3195 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3197 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3198 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3200 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_cache
);
3201 DeleteUrlCacheEntryA(cache_url
);
3203 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3204 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3206 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3208 ok(size
== 12, "read %d bytes of data\n", size
);
3209 InternetCloseHandle(req
);
3211 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3212 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3214 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3215 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3217 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3219 ok(size
== 0, "read %d bytes of data\n", size
);
3220 InternetCloseHandle(req
);
3221 DeleteUrlCacheEntryA(cache_url
);
3223 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_store
, NULL
, NULL
, NULL
, 0, 0);
3224 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3226 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_store
);
3227 DeleteUrlCacheEntryA(cache_url
);
3229 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3230 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3232 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3234 ok(size
== 12, "read %d bytes of data\n", size
);
3235 InternetCloseHandle(req
);
3237 ret
= DeleteUrlCacheEntryA(cache_url
);
3238 ok(!ret
&& GetLastError()==ERROR_FILE_NOT_FOUND
, "cache entry should not exist\n");
3240 InternetCloseHandle(con
);
3241 InternetCloseHandle(ses
);
3244 static void test_cache_read_gzipped(int port
)
3246 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3247 static const char get_gzip
[] = "/test_cache_gzip";
3248 static const char content
[] = "gzip test\n";
3249 static const char text_html
[] = "text/html";
3250 static const char raw_header
[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3252 HINTERNET ses
, con
, req
;
3254 char cache_url
[256], buf
[256];
3257 trace("Testing reading compressed content from cache\n");
3259 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3260 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3262 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3263 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3265 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3266 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3269 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3270 if(!ret
&& GetLastError()==ERROR_INTERNET_INVALID_OPTION
) {
3271 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3272 InternetCloseHandle(req
);
3273 InternetCloseHandle(con
);
3274 InternetCloseHandle(ses
);
3277 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3279 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3280 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3282 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-size
, &read
) && read
)
3284 ok(size
== 10, "read %d bytes of data\n", size
);
3286 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3288 size
= sizeof(buf
)-1;
3289 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3290 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3292 ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3294 size
= sizeof(buf
)-1;
3295 ret
= HttpQueryInfoA(req
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &size
, 0);
3296 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3298 ok(!strncmp(raw_header
, buf
, size
), "buf = %s\n", buf
);
3299 InternetCloseHandle(req
);
3301 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3302 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3305 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3306 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3308 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3309 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3311 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3313 todo_wine
ok(size
== 10, "read %d bytes of data\n", size
);
3315 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3318 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3319 ok(!ret
&& GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND
,
3320 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3321 ret
, GetLastError());
3323 size
= sizeof(buf
)-1;
3324 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3325 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3327 todo_wine
ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3328 InternetCloseHandle(req
);
3330 /* Decompression doesn't work while reading from cache */
3331 test_cache_gzip
= 0;
3332 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3333 DeleteUrlCacheEntryA(cache_url
);
3335 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3336 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3338 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3339 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3341 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3343 ok(size
== 31, "read %d bytes of data\n", size
);
3344 InternetCloseHandle(req
);
3346 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3347 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3350 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3351 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3353 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3354 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3356 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3358 todo_wine
ok(size
== 31, "read %d bytes of data\n", size
);
3361 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3362 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3363 InternetCloseHandle(req
);
3365 InternetCloseHandle(con
);
3366 InternetCloseHandle(ses
);
3368 DeleteUrlCacheEntryA(cache_url
);
3371 static void test_HttpSendRequestW(int port
)
3373 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3374 HINTERNET ses
, con
, req
;
3378 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3379 ok(ses
!= NULL
, "InternetOpen failed\n");
3381 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3382 ok(con
!= NULL
, "InternetConnect failed\n");
3384 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3385 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3387 SetLastError(0xdeadbeef);
3388 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
3389 error
= GetLastError();
3390 ok(!ret
, "HttpSendRequestW succeeded\n");
3391 ok(error
== ERROR_IO_PENDING
||
3392 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
3393 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
3394 "got %u expected ERROR_IO_PENDING\n", error
);
3396 InternetCloseHandle(req
);
3397 InternetCloseHandle(con
);
3398 InternetCloseHandle(ses
);
3401 static void test_cookie_header(int port
)
3403 HINTERNET ses
, con
, req
;
3408 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3409 ok(ses
!= NULL
, "InternetOpen failed\n");
3411 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3412 ok(con
!= NULL
, "InternetConnect failed\n");
3414 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3416 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3417 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3420 size
= sizeof(buffer
);
3421 SetLastError(0xdeadbeef);
3422 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3423 error
= GetLastError();
3424 ok(!ret
, "HttpQueryInfo succeeded\n");
3425 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3427 ret
= HttpAddRequestHeadersA(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
3428 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3431 size
= sizeof(buffer
);
3432 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3433 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3434 ok(!strcmp(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
3436 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3437 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3439 test_status_code(req
, 200);
3442 size
= sizeof(buffer
);
3443 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3444 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3445 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
3447 InternetCloseHandle(req
);
3448 InternetCloseHandle(con
);
3449 InternetCloseHandle(ses
);
3452 static void test_basic_authentication(int port
)
3454 HINTERNET session
, connect
, request
;
3457 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3458 ok(session
!= NULL
, "InternetOpen failed\n");
3460 connect
= InternetConnectA(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
3461 ok(connect
!= NULL
, "InternetConnect failed\n");
3463 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
3464 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3466 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3467 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3469 test_status_code(request
, 200);
3470 test_request_flags(request
, 0);
3472 InternetCloseHandle(request
);
3473 InternetCloseHandle(connect
);
3474 InternetCloseHandle(session
);
3477 static void test_premature_disconnect(int port
)
3479 HINTERNET session
, connect
, request
;
3483 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3484 ok(session
!= NULL
, "InternetOpen failed\n");
3486 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3487 ok(connect
!= NULL
, "InternetConnect failed\n");
3489 request
= HttpOpenRequestA(connect
, NULL
, "/premature_disconnect", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3490 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3492 SetLastError(0xdeadbeef);
3493 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3494 err
= GetLastError();
3495 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
3496 todo_wine
ok(err
== ERROR_HTTP_INVALID_SERVER_RESPONSE
, "got %u\n", err
);
3498 InternetCloseHandle(request
);
3499 InternetCloseHandle(connect
);
3500 InternetCloseHandle(session
);
3503 static void test_invalid_response_headers(int port
)
3505 HINTERNET session
, connect
, request
;
3510 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3511 ok(session
!= NULL
, "InternetOpen failed\n");
3513 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3514 ok(connect
!= NULL
, "InternetConnect failed\n");
3516 request
= HttpOpenRequestA(connect
, NULL
, "/testE", NULL
, NULL
, NULL
, 0, 0);
3517 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3519 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3520 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3522 test_status_code(request
, 401);
3523 test_request_flags(request
, 0);
3526 size
= sizeof(buffer
);
3527 ret
= HttpQueryInfoA( request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3528 ok(ret
, "HttpQueryInfo failed\n");
3529 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
3530 "headers wrong \"%s\"\n", buffer
);
3533 size
= sizeof(buffer
);
3534 ret
= HttpQueryInfoA( request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
3535 ok(ret
, "HttpQueryInfo failed\n");
3536 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
3538 InternetCloseHandle(request
);
3539 InternetCloseHandle(connect
);
3540 InternetCloseHandle(session
);
3543 static void test_response_without_headers(int port
)
3545 HINTERNET hi
, hc
, hr
;
3546 DWORD r
, count
, size
;
3549 SetLastError(0xdeadbeef);
3550 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3551 ok(hi
!= NULL
, "open failed %u\n", GetLastError());
3553 SetLastError(0xdeadbeef);
3554 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3555 ok(hc
!= NULL
, "connect failed %u\n", GetLastError());
3557 SetLastError(0xdeadbeef);
3558 hr
= HttpOpenRequestA(hc
, NULL
, "/testG", NULL
, NULL
, NULL
, 0, 0);
3559 ok(hr
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError());
3561 test_request_flags(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3563 SetLastError(0xdeadbeef);
3564 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
3565 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
3567 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3570 memset(buffer
, 0, sizeof buffer
);
3571 SetLastError(0xdeadbeef);
3572 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
3573 ok(r
, "InternetReadFile failed %u\n", GetLastError());
3574 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
3575 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
3577 test_status_code(hr
, 200);
3578 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3581 size
= sizeof(buffer
);
3582 SetLastError(0xdeadbeef);
3583 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
3584 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3585 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
3588 size
= sizeof(buffer
);
3589 SetLastError(0xdeadbeef);
3590 r
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
3591 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3592 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
3595 size
= sizeof(buffer
);
3596 SetLastError(0xdeadbeef);
3597 r
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3598 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3599 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
3601 InternetCloseHandle(hr
);
3602 InternetCloseHandle(hc
);
3603 InternetCloseHandle(hi
);
3606 static void test_HttpQueryInfo(int port
)
3608 HINTERNET hi
, hc
, hr
;
3609 DWORD size
, index
, error
;
3613 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3614 ok(hi
!= NULL
, "InternetOpen failed\n");
3616 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3617 ok(hc
!= NULL
, "InternetConnect failed\n");
3619 hr
= HttpOpenRequestA(hc
, NULL
, "/testD", NULL
, NULL
, NULL
, 0, 0);
3620 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
3622 size
= sizeof(buffer
);
3623 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3624 error
= GetLastError();
3625 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
3626 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3628 ret
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
3629 ok(ret
, "HttpSendRequest failed\n");
3632 size
= sizeof(buffer
);
3633 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
3634 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3635 ok(index
== 1, "expected 1 got %u\n", index
);
3638 size
= sizeof(buffer
);
3639 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
3640 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3641 ok(index
== 1, "expected 1 got %u\n", index
);
3644 size
= sizeof(buffer
);
3645 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3646 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3647 ok(index
== 0, "expected 0 got %u\n", index
);
3649 size
= sizeof(buffer
);
3650 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3651 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3652 ok(index
== 0, "expected 0 got %u\n", index
);
3654 index
= 0xdeadbeef; /* invalid start index */
3655 size
= sizeof(buffer
);
3656 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3657 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
3658 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
3659 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
3662 size
= sizeof(buffer
);
3663 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
3664 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3665 ok(index
== 0, "expected 0 got %u\n", index
);
3667 size
= sizeof(buffer
);
3668 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3669 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3670 ok(index
== 0, "expected 0 got %u\n", index
);
3672 size
= sizeof(buffer
);
3673 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
3674 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3675 ok(index
== 0, "expected 0 got %u\n", index
);
3677 test_status_code(hr
, 200);
3680 size
= sizeof(buffer
);
3681 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
3682 ok(!ret
, "HttpQueryInfo succeeded\n");
3683 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
3686 size
= sizeof(buffer
);
3687 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
3688 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3689 ok(index
== 1, "expected 1 got %u\n", index
);
3692 size
= sizeof(buffer
);
3693 strcpy(buffer
, "Server");
3694 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
3695 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3696 ok(index
== 1, "expected 1 got %u\n", index
);
3699 size
= sizeof(buffer
);
3700 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
3701 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3702 ok(index
== 1, "expected 1 got %u\n", index
);
3704 size
= sizeof(buffer
);
3705 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
3706 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3707 ok(index
== 2, "expected 2 got %u\n", index
);
3709 InternetCloseHandle(hr
);
3710 InternetCloseHandle(hc
);
3711 InternetCloseHandle(hi
);
3714 static void test_options(int port
)
3716 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi
;
3717 HINTERNET ses
, con
, req
;
3722 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3723 ok(ses
!= NULL
, "InternetOpen failed\n");
3725 SetLastError(0xdeadbeef);
3726 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
3727 error
= GetLastError();
3728 ok(!ret
, "InternetSetOption succeeded\n");
3729 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3731 SetLastError(0xdeadbeef);
3732 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
3733 ok(!ret
, "InternetSetOption succeeded\n");
3734 error
= GetLastError();
3735 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3737 SetLastError(0xdeadbeef);
3738 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
3739 ok(!ret
, "InternetSetOption succeeded\n");
3740 error
= GetLastError();
3741 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3744 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3745 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3747 SetLastError(0xdeadbeef);
3748 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
3749 error
= GetLastError();
3750 ok(!ret
, "InternetQueryOption succeeded\n");
3751 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3753 SetLastError(0xdeadbeef);
3754 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
3755 error
= GetLastError();
3756 ok(!ret
, "InternetQueryOption succeeded\n");
3757 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3760 SetLastError(0xdeadbeef);
3761 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
3762 error
= GetLastError();
3763 ok(!ret
, "InternetQueryOption succeeded\n");
3764 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
3767 SetLastError(0xdeadbeef);
3768 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3769 error
= GetLastError();
3770 ok(!ret
, "InternetQueryOption succeeded\n");
3771 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
3775 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3776 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3777 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
3779 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3780 ok(con
!= NULL
, "InternetConnect failed\n");
3784 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3785 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3786 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
3789 ret
= InternetSetOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3790 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3794 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3795 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3796 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
3798 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3799 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3803 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3804 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3805 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
3808 ret
= InternetSetOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3809 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3813 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3814 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3815 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
3817 size
= sizeof(idsi
);
3818 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO
, &idsi
, &size
);
3819 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3822 SetLastError(0xdeadbeef);
3823 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
3824 error
= GetLastError();
3825 ok(!ret
, "InternetQueryOption succeeded\n");
3826 ok(error
== ERROR_INTERNET_INVALID_OPERATION
, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error
);
3828 /* INTERNET_OPTION_PROXY */
3829 SetLastError(0xdeadbeef);
3830 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
3831 error
= GetLastError();
3832 ok(!ret
, "InternetQueryOption succeeded\n");
3833 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3835 SetLastError(0xdeadbeef);
3836 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
3837 error
= GetLastError();
3838 ok(!ret
, "InternetQueryOption succeeded\n");
3839 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3842 SetLastError(0xdeadbeef);
3843 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
3844 error
= GetLastError();
3845 ok(!ret
, "InternetQueryOption succeeded\n");
3846 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
3847 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
3849 InternetCloseHandle(req
);
3850 InternetCloseHandle(con
);
3851 InternetCloseHandle(ses
);
3855 const char *response_text
;
3857 const char *status_text
;
3858 const char *raw_headers
;
3859 } http_status_test_t
;
3861 static const http_status_test_t http_status_tests
[] = {
3863 "HTTP/1.1 200 OK\r\n"
3864 "Content-Length: 1\r\n"
3870 "HTTP/1.1 404 Fail\r\n"
3871 "Content-Length: 1\r\n"
3878 "Content-Length: 1\r\n"
3885 "Content-Length: 1\r\n"
3892 static void test_http_status(int port
)
3894 HINTERNET ses
, con
, req
;
3899 for(i
=0; i
< sizeof(http_status_tests
)/sizeof(*http_status_tests
); i
++) {
3900 send_buffer
= http_status_tests
[i
].response_text
;
3902 ses
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3903 ok(ses
!= NULL
, "InternetOpen failed\n");
3905 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3906 ok(con
!= NULL
, "InternetConnect failed\n");
3908 req
= HttpOpenRequestA(con
, NULL
, "/send_from_buffer", NULL
, NULL
, NULL
, 0, 0);
3909 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3911 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3912 ok(res
, "HttpSendRequest failed\n");
3914 test_status_code(req
, http_status_tests
[i
].status_code
);
3917 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_TEXT
, buf
, &size
, NULL
);
3918 ok(res
, "HttpQueryInfo failed: %u\n", GetLastError());
3919 ok(!strcmp(buf
, http_status_tests
[i
].status_text
), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
3920 i
, buf
, http_status_tests
[i
].status_text
);
3922 InternetCloseHandle(req
);
3923 InternetCloseHandle(con
);
3924 InternetCloseHandle(ses
);
3928 static void test_cache_control_verb(int port
)
3930 HINTERNET session
, connect
, request
;
3933 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3934 ok(session
!= NULL
, "InternetOpen failed\n");
3936 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3937 ok(connect
!= NULL
, "InternetConnect failed\n");
3939 request
= HttpOpenRequestA(connect
, "RPC_OUT_DATA", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3940 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3941 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3942 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3943 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3944 test_status_code(request
, 200);
3945 InternetCloseHandle(request
);
3947 request
= HttpOpenRequestA(connect
, "POST", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3948 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3949 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3950 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3951 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3952 test_status_code(request
, 200);
3953 InternetCloseHandle(request
);
3955 request
= HttpOpenRequestA(connect
, "HEAD", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3956 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3957 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3958 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3959 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3960 test_status_code(request
, 200);
3961 InternetCloseHandle(request
);
3963 request
= HttpOpenRequestA(connect
, "GET", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3964 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3965 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3966 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3967 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3968 test_status_code(request
, 200);
3969 InternetCloseHandle(request
);
3971 InternetCloseHandle(connect
);
3972 InternetCloseHandle(session
);
3975 static void test_http_connection(void)
3977 struct server_info si
;
3981 si
.hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
3984 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
3985 ok( hThread
!= NULL
, "create thread failed\n");
3987 r
= WaitForSingleObject(si
.hEvent
, 10000);
3988 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
3989 if (r
!= WAIT_OBJECT_0
)
3992 test_basic_request(si
.port
, "GET", "/test1");
3993 test_proxy_indirect(si
.port
);
3994 test_proxy_direct(si
.port
);
3995 test_header_handling_order(si
.port
);
3996 test_basic_request(si
.port
, "POST", "/test5");
3997 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
3998 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
3999 test_basic_request(si
.port
, "GET", "/test6");
4000 test_basic_request(si
.port
, "GET", "/testF");
4001 test_connection_header(si
.port
);
4002 test_http1_1(si
.port
);
4003 test_cookie_header(si
.port
);
4004 test_basic_authentication(si
.port
);
4005 test_invalid_response_headers(si
.port
);
4006 test_response_without_headers(si
.port
);
4007 test_HttpQueryInfo(si
.port
);
4008 test_HttpSendRequestW(si
.port
);
4009 test_options(si
.port
);
4010 test_no_content(si
.port
);
4011 test_conn_close(si
.port
);
4012 test_no_cache(si
.port
);
4013 test_cache_read_gzipped(si
.port
);
4014 test_http_status(si
.port
);
4015 test_premature_disconnect(si
.port
);
4016 test_connection_closing(si
.port
);
4017 test_cache_control_verb(si
.port
);
4018 test_successive_HttpSendRequest(si
.port
);
4020 /* send the basic request again to shutdown the server thread */
4021 test_basic_request(si
.port
, "GET", "/quit");
4023 r
= WaitForSingleObject(hThread
, 3000);
4024 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
4025 CloseHandle(hThread
);
4028 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
4030 LocalFree(info
->lpszSubjectInfo
);
4031 LocalFree(info
->lpszIssuerInfo
);
4032 LocalFree(info
->lpszProtocolName
);
4033 LocalFree(info
->lpszSignatureAlgName
);
4034 LocalFree(info
->lpszEncryptionAlgName
);
4038 const char *ex_subject
;
4039 const char *ex_issuer
;
4040 } cert_struct_test_t
;
4042 static const cert_struct_test_t test_winehq_org_cert
= {
4043 "6JcR7G3G8tgjkeoMcitK-bTbzcpumDSy\r\n"
4045 "See www.rapidssl.com/resources/cps (c)14\r\n"
4046 "Domain Control Validated - RapidSSL(R)\r\n"
4050 "\"GeoTrust, Inc.\"\r\n"
4054 static const cert_struct_test_t test_winehq_com_cert
= {
4059 "test.winehq.com\r\n"
4060 "webmaster@winehq.org",
4065 "test.winehq.com\r\n"
4066 "webmaster@winehq.org"
4069 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
4071 INTERNET_CERTIFICATE_INFOA info
;
4075 memset(&info
, 0x5, sizeof(info
));
4077 size
= sizeof(info
);
4078 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
4079 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
4080 ok(size
== sizeof(info
), "size = %u\n", size
);
4082 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
4083 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
4084 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
4085 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
4086 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
4087 ok(info
.dwKeySize
== 128, "dwKeySize = %u\n", info
.dwKeySize
);
4089 release_cert_info(&info
);
4092 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
4093 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
4095 char url
[INTERNET_MAX_URL_LENGTH
];
4096 const CERT_CHAIN_CONTEXT
*chain
;
4100 if(!pInternetGetSecurityInfoByURLA
) {
4101 win_skip("pInternetGetSecurityInfoByURLA not available\n");
4106 chain
= (void*)0xdeadbeef;
4108 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
4109 if(error
== ERROR_SUCCESS
) {
4110 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
4111 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
4112 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
4113 CertFreeCertificateChain(chain
);
4115 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
4116 "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res
, GetLastError(), error
);
4120 #define test_secflags_option(a,b) _test_secflags_option(__LINE__,a,b)
4121 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
)
4127 size
= sizeof(flags
);
4128 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4129 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4130 ok_(__FILE__
,line
)(flags
== ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n", flags
, ex_flags
);
4132 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
4134 size
= sizeof(flags
);
4135 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4136 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
4137 ok_(__FILE__
,line
)(flags
== ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n", flags
, ex_flags
);
4140 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
4141 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
4145 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
4146 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4149 static void test_security_flags(void)
4151 INTERNET_CERTIFICATE_INFOA
*cert
;
4152 HINTERNET ses
, conn
, req
;
4157 trace("Testing security flags...\n");
4159 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4161 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4162 ok(ses
!= NULL
, "InternetOpen failed\n");
4164 pInternetSetStatusCallbackA(ses
, &callback
);
4166 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4167 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
4168 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
4169 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
4170 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4172 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4173 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4174 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4176 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4177 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4180 size
= sizeof(flags
);
4181 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4182 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
4183 win_skip("Incomplete security flags support, skipping\n");
4185 close_async_handle(ses
, hCompleteEvent
, 2);
4186 CloseHandle(hCompleteEvent
);
4190 test_secflags_option(req
, 0);
4191 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4193 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4194 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
);
4196 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4197 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4199 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4200 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4202 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
4203 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
4204 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
4206 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
4207 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
4208 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4209 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4210 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4211 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4212 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4213 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4214 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4215 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4216 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4218 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4219 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4221 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4222 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4224 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
4225 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
4226 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4227 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4228 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4229 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4230 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4231 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4232 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4233 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4234 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4236 test_request_flags(req
, 0);
4237 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4238 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
);
4240 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4241 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4242 ok(size
, "size = 0\n");
4244 /* Collect all existing persistent connections */
4245 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4246 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4248 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4249 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4250 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4252 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4253 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4255 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
4256 res
= InternetSetOptionA(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
4257 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
4259 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4260 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4261 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4262 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4263 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4264 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4265 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4267 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4268 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4270 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4271 ok(req_error
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| broken(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
),
4272 "req_error = %d\n", req_error
);
4275 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
4276 ok(res
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4277 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %u\n", size
);
4278 cert
= HeapAlloc(GetProcessHeap(), 0, size
);
4279 cert
->lpszSubjectInfo
= NULL
;
4280 cert
->lpszIssuerInfo
= NULL
;
4281 cert
->lpszSignatureAlgName
= (char *)0xdeadbeef;
4282 cert
->lpszEncryptionAlgName
= (char *)0xdeadbeef;
4283 cert
->lpszProtocolName
= (char *)0xdeadbeef;
4284 cert
->dwKeySize
= 0xdeadbeef;
4285 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, cert
, &size
);
4286 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
4289 ok(cert
->lpszSubjectInfo
&& strlen(cert
->lpszSubjectInfo
) > 1, "expected a non-empty subject name\n");
4290 ok(cert
->lpszIssuerInfo
&& strlen(cert
->lpszIssuerInfo
) > 1, "expected a non-empty issuer name\n");
4291 ok(!cert
->lpszSignatureAlgName
, "unexpected signature algorithm name\n");
4292 ok(!cert
->lpszEncryptionAlgName
, "unexpected encryption algorithm name\n");
4293 ok(!cert
->lpszProtocolName
, "unexpected protocol name\n");
4294 ok(cert
->dwKeySize
!= 0xdeadbeef, "unexpected key size\n");
4296 HeapFree(GetProcessHeap(), 0, cert
);
4298 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4299 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4300 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4301 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4302 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4303 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4304 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4306 if(req_error
!= ERROR_INTERNET_SEC_CERT_REV_FAILED
) {
4307 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error
);
4309 close_async_handle(ses
, hCompleteEvent
, 3);
4310 CloseHandle(hCompleteEvent
);
4315 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
4316 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
4318 test_request_flags(req
, 8);
4319 test_secflags_option(req
, 0x800000);
4321 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4322 test_secflags_option(req
, 0x800000|SECURITY_FLAG_IGNORE_REVOCATION
);
4324 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4325 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4326 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4327 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4328 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4329 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4330 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4332 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4333 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4335 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4336 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
4338 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4339 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4340 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4341 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4342 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4343 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4344 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4346 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
4347 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4348 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4350 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4351 test_secflags_option(req
, 0x1800000|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4352 |SECURITY_FLAG_IGNORE_REVOCATION
);
4353 test_http_version(req
);
4355 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4356 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4357 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4358 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4359 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4360 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4361 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4362 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4363 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4365 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4366 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4368 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4369 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4371 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4372 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4373 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4374 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4375 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4376 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4377 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4378 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4379 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4381 test_request_flags(req
, 0);
4382 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
4383 |SECURITY_FLAG_STRENGTH_STRONG
|0x1800000);
4385 test_cert_struct(req
, &test_winehq_com_cert
);
4386 test_security_info("https://test.winehq.com/data/some_file.html?q", 0, 0x1800000);
4388 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4389 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4390 ok(size
, "size = 0\n");
4392 close_async_handle(ses
, hCompleteEvent
, 3);
4394 /* Collect all existing persistent connections */
4395 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4396 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4398 /* Make another request, without setting security flags */
4400 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4401 ok(ses
!= NULL
, "InternetOpen failed\n");
4403 pInternetSetStatusCallbackA(ses
, &callback
);
4405 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4406 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
4407 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
4408 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
4409 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4411 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4412 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4413 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4415 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4416 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4418 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
4419 |SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4420 test_http_version(req
);
4422 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4423 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4424 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4425 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4426 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4427 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4428 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4429 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4431 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4432 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4434 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4435 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4437 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4438 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4439 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4440 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4441 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4442 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4443 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4444 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4446 test_request_flags(req
, 0);
4447 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
4448 |SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4450 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4451 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4452 ok(size
, "size = 0\n");
4454 close_async_handle(ses
, hCompleteEvent
, 2);
4456 CloseHandle(hCompleteEvent
);
4458 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4459 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4460 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4463 static void test_secure_connection(void)
4465 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
4466 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
4467 static const WCHAR get
[] = {'G','E','T',0};
4468 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
4469 HINTERNET ses
, con
, req
;
4471 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
4472 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
4475 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4476 ok(ses
!= NULL
, "InternetOpen failed\n");
4478 con
= InternetConnectA(ses
, "test.winehq.org",
4479 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
4480 INTERNET_SERVICE_HTTP
, 0, 0);
4481 ok(con
!= NULL
, "InternetConnect failed\n");
4483 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4484 INTERNET_FLAG_SECURE
, 0);
4485 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4487 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4488 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
4490 size
= sizeof(flags
);
4491 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4492 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4493 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
4495 test_cert_struct(req
, &test_winehq_org_cert
);
4497 /* Querying the same option through InternetQueryOptionW still results in
4498 * ASCII strings being returned.
4501 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4503 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4504 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
4505 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
4506 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4507 certificate_structW
, &size
);
4508 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
4509 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4512 ok(certificate_structA
->lpszSubjectInfo
&&
4513 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4514 "expected a non-empty subject name\n");
4515 ok(certificate_structA
->lpszIssuerInfo
&&
4516 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4517 "expected a non-empty issuer name\n");
4518 ok(!certificate_structA
->lpszSignatureAlgName
,
4519 "unexpected signature algorithm name\n");
4520 ok(!certificate_structA
->lpszEncryptionAlgName
,
4521 "unexpected encryption algorithm name\n");
4522 ok(!certificate_structA
->lpszProtocolName
,
4523 "unexpected protocol name\n");
4524 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4525 release_cert_info(certificate_structA
);
4527 HeapFree(GetProcessHeap(), 0, certificate_structW
);
4529 InternetCloseHandle(req
);
4530 InternetCloseHandle(con
);
4531 InternetCloseHandle(ses
);
4533 /* Repeating the tests with the W functions has the same result: */
4534 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4535 ok(ses
!= NULL
, "InternetOpen failed\n");
4537 con
= InternetConnectW(ses
, testsite
,
4538 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
4539 INTERNET_SERVICE_HTTP
, 0, 0);
4540 ok(con
!= NULL
, "InternetConnect failed\n");
4542 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
4543 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
4544 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4546 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4547 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
4549 size
= sizeof(flags
);
4550 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4551 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4552 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %x\n", flags
);
4554 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4556 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4557 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
4558 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
4559 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4560 certificate_structA
, &size
);
4561 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4564 ok(certificate_structA
->lpszSubjectInfo
&&
4565 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4566 "expected a non-empty subject name\n");
4567 ok(certificate_structA
->lpszIssuerInfo
&&
4568 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4569 "expected a non-empty issuer name\n");
4570 ok(!certificate_structA
->lpszSignatureAlgName
,
4571 "unexpected signature algorithm name\n");
4572 ok(!certificate_structA
->lpszEncryptionAlgName
,
4573 "unexpected encryption algorithm name\n");
4574 ok(!certificate_structA
->lpszProtocolName
,
4575 "unexpected protocol name\n");
4576 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4577 release_cert_info(certificate_structA
);
4579 HeapFree(GetProcessHeap(), 0, certificate_structA
);
4581 /* Again, querying the same option through InternetQueryOptionW still
4582 * results in ASCII strings being returned.
4585 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4587 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4588 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
4589 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
4590 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4591 certificate_structW
, &size
);
4592 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
4593 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4596 ok(certificate_structA
->lpszSubjectInfo
&&
4597 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4598 "expected a non-empty subject name\n");
4599 ok(certificate_structA
->lpszIssuerInfo
&&
4600 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4601 "expected a non-empty issuer name\n");
4602 ok(!certificate_structA
->lpszSignatureAlgName
,
4603 "unexpected signature algorithm name\n");
4604 ok(!certificate_structA
->lpszEncryptionAlgName
,
4605 "unexpected encryption algorithm name\n");
4606 ok(!certificate_structA
->lpszProtocolName
,
4607 "unexpected protocol name\n");
4608 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4609 release_cert_info(certificate_structA
);
4611 HeapFree(GetProcessHeap(), 0, certificate_structW
);
4613 InternetCloseHandle(req
);
4614 InternetCloseHandle(con
);
4615 InternetCloseHandle(ses
);
4618 static void test_user_agent_header(void)
4620 HINTERNET ses
, con
, req
;
4625 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4626 ok(ses
!= NULL
, "InternetOpen failed\n");
4628 con
= InternetConnectA(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4629 ok(con
!= NULL
, "InternetConnect failed\n");
4631 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
4632 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4634 size
= sizeof(buffer
);
4635 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4636 err
= GetLastError();
4637 ok(!ret
, "HttpQueryInfo succeeded\n");
4638 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4640 ret
= HttpAddRequestHeadersA(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
4641 ok(ret
, "HttpAddRequestHeaders succeeded\n");
4643 size
= sizeof(buffer
);
4644 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4645 err
= GetLastError();
4646 ok(ret
, "HttpQueryInfo failed\n");
4647 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4649 InternetCloseHandle(req
);
4651 req
= HttpOpenRequestA(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
4652 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4654 size
= sizeof(buffer
);
4655 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4656 err
= GetLastError();
4657 ok(!ret
, "HttpQueryInfo succeeded\n");
4658 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4660 ret
= HttpAddRequestHeadersA(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
4661 ok(ret
, "HttpAddRequestHeaders failed\n");
4664 size
= sizeof(buffer
);
4665 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4666 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
4667 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
4669 InternetCloseHandle(req
);
4670 InternetCloseHandle(con
);
4671 InternetCloseHandle(ses
);
4674 static void test_bogus_accept_types_array(void)
4676 HINTERNET ses
, con
, req
;
4677 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
4682 ses
= InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
4683 con
= InternetConnectA(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4684 req
= HttpOpenRequestA(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
4686 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
4689 size
= sizeof(buffer
);
4690 SetLastError(0xdeadbeef);
4691 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4692 error
= GetLastError();
4693 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
4694 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
4695 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
4696 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
4697 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
4699 InternetCloseHandle(req
);
4700 InternetCloseHandle(con
);
4701 InternetCloseHandle(ses
);
4710 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
4712 INTERNET_ASYNC_RESULT
*result
= info
;
4713 struct context
*ctx
= (struct context
*)context
;
4715 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
4718 case INTERNET_STATUS_REQUEST_COMPLETE
:
4719 trace("request handle: 0x%08lx\n", result
->dwResult
);
4720 ctx
->req
= (HINTERNET
)result
->dwResult
;
4721 SetEvent(ctx
->event
);
4723 case INTERNET_STATUS_HANDLE_CLOSING
: {
4724 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
4726 if (InternetQueryOptionA(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
4727 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
4728 SetEvent(ctx
->event
);
4731 case INTERNET_STATUS_NAME_RESOLVED
:
4732 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
4733 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
4735 ok(str
[0] && str
[1], "Got string: %s\n", str
);
4736 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
4741 static void test_open_url_async(void)
4749 /* Collect all existing persistent connections */
4750 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4751 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4754 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
4755 * other versions never do. They also hang of following tests. We disable it for everything older
4758 if(!pInternetGetSecurityInfoByURLA
) {
4759 win_skip("Skipping async open on too old wininet version.\n");
4764 ctx
.event
= CreateEventA(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
4766 ses
= InternetOpenA("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4767 ok(ses
!= NULL
, "InternetOpen failed\n");
4769 SetLastError(0xdeadbeef);
4770 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
4771 error
= GetLastError();
4772 ok(!ret
, "InternetSetOptionA succeeded\n");
4773 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
4775 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
4776 error
= GetLastError();
4777 ok(!ret
, "InternetSetOptionA failed\n");
4778 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
4780 pInternetSetStatusCallbackW(ses
, cb
);
4781 ResetEvent(ctx
.event
);
4783 req
= InternetOpenUrlA(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
4784 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
4786 WaitForSingleObject(ctx
.event
, INFINITE
);
4789 size
= sizeof(type
);
4790 ret
= InternetQueryOptionA(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
4791 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
4792 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
4793 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
4796 ret
= HttpQueryInfoA(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
4797 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
4798 ok(size
> 0, "expected size > 0\n");
4800 ResetEvent(ctx
.event
);
4801 InternetCloseHandle(ctx
.req
);
4802 WaitForSingleObject(ctx
.event
, INFINITE
);
4804 InternetCloseHandle(ses
);
4805 CloseHandle(ctx
.event
);
4810 internet_connect
= 1,
4812 http_send_request_ex
,
4815 internet_close_handle
4820 enum api function
; /* api responsible for notification */
4821 unsigned int status
; /* status received */
4822 BOOL async
; /* delivered from another thread? */
4830 const struct notification
*test
;
4836 DWORD expect_result
;
4840 static CRITICAL_SECTION notification_cs
;
4842 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
4844 BOOL status_ok
, function_ok
;
4845 struct info
*info
= (struct info
*)context
;
4848 EnterCriticalSection( ¬ification_cs
);
4850 if(info
->is_aborted
) {
4851 LeaveCriticalSection(¬ification_cs
);
4855 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
4857 DWORD size
= sizeof(struct info
*);
4858 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
4859 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
4860 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
4862 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
4863 if(info
->expect_result
== ERROR_SUCCESS
) {
4864 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
4866 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
4867 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
4872 if (i
>= info
->count
)
4874 LeaveCriticalSection( ¬ification_cs
);
4878 while (info
->test
[i
].status
!= status
&&
4879 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
4880 i
< info
->count
- 1 &&
4881 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
4886 status_ok
= (info
->test
[i
].status
== status
);
4887 function_ok
= (info
->test
[i
].function
== info
->function
);
4889 if (!info
->test
[i
].todo
)
4891 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
4892 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
4894 if (info
->test
[i
].async
)
4895 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
4896 info
->line
, info
->thread
, GetCurrentThreadId());
4900 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
4902 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
4904 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
4907 LeaveCriticalSection( ¬ification_cs
);
4910 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
4912 info
->function
= function
;
4914 info
->expect_result
= expect_result
;
4917 struct notification_data
4919 const struct notification
*test
;
4920 const unsigned int count
;
4925 BOOL expect_conn_failure
;
4928 static const struct notification async_send_request_ex_test
[] =
4930 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
4931 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
4932 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
4933 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
4934 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
4935 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
4936 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
4937 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
4938 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
4939 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
4940 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
4941 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, FALSE
},
4942 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, FALSE
},
4943 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
4944 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
4945 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
4946 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
4947 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
4948 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
4949 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
4952 static const struct notification async_send_request_ex_test2
[] =
4954 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
4955 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
4956 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
4957 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
4958 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
4959 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
4960 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
, TRUE
},
4961 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
, TRUE
},
4962 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
4963 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
4964 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
4965 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
4966 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
4967 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
4968 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
4969 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
4970 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
4971 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
4974 static const struct notification async_send_request_ex_resolve_failure_test
[] =
4976 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
4977 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
4978 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
4979 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
},
4980 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
4981 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
4982 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
4983 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
4984 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
4985 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
4986 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
4989 static const struct notification async_send_request_ex_chunked_test
[] =
4991 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
},
4992 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
},
4993 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
4994 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
4995 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
4996 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
4997 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
4998 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
4999 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
5000 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
5001 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5002 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
5003 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
5004 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5005 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
},
5006 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
},
5007 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
},
5008 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
}
5011 static const struct notification_data notification_data
[] = {
5013 async_send_request_ex_chunked_test
,
5014 sizeof(async_send_request_ex_chunked_test
)/sizeof(async_send_request_ex_chunked_test
[0]),
5020 async_send_request_ex_test
,
5021 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
5024 "tests/posttest.php",
5025 "Public ID=codeweavers"
5028 async_send_request_ex_test2
,
5029 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
5032 "tests/posttest.php"
5035 async_send_request_ex_resolve_failure_test
,
5036 sizeof(async_send_request_ex_resolve_failure_test
)/sizeof(async_send_request_ex_resolve_failure_test
[0]),
5045 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
5048 HINTERNET ses
, req
, con
;
5050 DWORD size
, written
, error
;
5051 INTERNET_BUFFERSA b
;
5052 static const char *accept
[2] = {"*/*", NULL
};
5055 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
5057 InitializeCriticalSection( ¬ification_cs
);
5059 info
.test
= nd
->test
;
5060 info
.count
= nd
->count
;
5062 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
5063 info
.thread
= GetCurrentThreadId();
5064 info
.is_aborted
= FALSE
;
5066 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5067 ok( ses
!= NULL
, "InternetOpen failed\n" );
5069 pInternetSetStatusCallbackA( ses
, check_notification
);
5071 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
5072 con
= InternetConnectA( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
5073 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
5075 WaitForSingleObject( info
.wait
, 10000 );
5077 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
5078 req
= HttpOpenRequestA( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
5079 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
5081 WaitForSingleObject( info
.wait
, 10000 );
5084 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
5085 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
5086 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
5087 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
5088 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
5091 setup_test( &info
, http_send_request_ex
, __LINE__
,
5092 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
5093 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
5094 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
5096 error
= WaitForSingleObject( info
.wait
, 10000 );
5097 if(error
!= WAIT_OBJECT_0
) {
5098 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
5099 info
.is_aborted
= TRUE
;
5103 size
= sizeof(buffer
);
5104 SetLastError( 0xdeadbeef );
5105 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
5106 error
= GetLastError();
5107 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
5108 if(nd
->expect_conn_failure
) {
5109 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
5112 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
5113 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
5119 size
= strlen( nd
->data
);
5120 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
5121 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
5122 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
5123 ok( written
== size
, "expected %u got %u\n", written
, size
);
5125 WaitForSingleObject( info
.wait
, 10000 );
5127 SetLastError( 0xdeadbeef );
5128 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
5129 error
= GetLastError();
5130 ok( !ret
, "HttpEndRequestA succeeded\n" );
5131 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
5134 SetLastError( 0xdeadbeef );
5135 setup_test( &info
, http_end_request
, __LINE__
,
5136 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
5137 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
5138 error
= GetLastError();
5139 ok( !ret
, "HttpEndRequestA succeeded\n" );
5140 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
5142 WaitForSingleObject( info
.wait
, 10000 );
5144 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
5146 InternetCloseHandle( req
);
5147 InternetCloseHandle( con
);
5148 InternetCloseHandle( ses
);
5150 WaitForSingleObject( info
.wait
, 10000 );
5152 CloseHandle( info
.wait
);
5155 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
5156 static BOOL closetest_closed
;
5158 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
5159 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
5164 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
5166 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
5167 "Unexpected hInternet %p\n", hInternet
);
5168 if(!closetest_closed
)
5172 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
5173 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
5174 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5175 closetest_req
, res
, GetLastError());
5178 static void test_InternetCloseHandle(void)
5183 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5184 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
5186 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
5188 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
5189 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
5190 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
5192 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
5193 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
5195 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
5196 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
5197 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
5199 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
5201 res
= InternetCloseHandle(closetest_session
);
5202 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
5203 closetest_closed
= TRUE
;
5204 trace("Closed session handle\n");
5206 res
= InternetCloseHandle(closetest_conn
);
5207 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
5208 res
, GetLastError());
5210 res
= InternetCloseHandle(closetest_req
);
5211 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
5212 res
, GetLastError());
5214 len
= sizeof(flags
);
5215 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
5216 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
5217 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5218 closetest_req
, res
, GetLastError());
5221 static void test_connection_failure(void)
5223 HINTERNET session
, connect
, request
;
5227 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5228 ok(session
!= NULL
, "failed to get session handle\n");
5230 connect
= InternetConnectA(session
, "localhost", 1, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5231 ok(connect
!= NULL
, "failed to get connection handle\n");
5233 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
5234 ok(request
!= NULL
, "failed to get request handle\n");
5236 SetLastError(0xdeadbeef);
5237 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
5238 error
= GetLastError();
5239 ok(!ret
, "unexpected success\n");
5240 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
5242 InternetCloseHandle(request
);
5243 InternetCloseHandle(connect
);
5244 InternetCloseHandle(session
);
5247 static void test_default_service_port(void)
5249 HINTERNET session
, connect
, request
;
5253 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
5254 ok(session
!= NULL
, "InternetOpen failed\n");
5256 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
5257 INTERNET_SERVICE_HTTP
, 0, 0);
5258 ok(connect
!= NULL
, "InternetConnect failed\n");
5260 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
5261 ok(request
!= NULL
, "HttpOpenRequest failed\n");
5263 SetLastError(0xdeadbeef);
5264 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
5265 error
= GetLastError();
5266 ok(!ret
, "HttpSendRequest succeeded\n");
5267 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
5270 InternetCloseHandle(request
);
5271 InternetCloseHandle(connect
);
5272 InternetCloseHandle(session
);
5275 static void init_status_tests(void)
5277 memset(expect
, 0, sizeof(expect
));
5278 memset(optional
, 0, sizeof(optional
));
5279 memset(wine_allow
, 0, sizeof(wine_allow
));
5280 memset(notified
, 0, sizeof(notified
));
5281 memset(status_string
, 0, sizeof(status_string
));
5283 #define STATUS_STRING(status) status_string[status] = #status
5284 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
5285 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
5286 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5287 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5288 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
5289 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
5290 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
5291 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
5292 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
5293 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
5294 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
5295 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
5296 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
5297 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
5298 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
5299 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
5300 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
5301 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
5302 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
5303 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
5304 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
5305 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
5306 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
5307 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
5308 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
5309 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
5310 #undef STATUS_STRING
5316 hdll
= GetModuleHandleA("wininet.dll");
5318 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
5319 win_skip("Too old IE (older than 6.0)\n");
5323 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
5324 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
5325 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
5327 init_status_tests();
5328 test_InternetCloseHandle();
5329 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
5330 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
5331 InternetReadFile_test(0, &test_data
[1]);
5332 first_connection_to_test_url
= TRUE
;
5333 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
5334 test_security_flags();
5335 InternetReadFile_test(0, &test_data
[2]);
5336 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
5337 test_open_url_async();
5338 test_async_HttpSendRequestEx(¬ification_data
[0]);
5339 test_async_HttpSendRequestEx(¬ification_data
[1]);
5340 test_async_HttpSendRequestEx(¬ification_data
[2]);
5341 test_async_HttpSendRequestEx(¬ification_data
[3]);
5342 InternetOpenRequest_test();
5344 InternetLockRequestFile_test();
5345 InternetOpenUrlA_test();
5347 test_http_connection();
5348 test_secure_connection();
5349 test_user_agent_header();
5350 test_bogus_accept_types_array();
5351 InternetReadFile_chunked_test();
5352 HttpSendRequestEx_test();
5353 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
5354 test_connection_failure();
5355 test_default_service_port();