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
34 #include "wine/test.h"
36 /* Undocumented security flags */
37 #define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
38 #define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
39 #define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
40 #define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
42 #define TEST_URL "http://test.winehq.org/tests/hello.html"
44 static BOOL first_connection_to_test_url
= TRUE
;
45 static BOOL https_support
= TRUE
;
47 /* Adapted from dlls/urlmon/tests/protocol.c */
49 #define SET_EXPECT2(status, num) \
52 #define SET_EXPECT(status) \
53 SET_EXPECT2(status, 1)
55 #define SET_OPTIONAL2(status, num) \
56 optional[status] = num
58 #define SET_OPTIONAL(status) \
59 SET_OPTIONAL2(status, 1)
61 /* SET_WINE_ALLOW's should be used with an appropriate
62 * todo_wine CHECK_NOTIFIED at a later point in the code */
63 #define SET_WINE_ALLOW2(status, num) \
64 wine_allow[status] = num
66 #define SET_WINE_ALLOW(status) \
67 SET_WINE_ALLOW2(status, 1)
69 #define CHECK_EXPECT(status) \
71 if (!expect[status] && !optional[status] && wine_allow[status]) \
73 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
74 status < MAX_INTERNET_STATUS && status_string[status] ? \
75 status_string[status] : "unknown"); \
76 wine_allow[status]--; \
80 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
81 status < MAX_INTERNET_STATUS && status_string[status] ? \
82 status_string[status] : "unknown"); \
83 if (expect[status]) expect[status]--; \
84 else if(optional[status]) optional[status]--; \
89 /* CLEAR_NOTIFIED used in cases when notification behavior
90 * differs between Windows versions */
91 #define CLEAR_NOTIFIED(status) \
92 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
94 #define CHECK_NOTIFIED2(status, num) \
96 ok(notified[status] + optional[status] == (num), \
97 "expected status %d (%s) %d times, received %d times\n", \
98 status, status < MAX_INTERNET_STATUS && status_string[status] ? \
99 status_string[status] : "unknown", (num), notified[status]); \
100 CLEAR_NOTIFIED(status); \
103 #define CHECK_NOTIFIED(status) \
104 CHECK_NOTIFIED2(status, 1)
106 #define CHECK_NOT_NOTIFIED(status) \
107 CHECK_NOTIFIED2(status, 0)
109 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
110 static int expect
[MAX_INTERNET_STATUS
], optional
[MAX_INTERNET_STATUS
],
111 wine_allow
[MAX_INTERNET_STATUS
], notified
[MAX_INTERNET_STATUS
];
112 static const char *status_string
[MAX_INTERNET_STATUS
];
114 static HANDLE complete_event
, conn_close_event
, conn_wait_event
, server_req_rec_event
, request_sent_event
;
115 static DWORD req_error
;
116 static BOOL is_ie7plus
= TRUE
;
118 #define TESTF_REDIRECT 0x01
119 #define TESTF_COMPRESSED 0x02
120 #define TESTF_CHUNKED 0x04
124 const char *redirected_url
;
129 const char *post_data
;
133 static const test_data_t test_data
[] = {
135 "http://test.winehq.org/tests/data.php",
136 "http://test.winehq.org/tests/data.php",
143 "http://test.winehq.org/tests/redirect",
144 "http://test.winehq.org/tests/hello.html",
151 "http://test.winehq.org/tests/gzip.php",
152 "http://test.winehq.org/tests/gzip.php",
155 "Accept-Encoding: gzip, deflate",
159 "http://test.winehq.org/tests/post.php",
160 "http://test.winehq.org/tests/post.php",
163 "Content-Type: application/x-www-form-urlencoded",
170 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackA
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
171 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackW
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
172 static BOOL (WINAPI
*pInternetGetSecurityInfoByURLA
)(LPSTR
,PCCERT_CHAIN_CONTEXT
*,DWORD
*);
174 static BOOL
is_lang_english(void)
176 static HMODULE hkernel32
= NULL
;
177 static LANGID (WINAPI
*pGetThreadUILanguage
)(void) = NULL
;
178 static LANGID (WINAPI
*pGetUserDefaultUILanguage
)(void) = NULL
;
182 hkernel32
= GetModuleHandleA("kernel32.dll");
183 pGetThreadUILanguage
= (void*)GetProcAddress(hkernel32
, "GetThreadUILanguage");
184 pGetUserDefaultUILanguage
= (void*)GetProcAddress(hkernel32
, "GetUserDefaultUILanguage");
186 if (pGetThreadUILanguage
)
187 return PRIMARYLANGID(pGetThreadUILanguage()) == LANG_ENGLISH
;
188 if (pGetUserDefaultUILanguage
)
189 return PRIMARYLANGID(pGetUserDefaultUILanguage()) == LANG_ENGLISH
;
191 return PRIMARYLANGID(GetUserDefaultLangID()) == LANG_ENGLISH
;
194 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
197 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, ARRAY_SIZE(buf
));
198 return lstrcmpW(strw
, buf
);
201 static BOOL
proxy_active(void)
203 HKEY internet_settings
;
207 if (RegOpenKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
208 0, KEY_QUERY_VALUE
, &internet_settings
) != ERROR_SUCCESS
)
211 size
= sizeof(DWORD
);
212 if (RegQueryValueExA(internet_settings
, "ProxyEnable", NULL
, NULL
, (LPBYTE
) &proxy_enable
, &size
) != ERROR_SUCCESS
)
215 RegCloseKey(internet_settings
);
217 return proxy_enable
!= 0;
220 static void init_events(void)
222 complete_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
223 conn_close_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
224 conn_wait_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
225 server_req_rec_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
226 request_sent_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
229 static void free_events(void)
231 CloseHandle(complete_event
);
232 CloseHandle(conn_close_event
);
233 CloseHandle(conn_wait_event
);
234 CloseHandle(server_req_rec_event
);
235 CloseHandle(request_sent_event
);
238 static void reset_events(void)
240 ResetEvent(complete_event
);
241 ResetEvent(conn_close_event
);
242 ResetEvent(conn_wait_event
);
243 ResetEvent(server_req_rec_event
);
244 ResetEvent(request_sent_event
);
247 #define test_status_code(a,b) _test_status_code(__LINE__,a,b, FALSE)
248 #define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)
249 static void _test_status_code(unsigned line
, HINTERNET req
, DWORD excode
, BOOL is_todo
)
251 DWORD code
, size
, index
;
252 char exbuf
[12], bufa
[10];
258 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, NULL
);
259 ok_(__FILE__
,line
)(res
, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
260 todo_wine_if (is_todo
)
261 ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
262 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
267 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
268 ok_(__FILE__
,line
)(res
, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
269 ok_(__FILE__
,line
)(!index
, "index = %d, expected 0\n", index
);
270 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
272 sprintf(exbuf
, "%u", excode
);
275 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, bufa
, &size
, NULL
);
276 ok_(__FILE__
,line
)(res
, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
277 todo_wine_if (is_todo
)
278 ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
279 ok_(__FILE__
,line
)(size
== strlen(exbuf
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
282 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
283 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
284 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
285 ok_(__FILE__
,line
)(size
== strlen(exbuf
)+1, "unexpected size %d for \"%s\"\n", size
, exbuf
);
288 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
289 ok_(__FILE__
,line
)(res
, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
290 todo_wine_if (is_todo
)
291 ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
292 ok_(__FILE__
,line
)(size
== strlen(exbuf
)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
295 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
296 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
297 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
298 ok_(__FILE__
,line
)(size
== (strlen(exbuf
)+1)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
302 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
303 ok(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
304 ok(size
== sizeof(bufw
), "unexpected size %d\n", size
);
310 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
311 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
312 "[7] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
316 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, &code
, &size
, NULL
);
317 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST
,
318 "[8] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
321 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
322 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
323 static void _test_request_flags(unsigned line
, HINTERNET req
, DWORD exflags
, BOOL is_todo
)
329 size
= sizeof(flags
);
330 res
= InternetQueryOptionW(req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &size
);
331 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
333 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
334 flags
&= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED
;
335 todo_wine_if (is_todo
)
336 ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
339 #define test_request_url(a,b) _test_request_url(__LINE__,a,b)
340 static void _test_request_url(unsigned line
, HINTERNET req
, const char *expected_url
)
342 char buf
[INTERNET_MAX_URL_LENGTH
];
343 DWORD size
= sizeof(buf
);
346 res
= InternetQueryOptionA(req
, INTERNET_OPTION_URL
, buf
, &size
);
347 ok_(__FILE__
,line
)(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
348 ok_(__FILE__
,line
)(size
== strlen(expected_url
), "size = %u\n", size
);
349 ok_(__FILE__
,line
)(!strcmp(buf
, expected_url
), "unexpected URL %s, expected %s\n", buf
, expected_url
);
352 #define test_http_version(a) _test_http_version(__LINE__,a)
353 static void _test_http_version(unsigned line
, HINTERNET req
)
355 HTTP_VERSION_INFO v
= {0xdeadbeef, 0xdeadbeef};
360 res
= InternetQueryOptionW(req
, INTERNET_OPTION_HTTP_VERSION
, &v
, &size
);
361 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
362 ok_(__FILE__
,line
)(v
.dwMajorVersion
== 1, "dwMajorVersion = %d\n", v
.dwMajorVersion
);
363 ok_(__FILE__
,line
)(v
.dwMinorVersion
== 1, "dwMinorVersion = %d\n", v
.dwMinorVersion
);
366 static int close_handle_cnt
;
368 static VOID WINAPI
callback(
371 DWORD dwInternetStatus
,
372 LPVOID lpvStatusInformation
,
373 DWORD dwStatusInformationLength
376 CHECK_EXPECT(dwInternetStatus
);
377 switch (dwInternetStatus
)
379 case INTERNET_STATUS_RESOLVING_NAME
:
380 if(winetest_debug
> 1)
381 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
382 GetCurrentThreadId(), hInternet
, dwContext
,
383 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
384 *(LPSTR
)lpvStatusInformation
= '\0';
386 case INTERNET_STATUS_NAME_RESOLVED
:
387 if(winetest_debug
> 1)
388 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
389 GetCurrentThreadId(), hInternet
, dwContext
,
390 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
391 *(LPSTR
)lpvStatusInformation
= '\0';
393 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
394 if(winetest_debug
> 1)
395 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
396 GetCurrentThreadId(), hInternet
, dwContext
,
397 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
398 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
399 dwStatusInformationLength
);
400 *(LPSTR
)lpvStatusInformation
= '\0';
402 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
403 if(winetest_debug
> 1)
404 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
405 GetCurrentThreadId(), hInternet
, dwContext
,
406 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
407 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
408 dwStatusInformationLength
);
409 *(LPSTR
)lpvStatusInformation
= '\0';
411 case INTERNET_STATUS_SENDING_REQUEST
:
412 if(winetest_debug
> 1)
413 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
414 GetCurrentThreadId(), hInternet
, dwContext
,
415 lpvStatusInformation
,dwStatusInformationLength
);
417 case INTERNET_STATUS_REQUEST_SENT
:
418 ok(dwStatusInformationLength
== sizeof(DWORD
),
419 "info length should be sizeof(DWORD) instead of %d\n",
420 dwStatusInformationLength
);
421 if(winetest_debug
> 1)
422 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
423 GetCurrentThreadId(), hInternet
, dwContext
,
424 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
426 case INTERNET_STATUS_RECEIVING_RESPONSE
:
427 if(winetest_debug
> 1)
428 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
429 GetCurrentThreadId(), hInternet
, dwContext
,
430 lpvStatusInformation
,dwStatusInformationLength
);
432 case INTERNET_STATUS_RESPONSE_RECEIVED
:
433 ok(dwStatusInformationLength
== sizeof(DWORD
),
434 "info length should be sizeof(DWORD) instead of %d\n",
435 dwStatusInformationLength
);
436 if(winetest_debug
> 1)
437 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
438 GetCurrentThreadId(), hInternet
, dwContext
,
439 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
441 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
442 if(winetest_debug
> 1)
443 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
444 GetCurrentThreadId(), hInternet
,dwContext
,
445 lpvStatusInformation
,dwStatusInformationLength
);
447 case INTERNET_STATUS_PREFETCH
:
448 if(winetest_debug
> 1)
449 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
450 GetCurrentThreadId(), hInternet
, dwContext
,
451 lpvStatusInformation
,dwStatusInformationLength
);
453 case INTERNET_STATUS_CLOSING_CONNECTION
:
454 if(winetest_debug
> 1)
455 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
456 GetCurrentThreadId(), hInternet
, dwContext
,
457 lpvStatusInformation
,dwStatusInformationLength
);
459 case INTERNET_STATUS_CONNECTION_CLOSED
:
460 if(winetest_debug
> 1)
461 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
462 GetCurrentThreadId(), hInternet
, dwContext
,
463 lpvStatusInformation
,dwStatusInformationLength
);
465 case INTERNET_STATUS_HANDLE_CREATED
:
466 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
467 "info length should be sizeof(HINTERNET) instead of %d\n",
468 dwStatusInformationLength
);
469 if(winetest_debug
> 1)
470 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
471 GetCurrentThreadId(), hInternet
, dwContext
,
472 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
473 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
474 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
476 case INTERNET_STATUS_HANDLE_CLOSING
:
477 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
478 "info length should be sizeof(HINTERNET) instead of %d\n",
479 dwStatusInformationLength
);
480 if(winetest_debug
> 1)
481 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
482 GetCurrentThreadId(), hInternet
, dwContext
,
483 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
484 if(!InterlockedDecrement(&close_handle_cnt
))
485 SetEvent(complete_event
);
487 case INTERNET_STATUS_REQUEST_COMPLETE
:
489 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
490 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
491 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
492 dwStatusInformationLength
);
493 ok(iar
->dwResult
== 1 || iar
->dwResult
== 0, "iar->dwResult = %ld\n", iar
->dwResult
);
494 if(winetest_debug
> 1)
495 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
496 GetCurrentThreadId(), hInternet
, dwContext
,
497 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
498 req_error
= iar
->dwError
;
499 if(!close_handle_cnt
)
500 SetEvent(complete_event
);
503 case INTERNET_STATUS_REDIRECT
:
504 if(winetest_debug
> 1)
505 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
506 GetCurrentThreadId(), hInternet
, dwContext
,
507 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
508 *(LPSTR
)lpvStatusInformation
= '\0';
509 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
510 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
512 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
513 if(winetest_debug
> 1)
514 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
515 GetCurrentThreadId(), hInternet
, dwContext
,
516 lpvStatusInformation
, dwStatusInformationLength
);
519 if(winetest_debug
> 1)
520 trace("%04x:Callback %p 0x%lx %d %p %d\n",
521 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
522 lpvStatusInformation
, dwStatusInformationLength
);
528 HINTERNET connection
;
532 #define open_simple_request(a,b,c,d,e) _open_simple_request(__LINE__,a,b,c,d,e)
533 static void _open_simple_request(unsigned line
, test_request_t
*req
, const char *host
,
534 int port
, const char *verb
, const char *url
)
536 req
->session
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
537 ok_(__FILE__
,line
)(req
->session
!= NULL
, "InternetOpenA failed: %u\n", GetLastError());
539 req
->connection
= InternetConnectA(req
->session
, host
, port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
540 ok_(__FILE__
,line
)(req
->connection
!= NULL
, "InternetConnectA failed: %u\n", GetLastError());
542 req
->request
= HttpOpenRequestA(req
->connection
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
543 ok_(__FILE__
,line
)(req
->request
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
546 #define close_request(a) _close_request(__LINE__,a)
547 static void _close_request(unsigned line
, test_request_t
*req
)
551 ret
= InternetCloseHandle(req
->request
);
552 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(request) failed: %u\n", GetLastError());
553 ret
= InternetCloseHandle(req
->connection
);
554 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(connection) failed: %u\n", GetLastError());
555 ret
= InternetCloseHandle(req
->session
);
556 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(session) failed: %u\n", GetLastError());
559 #define receive_simple_request(a,b,c) _receive_simple_request(__LINE__,a,b,c)
560 static DWORD
_receive_simple_request(unsigned line
, HINTERNET req
, char *buf
, size_t buf_size
)
565 ret
= InternetReadFile(req
, buf
, buf_size
, &read
);
566 ok_(__FILE__
,line
)(ret
, "InternetReadFile failed: %u\n", GetLastError());
571 static void close_async_handle(HINTERNET handle
, int handle_cnt
)
575 close_handle_cnt
= handle_cnt
;
577 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
578 res
= InternetCloseHandle(handle
);
579 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
580 WaitForSingleObject(complete_event
, INFINITE
);
581 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
584 static void InternetReadFile_test(int flags
, const test_data_t
*test
)
586 char *post_data
= NULL
;
587 BOOL res
, on_async
= TRUE
;
590 DWORD length
, length2
, index
, exlen
= 0, post_len
= 0;
591 const char *types
[2] = { "*", NULL
};
592 HINTERNET hi
, hic
= 0, hor
= 0;
593 DWORD contents_length
, accepts_ranges
;
596 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags
,test
->url
);
599 trace("InternetOpenA <--\n");
600 hi
= InternetOpenA((test
->flags
& TESTF_COMPRESSED
) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
601 INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
602 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
603 trace("InternetOpenA -->\n");
605 if (hi
== 0x0) goto abort
;
607 pInternetSetStatusCallbackA(hi
,&callback
);
609 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
611 trace("InternetConnectA <--\n");
612 hic
=InternetConnectA(hi
, test
->host
, INTERNET_INVALID_PORT_NUMBER
,
613 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
614 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
615 trace("InternetConnectA -->\n");
617 if (hic
== 0x0) goto abort
;
619 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
620 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
622 trace("HttpOpenRequestA <--\n");
623 hor
= HttpOpenRequestA(hic
, test
->post_data
? "POST" : "GET", test
->path
, NULL
, NULL
, types
,
624 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
626 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
628 * If the internet name can't be resolved we are probably behind
629 * a firewall or in some other way not directly connected to the
630 * Internet. Not enough reason to fail the test. Just ignore and
634 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
636 trace("HttpOpenRequestA -->\n");
638 if (hor
== 0x0) goto abort
;
640 test_request_flags(hor
, INTERNET_REQFLAG_NO_HEADERS
);
641 test_request_url(hor
, test
->url
);
643 length
= sizeof(buffer
);
644 res
= HttpQueryInfoA(hor
, HTTP_QUERY_RAW_HEADERS
, buffer
, &length
, 0x0);
645 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
646 ok(length
== 0 || (length
== 1 && !*buffer
) /* win10 */, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length
);
647 ok(!strcmp(buffer
, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer
);
649 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
650 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
651 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
652 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
,2);
653 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED
,2);
654 if (first_connection_to_test_url
)
656 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
657 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
659 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
660 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
661 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
662 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
663 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
664 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
665 if(test
->flags
& TESTF_REDIRECT
) {
666 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
667 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
669 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
670 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
671 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
672 if (flags
& INTERNET_FLAG_ASYNC
)
673 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
675 if(test
->flags
& TESTF_COMPRESSED
) {
678 res
= InternetSetOptionA(hor
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
679 ok(res
|| broken(!res
&& GetLastError() == ERROR_INTERNET_INVALID_OPTION
),
680 "InternetSetOption failed: %u\n", GetLastError());
685 test_status_code(hor
, 0);
687 trace("HttpSendRequestA -->\n");
688 if(test
->post_data
) {
689 post_len
= strlen(test
->post_data
);
690 post_data
= HeapAlloc(GetProcessHeap(), 0, post_len
);
691 memcpy(post_data
, test
->post_data
, post_len
);
693 SetLastError(0xdeadbeef);
694 res
= HttpSendRequestA(hor
, test
->headers
, -1, post_data
, post_len
);
695 if (flags
& INTERNET_FLAG_ASYNC
)
696 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
697 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
699 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
700 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
701 trace("HttpSendRequestA <--\n");
703 if (flags
& INTERNET_FLAG_ASYNC
) {
704 WaitForSingleObject(complete_event
, INFINITE
);
705 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
707 HeapFree(GetProcessHeap(), 0, post_data
);
709 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
710 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED
);
711 if (first_connection_to_test_url
)
713 if (! proxy_active())
715 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
716 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
720 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
721 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
726 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
727 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
729 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
730 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
731 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
732 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
733 if(test
->flags
& TESTF_REDIRECT
)
734 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
735 if (flags
& INTERNET_FLAG_ASYNC
)
736 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
737 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
738 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
739 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
741 test_request_flags(hor
, 0);
744 res
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
745 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
747 length
= sizeof(buffer
)-2;
748 memset(buffer
, 0x77, sizeof(buffer
));
749 SetLastError(0xdeadbeef);
750 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
751 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
752 ok(GetLastError() == 0 ||
753 broken(GetLastError() == 0xdeadbeef /* XP/W2K3 */), "Last Error not reset %u\n", GetLastError());
754 /* show that the function writes data past the length returned */
755 ok(buffer
[length
-2], "Expected any header character, got 0x00\n");
756 ok(!buffer
[length
-1], "Expected 0x00, got %02X\n", buffer
[length
-1]);
757 ok(!buffer
[length
], "Expected 0x00, got %02X\n", buffer
[length
]);
758 ok(buffer
[length
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length
+1]);
761 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
762 ok(!res
, "Expected 0x00, got %d\n", res
);
763 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
764 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
765 /* the in length of the buffer must be +1 but the length returned does not count this */
767 memset(buffer
, 0x77, sizeof(buffer
));
768 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
769 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
770 ok(buffer
[length2
] == 0x00, "Expected 0x00, got %02X\n", buffer
[length2
]);
771 ok(buffer
[length2
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length2
+1]);
772 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
774 length
= sizeof(wbuffer
)-2*sizeof(WCHAR
);
775 memset(wbuffer
, 0x77, sizeof(wbuffer
));
776 res
= HttpQueryInfoW(hor
, HTTP_QUERY_RAW_HEADERS
, wbuffer
, &length
, 0x0);
777 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
778 ok(length
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length
);
779 length
/= sizeof(WCHAR
);
780 /* show that the function writes data past the length returned */
781 ok(wbuffer
[length
-2], "Expected any header character, got 0x0000\n");
782 ok(!wbuffer
[length
-1], "Expected 0x0000, got %04X\n", wbuffer
[length
-1]);
783 ok(!wbuffer
[length
], "Expected 0x0000, got %04X\n", wbuffer
[length
]);
784 ok(wbuffer
[length
+1] == 0x7777 || broken(wbuffer
[length
+1] != 0x7777),
785 "Expected 0x7777, got %04X\n", wbuffer
[length
+1]);
787 length2
= length
*sizeof(WCHAR
);
788 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
789 ok(!res
, "Expected 0x00, got %d\n", res
);
790 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
791 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
792 length2
/= sizeof(WCHAR
);
793 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
794 /* the in length of the buffer must be +1 but the length returned does not count this */
795 length2
= (length
+1)*sizeof(WCHAR
);
796 memset(wbuffer
, 0x77, sizeof(wbuffer
));
797 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
798 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
799 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
800 length2
/= sizeof(WCHAR
);
801 ok(!wbuffer
[length2
], "Expected 0x0000, got %04X\n", wbuffer
[length2
]);
802 ok(wbuffer
[length2
+1] == 0x7777, "Expected 0x7777, got %04X\n", wbuffer
[length2
+1]);
803 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
805 test_request_url(hor
, test
->redirected_url
);
809 SetLastError(0xdeadbeef);
810 ok(HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,NULL
,&length
,&index
) == FALSE
,"Query worked\n");
811 if(test
->flags
& TESTF_COMPRESSED
)
812 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
813 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
814 ok(index
== 0, "Index was incremented\n");
818 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,&index
);
819 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res
,buffer
,GetLastError());
820 if(test
->flags
& TESTF_COMPRESSED
)
822 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
823 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res
, GetLastError());
828 contents_length
= atoi(buffer
);
830 ok(!res
|| index
== 1, "Index was not incremented although result is %x (index = %u)\n", res
, index
);
834 res
= HttpQueryInfoA(hor
,HTTP_QUERY_ACCEPT_RANGES
,&buffer
,&length
,0x0);
835 trace("Option HTTP_QUERY_ACCEPT_RANGES -> %i %s (%u)\n",res
,buffer
,GetLastError());
836 accepts_ranges
= res
&& !strcmp(buffer
, "bytes");
839 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
841 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res
,buffer
);
844 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_ENCODING
,buffer
,&length
,0x0);
846 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res
,buffer
);
848 SetLastError(0xdeadbeef);
849 length
= InternetSetFilePointer(hor
, 0, NULL
, FILE_END
, 0);
850 not_supported
= length
== INVALID_SET_FILE_POINTER
851 && GetLastError() == ERROR_INTERNET_INVALID_OPERATION
;
853 todo_wine
ok((length
== contents_length
&& (GetLastError() == ERROR_SUCCESS
854 || broken(GetLastError() == 0xdeadbeef))) || broken(not_supported
),
855 "Got unexpected length %#x, GetLastError() %u, contents_length %u, accepts_ranges %#x.\n",
856 length
, GetLastError(), contents_length
, accepts_ranges
);
858 ok(not_supported
, "Got unexpected length %#x, GetLastError() %u.\n", length
, GetLastError());
860 if (length
!= INVALID_SET_FILE_POINTER
)
862 SetLastError(0xdeadbeef);
863 length
= InternetSetFilePointer(hor
, 0, NULL
, FILE_BEGIN
, 0);
864 ok(!length
&& (GetLastError() == ERROR_SUCCESS
|| broken(GetLastError() == 0xdeadbeef)),
865 "Got unexpected length %#x, GetLastError() %u.\n", length
, GetLastError());
868 SetLastError(0xdeadbeef);
869 res
= InternetReadFile(NULL
, buffer
, 100, &length
);
870 ok(!res
, "InternetReadFile should have failed\n");
871 ok(GetLastError() == ERROR_INVALID_HANDLE
,
872 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
876 if(winetest_debug
> 1)
877 trace("Entering Query loop\n");
881 if (flags
& INTERNET_FLAG_ASYNC
)
882 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
884 /* IE11 calls those in InternetQueryDataAvailable call. */
885 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
886 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
889 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
891 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
893 if (flags
& INTERNET_FLAG_ASYNC
)
897 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
899 ok(length
>= exlen
, "length %u < exlen %u\n", length
, exlen
);
903 else if (GetLastError() == ERROR_IO_PENDING
)
905 if(winetest_debug
> 1)
907 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
908 if(!(test
->flags
& TESTF_CHUNKED
))
909 ok(!length
, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length
);
910 WaitForSingleObject(complete_event
, INFINITE
);
912 ok(exlen
, "length = 0\n");
913 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
914 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
915 ok(req_error
, "req_error = 0\n");
918 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
921 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
923 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
925 if(winetest_debug
> 1)
926 trace("length %u\n", length
);
927 if(test
->flags
& TESTF_CHUNKED
)
928 ok(length
<= 8192, "length = %d, expected <= 8192\n", length
);
932 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
934 res
= InternetReadFile(hor
,buffer
,length
,&length
);
938 if(winetest_debug
> 1)
939 trace("ReadFile -> %s %i\n", res
? "TRUE" : "FALSE", length
);
942 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
943 HeapFree(GetProcessHeap(),0,buffer
);
945 ok(!on_async
, "Returned zero size in response to request complete\n");
950 if(test
->flags
& TESTF_REDIRECT
) {
951 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
952 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
955 if(winetest_debug
> 1)
957 close_async_handle(hi
, 2);
958 first_connection_to_test_url
= FALSE
;
961 static void InternetReadFile_chunked_test(void)
966 const char *types
[2] = { "*", NULL
};
967 HINTERNET hi
, hic
= 0, hor
= 0;
969 trace("Starting InternetReadFile chunked test\n");
971 trace("InternetOpenA <--\n");
972 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
973 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
974 trace("InternetOpenA -->\n");
976 if (hi
== 0x0) goto abort
;
978 trace("InternetConnectA <--\n");
979 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
980 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
981 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
982 trace("InternetConnectA -->\n");
984 if (hic
== 0x0) goto abort
;
986 trace("HttpOpenRequestA <--\n");
987 hor
= HttpOpenRequestA(hic
, "GET", "/tests/chunked", NULL
, NULL
, types
,
988 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
990 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
992 * If the internet name can't be resolved we are probably behind
993 * a firewall or in some other way not directly connected to the
994 * Internet. Not enough reason to fail the test. Just ignore and
998 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
1000 trace("HttpOpenRequestA -->\n");
1002 if (hor
== 0x0) goto abort
;
1004 trace("HttpSendRequestA -->\n");
1005 SetLastError(0xdeadbeef);
1006 res
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
1007 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
1008 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
1009 trace("HttpSendRequestA <--\n");
1011 test_request_flags(hor
, 0);
1014 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
1016 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
1018 SetLastError( 0xdeadbeef );
1020 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
1022 trace("Option TRANSFER_ENCODING -> %i %s\n",res
,buffer
);
1023 ok( res
|| ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
1024 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
1025 ok( !strcmp( buffer
, "chunked" ) || ( ! res
&& proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
1026 "Wrong transfer encoding '%s'\n", buffer
);
1028 SetLastError( 0xdeadbeef );
1030 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
1031 ok( !res
, "Found CONTENT_LENGTH option '%s'\n", buffer
);
1032 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Wrong error %u\n", GetLastError() );
1035 trace("Entering Query loop\n");
1039 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
1040 ok(!(!res
&& length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
1041 ok(res
, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
1042 trace("got %u available\n",length
);
1045 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
1047 SetLastError(0xdeadbeef);
1048 res
= InternetReadFile(hor
,buffer
,length
,&got
);
1049 ok(GetLastError() == 0 ||
1050 broken(GetLastError() == 0xdeadbeef /* XP/W2K3 */), "Last Error not reset %u\n", GetLastError());
1053 trace("ReadFile -> %i %i\n",res
,got
);
1054 ok( length
== got
, "only got %u of %u available\n", got
, length
);
1055 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
1057 HeapFree(GetProcessHeap(),0,buffer
);
1063 SetLastError(0xdeadbeef);
1064 res
= InternetReadFile( hor
, buffer
, 1, &got
);
1065 ok( res
, "InternetReadFile failed: %u\n", GetLastError() );
1066 ok(GetLastError() == 0 ||
1067 broken(GetLastError() == 0xdeadbeef /* XP/W2K3 */), "Last Error not reset %u\n", GetLastError());
1068 ok( !got
, "got %u\n", got
);
1073 trace("aborting\n");
1075 res
= InternetCloseHandle(hor
);
1076 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
1079 res
= InternetCloseHandle(hi
);
1080 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
1084 static void InternetReadFileExA_test(int flags
)
1088 const char *types
[2] = { "*", NULL
};
1089 HINTERNET hi
, hic
= 0, hor
= 0;
1090 INTERNET_BUFFERSA inetbuffers
;
1092 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
1095 trace("InternetOpenA <--\n");
1096 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
1097 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
1098 trace("InternetOpenA -->\n");
1100 if (hi
== 0x0) goto abort
;
1102 pInternetSetStatusCallbackA(hi
,&callback
);
1104 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1106 trace("InternetConnectA <--\n");
1107 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
1108 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1109 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
1110 trace("InternetConnectA -->\n");
1112 if (hic
== 0x0) goto abort
;
1114 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1115 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1117 trace("HttpOpenRequestA <--\n");
1118 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
1119 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
1121 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
1123 * If the internet name can't be resolved we are probably behind
1124 * a firewall or in some other way not directly connected to the
1125 * Internet. Not enough reason to fail the test. Just ignore and
1129 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
1131 trace("HttpOpenRequestA -->\n");
1133 if (hor
== 0x0) goto abort
;
1135 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1136 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1137 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1138 if (first_connection_to_test_url
)
1140 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
1141 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
1143 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
, 2);
1144 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1145 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1146 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1147 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
1148 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1149 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1150 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1151 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1152 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
1153 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1154 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1155 if (flags
& INTERNET_FLAG_ASYNC
)
1156 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1158 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1160 trace("HttpSendRequestA -->\n");
1161 SetLastError(0xdeadbeef);
1162 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
1163 if (flags
& INTERNET_FLAG_ASYNC
)
1164 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
1165 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
1167 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
1168 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
1169 trace("HttpSendRequestA <--\n");
1171 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
1172 WaitForSingleObject(complete_event
, INFINITE
);
1173 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1176 if (first_connection_to_test_url
)
1178 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1179 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1183 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1184 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1186 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1187 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
1188 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1189 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1190 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1191 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1192 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
1193 if (flags
& INTERNET_FLAG_ASYNC
)
1194 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1196 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1197 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
1198 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
1199 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1200 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1203 rc
= InternetReadFileExW(hor
, NULL
, 0, 0xdeadcafe);
1204 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1205 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1206 rc
? "TRUE" : "FALSE", GetLastError());
1209 /* tests invalid dwStructSize */
1210 inetbuffers
.dwStructSize
= sizeof(inetbuffers
)+1;
1211 inetbuffers
.lpcszHeader
= NULL
;
1212 inetbuffers
.dwHeadersLength
= 0;
1213 inetbuffers
.dwBufferLength
= 10;
1214 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
1215 inetbuffers
.dwOffsetHigh
= 1234;
1216 inetbuffers
.dwOffsetLow
= 5678;
1217 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1218 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1219 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1220 rc
? "TRUE" : "FALSE", GetLastError());
1221 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1223 test_request_flags(hor
, 0);
1225 /* tests to see whether lpcszHeader is used - it isn't */
1226 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1227 inetbuffers
.lpcszHeader
= (LPCSTR
)0xdeadbeef;
1228 inetbuffers
.dwHeadersLength
= 255;
1229 inetbuffers
.dwBufferLength
= 0;
1230 inetbuffers
.lpvBuffer
= NULL
;
1231 inetbuffers
.dwOffsetHigh
= 1234;
1232 inetbuffers
.dwOffsetLow
= 5678;
1233 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1234 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
1235 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1237 rc
= InternetReadFileExA(NULL
, &inetbuffers
, 0, 0xdeadcafe);
1238 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
1239 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1240 rc
? "TRUE" : "FALSE", GetLastError());
1243 trace("Entering Query loop\n");
1247 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1248 inetbuffers
.dwBufferLength
= 1024;
1249 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
1250 inetbuffers
.dwOffsetHigh
= 1234;
1251 inetbuffers
.dwOffsetLow
= 5678;
1253 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1254 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1255 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1256 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
1259 if (GetLastError() == ERROR_IO_PENDING
)
1261 trace("InternetReadFileEx -> PENDING\n");
1262 ok(flags
& INTERNET_FLAG_ASYNC
,
1263 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1264 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1265 WaitForSingleObject(complete_event
, INFINITE
);
1266 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1267 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1268 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1272 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1278 trace("InternetReadFileEx -> SUCCEEDED\n");
1279 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1280 if (inetbuffers
.dwBufferLength
)
1282 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1283 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1287 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1288 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1289 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1293 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1294 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
1296 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
1297 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1298 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
1300 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1302 if (!inetbuffers
.dwBufferLength
)
1305 length
+= inetbuffers
.dwBufferLength
;
1307 ok(length
> 0, "failed to read any of the document\n");
1308 trace("Finished. Read %d bytes\n", length
);
1311 close_async_handle(hi
, 2);
1312 first_connection_to_test_url
= FALSE
;
1315 static void InternetOpenUrlA_test(void)
1317 HINTERNET myhinternet
, myhttp
;
1319 DWORD size
, readbytes
, totalbytes
=0;
1322 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1323 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
1324 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret
, GetLastError());
1326 myhinternet
= InternetOpenA("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
1327 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
1329 ret
= InternetCanonicalizeUrlA(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1330 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1333 myhttp
= InternetOpenUrlA(myhinternet
, TEST_URL
, 0, 0,
1334 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
1335 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1336 return; /* WinXP returns this when not connected to the net */
1337 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1338 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
1339 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
1340 totalbytes
+= readbytes
;
1341 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
1342 totalbytes
+= readbytes
;
1343 trace("read 0x%08x bytes\n",totalbytes
);
1345 InternetCloseHandle(myhttp
);
1346 InternetCloseHandle(myhinternet
);
1348 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1349 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1352 static void HttpSendRequestEx_test(void)
1358 INTERNET_BUFFERSA BufferIn
;
1359 DWORD dwBytesWritten
, dwBytesRead
, error
;
1364 static char szPostData
[] = "mode=Test";
1365 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
1367 hSession
= InternetOpenA("Wine Regression Test",
1368 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1369 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1370 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1371 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1373 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1374 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1375 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1376 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1378 skip( "Network unreachable, skipping test\n" );
1381 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1383 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1385 BufferIn
.dwStructSize
= sizeof(BufferIn
);
1386 BufferIn
.Next
= (INTERNET_BUFFERSA
*)0xdeadcab;
1387 BufferIn
.lpcszHeader
= szContentType
;
1388 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1389 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1390 BufferIn
.lpvBuffer
= szPostData
;
1391 BufferIn
.dwBufferLength
= 3;
1392 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1393 BufferIn
.dwOffsetLow
= 0;
1394 BufferIn
.dwOffsetHigh
= 0;
1396 SetLastError(0xdeadbeef);
1397 ret
= HttpSendRequestExA(hRequest
, &BufferIn
, NULL
, 0 ,0);
1398 error
= GetLastError();
1399 ok(ret
, "HttpSendRequestEx Failed with error %u\n", error
);
1400 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", error
);
1402 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1404 for (i
= 3; szPostData
[i
]; i
++)
1405 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1406 "InternetWriteFile failed\n");
1408 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1410 ok(HttpEndRequestA(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1412 test_request_flags(hRequest
, 0);
1414 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1415 "Unable to read response\n");
1416 szBuffer
[dwBytesRead
] = 0;
1418 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
1419 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1421 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1423 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1424 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1427 static void InternetOpenRequest_test(void)
1429 HINTERNET session
, connect
, request
;
1430 static const char *types
[] = { "*", "", NULL
};
1431 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1432 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1435 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1436 ok(session
!= NULL
,"Unable to open Internet session\n");
1438 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1439 INTERNET_SERVICE_HTTP
, 0, 0);
1440 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1441 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1443 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1444 INTERNET_SERVICE_HTTP
, 0, 0);
1445 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1446 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1448 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1449 INTERNET_SERVICE_HTTP
, 0, 0);
1450 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1452 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1453 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1455 skip( "Network unreachable, skipping test\n" );
1458 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1460 ret
= HttpSendRequestW(request
, NULL
, 0, NULL
, 0);
1461 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1462 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1464 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1465 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1467 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1468 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1469 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1472 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1473 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1476 static void test_cache_read(void)
1478 HINTERNET session
, connection
, req
;
1479 FILETIME now
, tomorrow
, yesterday
;
1480 BYTE content
[1000], buf
[2000];
1481 char file_path
[MAX_PATH
];
1488 static const char cache_only_url
[] = "http://test.winehq.org/tests/cache-only";
1489 BYTE cache_headers
[] = "HTTP/1.1 200 OK\r\n\r\n";
1491 trace("Testing cache read...\n");
1494 for(i
= 0; i
< sizeof(content
); i
++)
1495 content
[i
] = '0' + (i
%10);
1497 GetSystemTimeAsFileTime(&now
);
1498 li
.u
.HighPart
= now
.dwHighDateTime
;
1499 li
.u
.LowPart
= now
.dwLowDateTime
;
1500 li
.QuadPart
+= (LONGLONG
)10000000 * 3600 * 24;
1501 tomorrow
.dwHighDateTime
= li
.u
.HighPart
;
1502 tomorrow
.dwLowDateTime
= li
.u
.LowPart
;
1503 li
.QuadPart
-= (LONGLONG
)10000000 * 3600 * 24 * 2;
1504 yesterday
.dwHighDateTime
= li
.u
.HighPart
;
1505 yesterday
.dwLowDateTime
= li
.u
.LowPart
;
1507 res
= CreateUrlCacheEntryA(cache_only_url
, sizeof(content
), "", file_path
, 0);
1508 ok(res
, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1510 file
= CreateFileA(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1511 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
1513 WriteFile(file
, content
, sizeof(content
), &size
, NULL
);
1516 res
= CommitUrlCacheEntryA(cache_only_url
, file_path
, tomorrow
, yesterday
, NORMAL_CACHE_ENTRY
,
1517 cache_headers
, sizeof(cache_headers
)-1, "", 0);
1518 ok(res
, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1520 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
1521 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
1523 pInternetSetStatusCallbackA(session
, callback
);
1525 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1526 connection
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
,
1527 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1528 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
1529 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1531 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1532 req
= HttpOpenRequestA(connection
, "GET", "/tests/cache-only", NULL
, NULL
, NULL
, 0, 0xdeadbead);
1533 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
1534 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1536 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1537 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1538 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST
);
1539 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT
);
1540 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1541 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1542 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1544 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
1546 ok(res
, "HttpSendRequest failed: %u\n", GetLastError());
1550 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
1551 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1552 ok(size
== sizeof(content
), "size = %u\n", size
);
1555 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
1556 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
1557 ok(size
== sizeof(content
), "size = %u\n", size
);
1558 ok(!memcmp(content
, buf
, sizeof(content
)), "unexpected content\n");
1561 close_async_handle(session
, 2);
1563 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1564 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1565 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
1566 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
1567 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1568 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1569 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1571 res
= DeleteUrlCacheEntryA(cache_only_url
);
1572 ok(res
, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1575 static void test_http_cache(void)
1577 HINTERNET session
, connect
, request
;
1578 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1579 DWORD size
, file_size
;
1583 FILETIME filetime_zero
= {0};
1585 static const char cached_content
[] = "data read from cache";
1586 static const char *types
[] = { "*", "", NULL
};
1588 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1589 ok(session
!= NULL
,"Unable to open Internet session\n");
1591 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1592 INTERNET_SERVICE_HTTP
, 0, 0);
1593 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1595 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1596 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1598 skip( "Network unreachable, skipping test\n" );
1600 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1601 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1605 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1608 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1609 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1610 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1612 size
= sizeof(file_name
);
1613 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1614 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1615 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1616 ok(!size
, "size = %d\n", size
);
1618 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1619 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1621 size
= sizeof(file_name
);
1622 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1623 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1625 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1626 FILE_ATTRIBUTE_NORMAL
, NULL
);
1627 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1628 file_size
= GetFileSize(file
, NULL
);
1629 ok(file_size
== 106, "file size = %u\n", file_size
);
1632 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1633 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1634 ok(size
== 100, "size = %u\n", size
);
1636 file_size
= GetFileSize(file
, NULL
);
1637 ok(file_size
== 106, "file size = %u\n", file_size
);
1640 ret
= DeleteFileA(file_name
);
1641 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1643 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1645 file
= CreateFileA(file_name
, GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1646 FILE_ATTRIBUTE_NORMAL
, NULL
);
1647 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1648 ret
= WriteFile(file
, cached_content
, sizeof(cached_content
), &size
, NULL
);
1649 ok(ret
&& size
, "WriteFile failed: %d, %d\n", ret
, size
);
1650 ret
= CommitUrlCacheEntryA(url
, file_name
, filetime_zero
, filetime_zero
, NORMAL_CACHE_ENTRY
, NULL
, 0, NULL
, 0);
1651 ok(ret
, "CommitUrlCacheEntry failed: %d\n", GetLastError());
1654 /* Send the same request, requiring it to be retrieved from the cache */
1655 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1657 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1658 ok(ret
, "HttpSendRequest failed\n");
1661 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1662 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1663 ok(size
== 100, "size = %u\n", size
);
1665 todo_wine
ok(!strcmp((char*)buf
, cached_content
), "incorrect page data: %s\n", (char*)buf
);
1667 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1669 DeleteUrlCacheEntryA(url
);
1670 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1671 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1672 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
1674 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError() = %d\n", GetLastError());
1675 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1677 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1678 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1680 size
= sizeof(file_name
);
1681 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1682 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1683 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1684 ok(!size
, "size = %d\n", size
);
1686 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1687 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1689 size
= sizeof(file_name
);
1691 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1694 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1695 FILE_ATTRIBUTE_NORMAL
, NULL
);
1696 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1702 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1705 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1706 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1707 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1712 static void InternetLockRequestFile_test(void)
1714 char file_name
[MAX_PATH
];
1720 open_simple_request(&req
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, "/tests/hello.html");
1722 size
= sizeof(file_name
);
1723 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1724 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1725 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1726 ok(!size
, "size = %d\n", size
);
1729 ret
= InternetLockRequestFile(req
.request
, &lock
);
1730 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1732 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
1733 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1735 size
= sizeof(file_name
);
1736 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1737 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1739 ret
= InternetLockRequestFile(req
.request
, &lock
);
1740 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1741 ok(lock
!= NULL
, "lock == NULL\n");
1743 ret
= InternetLockRequestFile(req
.request
, &lock2
);
1744 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1745 ok(lock
== lock2
, "lock != lock2\n");
1747 ret
= InternetUnlockRequestFile(lock2
);
1748 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1750 ret
= DeleteFileA(file_name
);
1751 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1753 ok(InternetCloseHandle(req
.request
), "Close request handle failed\n");
1755 ret
= DeleteFileA(file_name
);
1756 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1758 ret
= InternetUnlockRequestFile(lock
);
1759 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1761 ret
= DeleteFileA(file_name
);
1762 ok(ret
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1765 static void HttpHeaders_test(void)
1777 hSession
= InternetOpenA("Wine Regression Test",
1778 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1779 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1780 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1781 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1783 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1784 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1785 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1786 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1788 skip( "Network unreachable, skipping test\n" );
1791 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1794 len
= sizeof(buffer
);
1795 strcpy(buffer
,"Warning");
1796 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1797 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1799 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1800 "Failed to add new header\n");
1803 len
= sizeof(buffer
);
1804 strcpy(buffer
,"Warning");
1805 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1806 buffer
,&len
,&index
),"Unable to query header\n");
1807 ok(index
== 1, "Index was not incremented\n");
1808 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1809 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1810 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1811 len
= sizeof(buffer
);
1812 strcpy(buffer
,"Warning");
1813 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1814 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1817 len
= 5; /* could store the string but not the NULL terminator */
1818 strcpy(buffer
,"Warning");
1819 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1820 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1821 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1822 ok(index
== 0, "Index was incremented\n");
1823 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1824 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1826 /* a call with NULL will fail but will return the length */
1828 len
= sizeof(buffer
);
1829 SetLastError(0xdeadbeef);
1830 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1831 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1832 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1833 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1834 ok(index
== 0, "Index was incremented\n");
1836 /* even for a len that is too small */
1839 SetLastError(0xdeadbeef);
1840 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1841 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1842 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1843 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1844 ok(index
== 0, "Index was incremented\n");
1848 SetLastError(0xdeadbeef);
1849 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1850 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1851 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1852 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1853 ok(index
== 0, "Index was incremented\n");
1854 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1857 /* a working query */
1859 len
= sizeof(buffer
);
1860 memset(buffer
, 'x', sizeof(buffer
));
1861 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1862 buffer
,&len
,&index
),"Unable to query header\n");
1863 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1864 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1865 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1866 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1867 ok(strncmp(buffer
, "POST /tests/post.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1868 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1869 ok(index
== 0, "Index was incremented\n");
1871 /* Like above two tests, but for W version */
1875 SetLastError(0xdeadbeef);
1876 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1877 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1878 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1879 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1880 ok(index
== 0, "Index was incremented\n");
1881 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1883 /* a working query */
1885 len
= sizeof(wbuffer
);
1886 memset(wbuffer
, 'x', sizeof(wbuffer
));
1887 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1888 wbuffer
,&len
,&index
),"Unable to query header\n");
1889 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1890 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1891 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1892 ok(index
== 0, "Index was incremented\n");
1894 /* end of W version tests */
1896 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1898 len
= sizeof(buffer
);
1899 memset(buffer
, 'x', sizeof(buffer
));
1900 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1901 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1902 ok(len
== 2 || len
== 4 /* win10 */, "Expected 2 or 4, got %d\n", len
);
1903 ok(memcmp(buffer
, "\r\n\r\n", len
) == 0, "Expected CRLF, got '%s'\n", buffer
);
1904 ok(index
== 0, "Index was incremented\n");
1906 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1907 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1910 len
= sizeof(buffer
);
1911 strcpy(buffer
,"Warning");
1912 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1913 buffer
,&len
,&index
),"Unable to query header\n");
1914 ok(index
== 1, "Index was not incremented\n");
1915 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1916 len
= sizeof(buffer
);
1917 strcpy(buffer
,"Warning");
1918 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1919 buffer
,&len
,&index
),"Failed to get second header\n");
1920 ok(index
== 2, "Index was not incremented\n");
1921 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1922 len
= sizeof(buffer
);
1923 strcpy(buffer
,"Warning");
1924 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1925 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1927 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1930 len
= sizeof(buffer
);
1931 strcpy(buffer
,"Warning");
1932 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1933 buffer
,&len
,&index
),"Unable to query header\n");
1934 ok(index
== 1, "Index was not incremented\n");
1935 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1936 len
= sizeof(buffer
);
1937 strcpy(buffer
,"Warning");
1938 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1939 buffer
,&len
,&index
),"Failed to get second header\n");
1940 ok(index
== 2, "Index was not incremented\n");
1941 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1942 len
= sizeof(buffer
);
1943 strcpy(buffer
,"Warning");
1944 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1945 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1947 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1950 len
= sizeof(buffer
);
1951 strcpy(buffer
,"Warning");
1952 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1953 buffer
,&len
,&index
),"Unable to query header\n");
1954 ok(index
== 1, "Index was not incremented\n");
1955 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1956 len
= sizeof(buffer
);
1957 strcpy(buffer
,"Warning");
1958 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1959 buffer
,&len
,&index
),"Failed to get second header\n");
1960 ok(index
== 2, "Index was not incremented\n");
1961 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1962 len
= sizeof(buffer
);
1963 strcpy(buffer
,"Warning");
1964 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1965 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1967 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1970 len
= sizeof(buffer
);
1971 strcpy(buffer
,"Warning");
1972 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1973 buffer
,&len
,&index
),"Unable to query header\n");
1974 ok(index
== 1, "Index was not incremented\n");
1975 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1976 len
= sizeof(buffer
);
1977 strcpy(buffer
,"Warning");
1978 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1979 ok(index
== 2, "Index was not incremented\n");
1980 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1981 len
= sizeof(buffer
);
1982 strcpy(buffer
,"Warning");
1983 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1985 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1988 len
= sizeof(buffer
);
1989 strcpy(buffer
,"Warning");
1990 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1991 ok(index
== 1, "Index was not incremented\n");
1992 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1993 len
= sizeof(buffer
);
1994 strcpy(buffer
,"Warning");
1995 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1996 ok(index
== 2, "Index was not incremented\n");
1997 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1998 len
= sizeof(buffer
);
1999 strcpy(buffer
,"Warning");
2000 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
2002 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
2005 len
= sizeof(buffer
);
2006 strcpy(buffer
,"Warning");
2007 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2008 ok(index
== 1, "Index was not incremented\n");
2009 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
2010 len
= sizeof(buffer
);
2011 strcpy(buffer
,"Warning");
2012 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
2013 ok(index
== 2, "Index was not incremented\n");
2014 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
2015 len
= sizeof(buffer
);
2016 strcpy(buffer
,"Warning");
2017 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
2019 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");
2022 len
= sizeof(buffer
);
2023 strcpy(buffer
,"Warning");
2024 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2025 ok(index
== 1, "Index was not incremented\n");
2026 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
2027 len
= sizeof(buffer
);
2028 strcpy(buffer
,"Warning");
2029 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
2030 ok(index
== 2, "Index was not incremented\n");
2031 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
2032 len
= sizeof(buffer
);
2033 strcpy(buffer
,"Warning");
2034 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
2036 /* Ensure that blank headers are ignored and don't cause a failure */
2037 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");
2040 len
= sizeof(buffer
);
2041 strcpy(buffer
,"BlankTest");
2042 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2043 ok(index
== 1, "Index was not incremented\n");
2044 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
2046 /* Ensure that malformed header separators are ignored and don't cause a failure */
2047 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
),
2048 "Failed to add header with malformed entries in list\n");
2051 len
= sizeof(buffer
);
2052 strcpy(buffer
,"MalformedTest");
2053 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2054 ok(index
== 1, "Index was not incremented\n");
2055 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
2057 len
= sizeof(buffer
);
2058 strcpy(buffer
,"MalformedTestTwo");
2059 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2060 ok(index
== 1, "Index was not incremented\n");
2061 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
2063 len
= sizeof(buffer
);
2064 strcpy(buffer
,"MalformedTestThree");
2065 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2066 ok(index
== 1, "Index was not incremented\n");
2067 ok(strcmp(buffer
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
2069 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD
);
2070 ok(ret
, "unable to add header %u\n", GetLastError());
2074 len
= sizeof(buffer
);
2075 ret
= HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
);
2076 ok(ret
, "unable to query header %u\n", GetLastError());
2077 ok(index
== 1, "index was not incremented\n");
2078 ok(!strcmp(buffer
, "Basic"), "incorrect string was returned (%s)\n", buffer
);
2080 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE
);
2081 ok(ret
, "unable to remove header %u\n", GetLastError());
2084 len
= sizeof(buffer
);
2085 SetLastError(0xdeadbeef);
2086 ok(!HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
),
2087 "header still present\n");
2088 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "got %u\n", GetLastError());
2090 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
2092 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
2093 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
2096 static const char garbagemsg
[] =
2097 "Garbage: Header\r\n";
2099 static const char contmsg
[] =
2100 "HTTP/1.1 100 Continue\r\n";
2102 static const char expandcontmsg
[] =
2103 "HTTP/1.1 100 Continue\r\n"
2104 "Server: winecontinue\r\n"
2105 "Tag: something witty\r\n";
2107 static const char okmsg
[] =
2108 "HTTP/1.1 200 OK\r\n"
2109 "Server: winetest\r\n"
2112 static const char okmsg201
[] =
2113 "HTTP/1.1 201 OK\r\n"
2114 "Server: winetest\r\n"
2117 static const char okmsg2
[] =
2118 "HTTP/1.1 200 OK\r\n"
2119 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
2120 "Server: winetest\r\n"
2121 "Content-Length: 0\r\n"
2122 "Set-Cookie: one\r\n"
2123 "Set-Cookie: two\r\n"
2126 static DWORD64 content_length
;
2127 static const char largemsg
[] =
2128 "HTTP/1.1 200 OK\r\n"
2129 "Content-Length: %I64u\r\n"
2132 static const char notokmsg
[] =
2133 "HTTP/1.1 400 Bad Request\r\n"
2134 "Server: winetest\r\n"
2137 static const char noauthmsg
[] =
2138 "HTTP/1.1 401 Unauthorized\r\n"
2139 "Server: winetest\r\n"
2140 "Connection: close\r\n"
2141 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
2144 static const char noauthmsg2
[] =
2145 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
2146 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
2148 "Server: winetest\r\n";
2150 static const char proxymsg
[] =
2151 "HTTP/1.1 407 Proxy Authentication Required\r\n"
2152 "Server: winetest\r\n"
2153 "Proxy-Connection: close\r\n"
2154 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
2157 static const char page1
[] =
2159 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
2160 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
2163 static const char ok_with_length
[] =
2164 "HTTP/1.1 200 OK\r\n"
2165 "Connection: Keep-Alive\r\n"
2166 "Content-Length: 18\r\n\r\n"
2167 "HTTP/1.1 211 OK\r\n\r\n";
2169 static const char ok_with_length2
[] =
2170 "HTTP/1.1 210 OK\r\n"
2171 "Connection: Keep-Alive\r\n"
2172 "Content-Length: 19\r\n\r\n"
2173 "HTTP/1.1 211 OK\r\n\r\n";
2175 struct server_info
{
2180 static int test_cache_gzip
;
2181 static const char *send_buffer
;
2182 static int server_socket
;
2184 static DWORD CALLBACK
server_thread(LPVOID param
)
2186 struct server_info
*si
= param
;
2187 int r
, c
= -1, i
, on
, count
= 0;
2189 struct sockaddr_in sa
;
2193 int last_request
= 0;
2194 char host_header
[22];
2195 char host_header_override
[30];
2196 static int test_no_cache
= 0;
2198 WSAStartup(MAKEWORD(1,1), &wsaData
);
2200 s
= socket(AF_INET
, SOCK_STREAM
, 0);
2201 if (s
== INVALID_SOCKET
)
2205 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
2207 memset(&sa
, 0, sizeof sa
);
2208 sa
.sin_family
= AF_INET
;
2209 sa
.sin_port
= htons(si
->port
);
2210 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
2212 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
2218 SetEvent(si
->hEvent
);
2220 sprintf(host_header
, "Host: localhost:%d", si
->port
);
2221 sprintf(host_header_override
, "Host: test.local:%d\r\n", si
->port
);
2222 buffer
= HeapAlloc(GetProcessHeap(), 0, buffer_size
= 1000);
2227 c
= accept(s
, NULL
, NULL
);
2229 memset(buffer
, 0, buffer_size
);
2232 if(i
== buffer_size
)
2233 buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, buffer_size
*= 2);
2235 r
= recv(c
, buffer
+i
, 1, 0);
2239 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
2240 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
2243 if (strstr(buffer
, "GET /test1"))
2245 if (!strstr(buffer
, "Content-Length: 0"))
2247 send(c
, okmsg
, sizeof okmsg
-1, 0);
2248 send(c
, page1
, sizeof page1
-1, 0);
2251 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2253 if (strstr(buffer
, "CONNECT "))
2255 if (!strstr(buffer
, "Content-Length: 0"))
2256 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2258 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2260 if (strstr(buffer
, "/test2"))
2262 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2264 send(c
, okmsg
, sizeof okmsg
-1, 0);
2265 send(c
, page1
, sizeof page1
-1, 0);
2268 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2270 if (strstr(buffer
, "/test3"))
2272 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2273 send(c
, okmsg
, sizeof okmsg
-1, 0);
2275 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2277 if (strstr(buffer
, "/test4"))
2279 if (strstr(buffer
, "Connection: Close"))
2280 send(c
, okmsg
, sizeof okmsg
-1, 0);
2282 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2284 if (strstr(buffer
, "POST /test5") ||
2285 strstr(buffer
, "RPC_IN_DATA /test5") ||
2286 strstr(buffer
, "RPC_OUT_DATA /test5"))
2288 if (strstr(buffer
, "Content-Length: 0"))
2290 send(c
, okmsg
, sizeof okmsg
-1, 0);
2291 send(c
, page1
, sizeof page1
-1, 0);
2294 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2296 if (strstr(buffer
, "GET /test6"))
2298 send(c
, contmsg
, sizeof contmsg
-1, 0);
2299 send(c
, contmsg
, sizeof contmsg
-1, 0);
2300 send(c
, okmsg
, sizeof okmsg
-1, 0);
2301 send(c
, page1
, sizeof page1
-1, 0);
2303 if (strstr(buffer
, "POST /test7"))
2305 if (strstr(buffer
, "Content-Length: 100"))
2307 if (strstr(buffer
, "POST /test7b"))
2308 recvfrom(c
, buffer
, buffer_size
, 0, NULL
, NULL
);
2309 send(c
, okmsg
, sizeof okmsg
-1, 0);
2310 send(c
, page1
, sizeof page1
-1, 0);
2313 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2315 if (strstr(buffer
, "/test8"))
2317 if (!strstr(buffer
, "Connection: Close") &&
2318 strstr(buffer
, "Connection: Keep-Alive") &&
2319 !strstr(buffer
, "Cache-Control: no-cache") &&
2320 !strstr(buffer
, "Pragma: no-cache") &&
2321 strstr(buffer
, host_header
))
2322 send(c
, okmsg
, sizeof okmsg
-1, 0);
2324 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2326 if (strstr(buffer
, "/test9"))
2328 if (!strstr(buffer
, "Connection: Close") &&
2329 !strstr(buffer
, "Connection: Keep-Alive") &&
2330 !strstr(buffer
, "Cache-Control: no-cache") &&
2331 !strstr(buffer
, "Pragma: no-cache") &&
2332 strstr(buffer
, host_header
))
2333 send(c
, okmsg
, sizeof okmsg
-1, 0);
2335 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2337 if (strstr(buffer
, "/testA"))
2339 if (!strstr(buffer
, "Connection: Close") &&
2340 !strstr(buffer
, "Connection: Keep-Alive") &&
2341 (strstr(buffer
, "Cache-Control: no-cache") ||
2342 strstr(buffer
, "Pragma: no-cache")) &&
2343 strstr(buffer
, host_header
))
2344 send(c
, okmsg
, sizeof okmsg
-1, 0);
2346 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2348 if (strstr(buffer
, "/testC"))
2350 if (strstr(buffer
, "Cookie: cookie=biscuit"))
2351 send(c
, okmsg
, sizeof okmsg
-1, 0);
2353 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2355 if (strstr(buffer
, "/testD"))
2357 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
2359 if (strstr(buffer
, "/testE"))
2361 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
2363 if (strstr(buffer
, "GET /quit"))
2365 send(c
, okmsg
, sizeof okmsg
-1, 0);
2366 send(c
, page1
, sizeof page1
-1, 0);
2369 if (strstr(buffer
, "GET /testF"))
2371 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
2372 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2373 send(c
, contmsg
, sizeof contmsg
-1, 0);
2374 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2375 send(c
, okmsg
, sizeof okmsg
-1, 0);
2376 send(c
, page1
, sizeof page1
-1, 0);
2378 if (strstr(buffer
, "GET /testG"))
2380 send(c
, page1
, sizeof page1
-1, 0);
2383 if (strstr(buffer
, "GET /testJ"))
2388 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2392 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2396 if (strstr(buffer
, "GET /testH"))
2398 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2399 recvfrom(c
, buffer
, buffer_size
, 0, NULL
, NULL
);
2400 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2403 if (strstr(buffer
, "GET /test_no_content"))
2405 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2406 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2408 if (strstr(buffer
, "GET /test_conn_close"))
2410 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2411 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
2412 WaitForSingleObject(conn_close_event
, INFINITE
);
2413 trace("closing connection\n");
2415 if (strstr(buffer
, "GET /test_cache_control_no_cache"))
2417 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2418 if(!test_no_cache
++)
2419 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2421 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2423 if (strstr(buffer
, "GET /test_cache_control_no_store"))
2425 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2426 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2428 if (strstr(buffer
, "GET /test_cache_gzip"))
2430 static const char gzip_response
[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2431 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2432 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2433 if(!test_cache_gzip
++)
2434 send(c
, gzip_response
, sizeof(gzip_response
), 0);
2436 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2438 if (strstr(buffer
, "HEAD /test_head")) {
2439 static const char head_response
[] =
2440 "HTTP/1.1 200 OK\r\n"
2441 "Connection: Keep-Alive\r\n"
2442 "Content-Length: 100\r\n"
2445 send(c
, head_response
, sizeof(head_response
), 0);
2448 if (strstr(buffer
, "GET /send_from_buffer"))
2449 send(c
, send_buffer
, strlen(send_buffer
), 0);
2450 if (strstr(buffer
, "/test_cache_control_verb"))
2452 if (!memcmp(buffer
, "GET ", sizeof("GET ")-1) &&
2453 !strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2454 else if (strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2455 else send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2457 if (strstr(buffer
, "/test_request_content_length"))
2459 static char msg
[] = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\n\r\n";
2460 static int seen_content_length
;
2462 if (!seen_content_length
)
2464 if (strstr(buffer
, "Content-Length: 0"))
2466 seen_content_length
= 1;
2467 send(c
, msg
, sizeof msg
-1, 0);
2469 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2470 WaitForSingleObject(complete_event
, 5000);
2474 if (strstr(buffer
, "Content-Length: 0")) send(c
, msg
, sizeof msg
-1, 0);
2475 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2476 WaitForSingleObject(complete_event
, 5000);
2479 if (strstr(buffer
, "GET /test_premature_disconnect"))
2480 trace("closing connection\n");
2481 if (strstr(buffer
, "HEAD /upload.txt"))
2483 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2484 send(c
, okmsg
, sizeof okmsg
-1, 0);
2486 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2488 if (strstr(buffer
, "PUT /upload2.txt"))
2490 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2491 send(c
, okmsg
, sizeof okmsg
-1, 0);
2493 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2495 if (strstr(buffer
, "HEAD /upload3.txt"))
2497 if (strstr(buffer
, "Authorization: Basic dXNlcjE6cHdkMQ=="))
2498 send(c
, okmsg
, sizeof okmsg
-1, 0);
2500 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2502 if (strstr(buffer
, "HEAD /upload4.txt"))
2504 if (strstr(buffer
, "Authorization: Bearer dXNlcjE6cHdkMQ=="))
2505 send(c
, okmsg
, sizeof okmsg
-1, 0);
2506 else if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2507 send(c
, okmsg201
, sizeof okmsg
-1, 0);
2509 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2511 if (strstr(buffer
, "/test_host_override"))
2513 if (strstr(buffer
, host_header_override
))
2514 send(c
, okmsg
, sizeof okmsg
-1, 0);
2516 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2518 if (strstr(buffer
, "/async_read"))
2520 const char *page1_mid
= page1
+ (sizeof page1
- 1)/2;
2521 const char *page1_end
= page1
+ sizeof page1
- 1;
2522 send(c
, okmsg
, sizeof okmsg
-1, 0);
2523 send(c
, page1
, page1_mid
- page1
, 0);
2524 WaitForSingleObject(conn_wait_event
, INFINITE
);
2525 send(c
, page1_mid
, page1_end
- page1_mid
, 0);
2527 if (strstr(buffer
, "/socket"))
2530 SetEvent(server_req_rec_event
);
2531 WaitForSingleObject(conn_wait_event
, INFINITE
);
2533 if (strstr(buffer
, "/echo_request"))
2535 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2536 send(c
, buffer
, strlen(buffer
), 0);
2538 if (strstr(buffer
, "GET /test_remove_dot_segments"))
2540 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2542 if (strstr(buffer
, "HEAD /test_large_content"))
2544 char msg
[sizeof(largemsg
) + 16];
2545 sprintf(msg
, largemsg
, content_length
);
2546 send(c
, msg
, strlen(msg
), 0);
2551 } while (!last_request
);
2554 HeapFree(GetProcessHeap(), 0, buffer
);
2559 static void test_basic_request(int port
, const char *verb
, const char *url
)
2562 DWORD r
, count
, error
;
2565 trace("basic request %s %s\n", verb
, url
);
2567 open_simple_request(&req
, "localhost", port
, verb
, url
);
2569 SetLastError(0xdeadbeef);
2570 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
2571 error
= GetLastError();
2572 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
2573 ok(r
, "HttpSendRequest failed: %u\n", GetLastError());
2576 memset(buffer
, 0, sizeof buffer
);
2577 SetLastError(0xdeadbeef);
2578 r
= InternetReadFile(req
.request
, buffer
, sizeof buffer
, &count
);
2579 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2580 ok(count
== sizeof page1
- 1, "count was wrong\n");
2581 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2583 close_request(&req
);
2586 static void test_proxy_indirect(int port
)
2592 open_simple_request(&req
, "localhost", port
, NULL
, "/test2");
2594 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
2595 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2598 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2599 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
2602 skip("missing proxy header, not testing remaining proxy headers\n");
2605 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2607 test_status_code(req
.request
, 407);
2608 test_request_flags(req
.request
, 0);
2611 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2612 ok(r
, "HttpQueryInfo failed\n");
2613 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2616 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2617 ok(r
, "HttpQueryInfo failed\n");
2618 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2621 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2622 ok(r
, "HttpQueryInfo failed\n");
2623 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2626 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2627 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2628 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2631 close_request(&req
);
2634 static void test_proxy_direct(int port
)
2636 HINTERNET hi
, hc
, hr
;
2638 char buffer
[0x40], *url
;
2639 WCHAR bufferW
[0x40];
2640 static const char url_fmt
[] = "http://test.winehq.org:%u/test2";
2641 static CHAR username
[] = "mike",
2642 password
[] = "1101",
2643 useragent
[] = "winetest";
2644 static const WCHAR usernameW
[] = {'m','i','k','e',0},
2645 passwordW
[] = {'1','1','0','1',0},
2646 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2648 /* specify proxy type without the proxy and bypass */
2649 SetLastError(0xdeadbeef);
2650 hi
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2651 error
= GetLastError();
2652 ok(error
== ERROR_INVALID_PARAMETER
||
2653 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %u\n", error
);
2654 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2656 sprintf(buffer
, "localhost:%d\n", port
);
2657 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2658 ok(hi
!= NULL
, "open failed\n");
2660 /* try connect without authorization */
2661 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2662 ok(hc
!= NULL
, "connect failed\n");
2664 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2665 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2668 SetLastError(0xdeadbeef);
2669 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
2670 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2671 ok(!r
, "unexpected success\n");
2672 ok(sz
== 1, "got %u\n", sz
);
2675 SetLastError(0xdeadbeef);
2676 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
2677 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2678 ok(!r
, "unexpected success\n");
2679 ok(sz
== 1, "got %u\n", sz
);
2681 sz
= sizeof(buffer
);
2682 SetLastError(0xdeadbeef);
2683 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2684 ok(r
, "unexpected failure %u\n", GetLastError());
2685 ok(!sz
, "got %u\n", sz
);
2687 sz
= sizeof(buffer
);
2688 SetLastError(0xdeadbeef);
2689 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2690 ok(r
, "unexpected failure %u\n", GetLastError());
2691 ok(!sz
, "got %u\n", sz
);
2694 SetLastError(0xdeadbeef);
2695 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
2696 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2697 ok(!r
, "unexpected success\n");
2698 ok(sz
== 1, "got %u\n", sz
);
2701 SetLastError(0xdeadbeef);
2702 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
2703 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2704 ok(!r
, "unexpected success\n");
2705 ok(sz
== 1, "got %u\n", sz
);
2707 sz
= sizeof(buffer
);
2708 SetLastError(0xdeadbeef);
2709 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2710 ok(r
, "unexpected failure %u\n", GetLastError());
2711 ok(!sz
, "got %u\n", sz
);
2713 sz
= sizeof(buffer
);
2714 SetLastError(0xdeadbeef);
2715 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2716 ok(r
, "unexpected failure %u\n", GetLastError());
2717 ok(!sz
, "got %u\n", sz
);
2720 SetLastError(0xdeadbeef);
2721 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
2722 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2723 ok(!r
, "unexpected success\n");
2724 ok(sz
== 34, "got %u\n", sz
);
2726 sz
= sizeof(buffer
);
2727 SetLastError(0xdeadbeef);
2728 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2729 ok(r
, "unexpected failure %u\n", GetLastError());
2730 ok(sz
== 33, "got %u\n", sz
);
2732 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2733 ok(r
|| broken(!r
), "HttpSendRequest failed %u\n", GetLastError());
2736 win_skip("skipping proxy tests on broken wininet\n");
2740 test_status_code(hr
, 407);
2742 /* set the user + password then try again */
2743 r
= InternetSetOptionA(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2744 ok(!r
, "unexpected success\n");
2746 r
= InternetSetOptionA(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2747 ok(r
, "failed to set user\n");
2749 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2750 ok(r
, "failed to set user\n");
2754 SetLastError(0xdeadbeef);
2755 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2756 ok(!r
, "unexpected failure %u\n", GetLastError());
2757 ok(!buffer
[0], "got %s\n", buffer
);
2758 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2762 SetLastError(0xdeadbeef);
2763 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2764 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2765 ok(!r
, "unexpected success\n");
2766 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2770 SetLastError(0xdeadbeef);
2771 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2772 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2773 ok(!r
, "unexpected success\n");
2774 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2777 sz
= sizeof(buffer
);
2778 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2779 ok(r
, "failed to get username\n");
2780 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2781 ok(sz
== strlen(username
), "got %u\n", sz
);
2784 sz
= sizeof(bufferW
);
2785 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2786 ok(r
, "failed to get username\n");
2787 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
2788 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2790 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
2791 ok(r
, "failed to set user\n");
2794 sz
= sizeof(buffer
);
2795 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2796 ok(r
, "failed to get username\n");
2797 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2798 ok(sz
== strlen(username
), "got %u\n", sz
);
2800 r
= InternetSetOptionA(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
2801 ok(r
, "failed to set useragent\n");
2805 SetLastError(0xdeadbeef);
2806 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2807 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2808 ok(!r
, "unexpected success\n");
2809 ok(sz
== strlen(useragent
) + 1, "got %u\n", sz
);
2812 sz
= sizeof(buffer
);
2813 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2814 ok(r
, "failed to get user agent\n");
2815 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
2816 ok(sz
== strlen(useragent
), "got %u\n", sz
);
2820 SetLastError(0xdeadbeef);
2821 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2822 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2823 ok(!r
, "unexpected success\n");
2824 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2827 sz
= sizeof(bufferW
);
2828 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2829 ok(r
, "failed to get user agent\n");
2830 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
2831 ok(sz
== lstrlenW(useragentW
), "got %u\n", sz
);
2833 r
= InternetSetOptionA(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
2834 ok(r
, "failed to set user\n");
2838 SetLastError(0xdeadbeef);
2839 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2840 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2841 ok(!r
, "unexpected success\n");
2842 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2845 sz
= sizeof(buffer
);
2846 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2847 ok(r
, "failed to get user\n");
2848 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2849 ok(sz
== strlen(username
), "got %u\n", sz
);
2853 SetLastError(0xdeadbeef);
2854 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2855 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2856 ok(!r
, "unexpected success\n");
2857 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2860 sz
= sizeof(bufferW
);
2861 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2862 ok(r
, "failed to get user\n");
2863 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
2864 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2866 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
2867 ok(r
, "failed to set password\n");
2871 SetLastError(0xdeadbeef);
2872 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2873 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2874 ok(!r
, "unexpected success\n");
2875 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2878 sz
= sizeof(buffer
);
2879 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2880 ok(r
, "failed to get password\n");
2881 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2882 ok(sz
== strlen(password
), "got %u\n", sz
);
2886 SetLastError(0xdeadbeef);
2887 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2888 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2889 ok(!r
, "unexpected success\n");
2890 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2893 sz
= sizeof(bufferW
);
2894 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2895 ok(r
, "failed to get password\n");
2896 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2897 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2899 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
2900 sprintf(url
, url_fmt
, port
);
2903 SetLastError(0xdeadbeef);
2904 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2905 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2906 ok(!r
, "unexpected success\n");
2907 ok(sz
== strlen(url
) + 1, "got %u\n", sz
);
2910 sz
= sizeof(buffer
);
2911 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2912 ok(r
, "failed to get url\n");
2913 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
2914 ok(sz
== strlen(url
), "got %u\n", sz
);
2918 SetLastError(0xdeadbeef);
2919 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2920 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2921 ok(!r
, "unexpected success\n");
2922 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2925 sz
= sizeof(bufferW
);
2926 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2927 ok(r
, "failed to get url\n");
2928 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
2929 ok(sz
== strlen(url
), "got %u\n", sz
);
2930 HeapFree(GetProcessHeap(), 0, url
);
2932 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2933 ok(r
, "failed to set password\n");
2937 SetLastError(0xdeadbeef);
2938 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2939 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2940 ok(!r
, "unexpected success\n");
2941 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2944 sz
= sizeof(buffer
);
2945 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2946 ok(r
, "failed to get password\n");
2947 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2948 ok(sz
== strlen(password
), "got %u\n", sz
);
2952 SetLastError(0xdeadbeef);
2953 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2954 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2955 ok(!r
, "unexpected success\n");
2956 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2959 sz
= sizeof(bufferW
);
2960 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2961 ok(r
, "failed to get password\n");
2962 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2963 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2965 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2968 win_skip("skipping proxy tests on broken wininet\n");
2971 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2973 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2974 ok(r
, "HttpQueryInfo failed\n");
2975 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2977 InternetCloseHandle(hr
);
2978 InternetCloseHandle(hc
);
2979 InternetCloseHandle(hi
);
2981 sprintf(buffer
, "localhost:%d\n", port
);
2982 hi
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2983 ok(hi
!= NULL
, "InternetOpen failed\n");
2985 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2986 ok(hc
!= NULL
, "InternetConnect failed\n");
2988 hr
= HttpOpenRequestA(hc
, "POST", "/test2", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
2989 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2991 r
= HttpSendRequestA(hr
, NULL
, 0, (char *)"data", sizeof("data"));
2992 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2994 test_status_code(hr
, 407);
2997 InternetCloseHandle(hr
);
2998 InternetCloseHandle(hc
);
2999 InternetCloseHandle(hi
);
3002 static void test_header_handling_order(int port
)
3004 static const char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
3005 static const char connection
[] = "Connection: Close";
3006 static const char *types
[2] = { "*", NULL
};
3008 HINTERNET session
, connect
, request
;
3009 DWORD size
, status
, data_len
;
3012 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3013 ok(session
!= NULL
, "InternetOpen failed\n");
3015 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3016 ok(connect
!= NULL
, "InternetConnect failed\n");
3018 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3019 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3021 ret
= HttpAddRequestHeadersA(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3022 ok(ret
, "HttpAddRequestHeaders failed\n");
3024 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3025 ok(ret
, "HttpSendRequest failed\n");
3027 test_status_code(request
, 200);
3028 test_request_flags(request
, 0);
3030 InternetCloseHandle(request
);
3032 request
= HttpOpenRequestA(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3033 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3035 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
3036 ok(ret
, "HttpSendRequest failed\n");
3039 size
= sizeof(status
);
3040 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
3041 ok(ret
, "HttpQueryInfo failed\n");
3042 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
3044 InternetCloseHandle(request
);
3045 InternetCloseHandle(connect
);
3047 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3048 ok(connect
!= NULL
, "InternetConnect failed\n");
3050 request
= HttpOpenRequestA(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3051 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3053 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
3054 ok(ret
, "HttpAddRequestHeaders failed\n");
3056 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
3057 ok(ret
, "HttpSendRequest failed\n");
3060 size
= sizeof(status
);
3061 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
3062 ok(ret
, "HttpQueryInfo failed\n");
3063 ok(status
== 200, "got status %u, expected 200\n", status
);
3065 InternetCloseHandle(request
);
3066 InternetCloseHandle(connect
);
3068 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3069 ok(connect
!= NULL
, "InternetConnect failed\n");
3071 request
= HttpOpenRequestA(connect
, "POST", "/test7b", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3072 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3074 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
3075 ok(ret
, "HttpAddRequestHeaders failed\n");
3077 data_len
= sizeof(data
);
3078 memset(data
, 'a', sizeof(data
));
3079 ret
= HttpSendRequestA(request
, NULL
, 0, data
, data_len
);
3080 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3083 size
= sizeof(status
);
3084 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
3085 ok(ret
, "HttpQueryInfo failed\n");
3086 ok(status
== 200, "got status %u, expected 200\n", status
);
3088 InternetCloseHandle(request
);
3089 InternetCloseHandle(connect
);
3090 InternetCloseHandle(session
);
3093 static void test_connection_header(int port
)
3095 HINTERNET ses
, con
, req
;
3098 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3099 ok(ses
!= NULL
, "InternetOpen failed\n");
3101 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3102 ok(con
!= NULL
, "InternetConnect failed\n");
3104 req
= HttpOpenRequestA(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3105 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3107 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3108 ok(ret
, "HttpSendRequest failed\n");
3110 test_status_code(req
, 200);
3112 InternetCloseHandle(req
);
3114 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
3115 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3117 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3118 ok(ret
, "HttpSendRequest failed\n");
3120 test_status_code(req
, 200);
3122 InternetCloseHandle(req
);
3124 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3125 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3127 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3128 ok(ret
, "HttpSendRequest failed\n");
3130 test_status_code(req
, 200);
3132 InternetCloseHandle(req
);
3134 req
= HttpOpenRequestA(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3135 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3137 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3138 ok(ret
, "HttpSendRequest failed\n");
3140 test_status_code(req
, 200);
3142 InternetCloseHandle(req
);
3143 InternetCloseHandle(con
);
3144 InternetCloseHandle(ses
);
3147 static void test_header_override(int port
)
3149 char buffer
[128], host_header_override
[30], full_url
[128];
3150 HINTERNET ses
, con
, req
;
3151 DWORD size
, count
, err
;
3154 sprintf(host_header_override
, "Host: test.local:%d\r\n", port
);
3155 sprintf(full_url
, "http://localhost:%d/test_host_override", port
);
3157 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3158 ok(ses
!= NULL
, "InternetOpen failed\n");
3160 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3161 ok(con
!= NULL
, "InternetConnect failed\n");
3163 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3164 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3166 size
= sizeof(buffer
) - 1;
3168 memset(buffer
, 0, sizeof(buffer
));
3169 ret
= HttpQueryInfoA(req
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &count
);
3170 err
= GetLastError();
3171 ok(!ret
, "HttpQueryInfo succeeded\n");
3172 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err
);
3174 test_request_url(req
, full_url
);
3176 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3177 ok(ret
, "HttpAddRequestHeaders failed\n");
3179 size
= sizeof(buffer
) - 1;
3181 memset(buffer
, 0, sizeof(buffer
));
3182 ret
= HttpQueryInfoA(req
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &count
);
3183 ok(ret
, "HttpQueryInfo failed\n");
3185 test_request_url(req
, full_url
);
3187 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3188 ok(ret
, "HttpSendRequest failed\n");
3190 test_status_code(req
, 200);
3192 InternetCloseHandle(req
);
3193 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3194 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3196 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3197 ok(ret
, "HttpAddRequestHeaders failed\n");
3199 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3200 ok(ret
, "HttpAddRequestHeaders failed\n");
3202 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3203 ok(ret
, "HttpSendRequest failed\n");
3205 test_status_code(req
, 400);
3207 InternetCloseHandle(req
);
3208 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3209 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3211 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3212 ok(ret
, "HttpAddRequestHeaders failed\n");
3214 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3215 ok(ret
, "HttpSendRequest failed\n");
3217 test_status_code(req
, 200);
3219 InternetCloseHandle(req
);
3220 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3221 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3223 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_REPLACE
);
3224 if(ret
) { /* win10 returns success */
3225 trace("replacing host header is supported.\n");
3227 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3228 ok(ret
, "HttpSendRequest failed\n");
3230 test_status_code(req
, 200);
3232 trace("replacing host header is not supported.\n");
3234 err
= GetLastError();
3235 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err
);
3237 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3238 ok(ret
, "HttpSendRequest failed\n");
3240 test_status_code(req
, 400);
3243 InternetCloseHandle(req
);
3244 InternetCloseHandle(con
);
3245 InternetCloseHandle(ses
);
3248 static void test_connection_closing(int port
)
3250 HINTERNET session
, connection
, req
;
3255 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3256 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3258 pInternetSetStatusCallbackA(session
, callback
);
3260 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3261 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3262 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3263 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3265 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3266 req
= HttpOpenRequestA(connection
, "GET", "/testJ", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3267 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3268 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3270 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3271 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3272 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3273 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3274 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3275 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3276 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3277 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3278 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3279 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3280 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3282 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3283 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3284 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3285 WaitForSingleObject(complete_event
, INFINITE
);
3286 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3288 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3289 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3290 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3291 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3292 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3293 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3294 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3295 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3296 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3297 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3298 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3300 test_status_code(req
, 200);
3302 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3303 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3304 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3305 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3306 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3307 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3308 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3309 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3310 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3312 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3313 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3314 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3315 WaitForSingleObject(complete_event
, INFINITE
);
3316 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3318 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3319 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3320 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3321 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3322 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3323 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3324 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3325 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3326 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3328 test_status_code(req
, 210);
3330 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3331 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3332 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3333 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3334 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3335 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3336 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3337 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3338 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3339 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3340 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3342 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3343 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3344 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3345 WaitForSingleObject(complete_event
, INFINITE
);
3346 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3348 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3349 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3350 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3351 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3352 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3353 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3354 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3355 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3356 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3357 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3358 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3360 test_status_code(req
, 200);
3362 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3363 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3365 close_async_handle(session
, 2);
3368 static void test_successive_HttpSendRequest(int port
)
3370 HINTERNET session
, connection
, req
;
3375 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3376 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3378 pInternetSetStatusCallbackA(session
, callback
);
3380 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3381 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3382 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3383 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3385 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3386 req
= HttpOpenRequestA(connection
, "GET", "/testH", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3387 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3388 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3390 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3391 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3392 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3393 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3394 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3395 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3396 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3397 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3398 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3400 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3401 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3402 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3403 WaitForSingleObject(complete_event
, INFINITE
);
3404 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3406 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3407 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3408 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3409 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3410 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3411 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3412 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3413 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3414 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3416 test_status_code(req
, 210);
3418 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3419 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3420 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3421 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3422 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3423 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3424 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3425 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3426 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3428 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3429 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3430 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3431 WaitForSingleObject(complete_event
, INFINITE
);
3432 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3434 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3435 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3436 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3437 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3438 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3439 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3440 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3441 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3442 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3444 test_status_code(req
, 200);
3446 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3447 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3449 close_async_handle(session
, 2);
3452 static void test_no_content(int port
)
3454 HINTERNET session
, connection
, req
;
3457 trace("Testing 204 no content response...\n");
3461 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3462 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3464 pInternetSetStatusCallbackA(session
, callback
);
3466 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3467 connection
= InternetConnectA(session
, "localhost", port
,
3468 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3469 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3470 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3472 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3473 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
3474 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3475 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3476 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3478 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3479 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3480 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3481 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3482 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3483 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3484 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3485 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3486 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3487 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3489 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3490 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3491 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3492 WaitForSingleObject(complete_event
, INFINITE
);
3493 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3495 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3496 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3497 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3498 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3499 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3500 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3501 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3502 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3504 close_async_handle(session
, 2);
3507 * The connection should be closed before closing handle. This is true for most
3508 * wininet versions (including Wine), but some old win2k versions fail to do that.
3510 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3511 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3514 static void test_conn_close(int port
)
3516 HINTERNET session
, connection
, req
;
3517 DWORD res
, avail
, size
;
3520 trace("Testing connection close connection...\n");
3524 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3525 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3527 pInternetSetStatusCallbackA(session
, callback
);
3529 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3530 connection
= InternetConnectA(session
, "localhost", port
,
3531 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3532 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3533 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3535 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3536 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
3537 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3538 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3539 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3541 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3542 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3543 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3544 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3545 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3546 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3547 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3548 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3550 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3551 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3552 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3553 WaitForSingleObject(complete_event
, INFINITE
);
3554 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3556 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3557 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3558 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3559 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3560 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3561 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3562 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3563 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3566 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3567 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3568 ok(avail
!= 0, "avail = 0\n");
3571 res
= InternetReadFile(req
, buf
, avail
, &size
);
3572 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3574 /* IE11 calls those in InternetQueryDataAvailable call. */
3575 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
3576 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
3578 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3579 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3580 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3581 ok(!avail
, "avail = %u, expected 0\n", avail
);
3583 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3585 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3586 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3587 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3588 SetEvent(conn_close_event
);
3589 WaitForSingleObject(complete_event
, INFINITE
);
3590 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3591 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3592 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3593 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3594 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3596 close_async_handle(session
, 2);
3599 static void test_no_cache(int port
)
3601 static const char cache_control_no_cache
[] = "/test_cache_control_no_cache";
3602 static const char cache_control_no_store
[] = "/test_cache_control_no_store";
3603 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3605 char cache_url
[256], buf
[256];
3606 HINTERNET ses
, con
, req
;
3610 trace("Testing no-cache header\n");
3612 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3613 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3615 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3616 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3618 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3619 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3621 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_cache
);
3622 DeleteUrlCacheEntryA(cache_url
);
3624 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3625 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3627 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3629 ok(size
== 12, "read %d bytes of data\n", size
);
3630 InternetCloseHandle(req
);
3632 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3633 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3635 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3636 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3638 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3640 ok(size
== 0, "read %d bytes of data\n", size
);
3641 InternetCloseHandle(req
);
3642 DeleteUrlCacheEntryA(cache_url
);
3644 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_store
, NULL
, NULL
, NULL
, 0, 0);
3645 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3647 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_store
);
3648 DeleteUrlCacheEntryA(cache_url
);
3650 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3651 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3653 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3655 ok(size
== 12, "read %d bytes of data\n", size
);
3656 InternetCloseHandle(req
);
3658 ret
= DeleteUrlCacheEntryA(cache_url
);
3659 ok(!ret
&& GetLastError()==ERROR_FILE_NOT_FOUND
, "cache entry should not exist\n");
3661 InternetCloseHandle(con
);
3662 InternetCloseHandle(ses
);
3665 static void test_cache_read_gzipped(int port
)
3667 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3668 static const char get_gzip
[] = "/test_cache_gzip";
3669 static const char content
[] = "gzip test\n";
3670 static const char text_html
[] = "text/html";
3671 static const char raw_header
[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3673 HINTERNET ses
, con
, req
;
3675 char cache_url
[256], buf
[256];
3678 trace("Testing reading compressed content from cache\n");
3680 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3681 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3683 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3684 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3686 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3687 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3690 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3691 if(!ret
&& GetLastError()==ERROR_INTERNET_INVALID_OPTION
) {
3692 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3693 InternetCloseHandle(req
);
3694 InternetCloseHandle(con
);
3695 InternetCloseHandle(ses
);
3698 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3700 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3701 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3703 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-size
, &read
) && read
)
3705 ok(size
== 10, "read %d bytes of data\n", size
);
3707 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3709 size
= sizeof(buf
)-1;
3710 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3711 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3713 ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3715 size
= sizeof(buf
)-1;
3716 ret
= HttpQueryInfoA(req
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &size
, 0);
3717 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3719 ok(!strncmp(raw_header
, buf
, size
), "buf = %s\n", buf
);
3720 InternetCloseHandle(req
);
3722 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3723 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3726 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3727 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3729 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3730 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3732 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3734 todo_wine
ok(size
== 10, "read %d bytes of data\n", size
);
3736 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3739 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3740 ok(!ret
&& GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND
,
3741 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3742 ret
, GetLastError());
3744 size
= sizeof(buf
)-1;
3745 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3746 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3748 todo_wine
ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3749 InternetCloseHandle(req
);
3751 /* Decompression doesn't work while reading from cache */
3752 test_cache_gzip
= 0;
3753 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3754 DeleteUrlCacheEntryA(cache_url
);
3756 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3757 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3759 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3760 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3762 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3764 ok(size
== 31, "read %d bytes of data\n", size
);
3765 InternetCloseHandle(req
);
3767 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3768 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3771 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3772 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3774 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3775 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3777 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3779 todo_wine
ok(size
== 31, "read %d bytes of data\n", size
);
3782 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3783 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3784 InternetCloseHandle(req
);
3786 InternetCloseHandle(con
);
3787 InternetCloseHandle(ses
);
3789 /* Decompression doesn't work while reading from cache */
3790 test_cache_gzip
= 0;
3791 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3792 DeleteUrlCacheEntryA(cache_url
);
3794 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3795 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3798 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3799 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3801 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3802 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3804 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3805 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3807 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3808 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3810 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3812 ok(size
== 10, "read %d bytes of data\n", size
);
3814 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3815 InternetCloseHandle(req
);
3817 InternetCloseHandle(con
);
3818 InternetCloseHandle(ses
);
3820 /* Decompression doesn't work while reading from cache */
3821 test_cache_gzip
= 0;
3822 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3823 DeleteUrlCacheEntryA(cache_url
);
3825 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3826 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3828 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3829 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3832 ret
= InternetSetOptionA(con
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3833 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3835 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3836 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3838 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3839 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3841 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3843 ok(size
== 10, "read %d bytes of data\n", size
);
3845 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3846 InternetCloseHandle(req
);
3848 InternetCloseHandle(con
);
3849 InternetCloseHandle(ses
);
3851 DeleteUrlCacheEntryA(cache_url
);
3854 static void test_HttpSendRequestW(int port
)
3856 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3857 HINTERNET ses
, con
, req
;
3861 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3862 ok(ses
!= NULL
, "InternetOpen failed\n");
3864 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3865 ok(con
!= NULL
, "InternetConnect failed\n");
3867 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3868 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3870 SetLastError(0xdeadbeef);
3871 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
3872 error
= GetLastError();
3873 ok(!ret
, "HttpSendRequestW succeeded\n");
3874 ok(error
== ERROR_IO_PENDING
||
3875 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
3876 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
3877 "got %u expected ERROR_IO_PENDING\n", error
);
3879 InternetCloseHandle(req
);
3880 InternetCloseHandle(con
);
3881 InternetCloseHandle(ses
);
3884 static void test_cookie_header(int port
)
3886 HINTERNET ses
, con
, req
;
3891 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3892 ok(ses
!= NULL
, "InternetOpen failed\n");
3894 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3895 ok(con
!= NULL
, "InternetConnect failed\n");
3897 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3899 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3900 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3903 size
= sizeof(buffer
);
3904 SetLastError(0xdeadbeef);
3905 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3906 error
= GetLastError();
3907 ok(!ret
, "HttpQueryInfo succeeded\n");
3908 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3910 ret
= HttpAddRequestHeadersA(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
3911 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3914 size
= sizeof(buffer
);
3915 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3916 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3917 ok(!strcmp(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
3919 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3920 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3922 test_status_code(req
, 200);
3925 size
= sizeof(buffer
);
3926 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3927 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3928 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
3930 InternetCloseHandle(req
);
3931 InternetCloseHandle(con
);
3932 InternetCloseHandle(ses
);
3935 static void test_basic_authentication(int port
)
3937 HINTERNET session
, connect
, request
;
3940 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3941 ok(session
!= NULL
, "InternetOpen failed\n");
3943 connect
= InternetConnectA(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
3944 ok(connect
!= NULL
, "InternetConnect failed\n");
3946 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
3947 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3949 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3950 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3952 test_status_code(request
, 200);
3953 test_request_flags(request
, 0);
3955 InternetCloseHandle(request
);
3956 InternetCloseHandle(connect
);
3957 InternetCloseHandle(session
);
3960 static void test_premature_disconnect(int port
)
3966 open_simple_request(&req
, "localhost", port
, NULL
, "/premature_disconnect");
3968 SetLastError(0xdeadbeef);
3969 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
3970 err
= GetLastError();
3971 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
3972 todo_wine
ok(err
== ERROR_HTTP_INVALID_SERVER_RESPONSE
, "got %u\n", err
);
3974 close_request(&req
);
3977 static void test_invalid_response_headers(int port
)
3984 open_simple_request(&req
, "localhost", port
, NULL
, "/testE");
3986 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
3987 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3989 test_status_code(req
.request
, 401);
3990 test_request_flags(req
.request
, 0);
3993 size
= sizeof(buffer
);
3994 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3995 ok(ret
, "HttpQueryInfo failed\n");
3996 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
3997 "headers wrong \"%s\"\n", buffer
);
4000 size
= sizeof(buffer
);
4001 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
4002 ok(ret
, "HttpQueryInfo failed\n");
4003 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
4005 close_request(&req
);
4008 static void test_response_without_headers(int port
)
4011 DWORD r
, count
, size
;
4014 open_simple_request(&req
, "localhost", port
, NULL
, "/testG");
4016 test_request_flags(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
4018 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4019 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
4021 test_request_flags_todo(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
4024 memset(buffer
, 0, sizeof buffer
);
4025 r
= InternetReadFile(req
.request
, buffer
, sizeof buffer
, &count
);
4026 ok(r
, "InternetReadFile failed %u\n", GetLastError());
4027 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
4028 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
4030 test_status_code(req
.request
, 200);
4031 test_request_flags_todo(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
4034 size
= sizeof(buffer
);
4035 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
4036 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
4037 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
4040 size
= sizeof(buffer
);
4041 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
4042 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
4043 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
4046 size
= sizeof(buffer
);
4047 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
4048 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
4049 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
4051 close_request(&req
);
4054 static void test_head_request(int port
)
4056 DWORD len
, content_length
;
4061 open_simple_request(&req
, "localhost", port
, "HEAD", "/test_head");
4063 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4064 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
4066 len
= sizeof(content_length
);
4067 content_length
= -1;
4068 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
, &content_length
, &len
, 0);
4069 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
4070 ok(len
== sizeof(DWORD
), "len = %u\n", len
);
4071 ok(content_length
== 100, "content_length = %u\n", content_length
);
4074 ret
= InternetReadFile(req
.request
, buf
, sizeof(buf
), &len
);
4075 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
4078 ret
= InternetReadFile(req
.request
, buf
, sizeof(buf
), &len
);
4079 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
4081 close_request(&req
);
4084 static void test_HttpQueryInfo(int port
)
4087 DWORD size
, index
, error
;
4091 open_simple_request(&req
, "localhost", port
, NULL
, "/testD");
4093 size
= sizeof(buffer
);
4094 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
4095 error
= GetLastError();
4096 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
4097 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
4099 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4100 ok(ret
, "HttpSendRequest failed\n");
4103 size
= sizeof(buffer
);
4104 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
4105 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4106 ok(index
== 1, "expected 1 got %u\n", index
);
4109 size
= sizeof(buffer
);
4110 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
4111 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4112 ok(index
== 1, "expected 1 got %u\n", index
);
4115 size
= sizeof(buffer
);
4116 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4117 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4118 ok(index
== 0, "expected 0 got %u\n", index
);
4120 size
= sizeof(buffer
);
4121 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4122 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4123 ok(index
== 0, "expected 0 got %u\n", index
);
4125 index
= 0xdeadbeef; /* invalid start index */
4126 size
= sizeof(buffer
);
4127 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4128 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
4129 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
4130 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
4133 size
= sizeof(buffer
);
4134 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
4135 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4136 ok(index
== 0, "expected 0 got %u\n", index
);
4138 size
= sizeof(buffer
);
4139 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
4140 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4141 ok(index
== 0, "expected 0 got %u\n", index
);
4143 size
= sizeof(buffer
);
4144 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
4145 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4146 ok(index
== 0, "expected 0 got %u\n", index
);
4148 test_status_code(req
.request
, 200);
4151 size
= sizeof(buffer
);
4152 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
4153 ok(!ret
, "HttpQueryInfo succeeded\n");
4154 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
4157 size
= sizeof(buffer
);
4158 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
4159 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4160 ok(index
== 1, "expected 1 got %u\n", index
);
4163 size
= sizeof(buffer
);
4164 strcpy(buffer
, "Server");
4165 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
4166 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4167 ok(index
== 1, "expected 1 got %u\n", index
);
4170 size
= sizeof(buffer
);
4171 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
4172 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4173 ok(index
== 1, "expected 1 got %u\n", index
);
4175 size
= sizeof(buffer
);
4176 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
4177 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4178 ok(index
== 2, "expected 2 got %u\n", index
);
4180 close_request(&req
);
4183 static void test_options(int port
)
4185 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi
;
4186 HINTERNET ses
, con
, req
;
4191 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4192 ok(ses
!= NULL
, "InternetOpen failed\n");
4194 SetLastError(0xdeadbeef);
4195 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
4196 error
= GetLastError();
4197 ok(!ret
, "InternetSetOption succeeded\n");
4198 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4200 SetLastError(0xdeadbeef);
4201 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
4202 ok(!ret
, "InternetSetOption succeeded\n");
4203 error
= GetLastError();
4204 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4206 SetLastError(0xdeadbeef);
4207 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
4208 ok(!ret
, "InternetSetOption succeeded\n");
4209 error
= GetLastError();
4210 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4213 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4214 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4216 SetLastError(0xdeadbeef);
4217 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
4218 error
= GetLastError();
4219 ok(!ret
, "InternetQueryOption succeeded\n");
4220 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4222 SetLastError(0xdeadbeef);
4223 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
4224 error
= GetLastError();
4225 ok(!ret
, "InternetQueryOption succeeded\n");
4226 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4229 SetLastError(0xdeadbeef);
4230 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
4231 error
= GetLastError();
4232 ok(!ret
, "InternetQueryOption succeeded\n");
4233 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
4236 SetLastError(0xdeadbeef);
4237 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4238 error
= GetLastError();
4239 ok(!ret
, "InternetQueryOption succeeded\n");
4240 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
4244 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4245 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4246 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
4248 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4249 ok(con
!= NULL
, "InternetConnect failed\n");
4253 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4254 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4255 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
4258 ret
= InternetSetOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4259 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4263 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4264 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4265 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
4267 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
4268 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4272 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4273 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4274 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
4277 ret
= InternetSetOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4278 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4282 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4283 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4284 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
4286 size
= sizeof(idsi
);
4287 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO
, &idsi
, &size
);
4288 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4291 SetLastError(0xdeadbeef);
4292 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
4293 error
= GetLastError();
4294 ok(!ret
, "InternetQueryOption succeeded\n");
4295 ok(error
== ERROR_INTERNET_INVALID_OPERATION
, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error
);
4297 /* INTERNET_OPTION_PROXY */
4298 SetLastError(0xdeadbeef);
4299 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
4300 error
= GetLastError();
4301 ok(!ret
, "InternetQueryOption succeeded\n");
4302 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4304 SetLastError(0xdeadbeef);
4305 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
4306 error
= GetLastError();
4307 ok(!ret
, "InternetQueryOption succeeded\n");
4308 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4311 SetLastError(0xdeadbeef);
4312 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
4313 error
= GetLastError();
4314 ok(!ret
, "InternetQueryOption succeeded\n");
4315 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
4316 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
4318 InternetCloseHandle(req
);
4319 InternetCloseHandle(con
);
4320 InternetCloseHandle(ses
);
4324 const char *response_text
;
4326 const char *status_text
;
4327 const char *raw_headers
;
4328 } http_status_test_t
;
4330 static const http_status_test_t http_status_tests
[] = {
4332 "HTTP/1.1 200 OK\r\n"
4333 "Content-Length: 1\r\n"
4339 "HTTP/1.1 404 Fail\r\n"
4340 "Content-Length: 1\r\n"
4347 "Content-Length: 1\r\n"
4354 "Content-Length: 1\r\n"
4361 static void test_http_status(int port
)
4368 for(i
= 0; i
< ARRAY_SIZE(http_status_tests
); i
++) {
4369 send_buffer
= http_status_tests
[i
].response_text
;
4371 open_simple_request(&req
, "localhost", port
, NULL
, "/send_from_buffer");
4373 res
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4374 ok(res
, "HttpSendRequest failed\n");
4376 test_status_code(req
.request
, http_status_tests
[i
].status_code
);
4379 res
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buf
, &size
, NULL
);
4380 ok(res
, "HttpQueryInfo failed: %u\n", GetLastError());
4381 ok(!strcmp(buf
, http_status_tests
[i
].status_text
), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
4382 i
, buf
, http_status_tests
[i
].status_text
);
4384 close_request(&req
);
4388 static void test_cache_control_verb(int port
)
4390 HINTERNET session
, connect
, request
;
4393 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4394 ok(session
!= NULL
, "InternetOpen failed\n");
4396 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4397 ok(connect
!= NULL
, "InternetConnect failed\n");
4399 request
= HttpOpenRequestA(connect
, "RPC_OUT_DATA", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4400 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4401 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4402 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4403 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4404 test_status_code(request
, 200);
4405 InternetCloseHandle(request
);
4407 request
= HttpOpenRequestA(connect
, "POST", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4408 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4409 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4410 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4411 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4412 test_status_code(request
, 200);
4413 InternetCloseHandle(request
);
4415 request
= HttpOpenRequestA(connect
, "HEAD", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4416 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4417 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4418 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4419 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4420 test_status_code(request
, 200);
4421 InternetCloseHandle(request
);
4423 request
= HttpOpenRequestA(connect
, "GET", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4424 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4425 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4426 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4427 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4428 test_status_code(request
, 200);
4429 InternetCloseHandle(request
);
4431 InternetCloseHandle(connect
);
4432 InternetCloseHandle(session
);
4435 static void test_request_content_length(int port
)
4437 char data
[] = {'t','e','s','t'};
4442 open_simple_request(&req
, "localhost", port
, "POST", "/test_request_content_length");
4444 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4445 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4446 test_status_code(req
.request
, 200);
4448 SetEvent(complete_event
);
4450 ret
= HttpSendRequestA(req
.request
, NULL
, 0, data
, sizeof(data
));
4451 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4452 test_status_code(req
.request
, 200);
4454 SetEvent(complete_event
);
4455 close_request(&req
);
4458 static void test_accept_encoding(int port
)
4460 HINTERNET ses
, con
, req
;
4464 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4465 ok(ses
!= NULL
, "InternetOpen failed\n");
4467 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4468 ok(con
!= NULL
, "InternetConnect failed\n");
4470 req
= HttpOpenRequestA(con
, "GET", "/echo_request", "HTTP/1.0", NULL
, NULL
, 0, 0);
4471 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4473 ret
= HttpAddRequestHeadersA(req
, "Accept-Encoding: gzip\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDREQ_FLAG_ADD
);
4474 ok(ret
, "HttpAddRequestHeaders failed\n");
4476 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4477 ok(ret
, "HttpSendRequestA failed\n");
4479 test_status_code(req
, 200);
4480 receive_simple_request(req
, buf
, sizeof(buf
));
4481 ok(strstr(buf
, "Accept-Encoding: gzip") != NULL
, "Accept-Encoding header not found in %s\n", buf
);
4483 InternetCloseHandle(req
);
4485 req
= HttpOpenRequestA(con
, "GET", "/echo_request", "HTTP/1.0", NULL
, NULL
, 0, 0);
4486 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4488 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", ~0u, NULL
, 0);
4489 ok(ret
, "HttpSendRequestA failed\n");
4491 test_status_code(req
, 200);
4492 receive_simple_request(req
, buf
, sizeof(buf
));
4493 ok(strstr(buf
, "Accept-Encoding: gzip") != NULL
, "Accept-Encoding header not found in %s\n", buf
);
4495 InternetCloseHandle(req
);
4496 InternetCloseHandle(con
);
4497 InternetCloseHandle(ses
);
4500 static void test_basic_auth_credentials_reuse(int port
)
4502 HINTERNET ses
, con
, req
;
4507 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4508 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4510 con
= InternetConnectA( ses
, "localhost", port
, "user", "pwd",
4511 INTERNET_SERVICE_HTTP
, 0, 0 );
4512 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4514 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
4515 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4517 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4518 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4520 size
= sizeof(buffer
);
4521 SetLastError(0xdeadbeef);
4522 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_USERNAME
, buffer
, &size
);
4523 ok(ret
, "unexpected failure %u\n", GetLastError());
4524 ok(!strcmp(buffer
, "user"), "got %s\n", buffer
);
4525 ok(size
== 4, "got %u\n", size
);
4527 size
= sizeof(buffer
);
4528 SetLastError(0xdeadbeef);
4529 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_PASSWORD
, buffer
, &size
);
4530 ok(ret
, "unexpected failure %u\n", GetLastError());
4531 ok(!strcmp(buffer
, "pwd"), "got %s\n", buffer
);
4532 ok(size
== 3, "got %u\n", size
);
4534 status
= 0xdeadbeef;
4535 size
= sizeof(status
);
4536 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4537 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4538 ok( status
== 200, "got %u\n", status
);
4540 InternetCloseHandle( req
);
4541 InternetCloseHandle( con
);
4542 InternetCloseHandle( ses
);
4544 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4545 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4547 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
,
4548 INTERNET_SERVICE_HTTP
, 0, 0 );
4549 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4551 req
= HttpOpenRequestA( con
, "PUT", "/upload2.txt", NULL
, NULL
, NULL
, 0, 0 );
4552 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4554 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4555 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4557 size
= sizeof(buffer
);
4558 SetLastError(0xdeadbeef);
4559 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_USERNAME
, buffer
, &size
);
4560 ok(ret
, "unexpected failure %u\n", GetLastError());
4561 ok(!strcmp(buffer
, "user"), "got %s\n", buffer
);
4562 ok(size
== 4, "got %u\n", size
);
4564 size
= sizeof(buffer
);
4565 SetLastError(0xdeadbeef);
4566 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_PASSWORD
, buffer
, &size
);
4567 ok(ret
, "unexpected failure %u\n", GetLastError());
4568 ok(!strcmp(buffer
, "pwd"), "got %s\n", buffer
);
4569 ok(size
== 3, "got %u\n", size
);
4571 status
= 0xdeadbeef;
4572 size
= sizeof(status
);
4573 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4574 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4575 ok( status
== 200, "got %u\n", status
);
4577 InternetCloseHandle( req
);
4578 InternetCloseHandle( con
);
4579 InternetCloseHandle( ses
);
4582 static void test_basic_auth_credentials_end_session(int port
)
4584 HINTERNET ses
, con
, req
;
4589 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4590 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4592 con
= InternetConnectA( ses
, "localhost", port
, "user", "pwd",
4593 INTERNET_SERVICE_HTTP
, 0, 0 );
4594 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4596 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
4597 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4599 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4600 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4602 size
= sizeof(buffer
);
4603 SetLastError(0xdeadbeef);
4604 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_USERNAME
, buffer
, &size
);
4605 ok(ret
, "unexpected failure %u\n", GetLastError());
4606 ok(!strcmp(buffer
, "user"), "got %s\n", buffer
);
4607 ok(size
== 4, "got %u\n", size
);
4609 size
= sizeof(buffer
);
4610 SetLastError(0xdeadbeef);
4611 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_PASSWORD
, buffer
, &size
);
4612 ok(ret
, "unexpected failure %u\n", GetLastError());
4613 ok(!strcmp(buffer
, "pwd"), "got %s\n", buffer
);
4614 ok(size
== 3, "got %u\n", size
);
4616 status
= 0xdeadbeef;
4617 size
= sizeof(status
);
4618 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4619 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4620 ok( status
== HTTP_STATUS_OK
, "got %u\n", status
);
4622 InternetCloseHandle( req
);
4623 InternetCloseHandle( con
);
4624 InternetCloseHandle( ses
);
4626 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4627 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4629 /* Clear the cached credentials */
4630 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_END_BROWSER_SESSION
, NULL
, 0);
4631 ok(ret
, "unexpected failure %u\n", GetLastError());
4633 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
,
4634 INTERNET_SERVICE_HTTP
, 0, 0 );
4635 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4637 req
= HttpOpenRequestA( con
, "PUT", "/upload2.txt", NULL
, NULL
, NULL
, 0, 0 );
4638 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4640 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4641 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4643 size
= sizeof(buffer
);
4644 SetLastError(0xdeadbeef);
4645 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_USERNAME
, buffer
, &size
);
4646 ok(ret
, "unexpected failure %u\n", GetLastError());
4647 ok(!strcmp(buffer
, ""), "got %s\n", buffer
);
4648 ok(size
== 0, "got %u\n", size
);
4650 size
= sizeof(buffer
);
4651 SetLastError(0xdeadbeef);
4652 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_PASSWORD
, buffer
, &size
);
4653 ok(ret
, "unexpected failure %u\n", GetLastError());
4654 ok(!strcmp(buffer
, ""), "got %s\n", buffer
);
4655 ok(size
== 0, "got %u\n", size
);
4657 status
= 0xdeadbeef;
4658 size
= sizeof(status
);
4659 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4660 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4661 ok( status
== HTTP_STATUS_BAD_REQUEST
, "got %u\n", status
);
4663 InternetCloseHandle( req
);
4664 InternetCloseHandle( con
);
4665 InternetCloseHandle( ses
);
4668 static void test_basic_auth_credentials_different(int port
)
4670 HINTERNET ses
, con
, req
;
4675 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4676 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4678 con
= InternetConnectA( ses
, "localhost", port
, "user", "pwd",
4679 INTERNET_SERVICE_HTTP
, 0, 0 );
4680 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4682 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
4683 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4685 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4686 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4688 size
= sizeof(buffer
);
4689 SetLastError(0xdeadbeef);
4690 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_USERNAME
, buffer
, &size
);
4691 ok(ret
, "unexpected failure %u\n", GetLastError());
4692 ok(!strcmp(buffer
, "user"), "got %s\n", buffer
);
4693 ok(size
== 4, "got %u\n", size
);
4695 size
= sizeof(buffer
);
4696 SetLastError(0xdeadbeef);
4697 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_PASSWORD
, buffer
, &size
);
4698 ok(ret
, "unexpected failure %u\n", GetLastError());
4699 ok(!strcmp(buffer
, "pwd"), "got %s\n", buffer
);
4700 ok(size
== 3, "got %u\n", size
);
4702 status
= 0xdeadbeef;
4703 size
= sizeof(status
);
4704 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4705 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4706 ok( status
== 200, "got %u\n", status
);
4708 InternetCloseHandle( req
);
4709 InternetCloseHandle( con
);
4710 InternetCloseHandle( ses
);
4712 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4713 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4715 con
= InternetConnectA( ses
, "localhost", port
, "user1", "pwd1",
4716 INTERNET_SERVICE_HTTP
, 0, 0 );
4717 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4719 req
= HttpOpenRequestA( con
, "HEAD", "/upload3.txt", NULL
, NULL
, NULL
, 0, 0 );
4720 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4722 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4723 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4725 size
= sizeof(buffer
);
4726 SetLastError(0xdeadbeef);
4727 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_USERNAME
, buffer
, &size
);
4728 ok(ret
, "unexpected failure %u\n", GetLastError());
4729 ok(!strcmp(buffer
, "user1"), "got %s\n", buffer
);
4730 ok(size
== 5, "got %u\n", size
);
4732 size
= sizeof(buffer
);
4733 SetLastError(0xdeadbeef);
4734 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_PASSWORD
, buffer
, &size
);
4735 ok(ret
, "unexpected failure %u\n", GetLastError());
4736 ok(!strcmp(buffer
, "pwd1"), "got %s\n", buffer
);
4737 ok(size
== 4, "got %u\n", size
);
4739 status
= 0xdeadbeef;
4740 size
= sizeof(status
);
4741 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4742 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4743 ok( status
== 200, "got %u\n", status
);
4745 InternetCloseHandle( req
);
4746 InternetCloseHandle( con
);
4747 InternetCloseHandle( ses
);
4751 * Manually set the Authorization for both calls.
4753 static void test_basic_auth_credentials_manual(int port
)
4755 HINTERNET ses
, con
, req
;
4759 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4760 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4762 /* Clear the cached credentials */
4763 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_END_BROWSER_SESSION
, NULL
, 0);
4764 ok(ret
, "unexpected failure %u\n", GetLastError());
4766 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0 );
4767 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4769 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
4770 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4772 /* Set Authorization Header */
4773 ret
= HttpAddRequestHeadersA(req
, "Authorization: Basic dXNlcjpwd2Q=\r\n", ~0u,
4774 HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDREQ_FLAG_ADD
);
4775 ok(ret
, "HttpAddRequestHeaders Failed\n");
4777 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4778 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4780 status
= 0xdeadbeef;
4781 size
= sizeof(status
);
4782 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4783 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4784 ok( status
== 200, "got %u\n", status
);
4786 InternetCloseHandle( req
);
4787 InternetCloseHandle( con
);
4788 InternetCloseHandle( ses
);
4790 /* Show manual headers are cached. */
4791 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4792 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4794 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0 );
4795 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4797 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
4798 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4800 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4801 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4803 status
= 0xdeadbeef;
4804 size
= sizeof(status
);
4805 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4806 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4807 ok( status
== 401, "got %u\n", status
);
4809 InternetCloseHandle( req
);
4810 InternetCloseHandle( con
);
4811 InternetCloseHandle( ses
);
4813 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4814 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4816 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0 );
4817 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4819 req
= HttpOpenRequestA( con
, "HEAD", "/upload4.txt", NULL
, NULL
, NULL
, 0, 0 );
4820 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4822 /* Set Authorization Header */
4823 ret
= HttpAddRequestHeadersA(req
, "Authorization: Bearer dXNlcjE6cHdkMQ==\r\n", ~0u,
4824 HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDREQ_FLAG_ADD
);
4825 ok(ret
, "HttpAddRequestHeaders Failed\n");
4827 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4828 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4830 status
= 0xdeadbeef;
4831 size
= sizeof(status
);
4832 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4833 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4834 ok( status
== 200, "got %u\n", status
);
4836 InternetCloseHandle( req
);
4837 InternetCloseHandle( con
);
4838 InternetCloseHandle( ses
);
4842 * Manually set the Authorization for the bearer call, which shows the cached is used.
4844 static void test_basic_auth_credentials_cached_manual(int port
)
4846 HINTERNET ses
, con
, req
;
4850 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4851 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4853 /* Clear the cached credentials */
4854 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_END_BROWSER_SESSION
, NULL
, 0);
4855 ok(ret
, "unexpected failure %u\n", GetLastError());
4857 con
= InternetConnectA( ses
, "localhost", port
, "user", "pwd",
4858 INTERNET_SERVICE_HTTP
, 0, 0 );
4859 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4861 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
4862 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4864 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4865 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4867 status
= 0xdeadbeef;
4868 size
= sizeof(status
);
4869 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4870 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4871 ok( status
== 200, "got %u\n", status
);
4873 InternetCloseHandle( req
);
4874 InternetCloseHandle( con
);
4875 InternetCloseHandle( ses
);
4877 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4878 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4880 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0 );
4881 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4883 req
= HttpOpenRequestA( con
, "HEAD", "/upload4.txt", NULL
, NULL
, NULL
, 0, 0 );
4884 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4886 /* Setting an Authorization Header doesn't override the cached one. */
4887 ret
= HttpAddRequestHeadersA(req
, "Authorization: Bearer dXNlcjE6cHdkMQ==\r\n", ~0u,
4888 HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDREQ_FLAG_ADD
);
4889 ok(ret
, "HttpAddRequestHeaders Failed\n");
4891 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4892 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4894 status
= 0xdeadbeef;
4895 size
= sizeof(status
);
4896 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4897 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4898 ok( status
== 201, "got %u\n", status
);
4900 InternetCloseHandle( req
);
4901 InternetCloseHandle( con
);
4902 InternetCloseHandle( ses
);
4905 static void test_async_read(int port
)
4907 HINTERNET ses
, con
, req
;
4908 INTERNET_BUFFERSA ib
;
4910 DWORD pending_reads
;
4911 DWORD res
, count
, bytes
;
4916 /* test asynchronous InternetReadFileEx */
4917 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4918 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4919 pInternetSetStatusCallbackA( ses
, &callback
);
4921 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4922 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef );
4923 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4924 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4926 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4927 req
= HttpOpenRequestA( con
, "GET", "/async_read", NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef );
4928 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4929 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4931 SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT
);
4932 SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY
);
4933 SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4934 SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4935 SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST
);
4936 SET_EXPECT( INTERNET_STATUS_REQUEST_SENT
);
4937 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4938 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4939 SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION
);
4940 SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED
);
4941 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4943 SetLastError( 0xdeadbeef );
4944 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4945 ok( !ret
, "HttpSendRequestA unexpectedly succeeded\n" );
4946 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4947 WaitForSingleObject( complete_event
, INFINITE
);
4948 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4950 CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT
);
4951 CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY
);
4952 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4953 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4954 CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST
);
4955 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT
);
4956 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4957 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4958 CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION
);
4959 CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED
);
4960 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4963 memset( &ib
, 0, sizeof(ib
) );
4964 memset( buffer
, 0, sizeof(buffer
) );
4965 ib
.dwStructSize
= sizeof(ib
);
4966 for (count
= 0; count
< sizeof(buffer
); count
+= ib
.dwBufferLength
)
4968 ib
.lpvBuffer
= buffer
+ count
;
4969 ib
.dwBufferLength
= min(16, sizeof(buffer
) - count
);
4971 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4972 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4974 ret
= InternetReadFileExA( req
, &ib
, 0, 0xdeadbeef );
4975 if (!count
) /* the first part should arrive immediately */
4976 ok( ret
, "InternetReadFileExA failed %u\n", GetLastError() );
4979 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4980 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4981 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4982 if (!pending_reads
++)
4984 res
= WaitForSingleObject( complete_event
, 0 );
4985 ok( res
== WAIT_TIMEOUT
, "expected WAIT_TIMEOUT, got %u\n", res
);
4986 SetEvent( conn_wait_event
);
4988 res
= WaitForSingleObject( complete_event
, INFINITE
);
4989 ok( res
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", res
);
4990 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4991 todo_wine_if( pending_reads
> 1 )
4992 ok( ib
.dwBufferLength
!= 0, "expected ib.dwBufferLength != 0\n" );
4993 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4994 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4997 CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4998 CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4999 if (!ib
.dwBufferLength
) break;
5002 ok( pending_reads
== 1, "expected 1 pending read, got %u\n", pending_reads
);
5003 ok( !strcmp(buffer
, page1
), "unexpected buffer content\n" );
5004 close_async_handle( ses
, 2 );
5005 ResetEvent( conn_wait_event
);
5007 /* test asynchronous InternetReadFile */
5008 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5009 ok( ses
!= NULL
, "InternetOpenA failed\n" );
5010 pInternetSetStatusCallbackA( ses
, &callback
);
5012 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
5013 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef );
5014 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
5015 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
5017 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
5018 req
= HttpOpenRequestA( con
, "GET", "/async_read", NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef );
5019 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
5020 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
5022 SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT
);
5023 SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY
);
5024 SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER
);
5025 SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER
);
5026 SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST
);
5027 SET_EXPECT( INTERNET_STATUS_REQUEST_SENT
);
5028 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
5029 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
5030 SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION
);
5031 SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED
);
5032 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
5034 SetLastError( 0xdeadbeef );
5035 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
5036 ok( !ret
, "HttpSendRequestA unexpectedly succeeded\n" );
5037 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
5038 WaitForSingleObject( complete_event
, INFINITE
);
5039 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5041 CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT
);
5042 CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY
);
5043 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER
);
5044 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER
);
5045 CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST
);
5046 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT
);
5047 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
5048 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
5049 CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION
);
5050 CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED
);
5051 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
5054 memset( buffer
, 0, sizeof(buffer
) );
5055 for (count
= 0; count
< sizeof(buffer
); count
+= bytes
)
5057 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
5058 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
5061 ret
= InternetReadFile( req
, buffer
+ count
, min(16, sizeof(buffer
) - count
), &bytes
);
5062 if (!count
) /* the first part should arrive immediately */
5063 ok( ret
, "InternetReadFile failed %u\n", GetLastError() );
5066 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
5067 ok( bytes
== 0, "expected 0, got %u\n", bytes
);
5068 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
5069 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
5070 if (!pending_reads
++)
5072 res
= WaitForSingleObject( complete_event
, 0 );
5073 ok( res
== WAIT_TIMEOUT
, "expected WAIT_TIMEOUT, got %u\n", res
);
5074 SetEvent( conn_wait_event
);
5076 res
= WaitForSingleObject( complete_event
, INFINITE
);
5077 ok( res
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", res
);
5078 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5079 todo_wine_if( pending_reads
> 1 )
5080 ok( bytes
!= 0, "expected bytes != 0\n" );
5081 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
5082 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
5085 CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
5086 CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
5090 ok( pending_reads
== 1, "expected 1 pending read, got %u\n", pending_reads
);
5091 ok( !strcmp(buffer
, page1
), "unexpected buffer content\n" );
5092 close_async_handle( ses
, 2 );
5095 static void server_send_string(const char *msg
)
5097 send(server_socket
, msg
, strlen(msg
), 0);
5100 static size_t server_read_data(char *buf
, size_t buf_size
)
5102 return recv(server_socket
, buf
, buf_size
, 0);
5105 #define server_read_request(a) _server_read_request(__LINE__,a)
5106 static void _server_read_request(unsigned line
, const char *expected_request
)
5111 size
= server_read_data(buf
, sizeof(buf
) - 1);
5113 p
= strstr(buf
, "\r\n");
5115 ok_(__FILE__
,line
)(p
&& !strcmp(buf
, expected_request
), "unexpected request %s\n", buf
);
5118 static BOOL skip_receive_notification_tests
;
5119 static DWORD received_response_size
;
5121 static void WINAPI
readex_callback(HINTERNET handle
, DWORD_PTR context
, DWORD status
, void *info
, DWORD info_size
)
5124 case INTERNET_STATUS_RECEIVING_RESPONSE
:
5125 if(!skip_receive_notification_tests
)
5126 callback(handle
, context
, status
, info
, info_size
);
5128 case INTERNET_STATUS_RESPONSE_RECEIVED
:
5129 if(!skip_receive_notification_tests
)
5130 callback(handle
, context
, status
, info
, info_size
);
5131 received_response_size
= *(DWORD
*)info
;
5133 case INTERNET_STATUS_REQUEST_SENT
:
5134 callback(handle
, context
, status
, info
, info_size
);
5135 SetEvent(request_sent_event
);
5138 callback(handle
, context
, status
, info
, info_size
);
5142 static void send_socket_request(test_request_t
*req
, BOOL new_connection
)
5146 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5147 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5148 if(new_connection
) {
5149 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5150 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5152 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5153 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5154 if(!skip_receive_notification_tests
)
5155 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5157 SetLastError(0xdeadbeef);
5158 ret
= HttpSendRequestA(req
->request
, NULL
, 0, NULL
, 0);
5159 ok(!ret
, "HttpSendRequestA unexpectedly succeeded\n");
5160 ok(GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError());
5163 WaitForSingleObject(server_req_rec_event
, INFINITE
);
5164 WaitForSingleObject(request_sent_event
, INFINITE
);
5166 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5167 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5168 if(new_connection
) {
5169 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5170 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5172 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5173 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5176 static void open_socket_request(int port
, test_request_t
*req
, const char *verb
)
5178 /* We're connecting to new socket */
5182 req
->session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5183 ok(req
->session
!= NULL
, "InternetOpenA failed\n");
5184 pInternetSetStatusCallbackA(req
->session
, readex_callback
);
5186 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5187 req
->connection
= InternetConnectA(req
->session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef);
5188 ok(req
->connection
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
5189 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5191 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5192 req
->request
= HttpOpenRequestA(req
->connection
, "GET", verb
? verb
: "/socket",
5193 NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef);
5194 ok(req
->request
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
5195 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
5197 send_socket_request(req
, !verb
);
5200 static void open_read_test_request(int port
, test_request_t
*req
, const char *response
)
5202 if(!skip_receive_notification_tests
)
5203 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5205 open_socket_request(port
, req
, NULL
);
5207 if(!skip_receive_notification_tests
) {
5208 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5209 received_response_size
= 0xdeadbeef;
5211 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5213 server_send_string(response
);
5214 WaitForSingleObject(complete_event
, INFINITE
);
5216 if(!skip_receive_notification_tests
) {
5217 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5218 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5220 ok(received_response_size
== strlen(response
), "received_response_size = %u\n", received_response_size
);
5222 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5223 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5226 #define readex_expect_sync_data_len(a,b,c,d,e,f,g) _readex_expect_sync_data_len(__LINE__,a,b,c,d,e,f,g)
5227 static void _readex_expect_sync_data_len(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
5228 DWORD buf_size
, const char *exdata
, DWORD len
, DWORD expect_receive
)
5232 if(!skip_receive_notification_tests
&& expect_receive
) {
5233 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5234 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5235 received_response_size
= 0xdeadbeef;
5238 memset(buf
->lpvBuffer
, 0xff, buf_size
);
5239 buf
->dwBufferLength
= buf_size
;
5240 ret
= InternetReadFileExW(req
, buf
, flags
, 0xdeadbeef);
5241 ok_(__FILE__
,line
)(ret
, "InternetReadFileExW failed: %u\n", GetLastError());
5242 ok_(__FILE__
,line
)(buf
->dwBufferLength
== len
, "dwBufferLength = %u, expected %u\n", buf
->dwBufferLength
, len
);
5244 ok_(__FILE__
,line
)(!memcmp(buf
->lpvBuffer
, exdata
, len
), "Unexpected data\n");
5246 if(!skip_receive_notification_tests
&& expect_receive
) {
5247 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5248 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5249 ok_(__FILE__
,line
)(received_response_size
== len
, "received_response_size = %u\n", received_response_size
);
5253 #define readex_expect_sync_data(a,b,c,d,e,f) _readex_expect_sync_data(__LINE__,a,b,c,d,e,f)
5254 static void _readex_expect_sync_data(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
5255 DWORD buf_size
, const char *exdata
, DWORD expect_receive
)
5257 _readex_expect_sync_data_len(line
, req
, flags
, buf
, buf_size
, exdata
, strlen(exdata
), expect_receive
);
5260 #define read_expect_sync_data_len(a,b,c,d,e) _read_expect_sync_data_len(__LINE__,a,b,c,d,e)
5261 static void _read_expect_sync_data_len(unsigned line
, HINTERNET req
, void *buf
, DWORD buf_size
,
5262 const char *exdata
, DWORD len
)
5264 DWORD ret_size
= 0xdeadbeef;
5267 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5268 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5269 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5270 received_response_size
= 0xdeadbeef;
5272 memset(buf
, 0xff, buf_size
);
5273 ret
= InternetReadFile(req
, buf
, buf_size
, &ret_size
);
5274 ok_(__FILE__
,line
)(ret
, "InternetReadFileExW failed: %u\n", GetLastError());
5275 ok_(__FILE__
,line
)(ret_size
== len
, "dwBufferLength = %u, expected %u\n", ret_size
, len
);
5277 ok_(__FILE__
,line
)(!memcmp(buf
, exdata
, len
), "Unexpected data\n");
5279 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5280 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5281 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5282 ok_(__FILE__
,line
)(received_response_size
== len
, "received_response_size = %u\n", received_response_size
);
5283 ok_(__FILE__
,line
)(!req_error
, "req_error = %u\n", req_error
);
5286 #define read_expect_sync_data(a,b,c,d) _read_expect_sync_data(__LINE__,a,b,c,d)
5287 static void _read_expect_sync_data(unsigned line
, HINTERNET req
, void *buf
,
5288 DWORD buf_size
, const char *exdata
)
5290 _read_expect_sync_data_len(line
, req
, buf
, buf_size
, exdata
, strlen(exdata
));
5293 static void close_connection(void)
5296 SetEvent(conn_wait_event
);
5297 recv(server_socket
, &c
, 1, 0);
5300 #define send_response_and_wait(a,b,c,d,e,f,g,h) _send_response_and_wait(__LINE__,a,b,c,d,e,f,g,h)
5301 static void _send_response_and_wait(unsigned line
, const char *response
, BOOL do_close_connection
,
5302 void *buf
, DWORD
*ret_size
, const char *exdata
,
5303 DWORD expected_size
, DWORD expected_req_error
, DWORD expected_receive_size
)
5305 if(!skip_receive_notification_tests
)
5306 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5307 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5310 server_send_string(response
);
5312 if(do_close_connection
)
5315 WaitForSingleObject(complete_event
, INFINITE
);
5317 if(!skip_receive_notification_tests
)
5318 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5319 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5320 if(!skip_receive_notification_tests
&& expected_receive_size
!= -1)
5321 todo_wine_if(received_response_size
!= expected_receive_size
) /* FIXME! remove when wine is fixed */
5322 ok_(__FILE__
,line
)(received_response_size
== expected_receive_size
,
5323 "received_response_size = %u\n", received_response_size
);
5324 ok_(__FILE__
,line
)(req_error
== expected_req_error
, "req_error = %u, expected %u\n", req_error
, expected_req_error
);
5326 /* If IRF_NO_WAIT is used, buffer is not changed. */
5327 ok_(__FILE__
,line
)(*ret_size
== expected_size
, "dwBufferLength = %u\n", *ret_size
);
5329 ok_(__FILE__
,line
)(!memcmp(buf
, exdata
, strlen(exdata
)), "unexpected buffer data\n");
5331 ok_(__FILE__
,line
)(!*(DWORD
*)buf
, "buffer data changed\n");
5334 #define send_response_ex_and_wait(a,b,c,d,e,f) _send_response_ex_and_wait(__LINE__,a,b,c,d,e,f)
5335 static void _send_response_ex_and_wait(unsigned line
, const char *response
, BOOL close_connection
,
5336 INTERNET_BUFFERSW
*buf
, const char *exdata
, DWORD expected_req_error
,
5337 DWORD expected_receive_size
)
5339 _send_response_and_wait(line
, response
, close_connection
, buf
->lpvBuffer
, &buf
->dwBufferLength
,
5340 exdata
, exdata
? strlen(exdata
) : buf
->dwBufferLength
, expected_req_error
,
5341 expected_receive_size
);
5344 static void send_response_len_and_wait(unsigned len
, BOOL close_connection
, INTERNET_BUFFERSW
*buf
)
5348 response
= HeapAlloc(GetProcessHeap(), 0, len
+1);
5349 memset(response
, 'x', len
);
5351 send_response_ex_and_wait(response
, close_connection
, buf
, NULL
, 0, -1);
5352 HeapFree(GetProcessHeap(), 0, response
);
5355 #define readex_expect_async(a,b,c,d,e) _readex_expect_async(__LINE__,a,b,c,d,e)
5356 static void _readex_expect_async(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
5357 DWORD buf_size
, const char *exdata
)
5362 if(!skip_receive_notification_tests
)
5363 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5365 memset(buf
->lpvBuffer
, 0, max(buf_size
, sizeof(DWORD
)));
5366 buf
->dwBufferLength
= buf_size
;
5367 ret
= InternetReadFileExW(req
, buf
, flags
, 0xdeadbeef);
5368 ok_(__FILE__
,line
)(!ret
&& GetLastError() == ERROR_IO_PENDING
, "InternetReadFileExW returned %x (%u)\n", ret
, GetLastError());
5369 ok_(__FILE__
,line
)(buf
->dwBufferLength
== buf_size
, "dwBufferLength = %u, expected %u\n", buf
->dwBufferLength
, buf_size
);
5371 len
= strlen(exdata
);
5372 ok_(__FILE__
,line
)(!memcmp(buf
->lpvBuffer
, exdata
, len
), "unexpected buffer data\n");
5374 ok_(__FILE__
,line
)(!*(DWORD
*)buf
->lpvBuffer
, "buffer data changed\n");
5377 if(!skip_receive_notification_tests
)
5378 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5381 static void read_expect_async(HINTERNET req
, void *buf
, DWORD buf_size
, DWORD
*ret_size
, const char *exdata
)
5387 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5389 *ret_size
= 0xdeadbeef;
5390 memset(buf
, 0, buf_size
);
5391 ret
= InternetReadFile(req
, buf
, buf_size
, ret_size
);
5392 ok(!ret
&& GetLastError() == ERROR_IO_PENDING
, "InternetReadFileExW returned %x (%u)\n", ret
, GetLastError());
5393 ok(*ret_size
== 0, "dwBufferLength = %u\n", *ret_size
);
5395 len
= strlen(exdata
);
5396 ok(!memcmp(buf
, exdata
, len
), "unexpected buffer data\n");
5398 for(p
= (const char*)buf
+ len
; p
< (const char*)buf
+ buf_size
; p
++) {
5400 ok(0, "buffer data changed\n");
5403 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5406 #define expect_data_available(a,b) _expect_data_available(__LINE__,a,b)
5407 static DWORD
_expect_data_available(unsigned line
, HINTERNET req
, int exsize
)
5412 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
5413 ok_(__FILE__
,line
)(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
5415 ok_(__FILE__
,line
)(size
== exsize
, "size = %u, expected %u\n", size
, exsize
);
5420 #define async_query_data_available(a,b) _async_query_data_available(__LINE__,a,b)
5421 static void _async_query_data_available(unsigned line
, HINTERNET req
, DWORD
*size
)
5425 if(!skip_receive_notification_tests
)
5426 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5429 res
= InternetQueryDataAvailable(req
, size
, 0, 0);
5430 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_IO_PENDING
,
5431 "InternetQueryDataAvailable returned: %x(%u)\n", res
, GetLastError());
5432 ok_(__FILE__
,line
)(!*size
, "size = %u\n", *size
);
5434 if(!skip_receive_notification_tests
)
5435 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5438 static void test_http_read(int port
)
5440 INTERNET_BUFFERSW ib
;
5449 memset(&ib
, 0, sizeof(ib
));
5450 ib
.dwStructSize
= sizeof(ib
);
5453 trace("Testing InternetReadFileExW with IRF_ASYNC flag...\n");
5455 open_read_test_request(port
, &req
,
5456 "HTTP/1.1 200 OK\r\n"
5457 "Server: winetest\r\n"
5461 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, 4, "xx");
5463 send_response_ex_and_wait("yy1234567890", FALSE
, &ib
, "xxyy", 0, 2);
5464 readex_expect_sync_data(req
.request
, IRF_ASYNC
, &ib
, 4, "1234", 4);
5465 readex_expect_sync_data(req
.request
, IRF_ASYNC
, &ib
, 5, "56789", 5);
5467 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, sizeof(buf
), "0");
5468 send_response_ex_and_wait("123", TRUE
, &ib
, "0123", 0, 4);
5470 close_async_handle(req
.session
, 2);
5472 trace("Testing InternetReadFileExW with no flags...\n");
5474 open_read_test_request(port
, &req
,
5475 "HTTP/1.1 200 OK\r\n"
5476 "Server: winetest\r\n"
5480 readex_expect_async(req
.request
, 0, &ib
, 4, "xx");
5482 send_response_ex_and_wait("yy1234567890", FALSE
, &ib
, "xxyy", 0, 2);
5483 readex_expect_sync_data(req
.request
, 0, &ib
, 4, "1234", 4);
5484 readex_expect_sync_data(req
.request
, 0, &ib
, 5, "56789", 5);
5486 readex_expect_async(req
.request
, 0, &ib
, sizeof(buf
), "0");
5487 send_response_ex_and_wait("123", TRUE
, &ib
, "0123", 0, 4);
5489 close_async_handle(req
.session
, 2);
5491 trace("Testing InternetReadFile...\n");
5493 open_read_test_request(port
, &req
,
5494 "HTTP/1.1 200 OK\r\n"
5495 "Server: winetest\r\n"
5499 read_expect_async(req
.request
, buf
, 4, &read_size
, "xx");
5501 send_response_and_wait("yy1234567890", FALSE
, buf
, &read_size
, "xxyy", 4, 0, 2);
5502 read_expect_sync_data(req
.request
, buf
, 4, "1234");
5503 read_expect_sync_data(req
.request
, buf
, 5, "56789");
5505 read_expect_async(req
.request
, buf
, sizeof(buf
), &read_size
, "0");
5506 send_response_and_wait("123", TRUE
, buf
, &read_size
, "0123", 4, 0, 4);
5508 close_async_handle(req
.session
, 2);
5510 trace("Testing InternetReadFileExW with IRF_NO_WAIT flag...\n");
5512 open_read_test_request(port
, &req
,
5513 "HTTP/1.1 200 OK\r\n"
5514 "Server: winetest\r\n"
5518 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
5520 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "xx", 0);
5522 if(notified
[INTERNET_STATUS_RECEIVING_RESPONSE
]) {
5523 win_skip("Skipping receive notification tests on too old Windows.\n");
5524 skip_receive_notification_tests
= TRUE
;
5526 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5528 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5529 send_response_ex_and_wait("1234567890", FALSE
, &ib
, NULL
, 0, 10);
5530 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, 5, "12345", 0);
5531 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "67890", 0);
5533 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5534 send_response_ex_and_wait("12345", TRUE
, &ib
, NULL
, 0, 5);
5536 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "12345", 0);
5537 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "", TRUE
);
5539 close_async_handle(req
.session
, 2);
5541 open_read_test_request(port
, &req
,
5542 "HTTP/1.1 200 OK\r\n"
5543 "Server: winetest\r\n"
5544 "Transfer-Encoding: chunked\r\n"
5547 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123456789", 0);
5548 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5550 send_response_ex_and_wait("\r\n1\r\na\r\n1\r\nb\r", FALSE
, &ib
, NULL
, 0, 13);
5551 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
5552 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5554 send_response_ex_and_wait("\n3\r\nab", FALSE
, &ib
, NULL
, 0, 6);
5555 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
5556 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5558 send_response_ex_and_wait("c", FALSE
, &ib
, NULL
, 0, 1);
5559 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "c", 0);
5560 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5562 send_response_ex_and_wait("\r\n1\r\nx\r\n0\r\n\r\n", TRUE
, &ib
, NULL
, 0, 13);
5563 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "x", 0);
5564 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "", 0);
5566 close_async_handle(req
.session
, 2);
5568 open_read_test_request(port
, &req
,
5569 "HTTP/1.1 200 OK\r\n"
5570 "Server: winetest\r\n"
5571 "Transfer-Encoding: chunked\r\n"
5574 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123", 0);
5575 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5577 send_response_ex_and_wait("0\r\n\r\n", TRUE
, &ib
, NULL
, 0, 5);
5578 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "", 0);
5580 close_async_handle(req
.session
, 2);
5582 open_read_test_request(port
, &req
,
5583 "HTTP/1.1 200 OK\r\n"
5584 "Server: winetest\r\n"
5585 "Connection: close\r\n"
5587 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5588 send_response_ex_and_wait("123", TRUE
, &ib
, NULL
, 0, 3);
5589 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123", 0);
5591 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5592 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5593 close_async_handle(req
.session
, 2);
5594 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5595 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5597 trace("Testing InternetQueryDataAvailable...\n");
5599 open_read_test_request(port
, &req
,
5600 "HTTP/1.1 200 OK\r\n"
5601 "Server: winetest\r\n"
5604 expect_data_available(req
.request
, 3);
5605 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123", 0);
5606 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5608 send_response_len_and_wait(20000, TRUE
, &ib
);
5609 avail
= expect_data_available(req
.request
, -1);
5610 ok(avail
<= 20000, "avail = %u\n", avail
);
5612 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
5613 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
5614 close_async_handle(req
.session
, 2);
5615 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5616 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5618 open_read_test_request(port
, &req
,
5619 "HTTP/1.1 200 OK\r\n"
5620 "Server: winetest\r\n"
5621 "Connection: close\r\n"
5625 expect_data_available(req
.request
, 3);
5626 readex_expect_sync_data(req
.request
, 0, &ib
, 3, "123", 0);
5628 async_query_data_available(req
.request
, &read_size
);
5629 send_response_and_wait("1234567890", FALSE
, NULL
, &read_size
, NULL
, 10, 10, 10);
5631 readex_expect_sync_data(req
.request
, 0, &ib
, 9, "123456789", 0);
5632 expect_data_available(req
.request
, 1);
5633 readex_expect_sync_data(req
.request
, 0, &ib
, 1, "0", 0);
5635 async_query_data_available(req
.request
, &read_size
);
5636 send_response_and_wait("1234567890", FALSE
, NULL
, &read_size
, NULL
, 10, 10, 10);
5637 expect_data_available(req
.request
, 10);
5638 for(i
= 0; i
< 10; i
++)
5639 server_send_string("x");
5640 expect_data_available(req
.request
, 10);
5642 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, 21, "1234567890");
5643 send_response_ex_and_wait("X", FALSE
, &ib
, "1234567890xxxxxxxxxxX", 0, 11);
5644 async_query_data_available(req
.request
, &read_size
);
5646 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5647 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5648 send_response_and_wait(NULL
, TRUE
, NULL
, &read_size
, NULL
, 0, 0, 0);
5649 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5650 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5652 close_async_handle(req
.session
, 2);
5654 skip_receive_notification_tests
= FALSE
;
5657 static void test_connection_break(int port
)
5659 INTERNET_BUFFERSW ib
;
5666 memset(&ib
, 0, sizeof(ib
));
5667 ib
.dwStructSize
= sizeof(ib
);
5670 trace("Testing InternetReadFileExW on broken connection...\n");
5672 open_read_test_request(port
, &req
,
5673 "HTTP/1.1 200 OK\r\n"
5674 "Server: winetest\r\n"
5675 "Content-Length: 10000\r\n"
5679 /* close connection and make sure that it's closed on handle release. */
5681 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5682 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5683 close_async_handle(req
.session
, 2);
5684 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5685 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5688 static void test_long_url(int port
)
5690 char long_path
[INTERNET_MAX_PATH_LENGTH
*2] = "/echo_request?";
5691 char buf
[sizeof(long_path
)*2], url
[sizeof(buf
)];
5699 memset(long_path
+strlen(long_path
), 'x', sizeof(long_path
)-strlen(long_path
));
5700 long_path
[sizeof(long_path
)-1] = 0;
5701 open_simple_request(&req
, "localhost", port
, NULL
, long_path
);
5703 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
5704 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
5705 test_status_code(req
.request
, 200);
5707 receive_simple_request(req
.request
, buf
, sizeof(buf
));
5708 ok(strstr(buf
, long_path
) != NULL
, "long pathnot found in %s\n", buf
);
5710 sprintf(url
, "http://localhost:%u%s", port
, long_path
);
5713 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_URL
, buf
, &size
);
5714 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
5716 ok(size
== len
, "size = %u, expected %u\n", size
, len
);
5717 ok(!strcmp(buf
, url
), "Wrong URL %s, expected %s\n", buf
, url
);
5719 close_request(&req
);
5722 static void test_persistent_connection(int port
)
5724 INTERNET_BUFFERSW ib
;
5731 memset(&ib
, 0, sizeof(ib
));
5732 ib
.dwStructSize
= sizeof(ib
);
5735 skip_receive_notification_tests
= TRUE
;
5737 trace("Testing persistent connection...\n");
5739 open_read_test_request(port
, &req
,
5740 "HTTP/1.1 200 OK\r\n"
5741 "Server: winetest\r\n"
5742 "Content-Length: 2\r\n"
5745 readex_expect_sync_data(req
.request
, IRF_ASYNC
, &ib
, 4, "xx", 0);
5746 close_async_handle(req
.session
, 2);
5748 open_socket_request(port
, &req
, "/test_simple_chunked");
5749 server_read_request("GET /test_simple_chunked HTTP/1.1");
5751 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5752 server_send_string("HTTP/1.1 200 OK\r\n"
5753 "Server: winetest\r\n"
5754 "Transfer-Encoding: chunked\r\n"
5757 WaitForSingleObject(complete_event
, INFINITE
);
5758 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5759 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5761 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
5762 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, sizeof(buf
), NULL
);
5763 send_response_ex_and_wait("3\r\nabc\r\n0\r\n\r\n", FALSE
, &ib
, "abc", 0, 13);
5764 close_async_handle(req
.session
, 2);
5766 open_socket_request(port
, &req
, "/chunked");
5767 server_read_request("GET /chunked HTTP/1.1");
5769 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5770 server_send_string("HTTP/1.1 200 OK\r\n"
5771 "Server: winetest\r\n"
5772 "Transfer-Encoding: chunked\r\n"
5775 WaitForSingleObject(complete_event
, INFINITE
);
5776 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5777 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5779 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, 3, "ab", 0);
5780 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, 3, NULL
);
5781 send_response_ex_and_wait("3\r\nabc\r\n", FALSE
, &ib
, "abc", 0, 13);
5783 /* send another request on the same request handle, it must drain remaining last chunk marker */
5784 server_send_string("0\r\n\r\n");
5786 send_socket_request(&req
, FALSE
);
5787 server_read_request("GET /chunked HTTP/1.1");
5789 ResetEvent(complete_event
);
5790 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5791 server_send_string("HTTP/1.1 201 OK\r\n"
5792 "Server: winetest\r\n"
5793 "Content-Length: 0\r\n"
5794 "Connection: keep-alive\r\n"
5796 WaitForSingleObject(complete_event
, INFINITE
);
5797 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5798 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5800 test_status_code(req
.request
, 201);
5801 close_async_handle(req
.session
, 2);
5803 /* the connection is still valid */
5804 open_socket_request(port
, &req
, "/another_chunked");
5805 server_read_request("GET /another_chunked HTTP/1.1");
5807 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5808 server_send_string("HTTP/1.1 200 OK\r\n"
5809 "Server: winetest\r\n"
5810 "Transfer-Encoding: chunked\r\n"
5813 WaitForSingleObject(complete_event
, INFINITE
);
5814 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5815 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5817 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
5818 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, sizeof(buf
), NULL
);
5820 /* we're missing trailing '\n'; the connection can't be drained without blocking,
5821 * so it will be closed */
5822 send_response_ex_and_wait("3\r\nabc\r\n0\r\n\r", FALSE
, &ib
, "abc", 0, 13);
5824 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5825 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5826 close_async_handle(req
.session
, 2);
5827 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5828 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5831 skip_receive_notification_tests
= FALSE
;
5834 static void test_redirect(int port
)
5836 char buf
[4000], expect_url
[INTERNET_MAX_URL_LENGTH
];
5837 INTERNET_BUFFERSW ib
;
5843 skip_receive_notification_tests
= TRUE
;
5845 memset(&ib
, 0, sizeof(ib
));
5846 ib
.dwStructSize
= sizeof(ib
);
5849 trace("Testing redirection...\n");
5851 open_socket_request(port
, &req
, NULL
);
5853 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5854 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
5855 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5856 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5858 server_send_string("HTTP/1.1 302 Found\r\n"
5859 "Server: winetest\r\n"
5860 "Location: test_redirection\r\n"
5861 "Connection: keep-alive\r\n"
5862 "Content-Length: 0\r\n"
5865 server_read_request("GET /test_redirection HTTP/1.1");
5867 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5869 sprintf(expect_url
, "http://localhost:%u/test_redirection", port
);
5870 test_request_url(req
.request
, expect_url
);
5872 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5874 server_send_string("HTTP/1.1 200 OK\r\n"
5875 "Server: winetest\r\n"
5876 "Content-Length: 3\r\n"
5880 WaitForSingleObject(complete_event
, INFINITE
);
5882 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5883 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5884 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
5885 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5886 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5888 test_status_code(req
.request
, 200);
5891 close_async_handle(req
.session
, 2);
5893 trace("Test redirect to non-http URL...\n");
5895 open_socket_request(port
, &req
, NULL
);
5897 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5899 server_send_string("HTTP/1.1 302 Found\r\n"
5900 "Server: winetest\r\n"
5901 "Location: test:non:http/url\r\n"
5902 "Connection: keep-alive\r\n"
5903 "Content-Length: 0\r\n"
5906 WaitForSingleObject(complete_event
, INFINITE
);
5908 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5909 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5911 sprintf(expect_url
, "http://localhost:%u/socket", port
);
5912 test_request_url(req
.request
, expect_url
);
5913 test_status_code(req
.request
, 302);
5916 close_async_handle(req
.session
, 2);
5918 trace("Test redirect to http URL with no host name...\n");
5920 open_socket_request(port
, &req
, NULL
);
5922 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5924 server_send_string("HTTP/1.1 302 Found\r\n"
5925 "Server: winetest\r\n"
5926 "Location: http:///nohost\r\n"
5927 "Connection: keep-alive\r\n"
5928 "Content-Length: 0\r\n"
5931 WaitForSingleObject(complete_event
, INFINITE
);
5933 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5934 ok(req_error
== ERROR_INTERNET_INVALID_URL
, "expected ERROR_INTERNET_INVALID_URL, got %u\n", req_error
);
5936 sprintf(expect_url
, "http://localhost:%u/socket", port
);
5937 test_request_url(req
.request
, expect_url
);
5938 test_status_code(req
.request
, 302);
5941 close_async_handle(req
.session
, 2);
5943 skip_receive_notification_tests
= FALSE
;
5946 static void test_remove_dot_segments(int port
)
5951 open_simple_request(&req
, "localhost", port
, NULL
, "/A/../B/./C/../../test_remove_dot_segments");
5953 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
5954 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
5955 test_status_code(req
.request
, 200);
5957 close_request(&req
);
5962 DWORD64 content_length
;
5966 static void test_large_content(int port
)
5968 struct large_test tests
[] = {
5970 { UINT_MAX
-1, TRUE
},
5972 { (DWORD64
)UINT_MAX
+1, FALSE
},
5983 open_simple_request(&req
, "localhost", port
, "HEAD", "/test_large_content");
5985 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
5987 content_length
= tests
[i
].content_length
;
5988 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
5989 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
5992 sizelen
= sizeof(len
);
5993 SetLastError(0xdeadbeef);
5994 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
,
5998 ok(ret
, "HttpQueryInfo should have succeeded\n");
5999 ok(GetLastError() == ERROR_SUCCESS
||
6000 broken(GetLastError() == 0xdeadbeef), /* xp, 2k8, vista */
6001 "expected ERROR_SUCCESS, got %x\n", GetLastError());
6002 ok(len
== (DWORD
)tests
[i
].content_length
, "expected %u, got %u\n",
6003 (DWORD
)tests
[i
].content_length
, len
);
6007 ok(!ret
, "HttpQueryInfo should have failed\n");
6008 ok(GetLastError() == ERROR_HTTP_INVALID_HEADER
,
6009 "expected ERROR_HTTP_INVALID_HEADER, got %x\n", GetLastError());
6010 ok(len
== ~0, "expected ~0, got %u\n", len
);
6012 ok(sizelen
== sizeof(DWORD
), "sizelen %u\n", sizelen
);
6015 /* test argument size */
6017 sizelen
= sizeof(len64
);
6018 SetLastError(0xdeadbeef);
6019 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
,
6021 ok(!ret
, "HttpQueryInfo should have failed\n");
6022 ok(GetLastError() == ERROR_HTTP_INVALID_HEADER
,
6023 "expected ERROR_HTTP_INVALID_HEADER, got %x\n", GetLastError());
6024 ok(sizelen
== sizeof(DWORD64
), "sizelen %u\n", sizelen
);
6025 ok(len64
== ~0, "len64 %x%08x\n", (DWORD
)(len64
>> 32), (DWORD
)len64
);
6027 close_request(&req
);
6029 /* test internal use of HttpQueryInfo on large size */
6030 open_read_test_request(port
, &req
,
6031 "HTTP/1.1 200 OK\r\n"
6032 "Server: winetest\r\n"
6033 "Content-Length: 4294967296\r\n"
6036 read_expect_async(req
.request
, buf
, 4, &read_size
, "xx");
6037 send_response_and_wait("yy1234567890", FALSE
, buf
, &read_size
, "xxyy", 4, 0, 2);
6038 read_expect_sync_data(req
.request
, buf
, 10, "1234567890");
6040 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
6041 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
6042 close_async_handle(req
.session
, 2);
6043 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6044 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6048 static void test_http_connection(void)
6050 struct server_info si
;
6054 si
.hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
6057 hThread
= CreateThread(NULL
, 0, server_thread
, &si
, 0, &id
);
6058 ok( hThread
!= NULL
, "create thread failed\n");
6060 r
= WaitForSingleObject(si
.hEvent
, 10000);
6061 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
6062 if (r
!= WAIT_OBJECT_0
)
6064 CloseHandle(hThread
);
6068 test_basic_request(si
.port
, "GET", "/test1");
6069 test_proxy_indirect(si
.port
);
6070 test_proxy_direct(si
.port
);
6071 test_header_handling_order(si
.port
);
6072 test_basic_request(si
.port
, "POST", "/test5");
6073 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
6074 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
6075 test_basic_request(si
.port
, "GET", "/test6");
6076 test_basic_request(si
.port
, "GET", "/testF");
6077 test_connection_header(si
.port
);
6078 test_header_override(si
.port
);
6079 test_cookie_header(si
.port
);
6080 test_basic_authentication(si
.port
);
6081 test_invalid_response_headers(si
.port
);
6082 test_response_without_headers(si
.port
);
6083 test_HttpQueryInfo(si
.port
);
6084 test_HttpSendRequestW(si
.port
);
6085 test_options(si
.port
);
6086 test_no_content(si
.port
);
6087 test_conn_close(si
.port
);
6088 test_no_cache(si
.port
);
6089 test_cache_read_gzipped(si
.port
);
6090 test_http_status(si
.port
);
6091 test_premature_disconnect(si
.port
);
6092 test_connection_closing(si
.port
);
6093 test_cache_control_verb(si
.port
);
6094 test_successive_HttpSendRequest(si
.port
);
6095 test_head_request(si
.port
);
6096 test_request_content_length(si
.port
);
6097 test_accept_encoding(si
.port
);
6098 test_basic_auth_credentials_reuse(si
.port
);
6099 test_basic_auth_credentials_end_session(si
.port
);
6100 test_basic_auth_credentials_different(si
.port
);
6101 test_basic_auth_credentials_manual(si
.port
);
6102 test_basic_auth_credentials_cached_manual(si
.port
);
6103 test_async_read(si
.port
);
6104 test_http_read(si
.port
);
6105 test_connection_break(si
.port
);
6106 test_long_url(si
.port
);
6107 test_redirect(si
.port
);
6108 test_persistent_connection(si
.port
);
6109 test_remove_dot_segments(si
.port
);
6110 test_large_content(si
.port
);
6112 /* send the basic request again to shutdown the server thread */
6113 test_basic_request(si
.port
, "GET", "/quit");
6115 r
= WaitForSingleObject(hThread
, 3000);
6116 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
6117 CloseHandle(hThread
);
6120 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
6122 LocalFree(info
->lpszSubjectInfo
);
6123 LocalFree(info
->lpszIssuerInfo
);
6124 LocalFree(info
->lpszProtocolName
);
6125 LocalFree(info
->lpszSignatureAlgName
);
6126 LocalFree(info
->lpszEncryptionAlgName
);
6130 const char *ex_subject
;
6131 const char *ex_issuer
;
6132 } cert_struct_test_t
;
6134 static const cert_struct_test_t test_winehq_org_cert
= {
6140 "700 Raymond Ave\r\n"
6148 "Network Solutions L.L.C.\r\n"
6149 "Network Solutions OV Server CA 2"
6152 static const cert_struct_test_t test_winehq_com_cert
= {
6158 "test.winehq.com\r\n"
6159 "webmaster@winehq.org",
6166 "test.winehq.com\r\n"
6167 "webmaster@winehq.org"
6170 static const char *cert_string_fmt
=
6171 "Subject:\r\n%s\r\n"
6173 "Effective Date:\t%s %s\r\n"
6174 "Expiration Date:\t%s %s\r\n"
6175 "Security Protocol:\t%s\r\n"
6176 "Signature Type:\t%s\r\n"
6177 "Encryption Type:\t%s\r\n"
6178 "Privacy Strength:\t%s (%u bits)";
6180 static void test_cert_struct_string(HINTERNET req
, const INTERNET_CERTIFICATE_INFOA
*info
)
6182 SYSTEMTIME start
, expiry
;
6183 char expiry_date
[32];
6184 char expiry_time
[32];
6185 char start_date
[32];
6186 char start_time
[32];
6192 size
= sizeof(actual
);
6193 SetLastError(0xdeadbeef);
6194 memset(actual
, 0x55, sizeof(actual
));
6195 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, actual
, &size
);
6196 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
6198 FileTimeToSystemTime(&info
->ftStart
, &start
);
6199 FileTimeToSystemTime(&info
->ftExpiry
, &expiry
);
6201 GetDateFormatA(LOCALE_USER_DEFAULT
, 0, &start
, NULL
, start_date
, sizeof(start_date
));
6202 GetTimeFormatA(LOCALE_USER_DEFAULT
, 0, &start
, NULL
, start_time
, sizeof(start_time
));
6203 GetDateFormatA(LOCALE_USER_DEFAULT
, 0, &expiry
, NULL
, expiry_date
, sizeof(expiry_date
));
6204 GetTimeFormatA(LOCALE_USER_DEFAULT
, 0, &expiry
, NULL
, expiry_time
, sizeof(expiry_time
));
6206 snprintf(expect
, sizeof(expect
), cert_string_fmt
, info
->lpszSubjectInfo
, info
->lpszIssuerInfo
,
6207 start_date
, start_time
, expiry_date
, expiry_time
,
6208 info
->lpszSignatureAlgName
, info
->lpszEncryptionAlgName
, info
->lpszProtocolName
,
6209 info
->dwKeySize
>= 128 ? "High" : "Low", info
->dwKeySize
);
6210 ok(size
== strlen(actual
), "size = %u\n", size
);
6211 ok(!strcmp(actual
, expect
), "expected:\n%s\nactual:\n%s\n", expect
, actual
);
6214 SetLastError(0xdeadbeef);
6215 memset(actual
, 0x55, sizeof(actual
));
6216 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, actual
, &size
);
6217 ok(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
6218 ok(size
== 1, "unexpected size: %u\n", size
);
6219 ok(actual
[0] == 0x55, "unexpected byte: %02x\n", actual
[0]);
6222 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
6224 INTERNET_CERTIFICATE_INFOA info
;
6228 memset(&info
, 0x5, sizeof(info
));
6230 size
= sizeof(info
);
6231 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
6234 win_skip("Querying INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT failed, skipping tests\n");
6238 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
6239 ok(size
== sizeof(info
), "size = %u\n", size
);
6241 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
6242 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
6243 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
6244 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
6245 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
6246 ok(info
.dwKeySize
>= 128 && info
.dwKeySize
<= 256, "dwKeySize = %u\n", info
.dwKeySize
);
6248 if (is_lang_english())
6249 test_cert_struct_string(req
, &info
);
6251 skip("Skipping tests that are English-only\n");
6252 release_cert_info(&info
);
6255 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
6256 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
6258 char url
[INTERNET_MAX_URL_LENGTH
];
6259 const CERT_CHAIN_CONTEXT
*chain
;
6263 if(!pInternetGetSecurityInfoByURLA
) {
6264 win_skip("pInternetGetSecurityInfoByURLA not available\n");
6269 chain
= (void*)0xdeadbeef;
6271 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
6272 if(error
== ERROR_SUCCESS
) {
6273 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
6274 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
6275 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
6276 CertFreeCertificateChain(chain
);
6278 SetLastError(0xdeadbeef);
6279 res
= pInternetGetSecurityInfoByURLA(url
, NULL
, NULL
);
6280 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
,
6281 "InternetGetSecurityInfoByURLA returned: %x(%u)\n", res
, GetLastError());
6283 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, NULL
);
6284 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
6285 CertFreeCertificateChain(chain
);
6287 res
= pInternetGetSecurityInfoByURLA(url
, NULL
, &flags
);
6288 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
6290 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
6291 "InternetGetSecurityInfoByURLA returned: %x(%u), expected %u\n", res
, GetLastError(), error
);
6295 #define test_secflags_option(a,b,c) _test_secflags_option(__LINE__,a,b,c)
6296 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
, DWORD opt_flags
)
6302 size
= sizeof(flags
);
6303 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
6304 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
6305 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n",
6308 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
6310 size
= sizeof(flags
);
6311 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
6312 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
6313 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n",
6317 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
6318 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
6322 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
6323 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
6326 static void test_security_flags(void)
6328 INTERNET_CERTIFICATE_INFOA
*cert
;
6329 HINTERNET ses
, conn
, req
;
6336 win_skip("Can't make https connections, skipping security flags test\n");
6340 trace("Testing security flags...\n");
6343 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6344 ok(ses
!= NULL
, "InternetOpen failed\n");
6346 pInternetSetStatusCallbackA(ses
, &callback
);
6348 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
6349 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
6350 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
6351 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
6352 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
6354 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
6355 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
6356 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
6358 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6359 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
6362 size
= sizeof(flags
);
6363 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
6364 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
6365 win_skip("Incomplete security flags support, skipping\n");
6367 close_async_handle(ses
, 2);
6371 test_secflags_option(req
, 0, 0);
6372 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
6374 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
6375 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
, 0);
6377 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
6378 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
6380 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
6381 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
6383 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
6384 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
6385 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
6387 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
6388 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
6389 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6390 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6391 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
6392 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
6393 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
6394 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
6395 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
6396 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
6397 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
6398 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
6399 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6400 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
6401 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
6403 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
6404 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
6406 WaitForSingleObject(complete_event
, INFINITE
);
6407 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
6409 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
6410 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
6411 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
6412 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
6413 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6414 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6415 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
6416 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
6417 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
6418 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
6419 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6420 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
6421 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
6423 test_request_flags(req
, 0);
6424 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
6425 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
, 0);
6427 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
6428 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
6429 ok(size
, "size = 0\n");
6431 /* Collect all existing persistent connections */
6432 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
6433 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
6435 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
6436 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
6437 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
6439 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6440 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
6442 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
6443 res
= InternetSetOptionA(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
6444 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
6446 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6447 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6448 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
6449 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
6450 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
6451 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
6452 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
6453 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
6454 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6455 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
6456 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
6458 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
6459 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
6461 WaitForSingleObject(complete_event
, INFINITE
);
6462 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
,
6463 "req_error = %d\n", req_error
);
6466 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
6467 ok(res
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
6468 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %u\n", size
);
6469 cert
= HeapAlloc(GetProcessHeap(), 0, size
);
6470 cert
->lpszSubjectInfo
= NULL
;
6471 cert
->lpszIssuerInfo
= NULL
;
6472 cert
->lpszSignatureAlgName
= (char *)0xdeadbeef;
6473 cert
->lpszEncryptionAlgName
= (char *)0xdeadbeef;
6474 cert
->lpszProtocolName
= (char *)0xdeadbeef;
6475 cert
->dwKeySize
= 0xdeadbeef;
6476 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, cert
, &size
);
6477 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
6480 ok(cert
->lpszSubjectInfo
&& strlen(cert
->lpszSubjectInfo
) > 1, "expected a non-empty subject name\n");
6481 ok(cert
->lpszIssuerInfo
&& strlen(cert
->lpszIssuerInfo
) > 1, "expected a non-empty issuer name\n");
6482 ok(!cert
->lpszSignatureAlgName
, "unexpected signature algorithm name\n");
6483 ok(!cert
->lpszEncryptionAlgName
, "unexpected encryption algorithm name\n");
6484 ok(!cert
->lpszProtocolName
, "unexpected protocol name\n");
6485 ok(cert
->dwKeySize
!= 0xdeadbeef, "unexpected key size\n");
6487 LocalFree(cert
->lpszSubjectInfo
);
6488 LocalFree(cert
->lpszIssuerInfo
);
6490 HeapFree(GetProcessHeap(), 0, cert
);
6492 SetLastError(0xdeadbeef);
6493 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, NULL
, NULL
);
6494 ok(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
, "InternetQueryOption failed: %d\n", GetLastError());
6497 SetLastError(0xdeadbeef);
6498 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, NULL
, &size
);
6499 ok(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
6500 ok(size
== 1, "unexpected size: %u\n", size
);
6503 SetLastError(0xdeadbeef);
6504 memset(buf
, 0x55, sizeof(buf
));
6505 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, buf
, &size
);
6506 ok(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
6507 ok(size
== 1, "unexpected size: %u\n", size
);
6508 ok(buf
[0] == 0x55, "unexpected byte: %02x\n", buf
[0]);
6511 SetLastError(0xdeadbeef);
6512 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, buf
, &size
);
6513 ok(res
&& GetLastError() == ERROR_SUCCESS
, "InternetQueryOption failed: %d\n", GetLastError());
6514 ok(size
< sizeof(buf
), "unexpected size: %u\n", size
);
6516 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
6517 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
6518 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
6519 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
6520 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6521 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
6522 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
6524 if(req_error
!= ERROR_INTERNET_SEC_CERT_ERRORS
) {
6525 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error
);
6527 close_async_handle(ses
, 3);
6532 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
6533 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
6535 test_request_flags(req
, 8);
6536 /* IE11 finds both rev failure and invalid CA. Previous versions required rev failure
6537 to be ignored before invalid CA was reported. */
6538 test_secflags_option(req
, _SECURITY_FLAG_CERT_INVALID_CA
, _SECURITY_FLAG_CERT_REV_FAILED
);
6540 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
6541 test_secflags_option(req
, _SECURITY_FLAG_CERT_INVALID_CA
|SECURITY_FLAG_IGNORE_REVOCATION
, _SECURITY_FLAG_CERT_REV_FAILED
);
6543 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6544 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6545 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
6546 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
6547 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6548 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
6549 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
6551 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
6552 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
6554 WaitForSingleObject(complete_event
, INFINITE
);
6555 ok(req_error
== ERROR_INTERNET_INVALID_CA
|| req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
6557 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6558 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6559 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6560 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6561 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6562 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
6563 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
6565 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
6566 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
6567 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
6569 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
6570 test_secflags_option(req
, _SECURITY_FLAG_CERT_INVALID_CA
6571 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
, 0);
6572 test_http_version(req
);
6574 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6575 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6576 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
6577 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
6578 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
6579 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
6580 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
6581 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
6582 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
6583 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
6584 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6585 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
6586 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
6588 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
6589 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
6591 WaitForSingleObject(complete_event
, INFINITE
);
6592 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
6594 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
6595 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
6596 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6597 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6598 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
6599 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
6600 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
6601 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
6602 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6603 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
6604 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
6606 test_request_flags(req
, 0);
6607 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
6608 |SECURITY_FLAG_STRENGTH_STRONG
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
6610 test_cert_struct(req
, &test_winehq_com_cert
);
6611 test_security_info("https://test.winehq.com/data/some_file.html?q", 0,
6612 _SECURITY_FLAG_CERT_INVALID_CA
);
6614 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
6615 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
6616 ok(size
, "size = 0\n");
6618 close_async_handle(ses
, 3);
6620 /* Collect all existing persistent connections */
6621 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
6622 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
6624 /* Make another request, without setting security flags */
6626 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6627 ok(ses
!= NULL
, "InternetOpen failed\n");
6629 pInternetSetStatusCallbackA(ses
, &callback
);
6631 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
6632 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
6633 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
6634 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
6635 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
6637 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
6638 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
6639 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
6641 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6642 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
6644 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
6645 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
6646 test_http_version(req
);
6648 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6649 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6650 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
6651 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
6652 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
6653 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
6654 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
6655 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
6656 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
6657 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
6658 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6659 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
6661 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
6662 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
6664 WaitForSingleObject(complete_event
, INFINITE
);
6665 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
6667 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
6668 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
6669 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6670 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6671 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
6672 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
6673 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
6674 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
6675 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6676 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
6678 test_request_flags(req
, 0);
6679 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
6680 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
6682 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
6683 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
6684 ok(size
, "size = 0\n");
6686 close_async_handle(ses
, 2);
6688 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
6689 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
6690 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
6693 static void test_secure_connection(void)
6695 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
6696 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
6697 static const WCHAR get
[] = {'G','E','T',0};
6698 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
6699 HINTERNET ses
, con
, req
;
6700 DWORD size
, size2
, flags
, err
;
6701 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
6702 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
6703 char certstr1
[512], certstr2
[512];
6706 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
6707 ok(ses
!= NULL
, "InternetOpen failed\n");
6709 con
= InternetConnectA(ses
, "test.winehq.org",
6710 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
6711 INTERNET_SERVICE_HTTP
, 0, 0);
6712 ok(con
!= NULL
, "InternetConnect failed\n");
6714 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
6715 INTERNET_FLAG_SECURE
, 0);
6716 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6718 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
6719 err
= GetLastError();
6720 ok(ret
|| broken(err
== ERROR_INTERNET_CANNOT_CONNECT
) ||
6721 broken(err
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
), "HttpSendRequest failed: %u\n", err
);
6724 win_skip("Cannot connect to https.\n");
6725 if (err
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
) https_support
= FALSE
;
6729 size
= sizeof(flags
);
6730 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
6731 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6732 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
6734 test_cert_struct(req
, &test_winehq_org_cert
);
6736 /* Querying the same option through InternetQueryOptionW still results in
6737 * ASCII strings being returned.
6740 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6742 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
6743 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
6744 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
6745 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6746 certificate_structW
, &size
);
6747 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
6748 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6751 ok(certificate_structA
->lpszSubjectInfo
&&
6752 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
6753 "expected a non-empty subject name\n");
6754 ok(certificate_structA
->lpszIssuerInfo
&&
6755 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
6756 "expected a non-empty issuer name\n");
6757 ok(!certificate_structA
->lpszSignatureAlgName
,
6758 "unexpected signature algorithm name\n");
6759 ok(!certificate_structA
->lpszEncryptionAlgName
,
6760 "unexpected encryption algorithm name\n");
6761 ok(!certificate_structA
->lpszProtocolName
,
6762 "unexpected protocol name\n");
6763 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
6764 release_cert_info(certificate_structA
);
6766 HeapFree(GetProcessHeap(), 0, certificate_structW
);
6768 SetLastError(0xdeadbeef);
6769 size
= sizeof(certstr1
);
6770 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, certstr1
, &size
);
6771 ok(ret
&& GetLastError() == ERROR_SUCCESS
, "InternetQueryOption failed: %d\n", GetLastError());
6773 SetLastError(0xdeadbeef);
6774 size2
= sizeof(certstr2
);
6775 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, certstr2
, &size2
);
6776 ok(ret
&& GetLastError() == ERROR_SUCCESS
, "InternetQueryOption failed: %d\n", GetLastError());
6778 ok(size
== size2
, "expected same size\n");
6779 ok(!strcmp(certstr1
, certstr2
), "expected same string\n");
6781 InternetCloseHandle(req
);
6782 InternetCloseHandle(con
);
6783 InternetCloseHandle(ses
);
6785 /* Repeating the tests with the W functions has the same result: */
6786 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
6787 ok(ses
!= NULL
, "InternetOpen failed\n");
6789 con
= InternetConnectW(ses
, testsite
,
6790 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
6791 INTERNET_SERVICE_HTTP
, 0, 0);
6792 ok(con
!= NULL
, "InternetConnect failed\n");
6794 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
6795 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
6796 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6798 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
6799 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
6801 size
= sizeof(flags
);
6802 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
6803 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6804 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %x\n", flags
);
6806 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6808 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
6809 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
6810 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
6811 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6812 certificate_structA
, &size
);
6813 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6816 ok(certificate_structA
->lpszSubjectInfo
&&
6817 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
6818 "expected a non-empty subject name\n");
6819 ok(certificate_structA
->lpszIssuerInfo
&&
6820 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
6821 "expected a non-empty issuer name\n");
6822 ok(!certificate_structA
->lpszSignatureAlgName
,
6823 "unexpected signature algorithm name\n");
6824 ok(!certificate_structA
->lpszEncryptionAlgName
,
6825 "unexpected encryption algorithm name\n");
6826 ok(!certificate_structA
->lpszProtocolName
,
6827 "unexpected protocol name\n");
6828 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
6829 release_cert_info(certificate_structA
);
6831 HeapFree(GetProcessHeap(), 0, certificate_structA
);
6833 /* Again, querying the same option through InternetQueryOptionW still
6834 * results in ASCII strings being returned.
6837 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6839 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
6840 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
6841 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
6842 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6843 certificate_structW
, &size
);
6844 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
6845 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6848 ok(certificate_structA
->lpszSubjectInfo
&&
6849 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
6850 "expected a non-empty subject name\n");
6851 ok(certificate_structA
->lpszIssuerInfo
&&
6852 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
6853 "expected a non-empty issuer name\n");
6854 ok(!certificate_structA
->lpszSignatureAlgName
,
6855 "unexpected signature algorithm name\n");
6856 ok(!certificate_structA
->lpszEncryptionAlgName
,
6857 "unexpected encryption algorithm name\n");
6858 ok(!certificate_structA
->lpszProtocolName
,
6859 "unexpected protocol name\n");
6860 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
6861 release_cert_info(certificate_structA
);
6863 HeapFree(GetProcessHeap(), 0, certificate_structW
);
6866 InternetCloseHandle(req
);
6867 InternetCloseHandle(con
);
6868 InternetCloseHandle(ses
);
6871 static void test_user_agent_header(void)
6873 HINTERNET ses
, con
, req
;
6878 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
6879 ok(ses
!= NULL
, "InternetOpen failed\n");
6881 con
= InternetConnectA(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
6882 ok(con
!= NULL
, "InternetConnect failed\n");
6884 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
6885 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6887 size
= sizeof(buffer
);
6888 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6889 err
= GetLastError();
6890 ok(!ret
, "HttpQueryInfo succeeded\n");
6891 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
6893 ret
= HttpAddRequestHeadersA(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
6894 ok(ret
, "HttpAddRequestHeaders succeeded\n");
6896 size
= sizeof(buffer
);
6897 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6898 err
= GetLastError();
6899 ok(ret
, "HttpQueryInfo failed\n");
6901 InternetCloseHandle(req
);
6903 req
= HttpOpenRequestA(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
6904 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6906 size
= sizeof(buffer
);
6907 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6908 err
= GetLastError();
6909 ok(!ret
, "HttpQueryInfo succeeded\n");
6910 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
6912 ret
= HttpAddRequestHeadersA(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
6913 ok(ret
, "HttpAddRequestHeaders failed\n");
6916 size
= sizeof(buffer
);
6917 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6918 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
6919 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
6921 InternetCloseHandle(req
);
6922 InternetCloseHandle(con
);
6923 InternetCloseHandle(ses
);
6926 static void test_bogus_accept_types_array(void)
6928 HINTERNET ses
, con
, req
;
6929 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
6934 ses
= InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
6935 con
= InternetConnectA(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
6936 req
= HttpOpenRequestA(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
6938 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
6941 size
= sizeof(buffer
);
6942 SetLastError(0xdeadbeef);
6943 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6944 error
= GetLastError();
6945 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
6946 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
6947 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
6948 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
6949 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
6951 InternetCloseHandle(req
);
6952 InternetCloseHandle(con
);
6953 InternetCloseHandle(ses
);
6962 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
6964 INTERNET_ASYNC_RESULT
*result
= info
;
6965 struct context
*ctx
= (struct context
*)context
;
6967 if(winetest_debug
> 1)
6968 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
6971 case INTERNET_STATUS_REQUEST_COMPLETE
:
6972 trace("request handle: 0x%08lx\n", result
->dwResult
);
6973 ctx
->req
= (HINTERNET
)result
->dwResult
;
6974 SetEvent(ctx
->event
);
6976 case INTERNET_STATUS_HANDLE_CLOSING
: {
6977 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
6979 if (InternetQueryOptionA(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
6980 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
6981 SetEvent(ctx
->event
);
6984 case INTERNET_STATUS_NAME_RESOLVED
:
6985 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
6986 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
6988 ok(str
[0] && str
[1], "Got string: %s\n", str
);
6989 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
6994 static void test_open_url_async(void)
7002 /* Collect all existing persistent connections */
7003 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
7004 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
7007 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
7008 * other versions never do. They also hang of following tests. We disable it for everything older
7015 ctx
.event
= CreateEventA(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
7017 ses
= InternetOpenA("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
7018 ok(ses
!= NULL
, "InternetOpen failed\n");
7020 SetLastError(0xdeadbeef);
7021 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
7022 error
= GetLastError();
7023 ok(!ret
, "InternetSetOptionA succeeded\n");
7024 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
7026 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
7027 error
= GetLastError();
7028 ok(!ret
, "InternetSetOptionA failed\n");
7029 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
7031 pInternetSetStatusCallbackW(ses
, cb
);
7032 ResetEvent(ctx
.event
);
7034 req
= InternetOpenUrlA(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
7035 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
7037 WaitForSingleObject(ctx
.event
, INFINITE
);
7040 size
= sizeof(type
);
7041 ret
= InternetQueryOptionA(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
7042 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
7043 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
7044 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
7047 ret
= HttpQueryInfoA(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
7048 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
7049 ok(size
> 0, "expected size > 0\n");
7051 ResetEvent(ctx
.event
);
7052 InternetCloseHandle(ctx
.req
);
7053 WaitForSingleObject(ctx
.event
, INFINITE
);
7055 InternetCloseHandle(ses
);
7056 CloseHandle(ctx
.event
);
7061 internet_connect
= 1,
7063 http_send_request_ex
,
7066 internet_close_handle
7071 enum api function
; /* api responsible for notification */
7072 unsigned int status
; /* status received */
7073 BOOL async
; /* delivered from another thread? */
7081 const struct notification
*test
;
7087 DWORD expect_result
;
7091 static CRITICAL_SECTION notification_cs
;
7093 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
7095 BOOL status_ok
, function_ok
;
7096 struct info
*info
= (struct info
*)context
;
7099 EnterCriticalSection( ¬ification_cs
);
7101 if(info
->is_aborted
) {
7102 LeaveCriticalSection(¬ification_cs
);
7106 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
7108 DWORD size
= sizeof(struct info
*);
7109 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
7110 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
7111 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
7113 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
7114 if(info
->expect_result
== ERROR_SUCCESS
) {
7115 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
7117 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
7118 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
7123 if (i
>= info
->count
)
7125 LeaveCriticalSection( ¬ification_cs
);
7129 while (info
->test
[i
].status
!= status
&&
7130 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
7131 i
< info
->count
- 1 &&
7132 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
7137 status_ok
= (info
->test
[i
].status
== status
);
7138 function_ok
= (info
->test
[i
].function
== info
->function
);
7140 if (!info
->test
[i
].todo
)
7142 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
7143 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
7145 if (info
->test
[i
].async
)
7146 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
7147 info
->line
, info
->thread
, GetCurrentThreadId());
7151 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
7153 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
7155 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
7158 LeaveCriticalSection( ¬ification_cs
);
7161 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
7163 info
->function
= function
;
7165 info
->expect_result
= expect_result
;
7168 struct notification_data
7170 const struct notification
*test
;
7171 const unsigned int count
;
7176 BOOL expect_conn_failure
;
7179 static const struct notification async_send_request_ex_test
[] =
7181 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
7182 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
7183 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
7184 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
7185 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
7186 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
7187 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
7188 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
7189 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
7190 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
7191 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7192 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, FALSE
},
7193 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, FALSE
},
7194 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
7195 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
7196 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7197 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
7198 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
7199 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
7200 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
7203 static const struct notification async_send_request_ex_test2
[] =
7205 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
7206 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
7207 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
7208 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
7209 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
7210 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
7211 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
, TRUE
},
7212 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
, TRUE
},
7213 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
7214 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
7215 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7216 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
7217 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
7218 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7219 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
7220 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
7221 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
7222 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
7225 static const struct notification async_send_request_ex_resolve_failure_test
[] =
7227 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
7228 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
7229 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
7230 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
},
7231 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
7232 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7233 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7234 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
7235 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
7236 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
7237 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
7240 static const struct notification async_send_request_ex_chunked_test
[] =
7242 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
},
7243 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
},
7244 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
7245 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
7246 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
7247 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
7248 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
7249 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
7250 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
7251 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
7252 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7253 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
7254 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
7255 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7256 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
},
7257 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
},
7258 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
},
7259 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
}
7262 static const struct notification_data notification_data
[] = {
7264 async_send_request_ex_chunked_test
,
7265 ARRAY_SIZE(async_send_request_ex_chunked_test
),
7271 async_send_request_ex_test
,
7272 ARRAY_SIZE(async_send_request_ex_test
),
7276 "Public ID=codeweavers"
7279 async_send_request_ex_test2
,
7280 ARRAY_SIZE(async_send_request_ex_test2
),
7286 async_send_request_ex_resolve_failure_test
,
7287 ARRAY_SIZE(async_send_request_ex_resolve_failure_test
),
7296 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
7299 HINTERNET ses
, req
, con
;
7301 DWORD size
, written
, error
;
7302 INTERNET_BUFFERSA b
;
7303 static const char *accept
[2] = {"*/*", NULL
};
7306 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
7308 InitializeCriticalSection( ¬ification_cs
);
7310 info
.test
= nd
->test
;
7311 info
.count
= nd
->count
;
7313 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
7314 info
.thread
= GetCurrentThreadId();
7315 info
.is_aborted
= FALSE
;
7317 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
7318 ok( ses
!= NULL
, "InternetOpen failed\n" );
7320 pInternetSetStatusCallbackA( ses
, check_notification
);
7322 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
7323 con
= InternetConnectA( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
7324 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
7326 WaitForSingleObject( info
.wait
, 10000 );
7328 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
7329 req
= HttpOpenRequestA( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
7330 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
7332 WaitForSingleObject( info
.wait
, 10000 );
7335 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
7336 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
7337 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
7338 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
7339 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
7342 setup_test( &info
, http_send_request_ex
, __LINE__
,
7343 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
7344 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
7345 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
7347 error
= WaitForSingleObject( info
.wait
, 10000 );
7348 if(error
!= WAIT_OBJECT_0
) {
7349 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
7350 info
.is_aborted
= TRUE
;
7354 size
= sizeof(buffer
);
7355 SetLastError( 0xdeadbeef );
7356 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
7357 error
= GetLastError();
7358 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
7359 if(nd
->expect_conn_failure
) {
7360 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
7363 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
7364 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
7370 size
= strlen( nd
->data
);
7371 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
7372 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
7373 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
7374 ok( written
== size
, "expected %u got %u\n", written
, size
);
7376 WaitForSingleObject( info
.wait
, 10000 );
7378 SetLastError( 0xdeadbeef );
7379 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
7380 error
= GetLastError();
7381 ok( !ret
, "HttpEndRequestA succeeded\n" );
7382 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
7385 SetLastError( 0xdeadbeef );
7386 setup_test( &info
, http_end_request
, __LINE__
,
7387 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
7388 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
7389 error
= GetLastError();
7390 ok( !ret
, "HttpEndRequestA succeeded\n" );
7391 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
7393 WaitForSingleObject( info
.wait
, 10000 );
7395 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
7397 InternetCloseHandle( req
);
7398 InternetCloseHandle( con
);
7399 InternetCloseHandle( ses
);
7401 WaitForSingleObject( info
.wait
, 10000 );
7403 CloseHandle( info
.wait
);
7404 DeleteCriticalSection( ¬ification_cs
);
7407 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
7408 static BOOL closetest_closed
;
7410 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
7411 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
7416 if(winetest_debug
> 1)
7417 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
7419 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
7420 "Unexpected hInternet %p\n", hInternet
);
7421 if(!closetest_closed
)
7425 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
7426 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
7427 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
7428 closetest_req
, res
, GetLastError());
7431 static void test_InternetCloseHandle(void)
7436 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
7437 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
7439 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
7441 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
7442 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
7443 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
7445 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
7446 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
7448 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
7449 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
7450 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
7452 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
7454 res
= InternetCloseHandle(closetest_session
);
7455 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
7456 closetest_closed
= TRUE
;
7457 trace("Closed session handle\n");
7459 res
= InternetCloseHandle(closetest_conn
);
7460 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
7461 res
, GetLastError());
7463 res
= InternetCloseHandle(closetest_req
);
7464 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
7465 res
, GetLastError());
7467 len
= sizeof(flags
);
7468 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
7469 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
7470 "InternetQueryOptionA(%p INTERNET_OPTION_REQUEST_FLAGS) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
7471 closetest_req
, res
, GetLastError());
7474 static void test_connection_failure(void)
7480 open_simple_request(&req
, "localhost", 1, NULL
, "/");
7482 SetLastError(0xdeadbeef);
7483 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
7484 error
= GetLastError();
7485 ok(!ret
, "unexpected success\n");
7486 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
7488 close_request(&req
);
7491 static void test_default_service_port(void)
7493 HINTERNET session
, connect
, request
;
7501 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
7502 ok(session
!= NULL
, "InternetOpen failed\n");
7504 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
7505 INTERNET_SERVICE_HTTP
, 0, 0);
7506 ok(connect
!= NULL
, "InternetConnect failed\n");
7508 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
7509 ok(request
!= NULL
, "HttpOpenRequest failed\n");
7511 SetLastError(0xdeadbeef);
7512 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
7513 error
= GetLastError();
7514 ok(!ret
, "HttpSendRequest succeeded\n");
7515 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
7518 size
= sizeof(buffer
);
7519 memset(buffer
, 0, sizeof(buffer
));
7520 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
7521 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
7522 ok(!strcmp(buffer
, "test.winehq.org:80"), "Expected test.winehg.org:80, got '%s'\n", buffer
);
7524 InternetCloseHandle(request
);
7525 InternetCloseHandle(connect
);
7527 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
7528 INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
7529 ok(connect
!= NULL
, "InternetConnect failed\n");
7531 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
7532 ok(request
!= NULL
, "HttpOpenRequest failed\n");
7534 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
7535 if (!ret
&& GetLastError() == ERROR_INTERNET_SECURITY_CHANNEL_ERROR
)
7537 win_skip("Can't make https connection\n");
7540 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
7542 size
= sizeof(buffer
);
7543 memset(buffer
, 0, sizeof(buffer
));
7544 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
7545 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
7546 ok(!strcmp(buffer
, "test.winehq.org"), "Expected test.winehg.org, got '%s'\n", buffer
);
7548 InternetCloseHandle(request
);
7549 InternetCloseHandle(connect
);
7551 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
7552 INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
7553 ok(connect
!= NULL
, "InternetConnect failed\n");
7555 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
7556 ok(request
!= NULL
, "HttpOpenRequest failed\n");
7558 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
7559 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
7561 size
= sizeof(buffer
);
7562 memset(buffer
, 0, sizeof(buffer
));
7563 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
7564 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
7565 ok(!strcmp(buffer
, "test.winehq.org:443"), "Expected test.winehg.org:443, got '%s'\n", buffer
);
7568 InternetCloseHandle(request
);
7569 InternetCloseHandle(connect
);
7570 InternetCloseHandle(session
);
7573 static void init_status_tests(void)
7575 memset(expect
, 0, sizeof(expect
));
7576 memset(optional
, 0, sizeof(optional
));
7577 memset(wine_allow
, 0, sizeof(wine_allow
));
7578 memset(notified
, 0, sizeof(notified
));
7579 memset(status_string
, 0, sizeof(status_string
));
7581 #define STATUS_STRING(status) status_string[status] = #status
7582 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
7583 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
7584 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
7585 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
7586 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
7587 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
7588 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
7589 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
7590 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
7591 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
7592 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
7593 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
7594 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
7595 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
7596 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
7597 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
7598 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
7599 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
7600 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
7601 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
7602 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
7603 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
7604 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
7605 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
7606 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
7607 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
7608 #undef STATUS_STRING
7611 static void WINAPI
header_cb( HINTERNET handle
, DWORD_PTR ctx
, DWORD status
, LPVOID info
, DWORD len
)
7617 if (status
== INTERNET_STATUS_SENDING_REQUEST
)
7619 ret
= HttpAddRequestHeadersA( handle
, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD
);
7620 ok( ret
, "HttpAddRequestHeadersA failed %u\n", GetLastError() );
7621 SetEvent( (HANDLE
)ctx
);
7623 else if (status
== INTERNET_STATUS_REQUEST_SENT
)
7627 ret
= HttpQueryInfoA( handle
, HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
7628 buf
, &size
, &index
);
7629 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
7630 ok( strstr( buf
, "winetest: winetest" ) != NULL
, "header missing\n" );
7631 SetEvent( (HANDLE
)ctx
);
7635 static void test_concurrent_header_access(void)
7637 HINTERNET ses
, con
, req
;
7640 HANDLE wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
7642 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
7643 ok( ses
!= NULL
, "InternetOpenA failed\n" );
7645 con
= InternetConnectA( ses
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
7646 INTERNET_SERVICE_HTTP
, 0, 0 );
7647 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
7649 req
= HttpOpenRequestA( con
, NULL
, "/", NULL
, NULL
, NULL
, 0, (DWORD_PTR
)wait
);
7650 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
7652 pInternetSetStatusCallbackA( req
, header_cb
);
7654 SetLastError( 0xdeadbeef );
7655 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
7656 err
= GetLastError();
7657 ok( !ret
, "HttpSendRequestA succeeded\n" );
7658 ok( err
== ERROR_IO_PENDING
, "got %u\n", ERROR_IO_PENDING
);
7660 WaitForSingleObject( wait
, 5000 );
7661 WaitForSingleObject( wait
, 5000 );
7663 InternetCloseHandle( req
);
7664 InternetCloseHandle( con
);
7665 InternetCloseHandle( ses
);
7666 CloseHandle( wait
);
7669 static void test_cert_string(void)
7671 HINTERNET ses
, con
, req
;
7676 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, 0 );
7677 ok( ses
!= NULL
, "InternetOpenA failed\n" );
7679 con
= InternetConnectA( ses
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
7680 INTERNET_SERVICE_HTTP
, 0, 0 );
7681 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
7683 req
= HttpOpenRequestA( con
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0 );
7684 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
7686 size
= sizeof(actual
);
7687 SetLastError( 0xdeadbeef );
7688 memset( actual
, 0x55, sizeof(actual
) );
7689 res
= InternetQueryOptionA( req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, actual
, &size
);
7690 ok( !res
&& GetLastError() == ERROR_INTERNET_INVALID_OPERATION
,
7691 "InternetQueryOption failed: %u\n", GetLastError() );
7692 ok( size
== 0, "unexpected size: %u\n", size
);
7693 ok( actual
[0] == 0x55, "unexpected byte: %02x\n", actual
[0] );
7695 InternetCloseHandle( req
);
7696 InternetCloseHandle( con
);
7697 InternetCloseHandle( ses
);
7703 hdll
= GetModuleHandleA("wininet.dll");
7705 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
7706 win_skip("Too old IE (older than 6.0)\n");
7710 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
7711 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
7712 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
7714 if(!pInternetGetSecurityInfoByURLA
) {
7716 win_skip("IE6 found. It's too old for some tests.\n");
7720 init_status_tests();
7721 test_InternetCloseHandle();
7722 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
7723 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
7724 InternetReadFile_test(0, &test_data
[1]);
7725 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
7726 test_secure_connection();
7727 test_security_flags();
7728 InternetReadFile_test(0, &test_data
[2]);
7729 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
7730 test_open_url_async();
7731 test_async_HttpSendRequestEx(¬ification_data
[0]);
7732 test_async_HttpSendRequestEx(¬ification_data
[1]);
7733 test_async_HttpSendRequestEx(¬ification_data
[2]);
7734 test_async_HttpSendRequestEx(¬ification_data
[3]);
7735 InternetOpenRequest_test();
7737 InternetLockRequestFile_test();
7738 InternetOpenUrlA_test();
7740 test_http_connection();
7741 test_user_agent_header();
7742 test_bogus_accept_types_array();
7743 InternetReadFile_chunked_test();
7744 HttpSendRequestEx_test();
7745 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
7746 test_connection_failure();
7747 test_default_service_port();
7748 test_concurrent_header_access();