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 %ld (%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 %ld (%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: %lu\n", GetLastError());
260 todo_wine_if (is_todo
)
261 ok_(__FILE__
,line
)(code
== excode
, "code = %ld, expected %ld\n", code
, excode
);
262 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %lu\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: %lu\n", GetLastError());
269 ok_(__FILE__
,line
)(!index
, "index = %ld, expected 0\n", index
);
270 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %lu\n", size
);
272 sprintf(exbuf
, "%lu", excode
);
275 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, bufa
, &size
, NULL
);
276 ok_(__FILE__
,line
)(res
, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %lu\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 %ld 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: %lu\n", GetLastError());
285 ok_(__FILE__
,line
)(size
== strlen(exbuf
)+1, "unexpected size %ld 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: %lu\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 %ld 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: %lu\n", GetLastError());
298 ok_(__FILE__
,line
)(size
== (strlen(exbuf
)+1)*sizeof(WCHAR
), "unexpected size %ld 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: %lu\n", GetLastError());
304 ok(size
== sizeof(bufw
), "unexpected size %ld\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(%ld)\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(%ld)\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: %lu\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 = %lx, expected %lx\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: %lu\n", GetLastError());
348 ok_(__FILE__
,line
)(size
== strlen(expected_url
), "size = %lu\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: %lu\n", GetLastError());
362 ok_(__FILE__
,line
)(v
.dwMajorVersion
== 1, "dwMajorVersion = %ld\n", v
.dwMajorVersion
);
363 ok_(__FILE__
,line
)(v
.dwMinorVersion
== 1, "dwMinorVersion = %ld\n", v
.dwMinorVersion
);
366 static LONG 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("%04lx:Callback %p 0x%Ix INTERNET_STATUS_RESOLVING_NAME \"%s\" %ld\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("%04lx:Callback %p 0x%Ix INTERNET_STATUS_NAME_RESOLVED \"%s\" %ld\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("%04lx:Callback %p 0x%Ix INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %ld\n",
396 GetCurrentThreadId(), hInternet
, dwContext
,
397 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
398 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %lu\n",
399 dwStatusInformationLength
);
400 *(LPSTR
)lpvStatusInformation
= '\0';
402 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
403 if(winetest_debug
> 1)
404 trace("%04lx:Callback %p 0x%Ix INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %ld\n",
405 GetCurrentThreadId(), hInternet
, dwContext
,
406 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
407 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %lu\n",
408 dwStatusInformationLength
);
409 *(LPSTR
)lpvStatusInformation
= '\0';
411 case INTERNET_STATUS_SENDING_REQUEST
:
412 if(winetest_debug
> 1)
413 trace("%04lx:Callback %p 0x%Ix INTERNET_STATUS_SENDING_REQUEST %p %ld\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 %ld\n",
420 dwStatusInformationLength
);
421 if(winetest_debug
> 1)
422 trace("%04lx:Callback %p 0x%Ix INTERNET_STATUS_REQUEST_SENT 0x%lx %ld\n",
423 GetCurrentThreadId(), hInternet
, dwContext
,
424 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
426 case INTERNET_STATUS_RECEIVING_RESPONSE
:
427 if(winetest_debug
> 1)
428 trace("%04lx:Callback %p 0x%Ix INTERNET_STATUS_RECEIVING_RESPONSE %p %ld\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 %ld\n",
435 dwStatusInformationLength
);
436 if(winetest_debug
> 1)
437 trace("%04lx:Callback %p 0x%Ix INTERNET_STATUS_RESPONSE_RECEIVED 0x%lx %ld\n",
438 GetCurrentThreadId(), hInternet
, dwContext
,
439 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
441 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
442 if(winetest_debug
> 1)
443 trace("%04lx:Callback %p 0x%Ix INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %ld\n",
444 GetCurrentThreadId(), hInternet
,dwContext
,
445 lpvStatusInformation
,dwStatusInformationLength
);
447 case INTERNET_STATUS_PREFETCH
:
448 if(winetest_debug
> 1)
449 trace("%04lx:Callback %p 0x%Ix INTERNET_STATUS_PREFETCH %p %ld\n",
450 GetCurrentThreadId(), hInternet
, dwContext
,
451 lpvStatusInformation
,dwStatusInformationLength
);
453 case INTERNET_STATUS_CLOSING_CONNECTION
:
454 if(winetest_debug
> 1)
455 trace("%04lx:Callback %p 0x%Ix INTERNET_STATUS_CLOSING_CONNECTION %p %ld\n",
456 GetCurrentThreadId(), hInternet
, dwContext
,
457 lpvStatusInformation
,dwStatusInformationLength
);
459 case INTERNET_STATUS_CONNECTION_CLOSED
:
460 if(winetest_debug
> 1)
461 trace("%04lx:Callback %p 0x%Ix INTERNET_STATUS_CONNECTION_CLOSED %p %ld\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 %ld\n",
468 dwStatusInformationLength
);
469 if(winetest_debug
> 1)
470 trace("%04lx:Callback %p 0x%Ix INTERNET_STATUS_HANDLE_CREATED %p %ld\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 %ld\n",
479 dwStatusInformationLength
);
480 if(winetest_debug
> 1)
481 trace("%04lx:Callback %p 0x%Ix INTERNET_STATUS_HANDLE_CLOSING %p %ld\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 %ld\n",
492 dwStatusInformationLength
);
493 ok(iar
->dwResult
== 1 || iar
->dwResult
== 0, "iar->dwResult = %Id\n", iar
->dwResult
);
494 if(winetest_debug
> 1)
495 trace("%04lx:Callback %p 0x%Ix INTERNET_STATUS_REQUEST_COMPLETE {%Id,%ld} %ld\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("%04lx:Callback %p 0x%Ix INTERNET_STATUS_REDIRECT \"%s\" %ld\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("%04lx:Callback %p 0x%Ix INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %ld\n",
515 GetCurrentThreadId(), hInternet
, dwContext
,
516 lpvStatusInformation
, dwStatusInformationLength
);
519 if(winetest_debug
> 1)
520 trace("%04lx:Callback %p 0x%Ix %ld %p %ld\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,FALSE)
533 #define open_simple_request_proxy(a,b,c,d,e) _open_simple_request(__LINE__,a,b,c,d,e,TRUE)
534 static void _open_simple_request(unsigned line
, test_request_t
*req
, const char *host
,
535 int port
, const char *verb
, const char *url
, BOOL use_proxy
)
537 req
->session
= InternetOpenA(NULL
, use_proxy
? INTERNET_OPEN_TYPE_PRECONFIG
: INTERNET_OPEN_TYPE_DIRECT
,
539 ok_(__FILE__
,line
)(req
->session
!= NULL
, "InternetOpenA failed: %lu\n", GetLastError());
541 req
->connection
= InternetConnectA(req
->session
, host
, port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
542 ok_(__FILE__
,line
)(req
->connection
!= NULL
, "InternetConnectA failed: %lu\n", GetLastError());
544 req
->request
= HttpOpenRequestA(req
->connection
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
545 ok_(__FILE__
,line
)(req
->request
!= NULL
, "HttpOpenRequest failed: %lu\n", GetLastError());
548 #define close_request(a) _close_request(__LINE__,a)
549 static void _close_request(unsigned line
, test_request_t
*req
)
553 ret
= InternetCloseHandle(req
->request
);
554 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(request) failed: %lu\n", GetLastError());
555 ret
= InternetCloseHandle(req
->connection
);
556 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(connection) failed: %lu\n", GetLastError());
557 ret
= InternetCloseHandle(req
->session
);
558 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(session) failed: %lu\n", GetLastError());
561 #define receive_simple_request(a,b,c) _receive_simple_request(__LINE__,a,b,c)
562 static DWORD
_receive_simple_request(unsigned line
, HINTERNET req
, char *buf
, size_t buf_size
)
567 ret
= InternetReadFile(req
, buf
, buf_size
, &read
);
568 ok_(__FILE__
,line
)(ret
, "InternetReadFile failed: %lu\n", GetLastError());
573 static void close_async_handle(HINTERNET handle
, int handle_cnt
)
577 close_handle_cnt
= handle_cnt
;
579 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
580 res
= InternetCloseHandle(handle
);
581 ok(res
, "InternetCloseHandle failed: %lu\n", GetLastError());
582 WaitForSingleObject(complete_event
, INFINITE
);
583 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
586 static void InternetSetFilePointer_test(const char *host
, const char *path
)
588 BYTE expect_response
[8192], buf
[8192];
589 HINTERNET hi
= 0, hic
= 0, hor
= 0;
591 DWORD count
, size
, i
, pos
, err
;
593 hi
= InternetOpenA("Winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
594 ok(hi
!= 0x0, "InternetOpen failed: %lu\n", GetLastError());
595 if(hi
== 0x0) goto abort
;
597 hic
= InternetConnectA(hi
, host
, INTERNET_DEFAULT_HTTP_PORT
,
598 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
599 ok(hic
!= 0x0, "InternetConnect failed: %lu\n", GetLastError());
600 if(hic
== 0x0) goto abort
;
602 hor
= HttpOpenRequestA(hic
, NULL
, path
, NULL
, NULL
, NULL
,
603 INTERNET_FLAG_RELOAD
,
605 ok(hor
!= 0x0, "HttpOpenRequest failed: %lu\n", GetLastError());
606 if(hor
== 0x0) goto abort
;
608 res
= HttpSendRequestA(hor
, NULL
, 0, NULL
, 0);
609 ok(res
, "HttpSendRequest failed: %lu\n", GetLastError());
613 while(size
< sizeof(expect_response
)) {
614 res
= InternetReadFile(hor
, expect_response
+size
, sizeof(expect_response
)-size
, &count
);
619 ok(size
, "InternetReadFile returned no content\n");
620 if(!size
) goto abort
;
622 InternetCloseHandle(hor
);
623 InternetCloseHandle(hic
);
624 InternetCloseHandle(hi
);
628 hi
= InternetOpenA("Winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
629 ok(hi
!= 0x0, "InternetOpen failed: %lu\n", GetLastError());
630 if(hi
== 0x0) goto abort
;
632 pInternetSetStatusCallbackA(hi
, &callback
);
634 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
635 hic
= InternetConnectA(hi
, host
, INTERNET_DEFAULT_HTTP_PORT
,
636 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef);
637 ok(hic
!= 0x0, "InternetConnect failed: %lu\n", GetLastError());
638 if(hic
== 0x0) goto abort
;
639 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
641 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
642 hor
= HttpOpenRequestA(hic
, NULL
, path
, NULL
, NULL
, NULL
,
643 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_DONT_CACHE
,
645 ok(hor
!= 0x0, "HttpOpenRequest failed: %lu\n", GetLastError());
646 if(hor
== 0x0) goto abort
;
647 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
649 /* NULL handle tests */
650 pos
= InternetSetFilePointer(NULL
, 0, NULL
, FILE_BEGIN
, 0);
651 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
652 expected
= pos
== INVALID_SET_FILE_POINTER
&& err
== ERROR_INVALID_HANDLE
;
653 ok(expected
, "Expected ERROR_INVALID_HANDLE. Got %lu\n", err
);
654 pos
= InternetSetFilePointer(NULL
, 0, NULL
, FILE_CURRENT
, 0);
655 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
656 expected
= pos
== INVALID_SET_FILE_POINTER
&& err
== ERROR_INVALID_HANDLE
;
657 ok(expected
, "Expected ERROR_INVALID_HANDLE. Got %lu\n", err
);
658 pos
= InternetSetFilePointer(NULL
, 0, NULL
, FILE_END
, 0);
659 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
660 expected
= pos
== INVALID_SET_FILE_POINTER
&& err
== ERROR_INVALID_HANDLE
;
661 ok(expected
, "Expected ERROR_INVALID_HANDLE. Got %lu\n", err
);
663 /* INTERNET_FLAG_DONT_CACHE before sending request */
664 pos
= InternetSetFilePointer(hor
, 0, NULL
, FILE_BEGIN
, 0);
665 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
666 expected
= pos
== INVALID_SET_FILE_POINTER
&& err
== ERROR_INTERNET_INVALID_OPERATION
;
667 ok(expected
, "Expected ERROR_INTERNET_INVALID_OPERATION. Got %lu\n", err
);
668 pos
= InternetSetFilePointer(hor
, 0, NULL
, FILE_CURRENT
, 0);
669 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
670 expected
= pos
== INVALID_SET_FILE_POINTER
&& err
== ERROR_INTERNET_INVALID_OPERATION
;
671 ok(expected
, "Expected ERROR_INTERNET_INVALID_OPERATION. Got %lu\n", err
);
672 pos
= InternetSetFilePointer(hor
, 0, NULL
, FILE_END
, 0);
673 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
674 expected
= pos
== INVALID_SET_FILE_POINTER
&& err
== ERROR_INTERNET_INVALID_OPERATION
;
675 ok(expected
, "Expected ERROR_INTERNET_INVALID_OPERATION. Got %lu\n", err
);
677 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
678 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
680 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
681 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
682 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
683 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
685 res
= HttpSendRequestA(hor
, NULL
, 0, NULL
, 0);
686 err
= !res
? GetLastError() : NO_ERROR
;
687 expected
= res
&& err
== NO_ERROR
;
688 ok(expected
, "HttpSendRequest failed: %lu\n", err
);
690 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
691 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
692 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
693 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
695 /* INTERNET_FLAG_DONT_CACHE after sending request */
696 pos
= InternetSetFilePointer(hor
, 0, NULL
, FILE_BEGIN
, 0);
697 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
698 expected
= pos
== INVALID_SET_FILE_POINTER
&& err
== ERROR_INTERNET_INVALID_OPERATION
;
699 ok(expected
, "Expected ERROR_INTERNET_INVALID_OPERATION. Got %lu\n", err
);
700 pos
= InternetSetFilePointer(hor
, 0, NULL
, FILE_CURRENT
, 0);
701 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
702 expected
= pos
== INVALID_SET_FILE_POINTER
&& err
== ERROR_INTERNET_INVALID_OPERATION
;
703 ok(expected
, "Expected ERROR_INTERNET_INVALID_OPERATION. Got %lu\n", err
);
704 pos
= InternetSetFilePointer(hor
, 0, NULL
, FILE_END
, 0);
705 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
706 expected
= pos
== INVALID_SET_FILE_POINTER
&& err
== ERROR_INTERNET_INVALID_OPERATION
;
707 ok(expected
, "Expected ERROR_INTERNET_INVALID_OPERATION. Got %lu\n", err
);
709 SET_EXPECT(INTERNET_STATUS_HANDLE_CLOSING
);
710 InternetCloseHandle(hor
);
712 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
713 hor
= HttpOpenRequestA(hic
, NULL
, path
, NULL
, NULL
, NULL
,
714 INTERNET_FLAG_RELOAD
,
716 ok(hor
!= 0x0, "HttpOpenRequest failed: %lu\n", GetLastError());
717 if(hor
== 0x0) goto abort
;
718 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
720 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
721 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
723 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
724 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
725 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
726 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
728 res
= HttpSendRequestA(hor
, NULL
, 0, NULL
, 0);
729 err
= !res
? GetLastError() : NO_ERROR
;
730 expected
= res
&& err
== NO_ERROR
;
731 ok(expected
, "HttpSendRequest failed: %lu\n", err
);
733 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
734 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
735 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
736 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
738 /* FILE_BEGIN tests */
740 while(i
< min(size
, 4)) {
741 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
742 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
743 pos
= InternetSetFilePointer(hor
, i
, NULL
, FILE_BEGIN
, 0);
744 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
745 expected
= pos
== i
&& err
== NO_ERROR
;
746 ok(expected
, "Expected position %#lx. Got %#lx. GetLastError() %lu\n", i
, pos
, err
);
747 res
= InternetReadFile(hor
, buf
, sizeof(buf
), &count
);
748 err
= !res
? GetLastError() : NO_ERROR
;
749 ok(res
, "InternetReadFile failed: %lu\n", err
);
750 ok(count
, "InternetReadFile returned no content\n");
751 ok(!memcmp(expect_response
+i
, buf
, min(sizeof(buf
)-i
, count
)),
752 "Unexpected result from InternetReadFile\n");
756 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
757 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
758 pos
= InternetSetFilePointer(hor
, i
, NULL
, FILE_BEGIN
, 0);
759 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
760 expected
= pos
== i
&& err
== NO_ERROR
;
761 ok(expected
, "Expected position %#lx. Got %#lx. GetLastError() %lu\n", i
, pos
, err
);
762 res
= InternetReadFile(hor
, buf
, sizeof(buf
), &count
);
763 err
= !res
? GetLastError() : NO_ERROR
;
764 ok(res
, "InternetReadFile failed: %lu\n", err
);
765 ok(!memcmp(expect_response
+i
, buf
, min(sizeof(buf
)-i
, count
)),
766 "Unexpected result from InternetReadFile\n");
769 SetLastError(0xdeadbeef);
770 pos
= InternetSetFilePointer(hor
, INT_MAX
, NULL
, FILE_BEGIN
, 0);
771 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
772 expected
= pos
== INT_MAX
&& err
== NO_ERROR
;
773 ok(expected
, "Expected position %#x. Got %#lx. GetLastError() %lu\n", INT_MAX
, pos
, err
);
774 SetLastError(0xdeadbeef);
775 pos
= InternetSetFilePointer(hor
, -1, NULL
, FILE_BEGIN
, 0);
776 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
777 expected
= pos
== -1 && err
== NO_ERROR
;
778 ok(expected
, "Expected position %#x. Got %#lx. GetLastError() %lu\n", -1, pos
, err
);
780 /* FILE_CURRENT tests */
782 while(i
< min(size
, 4)) {
783 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
784 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
786 pos
= InternetSetFilePointer(hor
, 0, NULL
, FILE_BEGIN
, 0);
787 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
788 expected
= pos
== 0 && err
== NO_ERROR
;
789 ok(expected
, "Expected position %#lx. Got %#lx. GetLastError() %lu\n", i
, pos
, err
);
790 pos
= InternetSetFilePointer(hor
, i
, NULL
, FILE_CURRENT
, 0);
791 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
792 expected
= pos
== i
&& err
== NO_ERROR
;
793 ok(expected
, "Expected position %#lx. Got %#lx. GetLastError() %lu\n", i
, pos
, err
);
794 res
= InternetReadFile(hor
, buf
, 1024, &count
);
795 err
= !res
? GetLastError() : NO_ERROR
;
796 ok(res
, "InternetReadFile failed: %lu\n", err
);
797 ok(!memcmp(expect_response
+i
, buf
, min(sizeof(buf
)-i
, count
)),
798 "Unexpected result from InternetReadFile\n");
800 pos
= InternetSetFilePointer(hor
, -1, NULL
, FILE_CURRENT
, 0);
801 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
802 expected
= pos
== INVALID_SET_FILE_POINTER
&& err
== ERROR_NEGATIVE_SEEK
;
803 ok(expected
, "Expected ERROR_NEGATIVE_SEEK. Got %lu\n", err
);
804 pos
= InternetSetFilePointer(hor
, 0, NULL
, FILE_BEGIN
, 0);
805 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
806 expected
= pos
== 0 && err
== NO_ERROR
;
807 ok(expected
, "Expected position %#x. Got %#lx. GetLastError() %lu\n", 0, pos
, err
);
808 pos
= InternetSetFilePointer(hor
, -1, NULL
, FILE_CURRENT
, 0);
809 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
810 expected
= pos
== -1 && err
== NO_ERROR
;
811 ok(expected
, "Expected position %#x. Got %#lx. GetLastError() %lu\n", -1, pos
, err
);
812 pos
= InternetSetFilePointer(hor
, -1, NULL
, FILE_CURRENT
, 0);
813 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
814 expected
= pos
== INVALID_SET_FILE_POINTER
&& err
== ERROR_NEGATIVE_SEEK
;
815 ok(expected
, "Expected ERROR_NEGATIVE_SEEK. Got %lu\n", err
);
818 pos
= InternetSetFilePointer(hor
, 0, NULL
, FILE_END
, 0);
819 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
820 expected
= pos
== size
&& err
== NO_ERROR
;
821 todo_wine
ok(expected
, "Expected position %#lx. Got %#lx. GetLastError() %lu\n", size
, pos
, err
);
823 while(i
< min(size
, 4)) {
824 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
825 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
827 pos
= InternetSetFilePointer(hor
, i
, NULL
, FILE_END
, 0);
828 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
829 expected
= pos
== size
+i
&& err
== NO_ERROR
;
830 todo_wine
ok(expected
, "Expected position %#lx. Got %#lx. GetLastError() %lu\n",
834 while(i
< min(size
, 4)) {
835 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
836 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
838 pos
= InternetSetFilePointer(hor
, -i
, NULL
, FILE_END
, 0);
839 err
= pos
== INVALID_SET_FILE_POINTER
? GetLastError() : NO_ERROR
;
840 expected
= pos
== INVALID_SET_FILE_POINTER
&& err
== ERROR_NEGATIVE_SEEK
;
841 todo_wine
ok(expected
, "Expected ERROR_NEGATIVE_SEEK. Got %lu\n", err
);
844 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
845 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
848 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
849 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
850 SET_OPTIONAL(INTERNET_STATUS_HANDLE_CLOSING
);
851 if(hor
) InternetCloseHandle(hor
);
852 SET_OPTIONAL(INTERNET_STATUS_HANDLE_CLOSING
);
853 if(hic
) InternetCloseHandle(hic
);
854 if(hi
) InternetCloseHandle(hi
);
857 static void InternetReadFile_test(int flags
, const test_data_t
*test
)
859 char *post_data
= NULL
;
860 BOOL res
, on_async
= TRUE
;
863 DWORD length
, length2
, index
, exlen
= 0, post_len
= 0;
864 const char *types
[2] = { "*", NULL
};
865 HINTERNET hi
, hic
= 0, hor
= 0;
866 DWORD contents_length
, accepts_ranges
;
869 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags
,test
->url
);
872 hi
= InternetOpenA((test
->flags
& TESTF_COMPRESSED
) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
873 INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
874 ok((hi
!= 0x0),"InternetOpen failed with error %lu\n", GetLastError());
876 if (hi
== 0x0) goto abort
;
878 pInternetSetStatusCallbackA(hi
,&callback
);
880 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
882 hic
=InternetConnectA(hi
, test
->host
, INTERNET_INVALID_PORT_NUMBER
,
883 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
884 ok((hic
!= 0x0),"InternetConnect failed with error %lu\n", GetLastError());
886 if (hic
== 0x0) goto abort
;
888 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
889 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
891 hor
= HttpOpenRequestA(hic
, test
->post_data
? "POST" : "GET", test
->path
, NULL
, NULL
, types
,
892 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
894 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
896 * If the internet name can't be resolved we are probably behind
897 * a firewall or in some other way not directly connected to the
898 * Internet. Not enough reason to fail the test. Just ignore and
902 ok((hor
!= 0x0),"HttpOpenRequest failed with error %lu\n", GetLastError());
905 if (hor
== 0x0) goto abort
;
907 test_request_flags(hor
, INTERNET_REQFLAG_NO_HEADERS
);
908 test_request_url(hor
, test
->url
);
910 length
= sizeof(buffer
);
911 res
= HttpQueryInfoA(hor
, HTTP_QUERY_RAW_HEADERS
, buffer
, &length
, 0x0);
912 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %ld\n", GetLastError());
913 ok(length
== 0 || (length
== 1 && !*buffer
) /* win10 */, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %ld\n", length
);
914 ok(!strcmp(buffer
, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer
);
916 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
917 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
918 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
919 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
,2);
920 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED
,2);
921 if (first_connection_to_test_url
)
923 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
924 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
926 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
927 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
928 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
929 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
930 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
931 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
932 if(test
->flags
& TESTF_REDIRECT
) {
933 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
934 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
936 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
937 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
938 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
939 if (flags
& INTERNET_FLAG_ASYNC
)
940 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
942 if(test
->flags
& TESTF_COMPRESSED
) {
945 res
= InternetSetOptionA(hor
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
946 ok(res
|| broken(!res
&& GetLastError() == ERROR_INTERNET_INVALID_OPTION
),
947 "InternetSetOption failed: %lu\n", GetLastError());
952 test_status_code(hor
, 0);
954 if(test
->post_data
) {
955 post_len
= strlen(test
->post_data
);
956 post_data
= HeapAlloc(GetProcessHeap(), 0, post_len
);
957 memcpy(post_data
, test
->post_data
, post_len
);
959 SetLastError(0xdeadbeef);
960 res
= HttpSendRequestA(hor
, test
->headers
, -1, post_data
, post_len
);
961 if (flags
& INTERNET_FLAG_ASYNC
)
962 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
963 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
965 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
966 "Synchronous HttpSendRequest returning 0, error %lu\n", GetLastError());
968 if (flags
& INTERNET_FLAG_ASYNC
) {
969 WaitForSingleObject(complete_event
, INFINITE
);
970 ok(req_error
== ERROR_SUCCESS
, "req_error = %lu\n", req_error
);
972 HeapFree(GetProcessHeap(), 0, post_data
);
974 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
975 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED
);
976 if (first_connection_to_test_url
)
978 if (! proxy_active())
980 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
981 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
985 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
986 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
991 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
992 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
994 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
995 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
996 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
997 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
998 if(test
->flags
& TESTF_REDIRECT
)
999 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
1000 if (flags
& INTERNET_FLAG_ASYNC
)
1001 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1002 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
1003 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1004 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1006 test_request_flags(hor
, 0);
1009 res
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
1010 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %ld\n", GetLastError());
1012 length
= sizeof(buffer
)-2;
1013 memset(buffer
, 0x77, sizeof(buffer
));
1014 SetLastError(0xdeadbeef);
1015 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
1016 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %ld\n", GetLastError());
1017 ok(GetLastError() == 0 ||
1018 broken(GetLastError() == 0xdeadbeef /* XP/W2K3 */), "Last Error not reset %lu\n", GetLastError());
1019 /* show that the function writes data past the length returned */
1020 ok(buffer
[length
-2], "Expected any header character, got 0x00\n");
1021 ok(!buffer
[length
-1], "Expected 0x00, got %02X\n", buffer
[length
-1]);
1022 ok(!buffer
[length
], "Expected 0x00, got %02X\n", buffer
[length
]);
1023 ok(buffer
[length
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length
+1]);
1026 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
1027 ok(!res
, "Expected 0x00, got %d\n", res
);
1028 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %ld\n", GetLastError());
1029 ok(length2
== length
+1, "Expected %ld, got %ld\n", length
+1, length2
);
1030 /* the in length of the buffer must be +1 but the length returned does not count this */
1032 memset(buffer
, 0x77, sizeof(buffer
));
1033 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
1034 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %ld\n", GetLastError());
1035 ok(buffer
[length2
] == 0x00, "Expected 0x00, got %02X\n", buffer
[length2
]);
1036 ok(buffer
[length2
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length2
+1]);
1037 ok(length2
== length
, "Value should not have changed: %ld != %ld\n", length2
, length
);
1039 length
= sizeof(wbuffer
)-2*sizeof(WCHAR
);
1040 memset(wbuffer
, 0x77, sizeof(wbuffer
));
1041 res
= HttpQueryInfoW(hor
, HTTP_QUERY_RAW_HEADERS
, wbuffer
, &length
, 0x0);
1042 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %ld\n", GetLastError());
1043 ok(length
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %ld.\n", length
);
1044 length
/= sizeof(WCHAR
);
1045 /* show that the function writes data past the length returned */
1046 ok(wbuffer
[length
-2], "Expected any header character, got 0x0000\n");
1047 ok(!wbuffer
[length
-1], "Expected 0x0000, got %04X\n", wbuffer
[length
-1]);
1048 ok(!wbuffer
[length
], "Expected 0x0000, got %04X\n", wbuffer
[length
]);
1049 ok(wbuffer
[length
+1] == 0x7777 || broken(wbuffer
[length
+1] != 0x7777),
1050 "Expected 0x7777, got %04X\n", wbuffer
[length
+1]);
1052 length2
= length
*sizeof(WCHAR
);
1053 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
1054 ok(!res
, "Expected 0x00, got %d\n", res
);
1055 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %ld\n", GetLastError());
1056 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %ld.\n", length2
);
1057 length2
/= sizeof(WCHAR
);
1058 ok(length2
== length
+1, "Expected %ld, got %ld\n", length
+1, length2
);
1059 /* the in length of the buffer must be +1 but the length returned does not count this */
1060 length2
= (length
+1)*sizeof(WCHAR
);
1061 memset(wbuffer
, 0x77, sizeof(wbuffer
));
1062 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
1063 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %ld\n", GetLastError());
1064 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %ld.\n", length2
);
1065 length2
/= sizeof(WCHAR
);
1066 ok(!wbuffer
[length2
], "Expected 0x0000, got %04X\n", wbuffer
[length2
]);
1067 ok(wbuffer
[length2
+1] == 0x7777, "Expected 0x7777, got %04X\n", wbuffer
[length2
+1]);
1068 ok(length2
== length
, "Value should not have changed: %ld != %ld\n", length2
, length
);
1070 test_request_url(hor
, test
->redirected_url
);
1074 SetLastError(0xdeadbeef);
1075 ok(HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,NULL
,&length
,&index
) == FALSE
,"Query worked\n");
1076 if(test
->flags
& TESTF_COMPRESSED
)
1077 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
1078 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %lu\n", GetLastError());
1079 ok(index
== 0, "Index was incremented\n");
1083 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,&index
);
1084 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%lu)\n",res
,buffer
,GetLastError());
1085 if(test
->flags
& TESTF_COMPRESSED
)
1087 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
1088 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%lu)\n", res
, GetLastError());
1089 contents_length
= 0;
1093 contents_length
= atoi(buffer
);
1095 ok(!res
|| index
== 1, "Index was not incremented although result is %x (index = %lu)\n", res
, index
);
1099 res
= HttpQueryInfoA(hor
,HTTP_QUERY_ACCEPT_RANGES
,&buffer
,&length
,0x0);
1100 trace("Option HTTP_QUERY_ACCEPT_RANGES -> %i %s (%lu)\n",res
,buffer
,GetLastError());
1101 accepts_ranges
= res
&& !strcmp(buffer
, "bytes");
1104 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
1106 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res
,buffer
);
1109 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_ENCODING
,buffer
,&length
,0x0);
1111 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res
,buffer
);
1113 SetLastError(0xdeadbeef);
1114 length
= InternetSetFilePointer(hor
, 0, NULL
, FILE_END
, 0);
1115 not_supported
= length
== INVALID_SET_FILE_POINTER
1116 && GetLastError() == ERROR_INTERNET_INVALID_OPERATION
;
1118 todo_wine
ok((length
== contents_length
&& (GetLastError() == ERROR_SUCCESS
1119 || broken(GetLastError() == 0xdeadbeef))) || broken(not_supported
),
1120 "Got unexpected length %#lx, GetLastError() %lu, contents_length %lu, accepts_ranges %#lx.\n",
1121 length
, GetLastError(), contents_length
, accepts_ranges
);
1123 ok(not_supported
, "Got unexpected length %#lx, GetLastError() %lu.\n", length
, GetLastError());
1125 if (length
!= INVALID_SET_FILE_POINTER
)
1127 SetLastError(0xdeadbeef);
1128 length
= InternetSetFilePointer(hor
, 0, NULL
, FILE_BEGIN
, 0);
1129 ok(!length
&& (GetLastError() == ERROR_SUCCESS
|| broken(GetLastError() == 0xdeadbeef)),
1130 "Got unexpected length %#lx, GetLastError() %lu.\n", length
, GetLastError());
1133 SetLastError(0xdeadbeef);
1134 res
= InternetReadFile(NULL
, buffer
, 100, &length
);
1135 ok(!res
, "InternetReadFile should have failed\n");
1136 ok(GetLastError() == ERROR_INVALID_HANDLE
,
1137 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %lu\n",
1141 if(winetest_debug
> 1)
1142 trace("Entering Query loop\n");
1146 if (flags
& INTERNET_FLAG_ASYNC
)
1147 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1149 /* IE11 calls those in InternetQueryDataAvailable call. */
1150 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
1151 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
1154 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
1156 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1158 if (flags
& INTERNET_FLAG_ASYNC
)
1162 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1164 ok(length
>= exlen
, "length %lu < exlen %lu\n", length
, exlen
);
1168 else if (GetLastError() == ERROR_IO_PENDING
)
1170 if(winetest_debug
> 1)
1172 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
1173 if(!(test
->flags
& TESTF_CHUNKED
))
1174 ok(!length
, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %lu length\n", length
);
1175 WaitForSingleObject(complete_event
, INFINITE
);
1177 ok(exlen
, "length = 0\n");
1178 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1179 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1180 ok(req_error
, "req_error = 0\n");
1183 ok(0, "InternetQueryDataAvailable failed: %lu\n", GetLastError());
1186 ok(res
, "InternetQueryDataAvailable failed: %lu\n", GetLastError());
1188 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1190 if(winetest_debug
> 1)
1191 trace("length %lu\n", length
);
1192 if(test
->flags
& TESTF_CHUNKED
)
1193 ok(length
<= 8192, "length = %ld, expected <= 8192\n", length
);
1197 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
1199 res
= InternetReadFile(hor
,buffer
,length
,&length
);
1203 if(winetest_debug
> 1)
1204 trace("ReadFile -> %s %li\n", res
? "TRUE" : "FALSE", length
);
1207 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
1208 HeapFree(GetProcessHeap(),0,buffer
);
1210 ok(!on_async
, "Returned zero size in response to request complete\n");
1215 if(test
->flags
& TESTF_REDIRECT
) {
1216 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1217 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1220 if(winetest_debug
> 1)
1221 trace("aborting\n");
1222 close_async_handle(hi
, 2);
1223 first_connection_to_test_url
= FALSE
;
1226 static void InternetReadFile_chunked_test(void)
1231 const char *types
[2] = { "*", NULL
};
1232 HINTERNET hi
, hic
= 0, hor
= 0;
1234 trace("Starting InternetReadFile chunked test\n");
1236 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1237 ok((hi
!= 0x0),"InternetOpen failed with error %lu\n", GetLastError());
1239 if (hi
== 0x0) goto abort
;
1241 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
1242 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1243 ok((hic
!= 0x0),"InternetConnect failed with error %lu\n", GetLastError());
1245 if (hic
== 0x0) goto abort
;
1247 hor
= HttpOpenRequestA(hic
, "GET", "/tests/chunked", NULL
, NULL
, types
,
1248 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
1250 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
1252 * If the internet name can't be resolved we are probably behind
1253 * a firewall or in some other way not directly connected to the
1254 * Internet. Not enough reason to fail the test. Just ignore and
1258 ok((hor
!= 0x0),"HttpOpenRequest failed with error %lu\n", GetLastError());
1261 if (hor
== 0x0) goto abort
;
1263 SetLastError(0xdeadbeef);
1264 res
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
1265 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
1266 "Synchronous HttpSendRequest returning 0, error %lu\n", GetLastError());
1268 test_request_flags(hor
, 0);
1271 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
1273 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
1275 SetLastError( 0xdeadbeef );
1277 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
1279 trace("Option TRANSFER_ENCODING -> %i %s\n",res
,buffer
);
1280 ok( res
|| ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
1281 "Failed to get TRANSFER_ENCODING option, error %lu\n", GetLastError() );
1282 ok( !strcmp( buffer
, "chunked" ) || ( ! res
&& proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
1283 "Wrong transfer encoding '%s'\n", buffer
);
1285 SetLastError( 0xdeadbeef );
1287 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
1288 ok( !res
, "Found CONTENT_LENGTH option '%s'\n", buffer
);
1289 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Wrong error %lu\n", GetLastError() );
1292 trace("Entering Query loop\n");
1296 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
1297 ok(!(!res
&& length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
1298 ok(res
, "InternetQueryDataAvailable failed, error %ld\n", GetLastError());
1299 trace("got %lu available\n",length
);
1302 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
1304 SetLastError(0xdeadbeef);
1305 res
= InternetReadFile(hor
,buffer
,length
,&got
);
1306 ok(GetLastError() == 0 ||
1307 broken(GetLastError() == 0xdeadbeef /* XP/W2K3 */), "Last Error not reset %lu\n", GetLastError());
1310 trace("ReadFile -> %i %li\n",res
,got
);
1311 ok( length
== got
, "only got %lu of %lu available\n", got
, length
);
1312 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
1314 HeapFree(GetProcessHeap(),0,buffer
);
1320 SetLastError(0xdeadbeef);
1321 res
= InternetReadFile( hor
, buffer
, 1, &got
);
1322 ok( res
, "InternetReadFile failed: %lu\n", GetLastError() );
1323 ok(GetLastError() == 0 ||
1324 broken(GetLastError() == 0xdeadbeef /* XP/W2K3 */), "Last Error not reset %lu\n", GetLastError());
1325 ok( !got
, "got %lu\n", got
);
1330 trace("aborting\n");
1332 res
= InternetCloseHandle(hor
);
1333 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
1336 res
= InternetCloseHandle(hi
);
1337 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
1341 static void InternetReadFileExA_test(int flags
)
1345 const char *types
[2] = { "*", NULL
};
1346 HINTERNET hi
, hic
= 0, hor
= 0;
1347 INTERNET_BUFFERSA inetbuffers
;
1349 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
1352 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
1353 ok((hi
!= 0x0),"InternetOpen failed with error %lu\n", GetLastError());
1355 if (hi
== 0x0) goto abort
;
1357 pInternetSetStatusCallbackA(hi
,&callback
);
1359 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1361 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
1362 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1363 ok((hic
!= 0x0),"InternetConnect failed with error %lu\n", GetLastError());
1365 if (hic
== 0x0) goto abort
;
1367 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1368 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1370 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
1371 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
1373 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
1375 * If the internet name can't be resolved we are probably behind
1376 * a firewall or in some other way not directly connected to the
1377 * Internet. Not enough reason to fail the test. Just ignore and
1381 ok((hor
!= 0x0),"HttpOpenRequest failed with error %lu\n", GetLastError());
1384 if (hor
== 0x0) goto abort
;
1386 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1387 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1388 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1389 if (first_connection_to_test_url
)
1391 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
1392 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
1394 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
, 2);
1395 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1396 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1397 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1398 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
1399 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1400 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1401 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1402 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1403 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
1404 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1405 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1406 if (flags
& INTERNET_FLAG_ASYNC
)
1407 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1409 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1411 SetLastError(0xdeadbeef);
1412 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
1413 if (flags
& INTERNET_FLAG_ASYNC
)
1414 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
1415 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
1417 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
1418 "Synchronous HttpSendRequest returning 0, error %lu\n", GetLastError());
1420 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
1421 WaitForSingleObject(complete_event
, INFINITE
);
1422 ok(req_error
== ERROR_SUCCESS
, "req_error = %lu\n", req_error
);
1425 if (first_connection_to_test_url
)
1427 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1428 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1432 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1433 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1435 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1436 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
1437 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1438 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1439 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1440 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1441 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
1442 if (flags
& INTERNET_FLAG_ASYNC
)
1443 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1445 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1446 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
1447 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
1448 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1449 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1452 rc
= InternetReadFileExW(hor
, NULL
, 0, 0xdeadcafe);
1453 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1454 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %lu\n",
1455 rc
? "TRUE" : "FALSE", GetLastError());
1458 /* tests invalid dwStructSize */
1459 inetbuffers
.dwStructSize
= sizeof(inetbuffers
)+1;
1460 inetbuffers
.lpcszHeader
= NULL
;
1461 inetbuffers
.dwHeadersLength
= 0;
1462 inetbuffers
.dwBufferLength
= 10;
1463 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
1464 inetbuffers
.dwOffsetHigh
= 1234;
1465 inetbuffers
.dwOffsetLow
= 5678;
1466 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1467 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1468 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %lu\n",
1469 rc
? "TRUE" : "FALSE", GetLastError());
1470 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1472 test_request_flags(hor
, 0);
1474 /* tests to see whether lpcszHeader is used - it isn't */
1475 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1476 inetbuffers
.lpcszHeader
= (LPCSTR
)0xdeadbeef;
1477 inetbuffers
.dwHeadersLength
= 255;
1478 inetbuffers
.dwBufferLength
= 0;
1479 inetbuffers
.lpvBuffer
= NULL
;
1480 inetbuffers
.dwOffsetHigh
= 1234;
1481 inetbuffers
.dwOffsetLow
= 5678;
1482 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1483 ok(rc
, "InternetReadFileEx failed with error %lu\n", GetLastError());
1484 trace("read %li bytes\n", inetbuffers
.dwBufferLength
);
1486 rc
= InternetReadFileExA(NULL
, &inetbuffers
, 0, 0xdeadcafe);
1487 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
1488 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %lu\n",
1489 rc
? "TRUE" : "FALSE", GetLastError());
1492 trace("Entering Query loop\n");
1496 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1497 inetbuffers
.dwBufferLength
= 1024;
1498 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
1499 inetbuffers
.dwOffsetHigh
= 1234;
1500 inetbuffers
.dwOffsetLow
= 5678;
1502 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1503 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1504 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1505 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
1508 if (GetLastError() == ERROR_IO_PENDING
)
1510 trace("InternetReadFileEx -> PENDING\n");
1511 ok(flags
& INTERNET_FLAG_ASYNC
,
1512 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1513 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1514 WaitForSingleObject(complete_event
, INFINITE
);
1515 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1516 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1517 ok(req_error
== ERROR_SUCCESS
, "req_error = %lu\n", req_error
);
1521 trace("InternetReadFileEx -> FAILED %lu\n", GetLastError());
1527 trace("InternetReadFileEx -> SUCCEEDED\n");
1528 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1529 if (inetbuffers
.dwBufferLength
)
1531 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1532 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1536 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1537 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1538 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1542 trace("read %li bytes\n", inetbuffers
.dwBufferLength
);
1543 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
1545 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
1546 "InternetReadFileEx sets offsets to 0x%lx%08lx\n",
1547 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
1549 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1551 if (!inetbuffers
.dwBufferLength
)
1554 length
+= inetbuffers
.dwBufferLength
;
1556 ok(length
> 0, "failed to read any of the document\n");
1557 trace("Finished. Read %ld bytes\n", length
);
1560 close_async_handle(hi
, 2);
1561 first_connection_to_test_url
= FALSE
;
1564 static void InternetOpenUrlA_test(void)
1566 HINTERNET myhinternet
, myhttp
;
1568 DWORD size
, readbytes
, totalbytes
=0;
1571 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1572 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
1573 "DeleteUrlCacheEntry returned %x, GetLastError() = %ld\n", ret
, GetLastError());
1575 myhinternet
= InternetOpenA("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
1576 ok((myhinternet
!= 0), "InternetOpen failed, error %lu\n",GetLastError());
1578 ret
= InternetCanonicalizeUrlA(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1579 ok( ret
, "InternetCanonicalizeUrl failed, error %lu\n",GetLastError());
1582 myhttp
= InternetOpenUrlA(myhinternet
, TEST_URL
, 0, 0,
1583 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
1584 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1585 return; /* WinXP returns this when not connected to the net */
1586 ok((myhttp
!= 0),"InternetOpenUrl failed, error %lu\n",GetLastError());
1587 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
1588 ok( ret
, "InternetReadFile failed, error %lu\n",GetLastError());
1589 totalbytes
+= readbytes
;
1590 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
1591 totalbytes
+= readbytes
;
1592 trace("read 0x%08lx bytes\n",totalbytes
);
1594 InternetCloseHandle(myhttp
);
1595 InternetCloseHandle(myhinternet
);
1597 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1598 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1601 static void HttpSendRequestEx_test(void)
1607 INTERNET_BUFFERSA BufferIn
;
1608 DWORD dwBytesWritten
, dwBytesRead
, error
;
1613 static char szPostData
[] = "mode=Test";
1614 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
1616 hSession
= InternetOpenA("Wine Regression Test",
1617 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1618 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1619 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1620 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1622 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1623 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1624 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1625 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1627 skip( "Network unreachable, skipping test\n" );
1630 ok( hRequest
!= NULL
, "Failed to open request handle err %lu\n", GetLastError());
1632 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1634 BufferIn
.dwStructSize
= sizeof(BufferIn
);
1635 BufferIn
.Next
= (INTERNET_BUFFERSA
*)0xdeadcab;
1636 BufferIn
.lpcszHeader
= szContentType
;
1637 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1638 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1639 BufferIn
.lpvBuffer
= szPostData
;
1640 BufferIn
.dwBufferLength
= 3;
1641 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1642 BufferIn
.dwOffsetLow
= 0;
1643 BufferIn
.dwOffsetHigh
= 0;
1645 SetLastError(0xdeadbeef);
1646 ret
= HttpSendRequestExA(hRequest
, &BufferIn
, NULL
, 0 ,0);
1647 error
= GetLastError();
1648 ok(ret
, "HttpSendRequestEx Failed with error %lu\n", error
);
1649 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %lu\n", error
);
1651 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1653 for (i
= 3; szPostData
[i
]; i
++)
1654 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1655 "InternetWriteFile failed\n");
1657 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1659 ok(HttpEndRequestA(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1661 test_request_flags(hRequest
, 0);
1663 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1664 "Unable to read response\n");
1665 szBuffer
[dwBytesRead
] = 0;
1667 ok(dwBytesRead
== 13,"Read %lu bytes instead of 13\n",dwBytesRead
);
1668 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1670 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1672 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1673 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1676 static void InternetOpenRequest_test(void)
1678 HINTERNET session
, connect
, request
;
1679 static const char *types
[] = { "*", "", NULL
};
1680 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1681 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1684 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1685 ok(session
!= NULL
,"Unable to open Internet session\n");
1687 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1688 INTERNET_SERVICE_HTTP
, 0, 0);
1689 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1690 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %ld\n", GetLastError());
1692 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1693 INTERNET_SERVICE_HTTP
, 0, 0);
1694 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1695 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %ld\n", GetLastError());
1697 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1698 INTERNET_SERVICE_HTTP
, 0, 0);
1699 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %ld\n", GetLastError());
1701 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1702 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1704 skip( "Network unreachable, skipping test\n" );
1707 ok(request
!= NULL
, "Failed to open request handle err %lu\n", GetLastError());
1709 ret
= HttpSendRequestW(request
, NULL
, 0, NULL
, 0);
1710 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
1711 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1713 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1714 ok(request
!= NULL
, "Failed to open request handle err %lu\n", GetLastError());
1716 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1717 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
1718 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1721 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1722 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1725 static void test_cache_read(void)
1727 HINTERNET session
, connection
, req
;
1728 FILETIME now
, tomorrow
, yesterday
;
1729 BYTE content
[1000], buf
[2000];
1730 char file_path
[MAX_PATH
];
1737 static const char cache_only_url
[] = "http://test.winehq.org/tests/cache-only";
1738 BYTE cache_headers
[] = "HTTP/1.1 200 OK\r\n\r\n";
1740 trace("Testing cache read...\n");
1743 for(i
= 0; i
< sizeof(content
); i
++)
1744 content
[i
] = '0' + (i
%10);
1746 GetSystemTimeAsFileTime(&now
);
1747 li
.u
.HighPart
= now
.dwHighDateTime
;
1748 li
.u
.LowPart
= now
.dwLowDateTime
;
1749 li
.QuadPart
+= (LONGLONG
)10000000 * 3600 * 24;
1750 tomorrow
.dwHighDateTime
= li
.u
.HighPart
;
1751 tomorrow
.dwLowDateTime
= li
.u
.LowPart
;
1752 li
.QuadPart
-= (LONGLONG
)10000000 * 3600 * 24 * 2;
1753 yesterday
.dwHighDateTime
= li
.u
.HighPart
;
1754 yesterday
.dwLowDateTime
= li
.u
.LowPart
;
1756 res
= CreateUrlCacheEntryA(cache_only_url
, sizeof(content
), "", file_path
, 0);
1757 ok(res
, "CreateUrlCacheEntryA failed: %lu\n", GetLastError());
1759 file
= CreateFileA(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1760 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
1762 WriteFile(file
, content
, sizeof(content
), &size
, NULL
);
1765 res
= CommitUrlCacheEntryA(cache_only_url
, file_path
, tomorrow
, yesterday
, NORMAL_CACHE_ENTRY
,
1766 cache_headers
, sizeof(cache_headers
)-1, "", 0);
1767 ok(res
, "CommitUrlCacheEntryA failed: %lu\n", GetLastError());
1769 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
1770 ok(session
!= NULL
,"InternetOpen failed with error %lu\n", GetLastError());
1772 pInternetSetStatusCallbackA(session
, callback
);
1774 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1775 connection
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
,
1776 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1777 ok(connection
!= NULL
,"InternetConnect failed with error %lu\n", GetLastError());
1778 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1780 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1781 req
= HttpOpenRequestA(connection
, "GET", "/tests/cache-only", NULL
, NULL
, NULL
, 0, 0xdeadbead);
1782 ok(req
!= NULL
, "HttpOpenRequest failed: %lu\n", GetLastError());
1783 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1785 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1786 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1787 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST
);
1788 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT
);
1789 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1790 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1791 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1793 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
1795 ok(res
, "HttpSendRequest failed: %lu\n", GetLastError());
1799 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
1800 ok(res
, "InternetQueryDataAvailable failed: %lu\n", GetLastError());
1801 ok(size
== sizeof(content
), "size = %lu\n", size
);
1804 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
1805 ok(res
, "InternetReadFile failed: %lu\n", GetLastError());
1806 ok(size
== sizeof(content
), "size = %lu\n", size
);
1807 ok(!memcmp(content
, buf
, sizeof(content
)), "unexpected content\n");
1810 close_async_handle(session
, 2);
1812 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1813 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1814 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
1815 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
1816 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1817 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1818 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1820 res
= DeleteUrlCacheEntryA(cache_only_url
);
1821 ok(res
, "DeleteUrlCacheEntryA failed: %lu\n", GetLastError());
1824 static void test_http_cache(void)
1826 HINTERNET session
, connect
, request
;
1827 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1828 DWORD size
, file_size
;
1832 FILETIME filetime_zero
= {0};
1834 static const char cached_content
[] = "data read from cache";
1835 static const char *types
[] = { "*", "", NULL
};
1837 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1838 ok(session
!= NULL
,"Unable to open Internet session\n");
1840 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1841 INTERNET_SERVICE_HTTP
, 0, 0);
1842 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %ld\n", GetLastError());
1844 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1845 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1847 skip( "Network unreachable, skipping test\n" );
1849 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1850 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1854 ok(request
!= NULL
, "Failed to open request handle err %lu\n", GetLastError());
1857 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1858 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %lu\n", GetLastError());
1859 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1861 size
= sizeof(file_name
);
1862 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1863 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1864 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%lu\n", GetLastError());
1865 ok(!size
, "size = %ld\n", size
);
1867 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1868 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
1870 size
= sizeof(file_name
);
1871 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1872 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %lu\n", GetLastError());
1874 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1875 FILE_ATTRIBUTE_NORMAL
, NULL
);
1876 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %lu\n", GetLastError());
1877 file_size
= GetFileSize(file
, NULL
);
1878 ok(file_size
== 106, "file size = %lu\n", file_size
);
1881 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1882 ok(ret
, "InternetReadFile failed: %lu\n", GetLastError());
1883 ok(size
== 100, "size = %lu\n", size
);
1885 file_size
= GetFileSize(file
, NULL
);
1886 ok(file_size
== 106, "file size = %lu\n", file_size
);
1889 ret
= DeleteFileA(file_name
);
1890 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%lu)\n", ret
, GetLastError());
1892 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1894 file
= CreateFileA(file_name
, GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1895 FILE_ATTRIBUTE_NORMAL
, NULL
);
1896 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %lu\n", GetLastError());
1897 ret
= WriteFile(file
, cached_content
, sizeof(cached_content
), &size
, NULL
);
1898 ok(ret
&& size
, "WriteFile failed: %d, %ld\n", ret
, size
);
1899 ret
= CommitUrlCacheEntryA(url
, file_name
, filetime_zero
, filetime_zero
, NORMAL_CACHE_ENTRY
, NULL
, 0, NULL
, 0);
1900 ok(ret
, "CommitUrlCacheEntry failed: %ld\n", GetLastError());
1903 /* Send the same request, requiring it to be retrieved from the cache */
1904 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1906 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1907 ok(ret
, "HttpSendRequest failed\n");
1910 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1911 ok(ret
, "InternetReadFile failed: %lu\n", GetLastError());
1912 ok(size
== 100, "size = %lu\n", size
);
1914 todo_wine
ok(!strcmp((char*)buf
, cached_content
), "incorrect page data: %s\n", (char*)buf
);
1916 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1918 DeleteUrlCacheEntryA(url
);
1919 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1920 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1921 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
1923 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError() = %ld\n", GetLastError());
1924 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1926 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1927 ok(request
!= NULL
, "Failed to open request handle err %lu\n", GetLastError());
1929 size
= sizeof(file_name
);
1930 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1931 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1932 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%lu\n", GetLastError());
1933 ok(!size
, "size = %ld\n", size
);
1935 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1936 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
1938 size
= sizeof(file_name
);
1940 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1943 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1944 FILE_ATTRIBUTE_NORMAL
, NULL
);
1945 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %lu\n", GetLastError());
1951 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1954 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1955 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1956 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1961 static void InternetLockRequestFile_test(void)
1963 char file_name
[MAX_PATH
];
1969 open_simple_request(&req
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, "/tests/hello.html");
1971 size
= sizeof(file_name
);
1972 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1973 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1974 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%lu\n", GetLastError());
1975 ok(!size
, "size = %ld\n", size
);
1978 ret
= InternetLockRequestFile(req
.request
, &lock
);
1979 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "InternetLockRequestFile returned: %x(%lu)\n", ret
, GetLastError());
1981 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
1982 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
1984 size
= sizeof(file_name
);
1985 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1986 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %lu\n", GetLastError());
1988 ret
= InternetLockRequestFile(req
.request
, &lock
);
1989 ok(ret
, "InternetLockRequestFile returned: %x(%lu)\n", ret
, GetLastError());
1990 ok(lock
!= NULL
, "lock == NULL\n");
1992 ret
= InternetLockRequestFile(req
.request
, &lock2
);
1993 ok(ret
, "InternetLockRequestFile returned: %x(%lu)\n", ret
, GetLastError());
1994 ok(lock
== lock2
, "lock != lock2\n");
1996 ret
= InternetUnlockRequestFile(lock2
);
1997 ok(ret
, "InternetUnlockRequestFile failed: %lu\n", GetLastError());
1999 ret
= DeleteFileA(file_name
);
2000 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%lu)\n", ret
, GetLastError());
2002 ok(InternetCloseHandle(req
.request
), "Close request handle failed\n");
2004 ret
= DeleteFileA(file_name
);
2005 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%lu)\n", ret
, GetLastError());
2007 ret
= InternetUnlockRequestFile(lock
);
2008 ok(ret
, "InternetUnlockRequestFile failed: %lu\n", GetLastError());
2010 ret
= DeleteFileA(file_name
);
2011 ok(ret
, "Deleting file returned %x(%lu)\n", ret
, GetLastError());
2014 static void HttpHeaders_test(void)
2026 hSession
= InternetOpenA("Wine Regression Test",
2027 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
2028 ok( hSession
!= NULL
,"Unable to open Internet session\n");
2029 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
2030 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
2032 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
2033 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
2034 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2035 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
2037 skip( "Network unreachable, skipping test\n" );
2040 ok( hRequest
!= NULL
, "Failed to open request handle\n");
2043 len
= sizeof(buffer
);
2044 strcpy(buffer
,"Warning");
2045 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2046 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
2048 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
2049 "Failed to add new header\n");
2052 len
= sizeof(buffer
);
2053 strcpy(buffer
,"Warning");
2054 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2055 buffer
,&len
,&index
),"Unable to query header\n");
2056 ok(index
== 1, "Index was not incremented\n");
2057 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
2058 ok(len
== 5, "Invalid length (exp. 5, got %ld)\n", len
);
2059 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
2060 len
= sizeof(buffer
);
2061 strcpy(buffer
,"Warning");
2062 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2063 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
2066 len
= 5; /* could store the string but not the NULL terminator */
2067 strcpy(buffer
,"Warning");
2068 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2069 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
2070 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %ld\n", GetLastError());
2071 ok(index
== 0, "Index was incremented\n");
2072 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
2073 ok(len
== 6, "Invalid length (exp. 6, got %ld)\n", len
); /* unlike success, the length includes the NULL-terminator */
2075 /* a call with NULL will fail but will return the length */
2077 len
= sizeof(buffer
);
2078 SetLastError(0xdeadbeef);
2079 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2080 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
2081 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %ld\n", GetLastError());
2082 ok(len
> 40, "Invalid length (exp. more than 40, got %ld)\n", len
);
2083 ok(index
== 0, "Index was incremented\n");
2085 /* even for a len that is too small */
2088 SetLastError(0xdeadbeef);
2089 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2090 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
2091 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %ld\n", GetLastError());
2092 ok(len
> 40, "Invalid length (exp. more than 40, got %ld)\n", len
);
2093 ok(index
== 0, "Index was incremented\n");
2097 SetLastError(0xdeadbeef);
2098 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2099 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
2100 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %ld\n", GetLastError());
2101 ok(len
> 40, "Invalid length (exp. more than 40, got %ld)\n", len
);
2102 ok(index
== 0, "Index was incremented\n");
2103 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
2106 /* a working query */
2108 len
= sizeof(buffer
);
2109 memset(buffer
, 'x', sizeof(buffer
));
2110 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2111 buffer
,&len
,&index
),"Unable to query header\n");
2112 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
2113 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
2114 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
2115 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
2116 ok(strncmp(buffer
, "POST /tests/post.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
2117 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
2118 ok(index
== 0, "Index was incremented\n");
2120 /* Like above two tests, but for W version */
2124 SetLastError(0xdeadbeef);
2125 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2126 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
2127 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %ld\n", GetLastError());
2128 ok(len
> 80, "Invalid length (exp. more than 80, got %ld)\n", len
);
2129 ok(index
== 0, "Index was incremented\n");
2130 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
2132 /* a working query */
2134 len
= sizeof(wbuffer
);
2135 memset(wbuffer
, 'x', sizeof(wbuffer
));
2136 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2137 wbuffer
,&len
,&index
),"Unable to query header\n");
2138 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
2139 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
2140 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
2141 ok(index
== 0, "Index was incremented\n");
2143 /* end of W version tests */
2145 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
2147 len
= sizeof(buffer
);
2148 memset(buffer
, 'x', sizeof(buffer
));
2149 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
2150 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
2151 ok(len
== 2 || len
== 4 /* win10 */, "Expected 2 or 4, got %ld\n", len
);
2152 ok(memcmp(buffer
, "\r\n\r\n", len
) == 0, "Expected CRLF, got '%s'\n", buffer
);
2153 ok(index
== 0, "Index was incremented\n");
2155 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
2156 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
2159 len
= sizeof(buffer
);
2160 strcpy(buffer
,"Warning");
2161 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2162 buffer
,&len
,&index
),"Unable to query header\n");
2163 ok(index
== 1, "Index was not incremented\n");
2164 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
2165 len
= sizeof(buffer
);
2166 strcpy(buffer
,"Warning");
2167 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2168 buffer
,&len
,&index
),"Failed to get second header\n");
2169 ok(index
== 2, "Index was not incremented\n");
2170 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
2171 len
= sizeof(buffer
);
2172 strcpy(buffer
,"Warning");
2173 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2174 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
2176 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
2179 len
= sizeof(buffer
);
2180 strcpy(buffer
,"Warning");
2181 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2182 buffer
,&len
,&index
),"Unable to query header\n");
2183 ok(index
== 1, "Index was not incremented\n");
2184 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
2185 len
= sizeof(buffer
);
2186 strcpy(buffer
,"Warning");
2187 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2188 buffer
,&len
,&index
),"Failed to get second header\n");
2189 ok(index
== 2, "Index was not incremented\n");
2190 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
2191 len
= sizeof(buffer
);
2192 strcpy(buffer
,"Warning");
2193 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2194 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
2196 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
2199 len
= sizeof(buffer
);
2200 strcpy(buffer
,"Warning");
2201 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2202 buffer
,&len
,&index
),"Unable to query header\n");
2203 ok(index
== 1, "Index was not incremented\n");
2204 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
2205 len
= sizeof(buffer
);
2206 strcpy(buffer
,"Warning");
2207 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2208 buffer
,&len
,&index
),"Failed to get second header\n");
2209 ok(index
== 2, "Index was not incremented\n");
2210 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
2211 len
= sizeof(buffer
);
2212 strcpy(buffer
,"Warning");
2213 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2214 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
2216 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
2219 len
= sizeof(buffer
);
2220 strcpy(buffer
,"Warning");
2221 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
2222 buffer
,&len
,&index
),"Unable to query header\n");
2223 ok(index
== 1, "Index was not incremented\n");
2224 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
2225 len
= sizeof(buffer
);
2226 strcpy(buffer
,"Warning");
2227 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
2228 ok(index
== 2, "Index was not incremented\n");
2229 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
2230 len
= sizeof(buffer
);
2231 strcpy(buffer
,"Warning");
2232 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
2234 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
2237 len
= sizeof(buffer
);
2238 strcpy(buffer
,"Warning");
2239 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2240 ok(index
== 1, "Index was not incremented\n");
2241 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
2242 len
= sizeof(buffer
);
2243 strcpy(buffer
,"Warning");
2244 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
2245 ok(index
== 2, "Index was not incremented\n");
2246 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
2247 len
= sizeof(buffer
);
2248 strcpy(buffer
,"Warning");
2249 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
2251 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
2254 len
= sizeof(buffer
);
2255 strcpy(buffer
,"Warning");
2256 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2257 ok(index
== 1, "Index was not incremented\n");
2258 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
2259 len
= sizeof(buffer
);
2260 strcpy(buffer
,"Warning");
2261 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
2262 ok(index
== 2, "Index was not incremented\n");
2263 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
2264 len
= sizeof(buffer
);
2265 strcpy(buffer
,"Warning");
2266 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
2268 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");
2271 len
= sizeof(buffer
);
2272 strcpy(buffer
,"Warning");
2273 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2274 ok(index
== 1, "Index was not incremented\n");
2275 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
2276 len
= sizeof(buffer
);
2277 strcpy(buffer
,"Warning");
2278 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
2279 ok(index
== 2, "Index was not incremented\n");
2280 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
2281 len
= sizeof(buffer
);
2282 strcpy(buffer
,"Warning");
2283 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
2285 /* Ensure that blank headers are ignored and don't cause a failure */
2286 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");
2289 len
= sizeof(buffer
);
2290 strcpy(buffer
,"BlankTest");
2291 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2292 ok(index
== 1, "Index was not incremented\n");
2293 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
2295 /* Ensure that malformed header separators are ignored and don't cause a failure */
2296 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
),
2297 "Failed to add header with malformed entries in list\n");
2300 len
= sizeof(buffer
);
2301 strcpy(buffer
,"MalformedTest");
2302 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2303 ok(index
== 1, "Index was not incremented\n");
2304 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
2306 len
= sizeof(buffer
);
2307 strcpy(buffer
,"MalformedTestTwo");
2308 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2309 ok(index
== 1, "Index was not incremented\n");
2310 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
2312 len
= sizeof(buffer
);
2313 strcpy(buffer
,"MalformedTestThree");
2314 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2315 ok(index
== 1, "Index was not incremented\n");
2316 ok(strcmp(buffer
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
2318 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD
);
2319 ok(ret
, "unable to add header %lu\n", GetLastError());
2323 len
= sizeof(buffer
);
2324 ret
= HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
);
2325 ok(ret
, "unable to query header %lu\n", GetLastError());
2326 ok(index
== 1, "index was not incremented\n");
2327 ok(!strcmp(buffer
, "Basic"), "incorrect string was returned (%s)\n", buffer
);
2329 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE
);
2330 ok(ret
, "unable to remove header %lu\n", GetLastError());
2333 len
= sizeof(buffer
);
2334 SetLastError(0xdeadbeef);
2335 ok(!HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
),
2336 "header still present\n");
2337 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "got %lu\n", GetLastError());
2339 /* Header with empty value should cause a failure */
2342 SetLastError(0xdeadbeef);
2343 ok(!HttpAddRequestHeadersA(hRequest
, "EmptyTest1:", -1, HTTP_ADDREQ_FLAG_ADD
), "Empty header should not be added.\n");
2344 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Got unexpected error code %lu.\n", GetLastError());
2346 SetLastError(0xdeadbeef);
2347 ok(!HttpAddRequestHeadersA(hRequest
, "EmptyTest2:\r\n", -1, HTTP_ADDREQ_FLAG_ADD
), "Empty header should not be added.\n");
2348 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Got unexpected error code %lu.\n", GetLastError());
2350 len
= sizeof(buffer
);
2351 strcpy(buffer
, "EmptyTest1");
2352 SetLastError(0xdeadbeef);
2353 ok(!HttpQueryInfoA(hRequest
, HTTP_QUERY_CUSTOM
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, NULL
),
2354 "Header with empty value is present.\n");
2355 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Got unexpected error code %lu.\n", GetLastError());
2357 len
= sizeof(buffer
);
2358 strcpy(buffer
, "EmptyTest2");
2359 SetLastError(0xdeadbeef);
2360 ok(!HttpQueryInfoA(hRequest
, HTTP_QUERY_CUSTOM
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, NULL
),
2361 "Header with empty value is present.\n");
2362 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Got unexpected error code %lu.\n", GetLastError());
2365 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
2367 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
2368 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
2371 static const char garbagemsg
[] =
2372 "Garbage: Header\r\n";
2374 static const char contmsg
[] =
2375 "HTTP/1.1 100 Continue\r\n";
2377 static const char expandcontmsg
[] =
2378 "HTTP/1.1 100 Continue\r\n"
2379 "Server: winecontinue\r\n"
2380 "Tag: something witty\r\n";
2382 static const char okmsg
[] =
2383 "HTTP/1.1 200 OK\r\n"
2384 "Server: winetest\r\n"
2387 static const char okmsg201
[] =
2388 "HTTP/1.1 201 OK\r\n"
2389 "Server: winetest\r\n"
2392 static const char okmsg2
[] =
2393 "HTTP/1.1 200 OK\r\n"
2394 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
2395 "Server: winetest\r\n"
2396 "Content-Length: 0\r\n"
2397 "Set-Cookie: one\r\n"
2398 "Set-Cookie: two\r\n"
2401 static DWORD64 content_length
;
2402 static const char largemsg
[] =
2403 "HTTP/1.1 200 OK\r\n"
2404 "Content-Length: %I64u\r\n"
2407 static const char notokmsg
[] =
2408 "HTTP/1.1 400 Bad Request\r\n"
2409 "Server: winetest\r\n"
2412 static const char noauthmsg
[] =
2413 "HTTP/1.1 401 Unauthorized\r\n"
2414 "Server: winetest\r\n"
2415 "Connection: close\r\n"
2416 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
2419 static const char noauthmsg2
[] =
2420 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
2421 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
2423 "Server: winetest\r\n";
2425 static const char proxymsg
[] =
2426 "HTTP/1.1 407 Proxy Authentication Required\r\n"
2427 "Server: winetest\r\n"
2428 "Proxy-Connection: close\r\n"
2429 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
2432 static const char page1
[] =
2434 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
2435 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
2438 static const char ok_with_length
[] =
2439 "HTTP/1.1 200 OK\r\n"
2440 "Connection: Keep-Alive\r\n"
2441 "Content-Length: 18\r\n\r\n"
2442 "HTTP/1.1 211 OK\r\n\r\n";
2444 static const char ok_with_length2
[] =
2445 "HTTP/1.1 210 OK\r\n"
2446 "Connection: Keep-Alive\r\n"
2447 "Content-Length: 19\r\n\r\n"
2448 "HTTP/1.1 211 OK\r\n\r\n";
2450 static const char proxy_pac
[] =
2451 "function FindProxyForURL(url, host) {\r\n"
2452 " return 'PROXY localhost:%d';\r\n"
2455 struct server_info
{
2460 static int test_cache_gzip
;
2461 static const char *send_buffer
;
2462 static int server_socket
;
2464 static DWORD CALLBACK
server_thread(LPVOID param
)
2466 struct server_info
*si
= param
;
2467 int r
, c
= -1, i
, on
, count
= 0;
2469 struct sockaddr_in sa
;
2473 int last_request
= 0;
2474 char host_header
[22];
2475 char host_header_override
[30];
2476 static int test_no_cache
= 0;
2478 WSAStartup(MAKEWORD(1,1), &wsaData
);
2480 s
= socket(AF_INET
, SOCK_STREAM
, 0);
2481 if (s
== INVALID_SOCKET
)
2485 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
2487 memset(&sa
, 0, sizeof sa
);
2488 sa
.sin_family
= AF_INET
;
2489 sa
.sin_port
= htons(si
->port
);
2490 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
2492 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
2498 SetEvent(si
->hEvent
);
2500 sprintf(host_header
, "Host: localhost:%d", si
->port
);
2501 sprintf(host_header_override
, "Host: test.local:%d\r\n", si
->port
);
2502 buffer
= HeapAlloc(GetProcessHeap(), 0, buffer_size
= 1000);
2507 c
= accept(s
, NULL
, NULL
);
2509 memset(buffer
, 0, buffer_size
);
2512 if(i
== buffer_size
)
2513 buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, buffer_size
*= 2);
2515 r
= recv(c
, buffer
+i
, 1, 0);
2519 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
2520 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
2523 if (strstr(buffer
, "GET /test1"))
2525 if (!strstr(buffer
, "Content-Length: 0"))
2527 send(c
, okmsg
, sizeof okmsg
-1, 0);
2528 send(c
, page1
, sizeof page1
-1, 0);
2531 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2533 if (strstr(buffer
, "CONNECT "))
2535 if (!strstr(buffer
, "Content-Length: 0"))
2536 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2538 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2540 if (strstr(buffer
, "/test2"))
2542 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2544 send(c
, okmsg
, sizeof okmsg
-1, 0);
2545 send(c
, page1
, sizeof page1
-1, 0);
2548 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2550 if (strstr(buffer
, "/test3"))
2552 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2553 send(c
, okmsg
, sizeof okmsg
-1, 0);
2555 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2557 if (strstr(buffer
, "/test4"))
2559 if (strstr(buffer
, "Connection: Close"))
2560 send(c
, okmsg
, sizeof okmsg
-1, 0);
2562 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2564 if (strstr(buffer
, "POST /test5") ||
2565 strstr(buffer
, "RPC_IN_DATA /test5") ||
2566 strstr(buffer
, "RPC_OUT_DATA /test5"))
2568 if (strstr(buffer
, "Content-Length: 0"))
2570 send(c
, okmsg
, sizeof okmsg
-1, 0);
2571 send(c
, page1
, sizeof page1
-1, 0);
2574 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2576 if (strstr(buffer
, "GET /test6"))
2578 send(c
, contmsg
, sizeof contmsg
-1, 0);
2579 send(c
, contmsg
, sizeof contmsg
-1, 0);
2580 send(c
, okmsg
, sizeof okmsg
-1, 0);
2581 send(c
, page1
, sizeof page1
-1, 0);
2583 if (strstr(buffer
, "POST /test7"))
2585 if (strstr(buffer
, "Content-Length: 100"))
2587 if (strstr(buffer
, "POST /test7b"))
2588 recvfrom(c
, buffer
, buffer_size
, 0, NULL
, NULL
);
2589 send(c
, okmsg
, sizeof okmsg
-1, 0);
2590 send(c
, page1
, sizeof page1
-1, 0);
2593 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2595 if (strstr(buffer
, "/test8"))
2597 if (!strstr(buffer
, "Connection: Close") &&
2598 strstr(buffer
, "Connection: Keep-Alive") &&
2599 !strstr(buffer
, "Cache-Control: no-cache") &&
2600 !strstr(buffer
, "Pragma: no-cache") &&
2601 strstr(buffer
, host_header
))
2602 send(c
, okmsg
, sizeof okmsg
-1, 0);
2604 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2606 if (strstr(buffer
, "/test9"))
2608 if (!strstr(buffer
, "Connection: Close") &&
2609 !strstr(buffer
, "Connection: Keep-Alive") &&
2610 !strstr(buffer
, "Cache-Control: no-cache") &&
2611 !strstr(buffer
, "Pragma: no-cache") &&
2612 strstr(buffer
, host_header
))
2613 send(c
, okmsg
, sizeof okmsg
-1, 0);
2615 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2617 if (strstr(buffer
, "/testA"))
2619 if (!strstr(buffer
, "Connection: Close") &&
2620 !strstr(buffer
, "Connection: Keep-Alive") &&
2621 (strstr(buffer
, "Cache-Control: no-cache") ||
2622 strstr(buffer
, "Pragma: no-cache")) &&
2623 strstr(buffer
, host_header
))
2624 send(c
, okmsg
, sizeof okmsg
-1, 0);
2626 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2628 if (strstr(buffer
, "/testC"))
2630 if (strstr(buffer
, "Cookie: cookie=biscuit"))
2631 send(c
, okmsg
, sizeof okmsg
-1, 0);
2633 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2635 if (strstr(buffer
, "/testD"))
2637 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
2639 if (strstr(buffer
, "/testE"))
2641 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
2643 if (strstr(buffer
, "GET /quit"))
2645 send(c
, okmsg
, sizeof okmsg
-1, 0);
2646 send(c
, page1
, sizeof page1
-1, 0);
2649 if (strstr(buffer
, "GET /testF"))
2651 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
2652 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2653 send(c
, contmsg
, sizeof contmsg
-1, 0);
2654 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2655 send(c
, okmsg
, sizeof okmsg
-1, 0);
2656 send(c
, page1
, sizeof page1
-1, 0);
2658 if (strstr(buffer
, "GET /testG"))
2660 send(c
, page1
, sizeof page1
-1, 0);
2663 if (strstr(buffer
, "GET /testJ"))
2668 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2672 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2676 if (strstr(buffer
, "GET /testH"))
2678 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2679 recvfrom(c
, buffer
, buffer_size
, 0, NULL
, NULL
);
2680 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2682 if (strstr(buffer
, "GET /test_no_content_content_length"))
2684 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n"
2685 "Content-Length: 10\r\n\r\n0123456789";
2686 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2688 else if (strstr(buffer
, "GET /test_no_content"))
2690 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n"
2692 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2694 if (strstr(buffer
, "GET /test_not_modified_content_length"))
2696 static const char notmodifiedmsg
[] = "HTTP/1.1 304 Not Modified\r\nConnection: close\r\n"
2697 "Content-Length: 10\r\n\r\n0123456789";
2698 send(c
, notmodifiedmsg
, sizeof(notmodifiedmsg
)-1, 0);
2700 else if (strstr(buffer
, "GET /test_not_modified"))
2702 static const char notmodifiedmsg
[] = "HTTP/1.1 304 Not Modified\r\nConnection: close\r\n"
2704 send(c
, notmodifiedmsg
, sizeof(notmodifiedmsg
)-1, 0);
2706 if (strstr(buffer
, "HEAD /head_content_length"))
2708 static const char headmsg
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n"
2709 "Content-Length: 10\r\n\r\n0123456789";
2710 send(c
, headmsg
, sizeof(headmsg
)-1, 0);
2712 else if (strstr(buffer
, "HEAD /head"))
2714 static const char headmsg
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n0123456789";
2715 send(c
, headmsg
, sizeof(headmsg
)-1, 0);
2717 if (strstr(buffer
, "GET /test_large_header"))
2719 static const char allokmsg
[] = "HTTP/1.1 200 OK\r\nServer: winetest\r\n";
2720 char header
[4000 + sizeof("wine-header: ") - 1];
2722 memset(header
, 'A', sizeof(header
));
2723 memcpy(header
, "wine-header: ", sizeof("wine-header: ") - 1);
2724 send(c
, allokmsg
, sizeof(allokmsg
) - 1, 0);
2725 send(c
, header
, sizeof(header
), 0);
2726 send(c
, "\r\n\r\n", 4, 0);
2728 if (strstr(buffer
, "GET /test_conn_close"))
2730 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2731 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
2732 WaitForSingleObject(conn_close_event
, INFINITE
);
2733 trace("closing connection\n");
2735 if (strstr(buffer
, "GET /test_cache_control_no_cache"))
2737 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2738 if(!test_no_cache
++)
2739 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2741 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2743 if (strstr(buffer
, "GET /test_cache_control_no_store"))
2745 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2746 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2748 if (strstr(buffer
, "GET /test_cache_gzip"))
2750 static const char gzip_response
[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2751 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2752 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2753 if(!test_cache_gzip
++)
2754 send(c
, gzip_response
, sizeof(gzip_response
), 0);
2756 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2758 if (strstr(buffer
, "HEAD /test_head")) {
2759 static const char head_response
[] =
2760 "HTTP/1.1 200 OK\r\n"
2761 "Connection: Keep-Alive\r\n"
2762 "Content-Length: 100\r\n"
2765 send(c
, head_response
, sizeof(head_response
), 0);
2768 if (strstr(buffer
, "GET /send_from_buffer"))
2769 send(c
, send_buffer
, strlen(send_buffer
), 0);
2770 if (strstr(buffer
, "/test_cache_control_verb"))
2772 if (!memcmp(buffer
, "GET ", sizeof("GET ")-1) &&
2773 !strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2774 else if (strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2775 else send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2777 if (strstr(buffer
, "/test_request_content_length"))
2779 static char msg
[] = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\n\r\n";
2780 static int seen_content_length
;
2782 if (!seen_content_length
)
2784 if (strstr(buffer
, "Content-Length: 0"))
2786 seen_content_length
= 1;
2787 send(c
, msg
, sizeof msg
-1, 0);
2789 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2790 WaitForSingleObject(complete_event
, 5000);
2794 if (strstr(buffer
, "Content-Length: 0")) send(c
, msg
, sizeof msg
-1, 0);
2795 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2796 WaitForSingleObject(complete_event
, 5000);
2799 if (strstr(buffer
, "GET /test_premature_disconnect"))
2800 trace("closing connection\n");
2801 if (strstr(buffer
, "HEAD /upload.txt"))
2803 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2804 send(c
, okmsg
, sizeof okmsg
-1, 0);
2806 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2808 if (strstr(buffer
, "PUT /upload2.txt"))
2810 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2811 send(c
, okmsg
, sizeof okmsg
-1, 0);
2813 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2815 if (strstr(buffer
, "HEAD /upload3.txt"))
2817 if (strstr(buffer
, "Authorization: Basic dXNlcjE6cHdkMQ=="))
2818 send(c
, okmsg
, sizeof okmsg
-1, 0);
2820 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2822 if (strstr(buffer
, "HEAD /upload4.txt"))
2824 if (strstr(buffer
, "Authorization: Bearer dXNlcjE6cHdkMQ=="))
2825 send(c
, okmsg
, sizeof okmsg
-1, 0);
2826 else if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2827 send(c
, okmsg201
, sizeof okmsg
-1, 0);
2829 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2831 if (strstr(buffer
, "/test_host_override"))
2833 if (strstr(buffer
, host_header_override
))
2834 send(c
, okmsg
, sizeof okmsg
-1, 0);
2836 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2838 if (strstr(buffer
, "/async_read"))
2840 const char *page1_mid
= page1
+ (sizeof page1
- 1)/2;
2841 const char *page1_end
= page1
+ sizeof page1
- 1;
2842 send(c
, okmsg
, sizeof okmsg
-1, 0);
2843 send(c
, page1
, page1_mid
- page1
, 0);
2844 WaitForSingleObject(conn_wait_event
, INFINITE
);
2845 send(c
, page1_mid
, page1_end
- page1_mid
, 0);
2847 if (strstr(buffer
, "/socket"))
2850 SetEvent(server_req_rec_event
);
2851 WaitForSingleObject(conn_wait_event
, INFINITE
);
2853 if (strstr(buffer
, "/echo_request"))
2855 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2856 send(c
, buffer
, strlen(buffer
), 0);
2858 if (strstr(buffer
, "GET /test_remove_dot_segments"))
2860 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2862 if (strstr(buffer
, "HEAD /test_large_content"))
2864 char msg
[sizeof(largemsg
) + 16];
2865 sprintf(msg
, largemsg
, content_length
);
2866 send(c
, msg
, strlen(msg
), 0);
2868 if (strstr(buffer
, "GET /proxy.pac"))
2870 char script
[sizeof(proxy_pac
) + 16];
2871 sprintf(script
, proxy_pac
, si
->port
);
2872 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2873 send(c
, script
, strlen(script
), 0);
2875 if (strstr(buffer
, "GET http://test.winehq.org/tests/hello.html"))
2877 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2878 send(c
, page1
, sizeof(page1
)-1, 0);
2883 } while (!last_request
);
2886 HeapFree(GetProcessHeap(), 0, buffer
);
2891 static void test_basic_request(int port
, const char *verb
, const char *url
)
2894 DWORD r
, count
, error
;
2897 trace("basic request %s %s\n", verb
, url
);
2899 open_simple_request(&req
, "localhost", port
, verb
, url
);
2901 SetLastError(0xdeadbeef);
2902 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
2903 error
= GetLastError();
2904 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %lu\n", error
);
2905 ok(r
, "HttpSendRequest failed: %lu\n", GetLastError());
2908 memset(buffer
, 0, sizeof buffer
);
2909 SetLastError(0xdeadbeef);
2910 r
= InternetReadFile(req
.request
, buffer
, sizeof buffer
, &count
);
2911 ok(r
, "InternetReadFile failed %lu\n", GetLastError());
2912 ok(count
== sizeof page1
- 1, "count was wrong\n");
2913 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2915 close_request(&req
);
2918 static void test_proxy_indirect(int port
)
2924 open_simple_request(&req
, "localhost", port
, NULL
, "/test2");
2926 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
2927 ok(r
, "HttpSendRequest failed %lu\n", GetLastError());
2930 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2931 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %ld\n", GetLastError());
2934 skip("missing proxy header, not testing remaining proxy headers\n");
2937 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2939 test_status_code(req
.request
, 407);
2940 test_request_flags(req
.request
, 0);
2943 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2944 ok(r
, "HttpQueryInfo failed\n");
2945 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2948 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2949 ok(r
, "HttpQueryInfo failed\n");
2950 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2953 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2954 ok(r
, "HttpQueryInfo failed\n");
2955 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2958 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2959 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2960 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2963 close_request(&req
);
2966 static void test_proxy_direct(int port
)
2968 HINTERNET hi
, hc
, hr
;
2970 char buffer
[0x40], *url
;
2971 WCHAR bufferW
[0x40];
2972 static const char url_fmt
[] = "http://test.winehq.org:%u/test2";
2973 static CHAR username
[] = "mike",
2974 password
[] = "1101",
2975 useragent
[] = "winetest";
2976 static const WCHAR usernameW
[] = {'m','i','k','e',0},
2977 passwordW
[] = {'1','1','0','1',0},
2978 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2980 /* specify proxy type without the proxy and bypass */
2981 SetLastError(0xdeadbeef);
2982 hi
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2983 error
= GetLastError();
2984 ok(error
== ERROR_INVALID_PARAMETER
||
2985 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %lu\n", error
);
2986 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2988 sprintf(buffer
, "localhost:%d\n", port
);
2989 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2990 ok(hi
!= NULL
, "open failed\n");
2992 /* try connect without authorization */
2993 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2994 ok(hc
!= NULL
, "connect failed\n");
2996 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2997 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
3000 SetLastError(0xdeadbeef);
3001 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
3002 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3003 ok(!r
, "unexpected success\n");
3004 ok(sz
== 1, "got %lu\n", sz
);
3007 SetLastError(0xdeadbeef);
3008 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
3009 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3010 ok(!r
, "unexpected success\n");
3011 ok(sz
== 1, "got %lu\n", sz
);
3013 sz
= sizeof(buffer
);
3014 SetLastError(0xdeadbeef);
3015 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
3016 ok(r
, "unexpected failure %lu\n", GetLastError());
3017 ok(!sz
, "got %lu\n", sz
);
3019 sz
= sizeof(buffer
);
3020 SetLastError(0xdeadbeef);
3021 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
3022 ok(r
, "unexpected failure %lu\n", GetLastError());
3023 ok(!sz
, "got %lu\n", sz
);
3026 SetLastError(0xdeadbeef);
3027 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
3028 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3029 ok(!r
, "unexpected success\n");
3030 ok(sz
== 1, "got %lu\n", sz
);
3033 SetLastError(0xdeadbeef);
3034 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
3035 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3036 ok(!r
, "unexpected success\n");
3037 ok(sz
== 1, "got %lu\n", sz
);
3039 sz
= sizeof(buffer
);
3040 SetLastError(0xdeadbeef);
3041 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
3042 ok(r
, "unexpected failure %lu\n", GetLastError());
3043 ok(!sz
, "got %lu\n", sz
);
3045 sz
= sizeof(buffer
);
3046 SetLastError(0xdeadbeef);
3047 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
3048 ok(r
, "unexpected failure %lu\n", GetLastError());
3049 ok(!sz
, "got %lu\n", sz
);
3052 SetLastError(0xdeadbeef);
3053 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
3054 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3055 ok(!r
, "unexpected success\n");
3056 ok(sz
== 34, "got %lu\n", sz
);
3058 sz
= sizeof(buffer
);
3059 SetLastError(0xdeadbeef);
3060 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
3061 ok(r
, "unexpected failure %lu\n", GetLastError());
3062 ok(sz
== 33, "got %lu\n", sz
);
3064 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
3065 ok(r
|| broken(!r
), "HttpSendRequest failed %lu\n", GetLastError());
3068 win_skip("skipping proxy tests on broken wininet\n");
3072 test_status_code(hr
, 407);
3074 /* set the user + password then try again */
3075 r
= InternetSetOptionA(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
3076 ok(!r
, "unexpected success\n");
3078 r
= InternetSetOptionA(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
3079 ok(r
, "failed to set user\n");
3081 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
3082 ok(r
, "failed to set user\n");
3086 SetLastError(0xdeadbeef);
3087 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
3088 ok(!r
, "unexpected failure %lu\n", GetLastError());
3089 ok(!buffer
[0], "got %s\n", buffer
);
3090 ok(sz
== strlen(username
) + 1, "got %lu\n", sz
);
3094 SetLastError(0xdeadbeef);
3095 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
3096 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3097 ok(!r
, "unexpected success\n");
3098 ok(sz
== strlen(username
) + 1, "got %lu\n", sz
);
3102 SetLastError(0xdeadbeef);
3103 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
3104 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3105 ok(!r
, "unexpected success\n");
3106 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %lu\n", sz
);
3109 sz
= sizeof(buffer
);
3110 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
3111 ok(r
, "failed to get username\n");
3112 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
3113 ok(sz
== strlen(username
), "got %lu\n", sz
);
3116 sz
= sizeof(bufferW
);
3117 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
3118 ok(r
, "failed to get username\n");
3119 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
3120 ok(sz
== lstrlenW(usernameW
), "got %lu\n", sz
);
3122 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
3123 ok(r
, "failed to set user\n");
3126 sz
= sizeof(buffer
);
3127 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
3128 ok(r
, "failed to get username\n");
3129 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
3130 ok(sz
== strlen(username
), "got %lu\n", sz
);
3132 r
= InternetSetOptionA(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
3133 ok(r
, "failed to set useragent\n");
3137 SetLastError(0xdeadbeef);
3138 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
3139 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3140 ok(!r
, "unexpected success\n");
3141 ok(sz
== strlen(useragent
) + 1, "got %lu\n", sz
);
3144 sz
= sizeof(buffer
);
3145 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
3146 ok(r
, "failed to get user agent\n");
3147 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
3148 ok(sz
== strlen(useragent
), "got %lu\n", sz
);
3152 SetLastError(0xdeadbeef);
3153 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
3154 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3155 ok(!r
, "unexpected success\n");
3156 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %lu\n", sz
);
3159 sz
= sizeof(bufferW
);
3160 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
3161 ok(r
, "failed to get user agent\n");
3162 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
3163 ok(sz
== lstrlenW(useragentW
), "got %lu\n", sz
);
3165 r
= InternetSetOptionA(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
3166 ok(r
, "failed to set user\n");
3170 SetLastError(0xdeadbeef);
3171 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
3172 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3173 ok(!r
, "unexpected success\n");
3174 ok(sz
== strlen(username
) + 1, "got %lu\n", sz
);
3177 sz
= sizeof(buffer
);
3178 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
3179 ok(r
, "failed to get user\n");
3180 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
3181 ok(sz
== strlen(username
), "got %lu\n", sz
);
3185 SetLastError(0xdeadbeef);
3186 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
3187 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3188 ok(!r
, "unexpected success\n");
3189 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %lu\n", sz
);
3192 sz
= sizeof(bufferW
);
3193 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
3194 ok(r
, "failed to get user\n");
3195 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
3196 ok(sz
== lstrlenW(usernameW
), "got %lu\n", sz
);
3198 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
3199 ok(r
, "failed to set password\n");
3203 SetLastError(0xdeadbeef);
3204 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
3205 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3206 ok(!r
, "unexpected success\n");
3207 ok(sz
== strlen(password
) + 1, "got %lu\n", sz
);
3210 sz
= sizeof(buffer
);
3211 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
3212 ok(r
, "failed to get password\n");
3213 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
3214 ok(sz
== strlen(password
), "got %lu\n", sz
);
3218 SetLastError(0xdeadbeef);
3219 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
3220 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3221 ok(!r
, "unexpected success\n");
3222 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %lu\n", sz
);
3225 sz
= sizeof(bufferW
);
3226 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
3227 ok(r
, "failed to get password\n");
3228 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
3229 ok(sz
== lstrlenW(passwordW
), "got %lu\n", sz
);
3231 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
3232 sprintf(url
, url_fmt
, port
);
3235 SetLastError(0xdeadbeef);
3236 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
3237 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3238 ok(!r
, "unexpected success\n");
3239 ok(sz
== strlen(url
) + 1, "got %lu\n", sz
);
3242 sz
= sizeof(buffer
);
3243 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
3244 ok(r
, "failed to get url\n");
3245 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
3246 ok(sz
== strlen(url
), "got %lu\n", sz
);
3250 SetLastError(0xdeadbeef);
3251 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
3252 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3253 ok(!r
, "unexpected success\n");
3254 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %lu\n", sz
);
3257 sz
= sizeof(bufferW
);
3258 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
3259 ok(r
, "failed to get url\n");
3260 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
3261 ok(sz
== strlen(url
), "got %lu\n", sz
);
3262 HeapFree(GetProcessHeap(), 0, url
);
3264 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
3265 ok(r
, "failed to set password\n");
3269 SetLastError(0xdeadbeef);
3270 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
3271 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3272 ok(!r
, "unexpected success\n");
3273 ok(sz
== strlen(password
) + 1, "got %lu\n", sz
);
3276 sz
= sizeof(buffer
);
3277 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
3278 ok(r
, "failed to get password\n");
3279 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
3280 ok(sz
== strlen(password
), "got %lu\n", sz
);
3284 SetLastError(0xdeadbeef);
3285 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
3286 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %lu\n", GetLastError());
3287 ok(!r
, "unexpected success\n");
3288 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %lu\n", sz
);
3291 sz
= sizeof(bufferW
);
3292 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
3293 ok(r
, "failed to get password\n");
3294 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
3295 ok(sz
== lstrlenW(passwordW
), "got %lu\n", sz
);
3297 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
3300 win_skip("skipping proxy tests on broken wininet\n");
3303 ok(r
, "HttpSendRequest failed %lu\n", GetLastError());
3305 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
3306 ok(r
, "HttpQueryInfo failed\n");
3307 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
3309 InternetCloseHandle(hr
);
3310 InternetCloseHandle(hc
);
3311 InternetCloseHandle(hi
);
3313 sprintf(buffer
, "localhost:%d\n", port
);
3314 hi
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
3315 ok(hi
!= NULL
, "InternetOpen failed\n");
3317 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3318 ok(hc
!= NULL
, "InternetConnect failed\n");
3320 hr
= HttpOpenRequestA(hc
, "POST", "/test2", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
3321 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
3323 r
= HttpSendRequestA(hr
, NULL
, 0, (char *)"data", sizeof("data"));
3324 ok(r
, "HttpSendRequest failed %lu\n", GetLastError());
3326 test_status_code(hr
, 407);
3329 InternetCloseHandle(hr
);
3330 InternetCloseHandle(hc
);
3331 InternetCloseHandle(hi
);
3334 static void test_header_handling_order(int port
)
3336 static const char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
3337 static const char connection
[] = "Connection: Close";
3338 static const char *types
[2] = { "*", NULL
};
3340 HINTERNET session
, connect
, request
;
3341 DWORD size
, status
, data_len
;
3344 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3345 ok(session
!= NULL
, "InternetOpen failed\n");
3347 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3348 ok(connect
!= NULL
, "InternetConnect failed\n");
3350 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3351 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3353 ret
= HttpAddRequestHeadersA(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3354 ok(ret
, "HttpAddRequestHeaders failed\n");
3356 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3357 ok(ret
, "HttpSendRequest failed\n");
3359 test_status_code(request
, 200);
3360 test_request_flags(request
, 0);
3362 InternetCloseHandle(request
);
3364 request
= HttpOpenRequestA(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3365 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3367 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
3368 ok(ret
, "HttpSendRequest failed\n");
3371 size
= sizeof(status
);
3372 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
3373 ok(ret
, "HttpQueryInfo failed\n");
3374 ok(status
== 200 || status
== 400 /* IE6 */, "got status %lu, expected 200 or 400\n", status
);
3376 InternetCloseHandle(request
);
3377 InternetCloseHandle(connect
);
3379 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3380 ok(connect
!= NULL
, "InternetConnect failed\n");
3382 request
= HttpOpenRequestA(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3383 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3385 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
3386 ok(ret
, "HttpAddRequestHeaders failed\n");
3388 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
3389 ok(ret
, "HttpSendRequest failed\n");
3392 size
= sizeof(status
);
3393 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
3394 ok(ret
, "HttpQueryInfo failed\n");
3395 ok(status
== 200, "got status %lu, expected 200\n", status
);
3397 InternetCloseHandle(request
);
3398 InternetCloseHandle(connect
);
3400 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3401 ok(connect
!= NULL
, "InternetConnect failed\n");
3403 request
= HttpOpenRequestA(connect
, "POST", "/test7b", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3404 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3406 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
3407 ok(ret
, "HttpAddRequestHeaders failed\n");
3409 data_len
= sizeof(data
);
3410 memset(data
, 'a', sizeof(data
));
3411 ret
= HttpSendRequestA(request
, NULL
, 0, data
, data_len
);
3412 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
3415 size
= sizeof(status
);
3416 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
3417 ok(ret
, "HttpQueryInfo failed\n");
3418 ok(status
== 200, "got status %lu, expected 200\n", status
);
3420 InternetCloseHandle(request
);
3421 InternetCloseHandle(connect
);
3422 InternetCloseHandle(session
);
3425 static void test_connection_header(int port
)
3427 HINTERNET ses
, con
, req
;
3430 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3431 ok(ses
!= NULL
, "InternetOpen failed\n");
3433 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3434 ok(con
!= NULL
, "InternetConnect failed\n");
3436 req
= HttpOpenRequestA(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3437 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3439 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3440 ok(ret
, "HttpSendRequest failed\n");
3442 test_status_code(req
, 200);
3444 InternetCloseHandle(req
);
3446 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
3447 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3449 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3450 ok(ret
, "HttpSendRequest failed\n");
3452 test_status_code(req
, 200);
3454 InternetCloseHandle(req
);
3456 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3457 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3459 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3460 ok(ret
, "HttpSendRequest failed\n");
3462 test_status_code(req
, 200);
3464 InternetCloseHandle(req
);
3466 req
= HttpOpenRequestA(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3467 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3469 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3470 ok(ret
, "HttpSendRequest failed\n");
3472 test_status_code(req
, 200);
3474 InternetCloseHandle(req
);
3475 InternetCloseHandle(con
);
3476 InternetCloseHandle(ses
);
3479 static void test_header_override(int port
)
3481 char buffer
[128], host_header_override
[30], full_url
[128];
3482 HINTERNET ses
, con
, req
;
3483 DWORD size
, count
, err
;
3486 sprintf(host_header_override
, "Host: test.local:%d\r\n", port
);
3487 sprintf(full_url
, "http://localhost:%d/test_host_override", port
);
3489 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3490 ok(ses
!= NULL
, "InternetOpen failed\n");
3492 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3493 ok(con
!= NULL
, "InternetConnect failed\n");
3495 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3496 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3498 size
= sizeof(buffer
) - 1;
3500 memset(buffer
, 0, sizeof(buffer
));
3501 ret
= HttpQueryInfoA(req
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &count
);
3502 err
= GetLastError();
3503 ok(!ret
, "HttpQueryInfo succeeded\n");
3504 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %ld\n", err
);
3506 test_request_url(req
, full_url
);
3508 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3509 ok(ret
, "HttpAddRequestHeaders failed\n");
3511 size
= sizeof(buffer
) - 1;
3513 memset(buffer
, 0, sizeof(buffer
));
3514 ret
= HttpQueryInfoA(req
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &count
);
3515 ok(ret
, "HttpQueryInfo failed\n");
3517 test_request_url(req
, full_url
);
3519 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3520 ok(ret
, "HttpSendRequest failed\n");
3522 test_status_code(req
, 200);
3524 InternetCloseHandle(req
);
3525 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3526 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3528 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3529 ok(ret
, "HttpAddRequestHeaders failed\n");
3531 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3532 ok(ret
, "HttpAddRequestHeaders failed\n");
3534 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3535 ok(ret
, "HttpSendRequest failed\n");
3537 test_status_code(req
, 400);
3539 InternetCloseHandle(req
);
3540 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3541 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3543 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3544 ok(ret
, "HttpAddRequestHeaders failed\n");
3546 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3547 ok(ret
, "HttpSendRequest failed\n");
3549 test_status_code(req
, 200);
3551 InternetCloseHandle(req
);
3552 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3553 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3555 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_REPLACE
);
3556 if(ret
) { /* win10 returns success */
3557 trace("replacing host header is supported.\n");
3559 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3560 ok(ret
, "HttpSendRequest failed\n");
3562 test_status_code(req
, 200);
3564 trace("replacing host header is not supported.\n");
3566 err
= GetLastError();
3567 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %ld\n", err
);
3569 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3570 ok(ret
, "HttpSendRequest failed\n");
3572 test_status_code(req
, 400);
3575 InternetCloseHandle(req
);
3576 InternetCloseHandle(con
);
3577 InternetCloseHandle(ses
);
3580 static void test_connection_closing(int port
)
3582 HINTERNET session
, connection
, req
;
3587 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3588 ok(session
!= NULL
,"InternetOpen failed with error %lu\n", GetLastError());
3590 pInternetSetStatusCallbackA(session
, callback
);
3592 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3593 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3594 ok(connection
!= NULL
,"InternetConnect failed with error %lu\n", GetLastError());
3595 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3597 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3598 req
= HttpOpenRequestA(connection
, "GET", "/testJ", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3599 ok(req
!= NULL
, "HttpOpenRequest failed: %lu\n", GetLastError());
3600 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3602 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3603 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3604 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3605 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3606 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3607 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3608 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3609 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3610 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3611 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3612 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3614 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3615 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3616 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3617 WaitForSingleObject(complete_event
, INFINITE
);
3618 ok(req_error
== ERROR_SUCCESS
, "req_error = %lu\n", req_error
);
3620 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3621 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3622 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3623 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3624 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3625 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3626 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3627 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3628 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3629 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3630 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3632 test_status_code(req
, 200);
3634 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3635 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3636 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3637 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3638 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3639 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3640 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3641 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3642 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3644 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3645 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3646 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3647 WaitForSingleObject(complete_event
, INFINITE
);
3648 ok(req_error
== ERROR_SUCCESS
, "req_error = %lu\n", req_error
);
3650 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3651 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3652 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3653 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3654 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3655 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3656 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3657 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3658 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3660 test_status_code(req
, 210);
3662 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3663 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3664 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3665 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3666 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3667 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3668 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3669 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3670 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3671 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3672 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3674 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3675 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3676 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3677 WaitForSingleObject(complete_event
, INFINITE
);
3678 ok(req_error
== ERROR_SUCCESS
, "req_error = %lu\n", req_error
);
3680 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3681 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3682 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3683 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3684 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3685 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3686 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3687 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3688 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3689 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3690 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3692 test_status_code(req
, 200);
3694 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3695 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3697 close_async_handle(session
, 2);
3700 static void test_successive_HttpSendRequest(int port
)
3702 HINTERNET session
, connection
, req
;
3707 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3708 ok(session
!= NULL
,"InternetOpen failed with error %lu\n", GetLastError());
3710 pInternetSetStatusCallbackA(session
, callback
);
3712 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3713 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3714 ok(connection
!= NULL
,"InternetConnect failed with error %lu\n", GetLastError());
3715 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3717 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3718 req
= HttpOpenRequestA(connection
, "GET", "/testH", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3719 ok(req
!= NULL
, "HttpOpenRequest failed: %lu\n", GetLastError());
3720 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3722 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3723 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3724 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3725 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3726 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3727 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3728 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3729 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3730 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3732 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3733 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3734 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3735 WaitForSingleObject(complete_event
, INFINITE
);
3736 ok(req_error
== ERROR_SUCCESS
, "req_error = %lu\n", req_error
);
3738 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3739 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3740 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3741 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3742 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3743 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3744 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3745 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3746 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3748 test_status_code(req
, 210);
3750 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3751 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3752 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3753 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3754 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3755 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3756 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3757 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3758 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3760 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3761 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3762 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3763 WaitForSingleObject(complete_event
, INFINITE
);
3764 ok(req_error
== ERROR_SUCCESS
, "req_error = %lu\n", req_error
);
3766 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3767 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3768 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3769 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3770 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3771 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3772 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3773 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3774 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3776 test_status_code(req
, 200);
3778 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3779 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3781 close_async_handle(session
, 2);
3784 static void test_no_content(int port
)
3786 HINTERNET session
, connection
, req
;
3789 trace("Testing 204 no content response...\n");
3793 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3794 ok(session
!= NULL
,"InternetOpen failed with error %lu\n", GetLastError());
3796 pInternetSetStatusCallbackA(session
, callback
);
3798 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3799 connection
= InternetConnectA(session
, "localhost", port
,
3800 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3801 ok(connection
!= NULL
,"InternetConnect failed with error %lu\n", GetLastError());
3802 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3804 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3805 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
3806 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3807 ok(req
!= NULL
, "HttpOpenRequest failed: %lu\n", GetLastError());
3808 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3810 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3811 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3812 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3813 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3814 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3815 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3816 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3817 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3818 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3819 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3821 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3822 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3823 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3824 WaitForSingleObject(complete_event
, INFINITE
);
3825 ok(req_error
== ERROR_SUCCESS
, "req_error = %lu\n", req_error
);
3827 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3828 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3829 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3830 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3831 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3832 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3833 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3834 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3836 close_async_handle(session
, 2);
3839 * The connection should be closed before closing handle. This is true for most
3840 * wininet versions (including Wine), but some old win2k versions fail to do that.
3842 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3843 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3846 static void test_not_modified(int port
)
3849 HINTERNET ses
, con
, req
;
3852 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3853 ok(ses
!= NULL
, "InternetOpen failed\n");
3855 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3856 ok(con
!= NULL
, "InternetConnect failed\n");
3858 req
= HttpOpenRequestA(con
, NULL
, "/test_not_modified", NULL
, NULL
, NULL
, 0, 0);
3859 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3861 SetLastError(0xdeadbeef);
3862 ret
= HttpSendRequestW(req
, NULL
, 0, NULL
, 0);
3863 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
3864 test_status_code(req
, 304);
3867 ret
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3868 ok(ret
, "InternetQueryDataAvailable failed: %lu\n", GetLastError());
3869 ok(!avail
, "got %ld\n", avail
);
3870 InternetCloseHandle(req
);
3872 req
= HttpOpenRequestA(con
, NULL
, "/test_not_modified_content_length", NULL
, NULL
, NULL
, 0, 0);
3873 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3875 SetLastError(0xdeadbeef);
3876 ret
= HttpSendRequestW(req
, NULL
, 0, NULL
, 0);
3877 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
3878 test_status_code(req
, 304);
3881 ret
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3882 ok(ret
, "InternetQueryDataAvailable failed: %lu\n", GetLastError());
3883 ok(avail
== 10, "got %ld\n", avail
);
3884 InternetCloseHandle(req
);
3886 req
= HttpOpenRequestA(con
, NULL
, "/test_no_content", NULL
, NULL
, NULL
, 0, 0);
3887 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3889 SetLastError(0xdeadbeef);
3890 ret
= HttpSendRequestW(req
, NULL
, 0, NULL
, 0);
3891 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
3892 test_status_code(req
, 204);
3895 ret
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3896 ok(ret
, "InternetQueryDataAvailable failed: %lu\n", GetLastError());
3897 ok(!avail
, "got %ld\n", avail
);
3898 InternetCloseHandle(req
);
3900 req
= HttpOpenRequestA(con
, NULL
, "/test_no_content_content_length", NULL
, NULL
, NULL
, 0, 0);
3901 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3903 SetLastError(0xdeadbeef);
3904 ret
= HttpSendRequestW(req
, NULL
, 0, NULL
, 0);
3905 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
3906 test_status_code(req
, 204);
3909 ret
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3910 ok(ret
, "InternetQueryDataAvailable failed: %lu\n", GetLastError());
3911 ok(avail
== 10, "got %ld\n", avail
);
3912 InternetCloseHandle(req
);
3914 req
= HttpOpenRequestA(con
, "HEAD", "/head", NULL
, NULL
, NULL
, 0, 0);
3915 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3917 SetLastError(0xdeadbeef);
3918 ret
= HttpSendRequestW(req
, NULL
, 0, NULL
, 0);
3919 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
3920 test_status_code(req
, 200);
3923 ret
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3924 ok(ret
, "InternetQueryDataAvailable failed: %lu\n", GetLastError());
3925 ok(!avail
, "got %ld\n", avail
);
3926 InternetCloseHandle(req
);
3928 req
= HttpOpenRequestA(con
, "HEAD", "/head_content_length", NULL
, NULL
, NULL
, 0, 0);
3929 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3931 SetLastError(0xdeadbeef);
3932 ret
= HttpSendRequestW(req
, NULL
, 0, NULL
, 0);
3933 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
3934 test_status_code(req
, 200);
3937 ret
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3938 ok(ret
, "InternetQueryDataAvailable failed: %lu\n", GetLastError());
3939 ok(!avail
, "got %ld\n", avail
);
3941 InternetCloseHandle(req
);
3942 InternetCloseHandle(con
);
3943 InternetCloseHandle(ses
);
3946 static void test_large_header(int port
)
3948 HINTERNET ses
, con
, req
;
3950 DWORD size
, index
, error
;
3953 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3954 ok(ses
!= NULL
, "InternetOpen failed\n");
3956 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3957 ok(con
!= NULL
, "InternetConnect failed\n");
3959 req
= HttpOpenRequestA(con
, NULL
, "/test_large_header", NULL
, NULL
, NULL
, 0, 0);
3960 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3962 SetLastError(0xdeadbeef);
3963 ret
= HttpSendRequestW(req
, NULL
, 0, NULL
, 0);
3964 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
3965 test_status_code(req
, 200);
3968 size
= sizeof(buffer
);
3969 strcpy(buffer
, "wine-header");
3970 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
3971 error
= GetLastError();
3972 ok(!ret
, "HttpQueryInfoA succeeded\n");
3973 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %lu\n", error
);
3974 ok(size
== 4001, "got %lu\n", size
);
3976 InternetCloseHandle(req
);
3977 InternetCloseHandle(con
);
3978 InternetCloseHandle(ses
);
3981 static void test_conn_close(int port
)
3983 HINTERNET session
, connection
, req
;
3984 DWORD res
, avail
, size
;
3987 trace("Testing connection close connection...\n");
3991 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3992 ok(session
!= NULL
,"InternetOpen failed with error %lu\n", GetLastError());
3994 pInternetSetStatusCallbackA(session
, callback
);
3996 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3997 connection
= InternetConnectA(session
, "localhost", port
,
3998 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3999 ok(connection
!= NULL
,"InternetConnect failed with error %lu\n", GetLastError());
4000 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4002 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4003 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
4004 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
4005 ok(req
!= NULL
, "HttpOpenRequest failed: %lu\n", GetLastError());
4006 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4008 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4009 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4010 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4011 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4012 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4013 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4014 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4015 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4017 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
4018 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
4019 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
4020 WaitForSingleObject(complete_event
, INFINITE
);
4021 ok(req_error
== ERROR_SUCCESS
, "req_error = %lu\n", req_error
);
4023 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4024 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4025 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4026 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4027 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4028 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4029 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4030 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4033 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
4034 ok(res
, "InternetQueryDataAvailable failed: %lu\n", GetLastError());
4035 ok(avail
!= 0, "avail = 0\n");
4038 res
= InternetReadFile(req
, buf
, avail
, &size
);
4039 ok(res
, "InternetReadFile failed: %lu\n", GetLastError());
4041 /* IE11 calls those in InternetQueryDataAvailable call. */
4042 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
4043 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
4045 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
4046 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
4047 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
4048 ok(!avail
, "avail = %lu, expected 0\n", avail
);
4050 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4052 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4053 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4054 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4055 SetEvent(conn_close_event
);
4056 WaitForSingleObject(complete_event
, INFINITE
);
4057 ok(req_error
== ERROR_SUCCESS
, "req_error = %lu\n", req_error
);
4058 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4059 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4060 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4061 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4063 close_async_handle(session
, 2);
4066 static void test_no_cache(int port
)
4068 static const char cache_control_no_cache
[] = "/test_cache_control_no_cache";
4069 static const char cache_control_no_store
[] = "/test_cache_control_no_store";
4070 static const char cache_url_fmt
[] = "http://localhost:%d%s";
4072 char cache_url
[256], buf
[256];
4073 HINTERNET ses
, con
, req
;
4077 trace("Testing no-cache header\n");
4079 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4080 ok(ses
!= NULL
,"InternetOpen failed with error %lu\n", GetLastError());
4082 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4083 ok(con
!= NULL
, "InternetConnect failed with error %lu\n", GetLastError());
4085 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
4086 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4088 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_cache
);
4089 DeleteUrlCacheEntryA(cache_url
);
4091 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4092 ok(ret
, "HttpSendRequest failed with error %lu\n", GetLastError());
4094 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
4096 ok(size
== 12, "read %ld bytes of data\n", size
);
4097 InternetCloseHandle(req
);
4099 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
4100 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4102 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4103 ok(ret
, "HttpSendRequest failed with error %lu\n", GetLastError());
4105 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
4107 ok(size
== 0, "read %ld bytes of data\n", size
);
4108 InternetCloseHandle(req
);
4109 DeleteUrlCacheEntryA(cache_url
);
4111 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_store
, NULL
, NULL
, NULL
, 0, 0);
4112 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4114 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_store
);
4115 DeleteUrlCacheEntryA(cache_url
);
4117 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4118 ok(ret
, "HttpSendRequest failed with error %lu\n", GetLastError());
4120 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
4122 ok(size
== 12, "read %ld bytes of data\n", size
);
4123 InternetCloseHandle(req
);
4125 ret
= DeleteUrlCacheEntryA(cache_url
);
4126 ok(!ret
&& GetLastError()==ERROR_FILE_NOT_FOUND
, "cache entry should not exist\n");
4128 InternetCloseHandle(con
);
4129 InternetCloseHandle(ses
);
4132 static void test_cache_read_gzipped(int port
)
4134 static const char cache_url_fmt
[] = "http://localhost:%d%s";
4135 static const char get_gzip
[] = "/test_cache_gzip";
4136 static const char content
[] = "gzip test\n";
4137 static const char text_html
[] = "text/html";
4138 static const char raw_header
[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
4140 HINTERNET ses
, con
, req
;
4142 char cache_url
[256], buf
[256];
4145 trace("Testing reading compressed content from cache\n");
4147 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4148 ok(ses
!= NULL
,"InternetOpen failed with error %lu\n", GetLastError());
4150 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4151 ok(con
!= NULL
, "InternetConnect failed with error %lu\n", GetLastError());
4153 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
4154 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4157 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
4158 if(!ret
&& GetLastError()==ERROR_INTERNET_INVALID_OPTION
) {
4159 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
4160 InternetCloseHandle(req
);
4161 InternetCloseHandle(con
);
4162 InternetCloseHandle(ses
);
4165 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %ld\n", GetLastError());
4167 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
4168 ok(ret
, "HttpSendRequest failed with error %lu\n", GetLastError());
4170 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-size
, &read
) && read
)
4172 ok(size
== 10, "read %ld bytes of data\n", size
);
4174 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
4176 size
= sizeof(buf
)-1;
4177 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
4178 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %ld\n", GetLastError());
4180 ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
4182 size
= sizeof(buf
)-1;
4183 ret
= HttpQueryInfoA(req
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &size
, 0);
4184 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %ld\n", GetLastError());
4186 ok(!strncmp(raw_header
, buf
, size
), "buf = %s\n", buf
);
4187 InternetCloseHandle(req
);
4189 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
4190 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4193 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
4194 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %ld\n", GetLastError());
4196 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
4197 ok(ret
, "HttpSendRequest failed with error %lu\n", GetLastError());
4199 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
4201 todo_wine
ok(size
== 10, "read %ld bytes of data\n", size
);
4203 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
4206 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
4207 ok(!ret
&& GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND
,
4208 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %ld\n",
4209 ret
, GetLastError());
4211 size
= sizeof(buf
)-1;
4212 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
4213 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %ld\n", GetLastError());
4215 todo_wine
ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
4216 InternetCloseHandle(req
);
4218 /* Decompression doesn't work while reading from cache */
4219 test_cache_gzip
= 0;
4220 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
4221 DeleteUrlCacheEntryA(cache_url
);
4223 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
4224 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4226 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
4227 ok(ret
, "HttpSendRequest failed with error %lu\n", GetLastError());
4229 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
4231 ok(size
== 31, "read %ld bytes of data\n", size
);
4232 InternetCloseHandle(req
);
4234 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
4235 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4238 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
4239 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %ld\n", GetLastError());
4241 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
4242 ok(ret
, "HttpSendRequest failed with error %lu\n", GetLastError());
4244 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
4246 todo_wine
ok(size
== 31, "read %ld bytes of data\n", size
);
4249 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
4250 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %ld\n", GetLastError());
4251 InternetCloseHandle(req
);
4253 InternetCloseHandle(con
);
4254 InternetCloseHandle(ses
);
4256 /* Decompression doesn't work while reading from cache */
4257 test_cache_gzip
= 0;
4258 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
4259 DeleteUrlCacheEntryA(cache_url
);
4261 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4262 ok(ses
!= NULL
,"InternetOpen failed with error %lu\n", GetLastError());
4265 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
4266 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %ld\n", GetLastError());
4268 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4269 ok(con
!= NULL
, "InternetConnect failed with error %lu\n", GetLastError());
4271 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
4272 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4274 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
4275 ok(ret
, "HttpSendRequest failed with error %lu\n", GetLastError());
4277 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
4279 ok(size
== 10, "read %ld bytes of data\n", size
);
4281 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
4282 InternetCloseHandle(req
);
4284 InternetCloseHandle(con
);
4285 InternetCloseHandle(ses
);
4287 /* Decompression doesn't work while reading from cache */
4288 test_cache_gzip
= 0;
4289 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
4290 DeleteUrlCacheEntryA(cache_url
);
4292 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4293 ok(ses
!= NULL
,"InternetOpen failed with error %lu\n", GetLastError());
4295 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4296 ok(con
!= NULL
, "InternetConnect failed with error %lu\n", GetLastError());
4299 ret
= InternetSetOptionA(con
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
4300 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %ld\n", GetLastError());
4302 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
4303 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4305 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
4306 ok(ret
, "HttpSendRequest failed with error %lu\n", GetLastError());
4308 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
4310 ok(size
== 10, "read %ld bytes of data\n", size
);
4312 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
4313 InternetCloseHandle(req
);
4315 InternetCloseHandle(con
);
4316 InternetCloseHandle(ses
);
4318 DeleteUrlCacheEntryA(cache_url
);
4321 static void test_HttpSendRequestW(int port
)
4323 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
4324 HINTERNET ses
, con
, req
;
4328 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4329 ok(ses
!= NULL
, "InternetOpen failed\n");
4331 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4332 ok(con
!= NULL
, "InternetConnect failed\n");
4334 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
4335 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4337 SetLastError(0xdeadbeef);
4338 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
4339 error
= GetLastError();
4340 ok(!ret
, "HttpSendRequestW succeeded\n");
4341 ok(error
== ERROR_IO_PENDING
||
4342 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
4343 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
4344 "got %lu expected ERROR_IO_PENDING\n", error
);
4346 InternetCloseHandle(req
);
4347 InternetCloseHandle(con
);
4348 InternetCloseHandle(ses
);
4351 static void test_cookie_header(int port
)
4353 HINTERNET ses
, con
, req
;
4358 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4359 ok(ses
!= NULL
, "InternetOpen failed\n");
4361 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4362 ok(con
!= NULL
, "InternetConnect failed\n");
4364 InternetSetCookieA("http://localhost", "cookie", "biscuit");
4366 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
4367 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4370 size
= sizeof(buffer
);
4371 SetLastError(0xdeadbeef);
4372 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4373 error
= GetLastError();
4374 ok(!ret
, "HttpQueryInfo succeeded\n");
4375 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %lu expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
4377 ret
= HttpAddRequestHeadersA(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
4378 ok(ret
, "HttpAddRequestHeaders failed: %lu\n", GetLastError());
4381 size
= sizeof(buffer
);
4382 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4383 ok(ret
, "HttpQueryInfo failed: %lu\n", GetLastError());
4384 ok(!strcmp(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
4386 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4387 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
4389 test_status_code(req
, 200);
4392 size
= sizeof(buffer
);
4393 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4394 ok(ret
, "HttpQueryInfo failed: %lu\n", GetLastError());
4395 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
4397 InternetCloseHandle(req
);
4398 InternetCloseHandle(con
);
4399 InternetCloseHandle(ses
);
4402 static void test_basic_authentication(int port
)
4404 HINTERNET session
, connect
, request
;
4407 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4408 ok(session
!= NULL
, "InternetOpen failed\n");
4410 connect
= InternetConnectA(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
4411 ok(connect
!= NULL
, "InternetConnect failed\n");
4413 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
4414 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4416 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4417 ok(ret
, "HttpSendRequest failed %lu\n", GetLastError());
4419 test_status_code(request
, 200);
4420 test_request_flags(request
, 0);
4422 InternetCloseHandle(request
);
4423 InternetCloseHandle(connect
);
4424 InternetCloseHandle(session
);
4427 static void test_premature_disconnect(int port
)
4433 open_simple_request(&req
, "localhost", port
, NULL
, "/premature_disconnect");
4435 SetLastError(0xdeadbeef);
4436 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4437 err
= GetLastError();
4438 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
4439 todo_wine
ok(err
== ERROR_HTTP_INVALID_SERVER_RESPONSE
, "got %lu\n", err
);
4441 close_request(&req
);
4444 static void test_invalid_response_headers(int port
)
4451 open_simple_request(&req
, "localhost", port
, NULL
, "/testE");
4453 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4454 ok(ret
, "HttpSendRequest failed %lu\n", GetLastError());
4456 test_status_code(req
.request
, 401);
4457 test_request_flags(req
.request
, 0);
4460 size
= sizeof(buffer
);
4461 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
4462 ok(ret
, "HttpQueryInfo failed\n");
4463 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
4464 "headers wrong \"%s\"\n", buffer
);
4467 size
= sizeof(buffer
);
4468 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
4469 ok(ret
, "HttpQueryInfo failed\n");
4470 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
4472 close_request(&req
);
4475 static void test_response_without_headers(int port
)
4478 DWORD r
, count
, size
;
4481 open_simple_request(&req
, "localhost", port
, NULL
, "/testG");
4483 test_request_flags(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
4485 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4486 ok(r
, "HttpSendRequest failed %lu\n", GetLastError());
4488 test_request_flags_todo(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
4491 memset(buffer
, 0, sizeof buffer
);
4492 r
= InternetReadFile(req
.request
, buffer
, sizeof buffer
, &count
);
4493 ok(r
, "InternetReadFile failed %lu\n", GetLastError());
4494 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
4495 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
4497 test_status_code(req
.request
, 200);
4498 test_request_flags_todo(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
4501 size
= sizeof(buffer
);
4502 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
4503 ok(r
, "HttpQueryInfo failed %lu\n", GetLastError());
4504 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
4507 size
= sizeof(buffer
);
4508 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
4509 ok(r
, "HttpQueryInfo failed %lu\n", GetLastError());
4510 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
4513 size
= sizeof(buffer
);
4514 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
4515 ok(r
, "HttpQueryInfo failed %lu\n", GetLastError());
4516 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
4518 close_request(&req
);
4521 static void test_head_request(int port
)
4523 DWORD len
, content_length
;
4528 open_simple_request(&req
, "localhost", port
, "HEAD", "/test_head");
4530 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4531 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
4533 len
= sizeof(content_length
);
4534 content_length
= -1;
4535 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
, &content_length
, &len
, 0);
4536 ok(ret
, "HttpQueryInfo failed: %lu\n", GetLastError());
4537 ok(len
== sizeof(DWORD
), "len = %lu\n", len
);
4538 ok(content_length
== 100, "content_length = %lu\n", content_length
);
4541 ret
= InternetReadFile(req
.request
, buf
, sizeof(buf
), &len
);
4542 ok(ret
, "InternetReadFile failed: %lu\n", GetLastError());
4545 ret
= InternetReadFile(req
.request
, buf
, sizeof(buf
), &len
);
4546 ok(ret
, "InternetReadFile failed: %lu\n", GetLastError());
4548 close_request(&req
);
4551 static void test_HttpQueryInfo(int port
)
4554 DWORD size
, index
, error
;
4558 open_simple_request(&req
, "localhost", port
, NULL
, "/testD");
4560 size
= sizeof(buffer
);
4561 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
4562 error
= GetLastError();
4563 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
4564 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %lu expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
4566 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4567 ok(ret
, "HttpSendRequest failed\n");
4570 size
= sizeof(buffer
);
4571 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
4572 ok(ret
, "HttpQueryInfo failed %lu\n", GetLastError());
4573 ok(index
== 1, "expected 1 got %lu\n", index
);
4576 size
= sizeof(buffer
);
4577 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
4578 ok(ret
, "HttpQueryInfo failed %lu\n", GetLastError());
4579 ok(index
== 1, "expected 1 got %lu\n", index
);
4582 size
= sizeof(buffer
);
4583 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4584 ok(ret
, "HttpQueryInfo failed %lu\n", GetLastError());
4585 ok(index
== 0, "expected 0 got %lu\n", index
);
4587 size
= sizeof(buffer
);
4588 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4589 ok(ret
, "HttpQueryInfo failed %lu\n", GetLastError());
4590 ok(index
== 0, "expected 0 got %lu\n", index
);
4592 index
= 0xdeadbeef; /* invalid start index */
4593 size
= sizeof(buffer
);
4594 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4595 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
4596 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
4597 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %lu\n", GetLastError());
4600 size
= sizeof(buffer
);
4601 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
4602 ok(ret
, "HttpQueryInfo failed %lu\n", GetLastError());
4603 ok(index
== 0, "expected 0 got %lu\n", index
);
4605 size
= sizeof(buffer
);
4606 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
4607 ok(ret
, "HttpQueryInfo failed %lu\n", GetLastError());
4608 ok(index
== 0, "expected 0 got %lu\n", index
);
4610 size
= sizeof(buffer
);
4611 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
4612 ok(ret
, "HttpQueryInfo failed %lu\n", GetLastError());
4613 ok(index
== 0, "expected 0 got %lu\n", index
);
4615 test_status_code(req
.request
, 200);
4618 size
= sizeof(buffer
);
4619 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
4620 ok(!ret
, "HttpQueryInfo succeeded\n");
4621 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %lu\n", index
);
4624 size
= sizeof(buffer
);
4625 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
4626 ok(ret
, "HttpQueryInfo failed %lu\n", GetLastError());
4627 ok(index
== 1, "expected 1 got %lu\n", index
);
4630 size
= sizeof(buffer
);
4631 strcpy(buffer
, "Server");
4632 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
4633 ok(ret
, "HttpQueryInfo failed %lu\n", GetLastError());
4634 ok(index
== 1, "expected 1 got %lu\n", index
);
4637 size
= sizeof(buffer
);
4638 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
4639 ok(ret
, "HttpQueryInfo failed %lu\n", GetLastError());
4640 ok(index
== 1, "expected 1 got %lu\n", index
);
4642 size
= sizeof(buffer
);
4643 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
4644 ok(ret
, "HttpQueryInfo failed %lu\n", GetLastError());
4645 ok(index
== 2, "expected 2 got %lu\n", index
);
4647 close_request(&req
);
4650 static void test_options(int port
)
4652 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi
;
4653 HINTERNET ses
, con
, req
;
4658 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4659 ok(ses
!= NULL
, "InternetOpen failed\n");
4661 SetLastError(0xdeadbeef);
4662 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
4663 error
= GetLastError();
4664 ok(!ret
, "InternetSetOption succeeded\n");
4665 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %lu\n", error
);
4667 SetLastError(0xdeadbeef);
4668 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
4669 ok(!ret
, "InternetSetOption succeeded\n");
4670 error
= GetLastError();
4671 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %lu\n", error
);
4673 SetLastError(0xdeadbeef);
4674 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
4675 ok(!ret
, "InternetSetOption succeeded\n");
4676 error
= GetLastError();
4677 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %lu\n", error
);
4680 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4681 ok(ret
, "InternetSetOption failed %lu\n", GetLastError());
4683 SetLastError(0xdeadbeef);
4684 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
4685 error
= GetLastError();
4686 ok(!ret
, "InternetQueryOption succeeded\n");
4687 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %lu\n", error
);
4689 SetLastError(0xdeadbeef);
4690 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
4691 error
= GetLastError();
4692 ok(!ret
, "InternetQueryOption succeeded\n");
4693 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %lu\n", error
);
4696 SetLastError(0xdeadbeef);
4697 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
4698 error
= GetLastError();
4699 ok(!ret
, "InternetQueryOption succeeded\n");
4700 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %lu\n", error
);
4703 SetLastError(0xdeadbeef);
4704 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4705 error
= GetLastError();
4706 ok(!ret
, "InternetQueryOption succeeded\n");
4707 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %lu\n", error
);
4711 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4712 ok(ret
, "InternetQueryOption failed %lu\n", GetLastError());
4713 ok(ctx
== 1, "expected 1 got %Iu\n", ctx
);
4715 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4716 ok(con
!= NULL
, "InternetConnect failed\n");
4720 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4721 ok(ret
, "InternetQueryOption failed %lu\n", GetLastError());
4722 ok(ctx
== 0, "expected 0 got %Iu\n", ctx
);
4725 ret
= InternetSetOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4726 ok(ret
, "InternetSetOption failed %lu\n", GetLastError());
4730 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4731 ok(ret
, "InternetQueryOption failed %lu\n", GetLastError());
4732 ok(ctx
== 2, "expected 2 got %Iu\n", ctx
);
4734 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
4735 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4739 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4740 ok(ret
, "InternetQueryOption failed %lu\n", GetLastError());
4741 ok(ctx
== 0, "expected 0 got %Iu\n", ctx
);
4744 ret
= InternetSetOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4745 ok(ret
, "InternetSetOption failed %lu\n", GetLastError());
4749 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4750 ok(ret
, "InternetQueryOption failed %lu\n", GetLastError());
4751 ok(ctx
== 3, "expected 3 got %Iu\n", ctx
);
4753 size
= sizeof(idsi
);
4754 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO
, &idsi
, &size
);
4755 ok(ret
, "InternetQueryOption failed %lu\n", GetLastError());
4758 SetLastError(0xdeadbeef);
4759 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
4760 error
= GetLastError();
4761 ok(!ret
, "InternetQueryOption succeeded\n");
4762 ok(error
== ERROR_INTERNET_INVALID_OPERATION
, "expected ERROR_INTERNET_INVALID_OPERATION, got %lu\n", error
);
4764 /* INTERNET_OPTION_PROXY */
4765 SetLastError(0xdeadbeef);
4766 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
4767 error
= GetLastError();
4768 ok(!ret
, "InternetQueryOption succeeded\n");
4769 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %lu\n", error
);
4771 SetLastError(0xdeadbeef);
4772 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
4773 error
= GetLastError();
4774 ok(!ret
, "InternetQueryOption succeeded\n");
4775 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %lu\n", error
);
4778 SetLastError(0xdeadbeef);
4779 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
4780 error
= GetLastError();
4781 ok(!ret
, "InternetQueryOption succeeded\n");
4782 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %lu\n", error
);
4783 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
4785 InternetCloseHandle(req
);
4786 InternetCloseHandle(con
);
4787 InternetCloseHandle(ses
);
4791 const char *response_text
;
4793 const char *status_text
;
4794 const char *raw_headers
;
4795 } http_status_test_t
;
4797 static const http_status_test_t http_status_tests
[] = {
4799 "HTTP/1.1 200 OK\r\n"
4800 "Content-Length: 1\r\n"
4806 "HTTP/1.1 404 Fail\r\n"
4807 "Content-Length: 1\r\n"
4814 "Content-Length: 1\r\n"
4821 "Content-Length: 1\r\n"
4828 "Content-Length: 1\r\n"
4835 static void test_http_status(int port
)
4842 for(i
= 0; i
< ARRAY_SIZE(http_status_tests
); i
++) {
4843 send_buffer
= http_status_tests
[i
].response_text
;
4845 open_simple_request(&req
, "localhost", port
, NULL
, "/send_from_buffer");
4847 res
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4848 ok(res
, "HttpSendRequest failed\n");
4850 test_status_code(req
.request
, http_status_tests
[i
].status_code
);
4853 res
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buf
, &size
, NULL
);
4854 ok(res
, "HttpQueryInfo failed: %lu\n", GetLastError());
4855 ok(!strcmp(buf
, http_status_tests
[i
].status_text
), "[%lu] Unexpected status text \"%s\", expected \"%s\"\n",
4856 i
, buf
, http_status_tests
[i
].status_text
);
4858 close_request(&req
);
4862 static void test_cache_control_verb(int port
)
4864 HINTERNET session
, connect
, request
;
4867 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4868 ok(session
!= NULL
, "InternetOpen failed\n");
4870 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4871 ok(connect
!= NULL
, "InternetConnect failed\n");
4873 request
= HttpOpenRequestA(connect
, "RPC_OUT_DATA", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4874 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4875 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4876 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4877 ok(ret
, "HttpSendRequest failed %lu\n", GetLastError());
4878 test_status_code(request
, 200);
4879 InternetCloseHandle(request
);
4881 request
= HttpOpenRequestA(connect
, "POST", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4882 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4883 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4884 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4885 ok(ret
, "HttpSendRequest failed %lu\n", GetLastError());
4886 test_status_code(request
, 200);
4887 InternetCloseHandle(request
);
4889 request
= HttpOpenRequestA(connect
, "HEAD", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4890 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4891 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4892 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4893 ok(ret
, "HttpSendRequest failed %lu\n", GetLastError());
4894 test_status_code(request
, 200);
4895 InternetCloseHandle(request
);
4897 request
= HttpOpenRequestA(connect
, "GET", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4898 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4899 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4900 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4901 ok(ret
, "HttpSendRequest failed %lu\n", GetLastError());
4902 test_status_code(request
, 200);
4903 InternetCloseHandle(request
);
4905 InternetCloseHandle(connect
);
4906 InternetCloseHandle(session
);
4909 static void test_request_content_length(int port
)
4911 char data
[] = {'t','e','s','t'};
4916 open_simple_request(&req
, "localhost", port
, "POST", "/test_request_content_length");
4918 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4919 ok(ret
, "HttpSendRequest failed %lu\n", GetLastError());
4920 test_status_code(req
.request
, 200);
4922 SetEvent(complete_event
);
4924 ret
= HttpSendRequestA(req
.request
, NULL
, 0, data
, sizeof(data
));
4925 ok(ret
, "HttpSendRequest failed %lu\n", GetLastError());
4926 test_status_code(req
.request
, 200);
4928 SetEvent(complete_event
);
4929 close_request(&req
);
4932 static void test_accept_encoding(int port
)
4934 HINTERNET ses
, con
, req
;
4938 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4939 ok(ses
!= NULL
, "InternetOpen failed\n");
4941 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4942 ok(con
!= NULL
, "InternetConnect failed\n");
4944 req
= HttpOpenRequestA(con
, "GET", "/echo_request", "HTTP/1.0", NULL
, NULL
, 0, 0);
4945 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4947 ret
= HttpAddRequestHeadersA(req
, "Accept-Encoding: gzip\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDREQ_FLAG_ADD
);
4948 ok(ret
, "HttpAddRequestHeaders failed\n");
4950 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4951 ok(ret
, "HttpSendRequestA failed\n");
4953 test_status_code(req
, 200);
4954 receive_simple_request(req
, buf
, sizeof(buf
));
4955 ok(strstr(buf
, "Accept-Encoding: gzip") != NULL
, "Accept-Encoding header not found in %s\n", buf
);
4957 InternetCloseHandle(req
);
4959 req
= HttpOpenRequestA(con
, "GET", "/echo_request", "HTTP/1.0", NULL
, NULL
, 0, 0);
4960 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4962 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", ~0u, NULL
, 0);
4963 ok(ret
, "HttpSendRequestA failed\n");
4965 test_status_code(req
, 200);
4966 receive_simple_request(req
, buf
, sizeof(buf
));
4967 ok(strstr(buf
, "Accept-Encoding: gzip") != NULL
, "Accept-Encoding header not found in %s\n", buf
);
4969 InternetCloseHandle(req
);
4970 InternetCloseHandle(con
);
4971 InternetCloseHandle(ses
);
4974 static void test_basic_auth_credentials_reuse(int port
)
4976 HINTERNET ses
, con
, req
;
4981 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4982 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4984 con
= InternetConnectA( ses
, "localhost", port
, "user", "pwd",
4985 INTERNET_SERVICE_HTTP
, 0, 0 );
4986 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
4988 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
4989 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
4991 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4992 ok( ret
, "HttpSendRequestA failed %lu\n", GetLastError() );
4994 size
= sizeof(buffer
);
4995 SetLastError(0xdeadbeef);
4996 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_USERNAME
, buffer
, &size
);
4997 ok(ret
, "unexpected failure %lu\n", GetLastError());
4998 ok(!strcmp(buffer
, "user"), "got %s\n", buffer
);
4999 ok(size
== 4, "got %lu\n", size
);
5001 size
= sizeof(buffer
);
5002 SetLastError(0xdeadbeef);
5003 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_PASSWORD
, buffer
, &size
);
5004 ok(ret
, "unexpected failure %lu\n", GetLastError());
5005 ok(!strcmp(buffer
, "pwd"), "got %s\n", buffer
);
5006 ok(size
== 3, "got %lu\n", size
);
5008 status
= 0xdeadbeef;
5009 size
= sizeof(status
);
5010 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
5011 ok( ret
, "HttpQueryInfoA failed %lu\n", GetLastError() );
5012 ok( status
== 200, "got %lu\n", status
);
5014 InternetCloseHandle( req
);
5015 InternetCloseHandle( con
);
5016 InternetCloseHandle( ses
);
5018 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
5019 ok( ses
!= NULL
, "InternetOpenA failed\n" );
5021 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
,
5022 INTERNET_SERVICE_HTTP
, 0, 0 );
5023 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
5025 req
= HttpOpenRequestA( con
, "PUT", "/upload2.txt", NULL
, NULL
, NULL
, 0, 0 );
5026 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
5028 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
5029 ok( ret
, "HttpSendRequestA failed %lu\n", GetLastError() );
5031 size
= sizeof(buffer
);
5032 SetLastError(0xdeadbeef);
5033 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_USERNAME
, buffer
, &size
);
5034 ok(ret
, "unexpected failure %lu\n", GetLastError());
5035 ok(!strcmp(buffer
, "user"), "got %s\n", buffer
);
5036 ok(size
== 4, "got %lu\n", size
);
5038 size
= sizeof(buffer
);
5039 SetLastError(0xdeadbeef);
5040 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_PASSWORD
, buffer
, &size
);
5041 ok(ret
, "unexpected failure %lu\n", GetLastError());
5042 ok(!strcmp(buffer
, "pwd"), "got %s\n", buffer
);
5043 ok(size
== 3, "got %lu\n", size
);
5045 status
= 0xdeadbeef;
5046 size
= sizeof(status
);
5047 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
5048 ok( ret
, "HttpQueryInfoA failed %lu\n", GetLastError() );
5049 ok( status
== 200, "got %lu\n", status
);
5051 InternetCloseHandle( req
);
5052 InternetCloseHandle( con
);
5053 InternetCloseHandle( ses
);
5056 static void test_basic_auth_credentials_end_session(int port
)
5058 HINTERNET ses
, con
, req
;
5063 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
5064 ok( ses
!= NULL
, "InternetOpenA failed\n" );
5066 con
= InternetConnectA( ses
, "localhost", port
, "user", "pwd",
5067 INTERNET_SERVICE_HTTP
, 0, 0 );
5068 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
5070 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
5071 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
5073 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
5074 ok( ret
, "HttpSendRequestA failed %lu\n", GetLastError() );
5076 size
= sizeof(buffer
);
5077 SetLastError(0xdeadbeef);
5078 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_USERNAME
, buffer
, &size
);
5079 ok(ret
, "unexpected failure %lu\n", GetLastError());
5080 ok(!strcmp(buffer
, "user"), "got %s\n", buffer
);
5081 ok(size
== 4, "got %lu\n", size
);
5083 size
= sizeof(buffer
);
5084 SetLastError(0xdeadbeef);
5085 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_PASSWORD
, buffer
, &size
);
5086 ok(ret
, "unexpected failure %lu\n", GetLastError());
5087 ok(!strcmp(buffer
, "pwd"), "got %s\n", buffer
);
5088 ok(size
== 3, "got %lu\n", size
);
5090 status
= 0xdeadbeef;
5091 size
= sizeof(status
);
5092 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
5093 ok( ret
, "HttpQueryInfoA failed %lu\n", GetLastError() );
5094 ok( status
== HTTP_STATUS_OK
, "got %lu\n", status
);
5096 InternetCloseHandle( req
);
5097 InternetCloseHandle( con
);
5098 InternetCloseHandle( ses
);
5100 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
5101 ok( ses
!= NULL
, "InternetOpenA failed\n" );
5103 /* Clear the cached credentials */
5104 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_END_BROWSER_SESSION
, NULL
, 0);
5105 ok(ret
, "unexpected failure %lu\n", GetLastError());
5107 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
,
5108 INTERNET_SERVICE_HTTP
, 0, 0 );
5109 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
5111 req
= HttpOpenRequestA( con
, "PUT", "/upload2.txt", NULL
, NULL
, NULL
, 0, 0 );
5112 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
5114 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
5115 ok( ret
, "HttpSendRequestA failed %lu\n", GetLastError() );
5117 size
= sizeof(buffer
);
5118 SetLastError(0xdeadbeef);
5119 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_USERNAME
, buffer
, &size
);
5120 ok(ret
, "unexpected failure %lu\n", GetLastError());
5121 ok(!strcmp(buffer
, ""), "got %s\n", buffer
);
5122 ok(size
== 0, "got %lu\n", size
);
5124 size
= sizeof(buffer
);
5125 SetLastError(0xdeadbeef);
5126 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_PASSWORD
, buffer
, &size
);
5127 ok(ret
, "unexpected failure %lu\n", GetLastError());
5128 ok(!strcmp(buffer
, ""), "got %s\n", buffer
);
5129 ok(size
== 0, "got %lu\n", size
);
5131 status
= 0xdeadbeef;
5132 size
= sizeof(status
);
5133 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
5134 ok( ret
, "HttpQueryInfoA failed %lu\n", GetLastError() );
5135 ok( status
== HTTP_STATUS_BAD_REQUEST
, "got %lu\n", status
);
5137 InternetCloseHandle( req
);
5138 InternetCloseHandle( con
);
5139 InternetCloseHandle( ses
);
5142 static void test_basic_auth_credentials_different(int port
)
5144 HINTERNET ses
, con
, req
;
5149 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
5150 ok( ses
!= NULL
, "InternetOpenA failed\n" );
5152 con
= InternetConnectA( ses
, "localhost", port
, "user", "pwd",
5153 INTERNET_SERVICE_HTTP
, 0, 0 );
5154 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
5156 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
5157 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
5159 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
5160 ok( ret
, "HttpSendRequestA failed %lu\n", GetLastError() );
5162 size
= sizeof(buffer
);
5163 SetLastError(0xdeadbeef);
5164 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_USERNAME
, buffer
, &size
);
5165 ok(ret
, "unexpected failure %lu\n", GetLastError());
5166 ok(!strcmp(buffer
, "user"), "got %s\n", buffer
);
5167 ok(size
== 4, "got %lu\n", size
);
5169 size
= sizeof(buffer
);
5170 SetLastError(0xdeadbeef);
5171 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_PASSWORD
, buffer
, &size
);
5172 ok(ret
, "unexpected failure %lu\n", GetLastError());
5173 ok(!strcmp(buffer
, "pwd"), "got %s\n", buffer
);
5174 ok(size
== 3, "got %lu\n", size
);
5176 status
= 0xdeadbeef;
5177 size
= sizeof(status
);
5178 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
5179 ok( ret
, "HttpQueryInfoA failed %lu\n", GetLastError() );
5180 ok( status
== 200, "got %lu\n", status
);
5182 InternetCloseHandle( req
);
5183 InternetCloseHandle( con
);
5184 InternetCloseHandle( ses
);
5186 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
5187 ok( ses
!= NULL
, "InternetOpenA failed\n" );
5189 con
= InternetConnectA( ses
, "localhost", port
, "user1", "pwd1",
5190 INTERNET_SERVICE_HTTP
, 0, 0 );
5191 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
5193 req
= HttpOpenRequestA( con
, "HEAD", "/upload3.txt", NULL
, NULL
, NULL
, 0, 0 );
5194 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
5196 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
5197 ok( ret
, "HttpSendRequestA failed %lu\n", GetLastError() );
5199 size
= sizeof(buffer
);
5200 SetLastError(0xdeadbeef);
5201 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_USERNAME
, buffer
, &size
);
5202 ok(ret
, "unexpected failure %lu\n", GetLastError());
5203 ok(!strcmp(buffer
, "user1"), "got %s\n", buffer
);
5204 ok(size
== 5, "got %lu\n", size
);
5206 size
= sizeof(buffer
);
5207 SetLastError(0xdeadbeef);
5208 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_PASSWORD
, buffer
, &size
);
5209 ok(ret
, "unexpected failure %lu\n", GetLastError());
5210 ok(!strcmp(buffer
, "pwd1"), "got %s\n", buffer
);
5211 ok(size
== 4, "got %lu\n", size
);
5213 status
= 0xdeadbeef;
5214 size
= sizeof(status
);
5215 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
5216 ok( ret
, "HttpQueryInfoA failed %lu\n", GetLastError() );
5217 ok( status
== 200, "got %lu\n", status
);
5219 InternetCloseHandle( req
);
5220 InternetCloseHandle( con
);
5221 InternetCloseHandle( ses
);
5225 * Manually set the Authorization for both calls.
5227 static void test_basic_auth_credentials_manual(int port
)
5229 HINTERNET ses
, con
, req
;
5233 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
5234 ok( ses
!= NULL
, "InternetOpenA failed\n" );
5236 /* Clear the cached credentials */
5237 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_END_BROWSER_SESSION
, NULL
, 0);
5238 ok(ret
, "unexpected failure %lu\n", GetLastError());
5240 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0 );
5241 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
5243 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
5244 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
5246 /* Set Authorization Header */
5247 ret
= HttpAddRequestHeadersA(req
, "Authorization: Basic dXNlcjpwd2Q=\r\n", ~0u,
5248 HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDREQ_FLAG_ADD
);
5249 ok(ret
, "HttpAddRequestHeaders Failed\n");
5251 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
5252 ok( ret
, "HttpSendRequestA failed %lu\n", GetLastError() );
5254 status
= 0xdeadbeef;
5255 size
= sizeof(status
);
5256 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
5257 ok( ret
, "HttpQueryInfoA failed %lu\n", GetLastError() );
5258 ok( status
== 200, "got %lu\n", status
);
5260 InternetCloseHandle( req
);
5261 InternetCloseHandle( con
);
5262 InternetCloseHandle( ses
);
5264 /* Show manual headers are cached. */
5265 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
5266 ok( ses
!= NULL
, "InternetOpenA failed\n" );
5268 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0 );
5269 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
5271 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
5272 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
5274 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
5275 ok( ret
, "HttpSendRequestA failed %lu\n", GetLastError() );
5277 status
= 0xdeadbeef;
5278 size
= sizeof(status
);
5279 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
5280 ok( ret
, "HttpQueryInfoA failed %lu\n", GetLastError() );
5281 ok( status
== 401, "got %lu\n", status
);
5283 InternetCloseHandle( req
);
5284 InternetCloseHandle( con
);
5285 InternetCloseHandle( ses
);
5287 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
5288 ok( ses
!= NULL
, "InternetOpenA failed\n" );
5290 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0 );
5291 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
5293 req
= HttpOpenRequestA( con
, "HEAD", "/upload4.txt", NULL
, NULL
, NULL
, 0, 0 );
5294 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
5296 /* Set Authorization Header */
5297 ret
= HttpAddRequestHeadersA(req
, "Authorization: Bearer dXNlcjE6cHdkMQ==\r\n", ~0u,
5298 HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDREQ_FLAG_ADD
);
5299 ok(ret
, "HttpAddRequestHeaders Failed\n");
5301 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
5302 ok( ret
, "HttpSendRequestA failed %lu\n", GetLastError() );
5304 status
= 0xdeadbeef;
5305 size
= sizeof(status
);
5306 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
5307 ok( ret
, "HttpQueryInfoA failed %lu\n", GetLastError() );
5308 ok( status
== 200, "got %lu\n", status
);
5310 InternetCloseHandle( req
);
5311 InternetCloseHandle( con
);
5312 InternetCloseHandle( ses
);
5316 * Manually set the Authorization for the bearer call, which shows the cached is used.
5318 static void test_basic_auth_credentials_cached_manual(int port
)
5320 HINTERNET ses
, con
, req
;
5324 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
5325 ok( ses
!= NULL
, "InternetOpenA failed\n" );
5327 /* Clear the cached credentials */
5328 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_END_BROWSER_SESSION
, NULL
, 0);
5329 ok(ret
, "unexpected failure %lu\n", GetLastError());
5331 con
= InternetConnectA( ses
, "localhost", port
, "user", "pwd",
5332 INTERNET_SERVICE_HTTP
, 0, 0 );
5333 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
5335 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
5336 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
5338 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
5339 ok( ret
, "HttpSendRequestA failed %lu\n", GetLastError() );
5341 status
= 0xdeadbeef;
5342 size
= sizeof(status
);
5343 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
5344 ok( ret
, "HttpQueryInfoA failed %lu\n", GetLastError() );
5345 ok( status
== 200, "got %lu\n", status
);
5347 InternetCloseHandle( req
);
5348 InternetCloseHandle( con
);
5349 InternetCloseHandle( ses
);
5351 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
5352 ok( ses
!= NULL
, "InternetOpenA failed\n" );
5354 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0 );
5355 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
5357 req
= HttpOpenRequestA( con
, "HEAD", "/upload4.txt", NULL
, NULL
, NULL
, 0, 0 );
5358 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
5360 /* Setting an Authorization Header doesn't override the cached one. */
5361 ret
= HttpAddRequestHeadersA(req
, "Authorization: Bearer dXNlcjE6cHdkMQ==\r\n", ~0u,
5362 HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDREQ_FLAG_ADD
);
5363 ok(ret
, "HttpAddRequestHeaders Failed\n");
5365 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
5366 ok( ret
, "HttpSendRequestA failed %lu\n", GetLastError() );
5368 status
= 0xdeadbeef;
5369 size
= sizeof(status
);
5370 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
5371 ok( ret
, "HttpQueryInfoA failed %lu\n", GetLastError() );
5372 ok( status
== 201, "got %lu\n", status
);
5374 InternetCloseHandle( req
);
5375 InternetCloseHandle( con
);
5376 InternetCloseHandle( ses
);
5379 static void test_async_read(int port
)
5381 HINTERNET ses
, con
, req
;
5382 INTERNET_BUFFERSA ib
;
5384 DWORD pending_reads
;
5385 DWORD res
, count
, bytes
;
5390 /* test asynchronous InternetReadFileEx */
5391 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5392 ok( ses
!= NULL
, "InternetOpenA failed\n" );
5393 pInternetSetStatusCallbackA( ses
, &callback
);
5395 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
5396 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef );
5397 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
5398 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
5400 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
5401 req
= HttpOpenRequestA( con
, "GET", "/async_read", NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef );
5402 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
5403 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
5405 SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT
);
5406 SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY
);
5407 SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER
);
5408 SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER
);
5409 SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST
);
5410 SET_EXPECT( INTERNET_STATUS_REQUEST_SENT
);
5411 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
5412 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
5413 SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION
);
5414 SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED
);
5415 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
5417 SetLastError( 0xdeadbeef );
5418 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
5419 ok( !ret
, "HttpSendRequestA unexpectedly succeeded\n" );
5420 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %lu\n", GetLastError() );
5421 WaitForSingleObject( complete_event
, INFINITE
);
5422 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %lu\n", req_error
);
5424 CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT
);
5425 CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY
);
5426 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER
);
5427 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER
);
5428 CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST
);
5429 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT
);
5430 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
5431 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
5432 CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION
);
5433 CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED
);
5434 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
5437 memset( &ib
, 0, sizeof(ib
) );
5438 memset( buffer
, 0, sizeof(buffer
) );
5439 ib
.dwStructSize
= sizeof(ib
);
5440 for (count
= 0; count
< sizeof(buffer
); count
+= ib
.dwBufferLength
)
5442 ib
.lpvBuffer
= buffer
+ count
;
5443 ib
.dwBufferLength
= min(16, sizeof(buffer
) - count
);
5445 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
5446 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
5448 ret
= InternetReadFileExA( req
, &ib
, 0, 0xdeadbeef );
5449 if (!count
) /* the first part should arrive immediately */
5450 ok( ret
, "InternetReadFileExA failed %lu\n", GetLastError() );
5453 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %lu\n", GetLastError() );
5454 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
5455 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
5456 if (!pending_reads
++)
5458 res
= WaitForSingleObject( complete_event
, 0 );
5459 ok( res
== WAIT_TIMEOUT
, "expected WAIT_TIMEOUT, got %lu\n", res
);
5460 SetEvent( conn_wait_event
);
5462 res
= WaitForSingleObject( complete_event
, INFINITE
);
5463 ok( res
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %lu\n", res
);
5464 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %lu\n", req_error
);
5465 todo_wine_if( pending_reads
> 1 )
5466 ok( ib
.dwBufferLength
!= 0, "expected ib.dwBufferLength != 0\n" );
5467 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
5468 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
5471 CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
5472 CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
5473 if (!ib
.dwBufferLength
) break;
5476 ok( pending_reads
== 1, "expected 1 pending read, got %lu\n", pending_reads
);
5477 ok( !strcmp(buffer
, page1
), "unexpected buffer content\n" );
5478 close_async_handle( ses
, 2 );
5479 ResetEvent( conn_wait_event
);
5481 /* test asynchronous InternetReadFile */
5482 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5483 ok( ses
!= NULL
, "InternetOpenA failed\n" );
5484 pInternetSetStatusCallbackA( ses
, &callback
);
5486 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
5487 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef );
5488 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
5489 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
5491 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
5492 req
= HttpOpenRequestA( con
, "GET", "/async_read", NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef );
5493 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
5494 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
5496 SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT
);
5497 SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY
);
5498 SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER
);
5499 SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER
);
5500 SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST
);
5501 SET_EXPECT( INTERNET_STATUS_REQUEST_SENT
);
5502 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
5503 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
5504 SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION
);
5505 SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED
);
5506 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
5508 SetLastError( 0xdeadbeef );
5509 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
5510 ok( !ret
, "HttpSendRequestA unexpectedly succeeded\n" );
5511 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %lu\n", GetLastError() );
5512 WaitForSingleObject( complete_event
, INFINITE
);
5513 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %lu\n", req_error
);
5515 CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT
);
5516 CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY
);
5517 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER
);
5518 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER
);
5519 CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST
);
5520 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT
);
5521 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
5522 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
5523 CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION
);
5524 CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED
);
5525 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
5528 memset( buffer
, 0, sizeof(buffer
) );
5529 for (count
= 0; count
< sizeof(buffer
); count
+= bytes
)
5531 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
5532 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
5535 ret
= InternetReadFile( req
, buffer
+ count
, min(16, sizeof(buffer
) - count
), &bytes
);
5536 if (!count
) /* the first part should arrive immediately */
5537 ok( ret
, "InternetReadFile failed %lu\n", GetLastError() );
5540 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %lu\n", GetLastError() );
5541 ok( bytes
== 0, "expected 0, got %lu\n", bytes
);
5542 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
5543 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
5544 if (!pending_reads
++)
5546 res
= WaitForSingleObject( complete_event
, 0 );
5547 ok( res
== WAIT_TIMEOUT
, "expected WAIT_TIMEOUT, got %lu\n", res
);
5548 SetEvent( conn_wait_event
);
5550 res
= WaitForSingleObject( complete_event
, INFINITE
);
5551 ok( res
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %lu\n", res
);
5552 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %lu\n", req_error
);
5553 todo_wine_if( pending_reads
> 1 )
5554 ok( bytes
!= 0, "expected bytes != 0\n" );
5555 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
5556 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
5559 CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
5560 CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
5564 ok( pending_reads
== 1, "expected 1 pending read, got %lu\n", pending_reads
);
5565 ok( !strcmp(buffer
, page1
), "unexpected buffer content\n" );
5566 close_async_handle( ses
, 2 );
5569 static void server_send_string(const char *msg
)
5571 send(server_socket
, msg
, strlen(msg
), 0);
5574 static size_t server_read_data(char *buf
, size_t buf_size
)
5576 return recv(server_socket
, buf
, buf_size
, 0);
5579 #define server_read_request(a) _server_read_request(__LINE__,a)
5580 static void _server_read_request(unsigned line
, const char *expected_request
)
5585 size
= server_read_data(buf
, sizeof(buf
) - 1);
5587 p
= strstr(buf
, "\r\n");
5589 ok_(__FILE__
,line
)(p
&& !strcmp(buf
, expected_request
), "unexpected request %s\n", buf
);
5592 static BOOL skip_receive_notification_tests
;
5593 static DWORD received_response_size
;
5595 static void WINAPI
readex_callback(HINTERNET handle
, DWORD_PTR context
, DWORD status
, void *info
, DWORD info_size
)
5598 case INTERNET_STATUS_RECEIVING_RESPONSE
:
5599 if(!skip_receive_notification_tests
)
5600 callback(handle
, context
, status
, info
, info_size
);
5602 case INTERNET_STATUS_RESPONSE_RECEIVED
:
5603 if(!skip_receive_notification_tests
)
5604 callback(handle
, context
, status
, info
, info_size
);
5605 received_response_size
= *(DWORD
*)info
;
5607 case INTERNET_STATUS_REQUEST_SENT
:
5608 callback(handle
, context
, status
, info
, info_size
);
5609 SetEvent(request_sent_event
);
5612 callback(handle
, context
, status
, info
, info_size
);
5616 static void send_socket_request(test_request_t
*req
, BOOL new_connection
)
5620 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5621 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5622 if(new_connection
) {
5623 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5624 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5626 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5627 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5628 if(!skip_receive_notification_tests
)
5629 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5631 SetLastError(0xdeadbeef);
5632 ret
= HttpSendRequestA(req
->request
, NULL
, 0, NULL
, 0);
5633 ok(!ret
, "HttpSendRequestA unexpectedly succeeded\n");
5634 ok(GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %lu\n", GetLastError());
5637 WaitForSingleObject(server_req_rec_event
, INFINITE
);
5638 WaitForSingleObject(request_sent_event
, INFINITE
);
5640 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5641 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5642 if(new_connection
) {
5643 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5644 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5646 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5647 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5650 static void open_socket_request(int port
, test_request_t
*req
, const char *verb
)
5652 /* We're connecting to new socket */
5656 req
->session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5657 ok(req
->session
!= NULL
, "InternetOpenA failed\n");
5658 pInternetSetStatusCallbackA(req
->session
, readex_callback
);
5660 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5661 req
->connection
= InternetConnectA(req
->session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef);
5662 ok(req
->connection
!= NULL
, "InternetConnectA failed %lu\n", GetLastError());
5663 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5665 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5666 req
->request
= HttpOpenRequestA(req
->connection
, "GET", verb
? verb
: "/socket",
5667 NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef);
5668 ok(req
->request
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError());
5669 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
5671 send_socket_request(req
, !verb
);
5674 static void open_read_test_request(int port
, test_request_t
*req
, const char *response
)
5676 if(!skip_receive_notification_tests
)
5677 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5679 open_socket_request(port
, req
, NULL
);
5681 if(!skip_receive_notification_tests
) {
5682 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5683 received_response_size
= 0xdeadbeef;
5685 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5687 server_send_string(response
);
5688 WaitForSingleObject(complete_event
, INFINITE
);
5690 if(!skip_receive_notification_tests
) {
5691 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5692 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5694 ok(received_response_size
== strlen(response
), "received_response_size = %lu\n", received_response_size
);
5696 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5697 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %lu\n", req_error
);
5700 #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)
5701 static void _readex_expect_sync_data_len(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
5702 DWORD buf_size
, const char *exdata
, DWORD len
, DWORD expect_receive
)
5706 if(!skip_receive_notification_tests
&& expect_receive
) {
5707 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5708 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5709 received_response_size
= 0xdeadbeef;
5712 memset(buf
->lpvBuffer
, 0xff, buf_size
);
5713 buf
->dwBufferLength
= buf_size
;
5714 ret
= InternetReadFileExW(req
, buf
, flags
, 0xdeadbeef);
5715 ok_(__FILE__
,line
)(ret
, "InternetReadFileExW failed: %lu\n", GetLastError());
5716 ok_(__FILE__
,line
)(buf
->dwBufferLength
== len
, "dwBufferLength = %lu, expected %lu\n", buf
->dwBufferLength
, len
);
5718 ok_(__FILE__
,line
)(!memcmp(buf
->lpvBuffer
, exdata
, len
), "Unexpected data\n");
5720 if(!skip_receive_notification_tests
&& expect_receive
) {
5721 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5722 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5723 ok_(__FILE__
,line
)(received_response_size
== len
, "received_response_size = %lu\n", received_response_size
);
5727 #define readex_expect_sync_data(a,b,c,d,e,f) _readex_expect_sync_data(__LINE__,a,b,c,d,e,f)
5728 static void _readex_expect_sync_data(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
5729 DWORD buf_size
, const char *exdata
, DWORD expect_receive
)
5731 _readex_expect_sync_data_len(line
, req
, flags
, buf
, buf_size
, exdata
, strlen(exdata
), expect_receive
);
5734 #define read_expect_sync_data_len(a,b,c,d,e) _read_expect_sync_data_len(__LINE__,a,b,c,d,e)
5735 static void _read_expect_sync_data_len(unsigned line
, HINTERNET req
, void *buf
, DWORD buf_size
,
5736 const char *exdata
, DWORD len
)
5738 DWORD ret_size
= 0xdeadbeef;
5741 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5742 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5743 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5744 received_response_size
= 0xdeadbeef;
5746 memset(buf
, 0xff, buf_size
);
5747 ret
= InternetReadFile(req
, buf
, buf_size
, &ret_size
);
5748 ok_(__FILE__
,line
)(ret
, "InternetReadFileExW failed: %lu\n", GetLastError());
5749 ok_(__FILE__
,line
)(ret_size
== len
, "dwBufferLength = %lu, expected %lu\n", ret_size
, len
);
5751 ok_(__FILE__
,line
)(!memcmp(buf
, exdata
, len
), "Unexpected data\n");
5753 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5754 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5755 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5756 ok_(__FILE__
,line
)(received_response_size
== len
, "received_response_size = %lu\n", received_response_size
);
5757 ok_(__FILE__
,line
)(!req_error
, "req_error = %lu\n", req_error
);
5760 #define read_expect_sync_data(a,b,c,d) _read_expect_sync_data(__LINE__,a,b,c,d)
5761 static void _read_expect_sync_data(unsigned line
, HINTERNET req
, void *buf
,
5762 DWORD buf_size
, const char *exdata
)
5764 _read_expect_sync_data_len(line
, req
, buf
, buf_size
, exdata
, strlen(exdata
));
5767 static void close_connection(void)
5770 SetEvent(conn_wait_event
);
5771 recv(server_socket
, &c
, 1, 0);
5774 #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)
5775 static void _send_response_and_wait(unsigned line
, const char *response
, BOOL do_close_connection
,
5776 void *buf
, DWORD
*ret_size
, const char *exdata
,
5777 DWORD expected_size
, DWORD expected_req_error
, DWORD expected_receive_size
)
5779 if(!skip_receive_notification_tests
)
5780 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5781 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5784 server_send_string(response
);
5786 if(do_close_connection
)
5789 WaitForSingleObject(complete_event
, INFINITE
);
5791 if(!skip_receive_notification_tests
)
5792 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5793 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5794 if(!skip_receive_notification_tests
&& expected_receive_size
!= -1)
5795 todo_wine_if(received_response_size
!= expected_receive_size
) /* FIXME! remove when wine is fixed */
5796 ok_(__FILE__
,line
)(received_response_size
== expected_receive_size
,
5797 "received_response_size = %lu\n", received_response_size
);
5798 ok_(__FILE__
,line
)(req_error
== expected_req_error
, "req_error = %lu, expected %lu\n", req_error
, expected_req_error
);
5800 /* If IRF_NO_WAIT is used, buffer is not changed. */
5801 ok_(__FILE__
,line
)(*ret_size
== expected_size
, "dwBufferLength = %lu\n", *ret_size
);
5803 ok_(__FILE__
,line
)(!memcmp(buf
, exdata
, strlen(exdata
)), "unexpected buffer data\n");
5805 ok_(__FILE__
,line
)(!*(DWORD
*)buf
, "buffer data changed\n");
5808 #define send_response_ex_and_wait(a,b,c,d,e,f) _send_response_ex_and_wait(__LINE__,a,b,c,d,e,f)
5809 static void _send_response_ex_and_wait(unsigned line
, const char *response
, BOOL close_connection
,
5810 INTERNET_BUFFERSW
*buf
, const char *exdata
, DWORD expected_req_error
,
5811 DWORD expected_receive_size
)
5813 _send_response_and_wait(line
, response
, close_connection
, buf
->lpvBuffer
, &buf
->dwBufferLength
,
5814 exdata
, exdata
? strlen(exdata
) : buf
->dwBufferLength
, expected_req_error
,
5815 expected_receive_size
);
5818 static void send_response_len_and_wait(unsigned len
, BOOL close_connection
, INTERNET_BUFFERSW
*buf
)
5822 response
= HeapAlloc(GetProcessHeap(), 0, len
+1);
5823 memset(response
, 'x', len
);
5825 send_response_ex_and_wait(response
, close_connection
, buf
, NULL
, 0, -1);
5826 HeapFree(GetProcessHeap(), 0, response
);
5829 #define readex_expect_async(a,b,c,d,e) _readex_expect_async(__LINE__,a,b,c,d,e)
5830 static void _readex_expect_async(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
5831 DWORD buf_size
, const char *exdata
)
5836 if(!skip_receive_notification_tests
)
5837 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5839 memset(buf
->lpvBuffer
, 0, max(buf_size
, sizeof(DWORD
)));
5840 buf
->dwBufferLength
= buf_size
;
5841 ret
= InternetReadFileExW(req
, buf
, flags
, 0xdeadbeef);
5842 ok_(__FILE__
,line
)(!ret
&& GetLastError() == ERROR_IO_PENDING
, "InternetReadFileExW returned %x (%lu)\n", ret
, GetLastError());
5843 ok_(__FILE__
,line
)(buf
->dwBufferLength
== buf_size
, "dwBufferLength = %lu, expected %lu\n", buf
->dwBufferLength
, buf_size
);
5845 len
= strlen(exdata
);
5846 ok_(__FILE__
,line
)(!memcmp(buf
->lpvBuffer
, exdata
, len
), "unexpected buffer data\n");
5848 ok_(__FILE__
,line
)(!*(DWORD
*)buf
->lpvBuffer
, "buffer data changed\n");
5851 if(!skip_receive_notification_tests
)
5852 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5855 static void read_expect_async(HINTERNET req
, void *buf
, DWORD buf_size
, DWORD
*ret_size
, const char *exdata
)
5861 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5863 *ret_size
= 0xdeadbeef;
5864 memset(buf
, 0, buf_size
);
5865 ret
= InternetReadFile(req
, buf
, buf_size
, ret_size
);
5866 ok(!ret
&& GetLastError() == ERROR_IO_PENDING
, "InternetReadFileExW returned %x (%lu)\n", ret
, GetLastError());
5867 ok(*ret_size
== 0, "dwBufferLength = %lu\n", *ret_size
);
5869 len
= strlen(exdata
);
5870 ok(!memcmp(buf
, exdata
, len
), "unexpected buffer data\n");
5872 for(p
= (const char*)buf
+ len
; p
< (const char*)buf
+ buf_size
; p
++) {
5874 ok(0, "buffer data changed\n");
5877 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5880 #define expect_data_available(a,b) _expect_data_available(__LINE__,a,b)
5881 static DWORD
_expect_data_available(unsigned line
, HINTERNET req
, int exsize
)
5886 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
5887 ok_(__FILE__
,line
)(res
, "InternetQueryDataAvailable failed: %lu\n", GetLastError());
5889 ok_(__FILE__
,line
)(size
== exsize
, "size = %lu, expected %u\n", size
, exsize
);
5894 #define async_query_data_available(a,b) _async_query_data_available(__LINE__,a,b)
5895 static void _async_query_data_available(unsigned line
, HINTERNET req
, DWORD
*size
)
5899 if(!skip_receive_notification_tests
)
5900 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5903 res
= InternetQueryDataAvailable(req
, size
, 0, 0);
5904 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_IO_PENDING
,
5905 "InternetQueryDataAvailable returned: %x(%lu)\n", res
, GetLastError());
5906 ok_(__FILE__
,line
)(!*size
, "size = %lu\n", *size
);
5908 if(!skip_receive_notification_tests
)
5909 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5912 static void test_http_read(int port
)
5914 INTERNET_BUFFERSW ib
;
5923 memset(&ib
, 0, sizeof(ib
));
5924 ib
.dwStructSize
= sizeof(ib
);
5927 trace("Testing InternetReadFileExW with IRF_ASYNC flag...\n");
5929 open_read_test_request(port
, &req
,
5930 "HTTP/1.1 200 OK\r\n"
5931 "Server: winetest\r\n"
5935 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, 4, "xx");
5937 send_response_ex_and_wait("yy1234567890", FALSE
, &ib
, "xxyy", 0, 2);
5938 readex_expect_sync_data(req
.request
, IRF_ASYNC
, &ib
, 4, "1234", 4);
5939 readex_expect_sync_data(req
.request
, IRF_ASYNC
, &ib
, 5, "56789", 5);
5941 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, sizeof(buf
), "0");
5942 send_response_ex_and_wait("123", TRUE
, &ib
, "0123", 0, 4);
5944 close_async_handle(req
.session
, 2);
5946 trace("Testing InternetReadFileExW with no flags...\n");
5948 open_read_test_request(port
, &req
,
5949 "HTTP/1.1 200 OK\r\n"
5950 "Server: winetest\r\n"
5954 readex_expect_async(req
.request
, 0, &ib
, 4, "xx");
5956 send_response_ex_and_wait("yy1234567890", FALSE
, &ib
, "xxyy", 0, 2);
5957 readex_expect_sync_data(req
.request
, 0, &ib
, 4, "1234", 4);
5958 readex_expect_sync_data(req
.request
, 0, &ib
, 5, "56789", 5);
5960 readex_expect_async(req
.request
, 0, &ib
, sizeof(buf
), "0");
5961 send_response_ex_and_wait("123", TRUE
, &ib
, "0123", 0, 4);
5963 close_async_handle(req
.session
, 2);
5965 trace("Testing InternetReadFile...\n");
5967 open_read_test_request(port
, &req
,
5968 "HTTP/1.1 200 OK\r\n"
5969 "Server: winetest\r\n"
5973 read_expect_async(req
.request
, buf
, 4, &read_size
, "xx");
5975 send_response_and_wait("yy1234567890", FALSE
, buf
, &read_size
, "xxyy", 4, 0, 2);
5976 read_expect_sync_data(req
.request
, buf
, 4, "1234");
5977 read_expect_sync_data(req
.request
, buf
, 5, "56789");
5979 read_expect_async(req
.request
, buf
, sizeof(buf
), &read_size
, "0");
5980 send_response_and_wait("123", TRUE
, buf
, &read_size
, "0123", 4, 0, 4);
5982 close_async_handle(req
.session
, 2);
5984 trace("Testing InternetReadFileExW with IRF_NO_WAIT flag...\n");
5986 open_read_test_request(port
, &req
,
5987 "HTTP/1.1 200 OK\r\n"
5988 "Server: winetest\r\n"
5992 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
5994 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "xx", 0);
5996 if(notified
[INTERNET_STATUS_RECEIVING_RESPONSE
]) {
5997 win_skip("Skipping receive notification tests on too old Windows.\n");
5998 skip_receive_notification_tests
= TRUE
;
6000 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
6002 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
6003 send_response_ex_and_wait("1234567890", FALSE
, &ib
, NULL
, 0, 10);
6004 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, 5, "12345", 0);
6005 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "67890", 0);
6007 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
6008 send_response_ex_and_wait("12345", TRUE
, &ib
, NULL
, 0, 5);
6010 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "12345", 0);
6011 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "", TRUE
);
6013 close_async_handle(req
.session
, 2);
6015 open_read_test_request(port
, &req
,
6016 "HTTP/1.1 200 OK\r\n"
6017 "Server: winetest\r\n"
6018 "Transfer-Encoding: chunked\r\n"
6021 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123456789", 0);
6022 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
6024 send_response_ex_and_wait("\r\n1\r\na\r\n1\r\nb\r", FALSE
, &ib
, NULL
, 0, 13);
6025 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
6026 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
6028 send_response_ex_and_wait("\n3\r\nab", FALSE
, &ib
, NULL
, 0, 6);
6029 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
6030 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
6032 send_response_ex_and_wait("c", FALSE
, &ib
, NULL
, 0, 1);
6033 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "c", 0);
6034 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
6036 send_response_ex_and_wait("\r\n1\r\nx\r\n0\r\n\r\n", TRUE
, &ib
, NULL
, 0, 13);
6037 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "x", 0);
6038 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "", 0);
6040 close_async_handle(req
.session
, 2);
6042 open_read_test_request(port
, &req
,
6043 "HTTP/1.1 200 OK\r\n"
6044 "Server: winetest\r\n"
6045 "Transfer-Encoding: chunked\r\n"
6048 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123", 0);
6049 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
6051 send_response_ex_and_wait("0\r\n\r\n", TRUE
, &ib
, NULL
, 0, 5);
6052 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "", 0);
6054 close_async_handle(req
.session
, 2);
6056 open_read_test_request(port
, &req
,
6057 "HTTP/1.1 200 OK\r\n"
6058 "Server: winetest\r\n"
6059 "Connection: close\r\n"
6061 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
6062 send_response_ex_and_wait("123", TRUE
, &ib
, NULL
, 0, 3);
6063 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123", 0);
6065 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
6066 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
6067 close_async_handle(req
.session
, 2);
6068 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6069 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6071 trace("Testing InternetQueryDataAvailable...\n");
6073 open_read_test_request(port
, &req
,
6074 "HTTP/1.1 200 OK\r\n"
6075 "Server: winetest\r\n"
6078 expect_data_available(req
.request
, 3);
6079 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123", 0);
6080 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
6082 send_response_len_and_wait(20000, TRUE
, &ib
);
6083 avail
= expect_data_available(req
.request
, -1);
6084 ok(avail
<= 20000, "avail = %lu\n", avail
);
6086 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
6087 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
6088 close_async_handle(req
.session
, 2);
6089 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6090 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6092 open_read_test_request(port
, &req
,
6093 "HTTP/1.1 200 OK\r\n"
6094 "Server: winetest\r\n"
6095 "Connection: close\r\n"
6099 expect_data_available(req
.request
, 3);
6100 readex_expect_sync_data(req
.request
, 0, &ib
, 3, "123", 0);
6102 async_query_data_available(req
.request
, &read_size
);
6103 send_response_and_wait("1234567890", FALSE
, NULL
, &read_size
, NULL
, 10, 10, 10);
6105 readex_expect_sync_data(req
.request
, 0, &ib
, 9, "123456789", 0);
6106 expect_data_available(req
.request
, 1);
6107 readex_expect_sync_data(req
.request
, 0, &ib
, 1, "0", 0);
6109 async_query_data_available(req
.request
, &read_size
);
6110 send_response_and_wait("1234567890", FALSE
, NULL
, &read_size
, NULL
, 10, 10, 10);
6111 expect_data_available(req
.request
, 10);
6112 for(i
= 0; i
< 10; i
++)
6113 server_send_string("x");
6114 expect_data_available(req
.request
, 10);
6116 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, 21, "1234567890");
6117 send_response_ex_and_wait("X", FALSE
, &ib
, "1234567890xxxxxxxxxxX", 0, 11);
6118 async_query_data_available(req
.request
, &read_size
);
6120 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
6121 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
6122 send_response_and_wait(NULL
, TRUE
, NULL
, &read_size
, NULL
, 0, 0, 0);
6123 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6124 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6126 close_async_handle(req
.session
, 2);
6128 skip_receive_notification_tests
= FALSE
;
6131 static void test_file_pointer(int port
)
6133 INTERNET_BUFFERSW ib
;
6136 DWORD pos
, read_size
;
6138 skip_receive_notification_tests
= TRUE
;
6140 memset(&ib
, 0, sizeof(ib
));
6141 ib
.dwStructSize
= sizeof(ib
);
6144 open_read_test_request(port
, &req
,
6145 "HTTP/1.1 200 OK\r\n"
6146 "Server: winetest\r\n"
6147 "Content-Length: 100\r\n"
6151 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
6152 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "xyz", 0);
6153 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
6155 /* jump back to 2nd byte */
6156 pos
= InternetSetFilePointer(req
.request
, 2, NULL
, FILE_BEGIN
, 0);
6157 ok(pos
== 2, "pos = %ld (gle %lu)\n", pos
, GetLastError());
6159 expect_data_available(req
.request
, 1);
6160 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "z", 0);
6162 /* jump forward to 5th byte (not yet available) */
6163 pos
= InternetSetFilePointer(req
.request
, 5, NULL
, FILE_BEGIN
, 0);
6164 ok(pos
== 5, "pos = %ld (gle %lu)\n", pos
, GetLastError());
6166 /* querying available data will wait until we have enough data */
6167 async_query_data_available(req
.request
, &read_size
);
6168 send_response_and_wait("12345", FALSE
, NULL
, &read_size
, NULL
, 3, 3, 61);
6169 expect_data_available(req
.request
, 3);
6171 /* skip one byte and verify that we're at expected position by reading one byte */
6172 pos
= InternetSetFilePointer(req
.request
, 1, NULL
, FILE_CURRENT
, 0);
6173 ok(pos
== 6, "pos = %ld (gle %lu)\n", pos
, GetLastError());
6174 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, 1, "4", 0);
6176 /* jump past available bytes, read will wait for available data */
6177 pos
= InternetSetFilePointer(req
.request
, 2, NULL
, FILE_CURRENT
, 0);
6178 ok(pos
== 9, "pos = %ld (gle %lu)\n", pos
, GetLastError());
6180 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, 3, "");
6181 send_response_ex_and_wait("abcde", FALSE
, &ib
, "bcd", 0, 61);
6183 /* jump back to the beginning */
6184 pos
= InternetSetFilePointer(req
.request
, 0, NULL
, FILE_BEGIN
, 0);
6185 ok(pos
== 0, "pos = %ld (gle %lu)\n", pos
, GetLastError());
6186 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, 12, "xyz12345abcd", 0);
6188 /* jump past the available data then send more data and close the connection */
6189 pos
= InternetSetFilePointer(req
.request
, 3, NULL
, FILE_CURRENT
, 0);
6190 ok(pos
== 15, "pos = %ld (gle %lu)\n", pos
, GetLastError());
6191 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, sizeof(buf
), "");
6192 send_response_ex_and_wait("12345", TRUE
, &ib
, "345", 0, 61);
6194 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
6195 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
6196 close_async_handle(req
.session
, 2);
6198 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6200 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6202 skip_receive_notification_tests
= FALSE
;
6205 static void test_connection_break(int port
)
6207 INTERNET_BUFFERSW ib
;
6214 memset(&ib
, 0, sizeof(ib
));
6215 ib
.dwStructSize
= sizeof(ib
);
6218 trace("Testing InternetReadFileExW on broken connection...\n");
6220 open_read_test_request(port
, &req
,
6221 "HTTP/1.1 200 OK\r\n"
6222 "Server: winetest\r\n"
6223 "Content-Length: 10000\r\n"
6227 /* close connection and make sure that it's closed on handle release. */
6229 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
6230 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
6231 close_async_handle(req
.session
, 2);
6232 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6233 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6236 static void test_long_url(int port
)
6238 char long_path
[INTERNET_MAX_PATH_LENGTH
*2] = "/echo_request?";
6239 char buf
[sizeof(long_path
)*2], url
[sizeof(buf
)];
6247 memset(long_path
+strlen(long_path
), 'x', sizeof(long_path
)-strlen(long_path
));
6248 long_path
[sizeof(long_path
)-1] = 0;
6249 open_simple_request(&req
, "localhost", port
, NULL
, long_path
);
6251 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
6252 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
6253 test_status_code(req
.request
, 200);
6255 receive_simple_request(req
.request
, buf
, sizeof(buf
));
6256 ok(strstr(buf
, long_path
) != NULL
, "long pathnot found in %s\n", buf
);
6258 sprintf(url
, "http://localhost:%u%s", port
, long_path
);
6261 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_URL
, buf
, &size
);
6262 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %lu\n", GetLastError());
6264 ok(size
== len
, "size = %lu, expected %lu\n", size
, len
);
6265 ok(!strcmp(buf
, url
), "Wrong URL %s, expected %s\n", buf
, url
);
6267 close_request(&req
);
6270 static void test_persistent_connection(int port
)
6272 INTERNET_BUFFERSW ib
;
6279 memset(&ib
, 0, sizeof(ib
));
6280 ib
.dwStructSize
= sizeof(ib
);
6283 skip_receive_notification_tests
= TRUE
;
6285 trace("Testing persistent connection...\n");
6287 open_read_test_request(port
, &req
,
6288 "HTTP/1.1 200 OK\r\n"
6289 "Server: winetest\r\n"
6290 "Content-Length: 2\r\n"
6293 readex_expect_sync_data(req
.request
, IRF_ASYNC
, &ib
, 4, "xx", 0);
6294 close_async_handle(req
.session
, 2);
6296 open_socket_request(port
, &req
, "/test_simple_chunked");
6297 server_read_request("GET /test_simple_chunked HTTP/1.1");
6299 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6300 server_send_string("HTTP/1.1 200 OK\r\n"
6301 "Server: winetest\r\n"
6302 "Transfer-Encoding: chunked\r\n"
6305 WaitForSingleObject(complete_event
, INFINITE
);
6306 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6307 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %lu\n", req_error
);
6309 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
6310 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, sizeof(buf
), NULL
);
6311 send_response_ex_and_wait("3\r\nabc\r\n0\r\n\r\n", FALSE
, &ib
, "abc", 0, 13);
6312 close_async_handle(req
.session
, 2);
6314 open_socket_request(port
, &req
, "/chunked");
6315 server_read_request("GET /chunked HTTP/1.1");
6317 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6318 server_send_string("HTTP/1.1 200 OK\r\n"
6319 "Server: winetest\r\n"
6320 "Transfer-Encoding: chunked\r\n"
6323 WaitForSingleObject(complete_event
, INFINITE
);
6324 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6325 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %lu\n", req_error
);
6327 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, 3, "ab", 0);
6328 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, 3, NULL
);
6329 send_response_ex_and_wait("3\r\nabc\r\n", FALSE
, &ib
, "abc", 0, 13);
6331 /* send another request on the same request handle, it must drain remaining last chunk marker */
6332 server_send_string("0\r\n\r\n");
6334 send_socket_request(&req
, FALSE
);
6335 server_read_request("GET /chunked HTTP/1.1");
6337 ResetEvent(complete_event
);
6338 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6339 server_send_string("HTTP/1.1 201 OK\r\n"
6340 "Server: winetest\r\n"
6341 "Content-Length: 0\r\n"
6342 "Connection: keep-alive\r\n"
6344 WaitForSingleObject(complete_event
, INFINITE
);
6345 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6346 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %lu\n", req_error
);
6348 test_status_code(req
.request
, 201);
6349 close_async_handle(req
.session
, 2);
6351 /* the connection is still valid */
6352 open_socket_request(port
, &req
, "/another_chunked");
6353 server_read_request("GET /another_chunked HTTP/1.1");
6355 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6356 server_send_string("HTTP/1.1 200 OK\r\n"
6357 "Server: winetest\r\n"
6358 "Transfer-Encoding: chunked\r\n"
6361 WaitForSingleObject(complete_event
, INFINITE
);
6362 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6363 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %lu\n", req_error
);
6365 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
6366 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, sizeof(buf
), NULL
);
6368 /* we're missing trailing '\n'; the connection can't be drained without blocking,
6369 * so it will be closed */
6370 send_response_ex_and_wait("3\r\nabc\r\n0\r\n\r", FALSE
, &ib
, "abc", 0, 13);
6372 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
6373 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
6374 close_async_handle(req
.session
, 2);
6375 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6376 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6379 skip_receive_notification_tests
= FALSE
;
6382 static void test_redirect(int port
)
6384 char buf
[4000], expect_url
[INTERNET_MAX_URL_LENGTH
];
6385 INTERNET_BUFFERSW ib
;
6391 skip_receive_notification_tests
= TRUE
;
6393 memset(&ib
, 0, sizeof(ib
));
6394 ib
.dwStructSize
= sizeof(ib
);
6397 trace("Testing redirection...\n");
6399 open_socket_request(port
, &req
, NULL
);
6401 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
6402 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
6403 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
6404 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
6406 server_send_string("HTTP/1.1 302 Found\r\n"
6407 "Server: winetest\r\n"
6408 "Location: test_redirection\r\n"
6409 "Connection: keep-alive\r\n"
6410 "Content-Length: 0\r\n"
6413 server_read_request("GET /test_redirection HTTP/1.1");
6415 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
6417 sprintf(expect_url
, "http://localhost:%u/test_redirection", port
);
6418 test_request_url(req
.request
, expect_url
);
6420 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6422 server_send_string("HTTP/1.1 200 OK\r\n"
6423 "Server: winetest\r\n"
6424 "Content-Length: 3\r\n"
6428 WaitForSingleObject(complete_event
, INFINITE
);
6430 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
6431 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
6432 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
6433 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6434 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %lu\n", req_error
);
6436 test_status_code(req
.request
, 200);
6439 close_async_handle(req
.session
, 2);
6441 trace("Test redirect to non-http URL...\n");
6443 open_socket_request(port
, &req
, NULL
);
6445 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6447 server_send_string("HTTP/1.1 302 Found\r\n"
6448 "Server: winetest\r\n"
6449 "Location: test:non:http/url\r\n"
6450 "Connection: keep-alive\r\n"
6451 "Content-Length: 0\r\n"
6454 WaitForSingleObject(complete_event
, INFINITE
);
6456 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6457 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %lu\n", req_error
);
6459 sprintf(expect_url
, "http://localhost:%u/socket", port
);
6460 test_request_url(req
.request
, expect_url
);
6461 test_status_code(req
.request
, 302);
6464 close_async_handle(req
.session
, 2);
6466 trace("Test redirect to http URL with no host name...\n");
6468 open_socket_request(port
, &req
, NULL
);
6470 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6472 server_send_string("HTTP/1.1 302 Found\r\n"
6473 "Server: winetest\r\n"
6474 "Location: http:///nohost\r\n"
6475 "Connection: keep-alive\r\n"
6476 "Content-Length: 0\r\n"
6479 WaitForSingleObject(complete_event
, INFINITE
);
6481 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6482 ok(req_error
== ERROR_INTERNET_INVALID_URL
, "expected ERROR_INTERNET_INVALID_URL, got %lu\n", req_error
);
6484 sprintf(expect_url
, "http://localhost:%u/socket", port
);
6485 test_request_url(req
.request
, expect_url
);
6486 test_status_code(req
.request
, 302);
6489 close_async_handle(req
.session
, 2);
6491 skip_receive_notification_tests
= FALSE
;
6494 static void test_remove_dot_segments(int port
)
6499 open_simple_request(&req
, "localhost", port
, NULL
, "/A/../B/./C/../../test_remove_dot_segments");
6501 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
6502 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
6503 test_status_code(req
.request
, 200);
6505 close_request(&req
);
6510 DWORD64 content_length
;
6514 static void test_large_content(int port
)
6516 struct large_test tests
[] = {
6518 { UINT_MAX
-1, TRUE
},
6520 { (DWORD64
)UINT_MAX
+1, FALSE
},
6531 open_simple_request(&req
, "localhost", port
, "HEAD", "/test_large_content");
6533 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
6535 content_length
= tests
[i
].content_length
;
6536 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
6537 ok(ret
, "HttpSendRequest failed: %lu\n", GetLastError());
6540 sizelen
= sizeof(len
);
6541 SetLastError(0xdeadbeef);
6542 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
,
6546 ok(ret
, "HttpQueryInfo should have succeeded\n");
6547 ok(GetLastError() == ERROR_SUCCESS
||
6548 broken(GetLastError() == 0xdeadbeef), /* xp, 2k8, vista */
6549 "expected ERROR_SUCCESS, got %lx\n", GetLastError());
6550 ok(len
== (DWORD
)tests
[i
].content_length
, "expected %lu, got %lu\n",
6551 (DWORD
)tests
[i
].content_length
, len
);
6555 ok(!ret
, "HttpQueryInfo should have failed\n");
6556 ok(GetLastError() == ERROR_HTTP_INVALID_HEADER
,
6557 "expected ERROR_HTTP_INVALID_HEADER, got %lx\n", GetLastError());
6558 ok(len
== ~0, "expected ~0, got %lu\n", len
);
6560 ok(sizelen
== sizeof(DWORD
), "sizelen %lu\n", sizelen
);
6563 /* test argument size */
6565 sizelen
= sizeof(len64
);
6566 SetLastError(0xdeadbeef);
6567 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
,
6569 ok(!ret
, "HttpQueryInfo should have failed\n");
6570 ok(GetLastError() == ERROR_HTTP_INVALID_HEADER
,
6571 "expected ERROR_HTTP_INVALID_HEADER, got %lx\n", GetLastError());
6572 ok(sizelen
== sizeof(DWORD64
), "sizelen %lu\n", sizelen
);
6573 ok(len64
== ~0, "len64 %I64x\n", len64
);
6575 close_request(&req
);
6577 /* test internal use of HttpQueryInfo on large size */
6578 open_read_test_request(port
, &req
,
6579 "HTTP/1.1 200 OK\r\n"
6580 "Server: winetest\r\n"
6581 "Content-Length: 4294967296\r\n"
6584 read_expect_async(req
.request
, buf
, 4, &read_size
, "xx");
6585 send_response_and_wait("yy1234567890", FALSE
, buf
, &read_size
, "xxyy", 4, 0, 2);
6586 read_expect_sync_data(req
.request
, buf
, 10, "1234567890");
6588 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
6589 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
6590 close_async_handle(req
.session
, 2);
6591 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6592 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6596 static void test_header_length(int port
)
6601 char header
[] = "Test-Header: winetest";
6602 WCHAR wheader
[] = L
"Test-Header: winetest";
6603 INTERNET_BUFFERSA buffer_in
;
6604 INTERNET_BUFFERSW wbuffer_in
;
6606 open_simple_request(&req
, "localhost", port
, "GET", "/echo_request");
6608 ret
= HttpSendRequestA(req
.request
, header
, 0, NULL
, 0);
6609 ok(ret
== FALSE
, "HttpSendRequestA should have failed\n");
6610 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER\n");
6612 ret
= HttpSendRequestW(req
.request
, wheader
, 0, NULL
, 0);
6613 ok(ret
, "HttpSendRequestW failed: %lu\n", GetLastError());
6614 test_status_code(req
.request
, 200);
6616 receive_simple_request(req
.request
, buf
, sizeof(buf
));
6617 ok(strstr(buf
, header
) != NULL
, "custom header was not sent: %s\n", buf
);
6619 close_request(&req
);
6621 open_simple_request(&req
, "localhost", port
, "GET", "/echo_request");
6623 ZeroMemory(&buffer_in
, sizeof(buffer_in
));
6624 buffer_in
.dwStructSize
= sizeof(buffer_in
);
6625 buffer_in
.lpcszHeader
= header
;
6626 ret
= HttpSendRequestExA(req
.request
, &buffer_in
, NULL
, 0, 0);
6627 ok(ret
== FALSE
, "HttpSendRequestExA should have failed\n");
6628 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER\n");
6630 ZeroMemory(&wbuffer_in
, sizeof(wbuffer_in
));
6631 wbuffer_in
.dwStructSize
= sizeof(wbuffer_in
);
6632 wbuffer_in
.lpcszHeader
= wheader
;
6633 ret
= HttpSendRequestExW(req
.request
, &wbuffer_in
, NULL
, 0, 0);
6634 ok(ret
, "HttpSendRequestExW failed: %lu\n", GetLastError());
6636 ret
= HttpEndRequestW(req
.request
, NULL
, 0, 0);
6637 ok(ret
, "HttpEndRequestW failed: %lu\n", GetLastError());
6639 test_status_code(req
.request
, 200);
6641 receive_simple_request(req
.request
, buf
, sizeof(buf
));
6642 ok(strstr(buf
, header
) != NULL
, "custom header was not sent: %s\n", buf
);
6644 close_request(&req
);
6647 static void test_pac(int port
)
6649 static const WCHAR autoconf_url_fmt
[] = L
"http://localhost:%d/proxy.pac?ver=1";
6650 INTERNET_PER_CONN_OPTION_LISTW option_list
;
6651 INTERNET_PER_CONN_OPTIONW options
[2];
6652 WCHAR autoconf_url
[64];
6658 open_simple_request_proxy(&req
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, "GET", "/tests/hello.html");
6660 swprintf(autoconf_url
, ARRAY_SIZE(autoconf_url
), autoconf_url_fmt
, port
);
6661 memset(&option_list
, 0, sizeof(option_list
));
6662 option_list
.dwSize
= sizeof(option_list
);
6663 option_list
.dwOptionCount
= ARRAY_SIZE(options
);
6664 option_list
.pOptions
= options
;
6665 options
[0].dwOption
= INTERNET_PER_CONN_AUTOCONFIG_URL
;
6666 options
[0].Value
.pszValue
= autoconf_url
;
6667 options
[1].dwOption
= INTERNET_PER_CONN_FLAGS
;
6668 options
[1].Value
.dwValue
= PROXY_TYPE_AUTO_PROXY_URL
;
6669 r
= InternetSetOptionW(req
.session
, INTERNET_OPTION_PER_CONNECTION_OPTION
, (void*)&option_list
, sizeof(option_list
));
6670 ok(r
, "InternetSetOptionW failed: %lu\n", GetLastError());
6672 r
= HttpSendRequestW(req
.request
, NULL
, 0, NULL
, 0);
6673 ok(r
, "HttpSendRequestW failed: %lu\n", GetLastError());
6675 test_status_code(req
.request
, 200);
6676 len
= receive_simple_request(req
.request
, buf
, sizeof(buf
));
6678 ok(len
== sizeof(page1
) - 1, "unexpected buffer size\n");
6681 ok(!strcmp(buf
, page1
), "unexpected buffer content\n");
6683 len
= sizeof(option_list
);
6684 r
= InternetQueryOptionW(NULL
, INTERNET_OPTION_PER_CONNECTION_OPTION
, (void*)&option_list
, &len
);
6685 ok(r
, "InternetGetOptionW failed: %lu\n", GetLastError());
6686 r
= InternetSetOptionW(req
.session
, INTERNET_OPTION_PER_CONNECTION_OPTION
, (void*)&option_list
, sizeof(option_list
));
6687 ok(r
, "InternetSetOptionW failed: %lu\n", GetLastError());
6688 GlobalFree(options
[0].Value
.pszValue
);
6690 close_request(&req
);
6693 static void test_http_connection(void)
6695 struct server_info si
;
6699 si
.hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
6702 hThread
= CreateThread(NULL
, 0, server_thread
, &si
, 0, &id
);
6703 ok( hThread
!= NULL
, "create thread failed\n");
6705 r
= WaitForSingleObject(si
.hEvent
, 10000);
6706 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
6707 if (r
!= WAIT_OBJECT_0
)
6709 CloseHandle(hThread
);
6713 test_basic_request(si
.port
, "GET", "/test1");
6714 test_proxy_indirect(si
.port
);
6715 test_proxy_direct(si
.port
);
6716 test_header_handling_order(si
.port
);
6717 test_basic_request(si
.port
, "POST", "/test5");
6718 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
6719 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
6720 test_basic_request(si
.port
, "GET", "/test6");
6721 test_basic_request(si
.port
, "GET", "/testF");
6722 test_connection_header(si
.port
);
6723 test_header_override(si
.port
);
6724 test_cookie_header(si
.port
);
6725 test_basic_authentication(si
.port
);
6726 test_invalid_response_headers(si
.port
);
6727 test_response_without_headers(si
.port
);
6728 test_HttpQueryInfo(si
.port
);
6729 test_HttpSendRequestW(si
.port
);
6730 test_options(si
.port
);
6731 test_no_content(si
.port
);
6732 test_not_modified(si
.port
);
6733 test_large_header(si
.port
);
6734 test_conn_close(si
.port
);
6735 test_no_cache(si
.port
);
6736 test_cache_read_gzipped(si
.port
);
6737 test_http_status(si
.port
);
6738 test_premature_disconnect(si
.port
);
6739 test_connection_closing(si
.port
);
6740 test_cache_control_verb(si
.port
);
6741 test_successive_HttpSendRequest(si
.port
);
6742 test_head_request(si
.port
);
6743 test_request_content_length(si
.port
);
6744 test_accept_encoding(si
.port
);
6745 test_basic_auth_credentials_reuse(si
.port
);
6746 test_basic_auth_credentials_end_session(si
.port
);
6747 test_basic_auth_credentials_different(si
.port
);
6748 test_basic_auth_credentials_manual(si
.port
);
6749 test_basic_auth_credentials_cached_manual(si
.port
);
6750 test_async_read(si
.port
);
6751 test_http_read(si
.port
);
6752 test_file_pointer(si
.port
);
6753 test_connection_break(si
.port
);
6754 test_long_url(si
.port
);
6755 test_redirect(si
.port
);
6756 test_persistent_connection(si
.port
);
6757 test_remove_dot_segments(si
.port
);
6758 test_large_content(si
.port
);
6759 test_header_length(si
.port
);
6762 /* send the basic request again to shutdown the server thread */
6763 test_basic_request(si
.port
, "GET", "/quit");
6765 r
= WaitForSingleObject(hThread
, 3000);
6766 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
6767 CloseHandle(hThread
);
6770 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
6772 LocalFree(info
->lpszSubjectInfo
);
6773 LocalFree(info
->lpszIssuerInfo
);
6774 LocalFree(info
->lpszProtocolName
);
6775 LocalFree(info
->lpszSignatureAlgName
);
6776 LocalFree(info
->lpszEncryptionAlgName
);
6780 const char *ex_subject
;
6781 const char *ex_issuer
;
6782 } cert_struct_test_t
;
6784 static const cert_struct_test_t test_winehq_org_cert
= {
6792 static const cert_struct_test_t test_winehq_com_cert
= {
6798 "test.winehq.com\r\n"
6799 "webmaster@winehq.org",
6806 "test.winehq.com\r\n"
6807 "webmaster@winehq.org"
6810 static const char *cert_string_fmt
=
6811 "Subject:\r\n%s\r\n"
6813 "Effective Date:\t%s %s\r\n"
6814 "Expiration Date:\t%s %s\r\n"
6815 "Security Protocol:\t%s\r\n"
6816 "Signature Type:\t%s\r\n"
6817 "Encryption Type:\t%s\r\n"
6818 "Privacy Strength:\t%s (%u bits)";
6820 static void test_cert_struct_string(HINTERNET req
, const INTERNET_CERTIFICATE_INFOA
*info
)
6822 SYSTEMTIME start
, expiry
;
6823 char expiry_date
[32];
6824 char expiry_time
[32];
6825 char start_date
[32];
6826 char start_time
[32];
6832 size
= sizeof(actual
);
6833 SetLastError(0xdeadbeef);
6834 memset(actual
, 0x55, sizeof(actual
));
6835 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, actual
, &size
);
6836 ok(res
, "InternetQueryOption failed: %lu\n", GetLastError());
6838 FileTimeToSystemTime(&info
->ftStart
, &start
);
6839 FileTimeToSystemTime(&info
->ftExpiry
, &expiry
);
6841 GetDateFormatA(LOCALE_USER_DEFAULT
, 0, &start
, NULL
, start_date
, sizeof(start_date
));
6842 GetTimeFormatA(LOCALE_USER_DEFAULT
, 0, &start
, NULL
, start_time
, sizeof(start_time
));
6843 GetDateFormatA(LOCALE_USER_DEFAULT
, 0, &expiry
, NULL
, expiry_date
, sizeof(expiry_date
));
6844 GetTimeFormatA(LOCALE_USER_DEFAULT
, 0, &expiry
, NULL
, expiry_time
, sizeof(expiry_time
));
6846 snprintf(expect
, sizeof(expect
), cert_string_fmt
, info
->lpszSubjectInfo
, info
->lpszIssuerInfo
,
6847 start_date
, start_time
, expiry_date
, expiry_time
,
6848 info
->lpszSignatureAlgName
, info
->lpszEncryptionAlgName
, info
->lpszProtocolName
,
6849 info
->dwKeySize
>= 128 ? "High" : "Low", info
->dwKeySize
);
6850 ok(size
== strlen(actual
), "size = %lu\n", size
);
6851 ok(!strcmp(actual
, expect
), "expected:\n%s\nactual:\n%s\n", expect
, actual
);
6854 SetLastError(0xdeadbeef);
6855 memset(actual
, 0x55, sizeof(actual
));
6856 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, actual
, &size
);
6857 ok(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %ld\n", GetLastError());
6858 ok(size
== 1, "unexpected size: %lu\n", size
);
6859 ok(actual
[0] == 0x55, "unexpected byte: %02x\n", actual
[0]);
6862 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
6864 INTERNET_CERTIFICATE_INFOA info
;
6868 memset(&info
, 0x5, sizeof(info
));
6870 size
= sizeof(info
);
6871 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
6874 win_skip("Querying INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT failed, skipping tests\n");
6878 ok(res
, "InternetQueryOption failed: %lu\n", GetLastError());
6879 ok(size
== sizeof(info
), "size = %lu\n", size
);
6881 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
6882 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
6883 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
6884 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
6885 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
6886 ok(info
.dwKeySize
>= 128 && info
.dwKeySize
<= 256, "dwKeySize = %lu\n", info
.dwKeySize
);
6888 if (is_lang_english())
6889 test_cert_struct_string(req
, &info
);
6891 skip("Skipping tests that are English-only\n");
6892 release_cert_info(&info
);
6895 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
6896 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
6898 char url
[INTERNET_MAX_URL_LENGTH
];
6899 const CERT_CHAIN_CONTEXT
*chain
;
6903 if(!pInternetGetSecurityInfoByURLA
) {
6904 win_skip("pInternetGetSecurityInfoByURLA not available\n");
6909 chain
= (void*)0xdeadbeef;
6911 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
6912 if(error
== ERROR_SUCCESS
) {
6913 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %lu\n", GetLastError());
6914 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
6915 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %lx\n", flags
);
6916 CertFreeCertificateChain(chain
);
6918 SetLastError(0xdeadbeef);
6919 res
= pInternetGetSecurityInfoByURLA(url
, NULL
, NULL
);
6920 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
,
6921 "InternetGetSecurityInfoByURLA returned: %x(%lu)\n", res
, GetLastError());
6923 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, NULL
);
6924 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %lu\n", GetLastError());
6925 CertFreeCertificateChain(chain
);
6927 res
= pInternetGetSecurityInfoByURLA(url
, NULL
, &flags
);
6928 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %lu\n", GetLastError());
6930 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
6931 "InternetGetSecurityInfoByURLA returned: %x(%lu), expected %lu\n", res
, GetLastError(), error
);
6935 #define test_secflags_option(a,b,c) _test_secflags_option(__LINE__,a,b,c)
6936 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
, DWORD opt_flags
)
6942 size
= sizeof(flags
);
6943 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
6944 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %lu\n", GetLastError());
6945 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %lx, expected %lx\n",
6948 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
6950 size
= sizeof(flags
);
6951 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
6952 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %lu\n", GetLastError());
6953 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %lx, expected %lx\n",
6957 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
6958 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
6962 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
6963 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %lu\n", GetLastError());
6966 static void test_security_flags(void)
6968 INTERNET_CERTIFICATE_INFOA
*cert
;
6969 HINTERNET ses
, conn
, req
;
6976 win_skip("Can't make https connections, skipping security flags test\n");
6980 trace("Testing security flags...\n");
6983 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6984 ok(ses
!= NULL
, "InternetOpen failed\n");
6986 pInternetSetStatusCallbackA(ses
, &callback
);
6988 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
6989 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
6990 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
6991 ok(conn
!= NULL
, "InternetConnect failed with error %lu\n", GetLastError());
6992 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
6994 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
6995 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
6996 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
6998 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6999 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
7002 size
= sizeof(flags
);
7003 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
7004 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
7005 win_skip("Incomplete security flags support, skipping\n");
7007 close_async_handle(ses
, 2);
7011 test_secflags_option(req
, 0, 0);
7012 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
7014 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
7015 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
, 0);
7017 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
7018 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
7020 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
7021 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
7023 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
7024 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
7025 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %lu\n", GetLastError());
7027 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
7028 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
7029 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
7030 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
7031 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
7032 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
7033 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
7034 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
7035 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
7036 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
7037 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
7038 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
7039 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
7040 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
7041 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
7043 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
7044 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %lu\n", GetLastError());
7046 WaitForSingleObject(complete_event
, INFINITE
);
7047 ok(req_error
== ERROR_SUCCESS
, "req_error = %ld\n", req_error
);
7049 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
7050 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
7051 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
7052 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
7053 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
7054 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
7055 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
7056 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
7057 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
7058 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
7059 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
7060 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
7061 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
7063 test_request_flags(req
, 0);
7064 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
7065 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
, 0);
7067 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
7068 ok(res
, "InternetReadFile failed: %lu\n", GetLastError());
7069 ok(size
, "size = 0\n");
7071 /* Collect all existing persistent connections */
7072 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
7073 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %lu\n", GetLastError());
7075 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
7076 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
7077 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
7079 ok(req
!= NULL
, "HttpOpenRequest failed\n");
7080 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
7082 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
7083 res
= InternetSetOptionA(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
7084 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %lu\n", GetLastError());
7086 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
7087 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
7088 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
7089 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
7090 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
7091 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
7092 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
7093 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
7094 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
7095 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
7096 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
7098 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
7099 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %lu\n", GetLastError());
7101 WaitForSingleObject(complete_event
, INFINITE
);
7103 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
,
7104 "req_error = %ld\n", req_error
);
7107 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
7108 ok(res
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %ld\n", GetLastError());
7109 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %lu\n", size
);
7110 cert
= HeapAlloc(GetProcessHeap(), 0, size
);
7111 cert
->lpszSubjectInfo
= NULL
;
7112 cert
->lpszIssuerInfo
= NULL
;
7113 cert
->lpszSignatureAlgName
= (char *)0xdeadbeef;
7114 cert
->lpszEncryptionAlgName
= (char *)0xdeadbeef;
7115 cert
->lpszProtocolName
= (char *)0xdeadbeef;
7116 cert
->dwKeySize
= 0xdeadbeef;
7117 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, cert
, &size
);
7118 ok(res
, "InternetQueryOption failed: %lu\n", GetLastError());
7121 ok(cert
->lpszSubjectInfo
&& strlen(cert
->lpszSubjectInfo
) > 1, "expected a non-empty subject name\n");
7122 ok(cert
->lpszIssuerInfo
&& strlen(cert
->lpszIssuerInfo
) > 1, "expected a non-empty issuer name\n");
7123 ok(!cert
->lpszSignatureAlgName
, "unexpected signature algorithm name\n");
7124 ok(!cert
->lpszEncryptionAlgName
, "unexpected encryption algorithm name\n");
7125 ok(!cert
->lpszProtocolName
, "unexpected protocol name\n");
7126 ok(cert
->dwKeySize
!= 0xdeadbeef, "unexpected key size\n");
7128 LocalFree(cert
->lpszSubjectInfo
);
7129 LocalFree(cert
->lpszIssuerInfo
);
7131 HeapFree(GetProcessHeap(), 0, cert
);
7133 SetLastError(0xdeadbeef);
7134 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, NULL
, NULL
);
7135 ok(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
, "InternetQueryOption failed: %ld\n", GetLastError());
7138 SetLastError(0xdeadbeef);
7139 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, NULL
, &size
);
7140 ok(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %ld\n", GetLastError());
7141 ok(size
== 1, "unexpected size: %lu\n", size
);
7144 SetLastError(0xdeadbeef);
7145 memset(buf
, 0x55, sizeof(buf
));
7146 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, buf
, &size
);
7147 ok(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %ld\n", GetLastError());
7148 ok(size
== 1, "unexpected size: %lu\n", size
);
7149 ok(buf
[0] == 0x55, "unexpected byte: %02x\n", buf
[0]);
7152 SetLastError(0xdeadbeef);
7153 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, buf
, &size
);
7154 ok(res
&& GetLastError() == ERROR_SUCCESS
, "InternetQueryOption failed: %ld\n", GetLastError());
7155 ok(size
< sizeof(buf
), "unexpected size: %lu\n", size
);
7157 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
7158 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
7159 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
7160 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
7161 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
7162 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
7163 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
7165 if(req_error
!= ERROR_INTERNET_SEC_CERT_ERRORS
) {
7166 skip("Unexpected cert errors %lu, skipping security flags tests\n", req_error
);
7168 close_async_handle(ses
, 3);
7173 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
7174 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %lu\n", GetLastError());
7176 test_request_flags(req
, 8);
7177 /* IE11 finds both rev failure and invalid CA. Previous versions required rev failure
7178 to be ignored before invalid CA was reported. */
7179 test_secflags_option(req
, _SECURITY_FLAG_CERT_INVALID_CA
, _SECURITY_FLAG_CERT_REV_FAILED
);
7181 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
7182 test_secflags_option(req
, _SECURITY_FLAG_CERT_INVALID_CA
|SECURITY_FLAG_IGNORE_REVOCATION
, _SECURITY_FLAG_CERT_REV_FAILED
);
7184 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
7185 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
7186 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
7187 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
7188 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
7189 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
7190 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
7192 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
7193 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %lu\n", GetLastError());
7195 WaitForSingleObject(complete_event
, INFINITE
);
7196 ok(req_error
== ERROR_INTERNET_INVALID_CA
|| req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %ld\n", req_error
);
7198 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
7199 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
7200 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
7201 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
7202 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
7203 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
7204 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
7206 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
7207 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
7208 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
7210 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
7211 test_secflags_option(req
, _SECURITY_FLAG_CERT_INVALID_CA
7212 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
, 0);
7213 test_http_version(req
);
7215 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
7216 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
7217 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
7218 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
7219 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
7220 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
7221 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
7222 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
7223 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
7224 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
7225 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
7226 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
7227 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
7229 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
7230 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %lu\n", GetLastError());
7232 WaitForSingleObject(complete_event
, INFINITE
);
7233 ok(req_error
== ERROR_SUCCESS
, "req_error = %ld\n", req_error
);
7235 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
7236 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
7237 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
7238 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
7239 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
7240 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
7241 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
7242 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
7243 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
7244 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
7245 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
7247 test_request_flags(req
, 0);
7248 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
7249 |SECURITY_FLAG_STRENGTH_STRONG
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
7251 test_cert_struct(req
, &test_winehq_com_cert
);
7252 test_security_info("https://test.winehq.com/data/some_file.html?q", 0,
7253 _SECURITY_FLAG_CERT_INVALID_CA
);
7255 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
7256 ok(res
, "InternetReadFile failed: %lu\n", GetLastError());
7257 ok(size
, "size = 0\n");
7259 close_async_handle(ses
, 3);
7261 /* Collect all existing persistent connections */
7262 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
7263 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %lu\n", GetLastError());
7265 /* Make another request, without setting security flags */
7267 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
7268 ok(ses
!= NULL
, "InternetOpen failed\n");
7270 pInternetSetStatusCallbackA(ses
, &callback
);
7272 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
7273 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
7274 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
7275 ok(conn
!= NULL
, "InternetConnect failed with error %lu\n", GetLastError());
7276 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
7278 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
7279 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
7280 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
7282 ok(req
!= NULL
, "HttpOpenRequest failed\n");
7283 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
7285 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
7286 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
7287 test_http_version(req
);
7289 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
7290 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
7291 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
7292 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
7293 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
7294 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
7295 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
7296 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
7297 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
7298 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
7299 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
7300 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
7302 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
7303 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %lu\n", GetLastError());
7305 WaitForSingleObject(complete_event
, INFINITE
);
7306 ok(req_error
== ERROR_SUCCESS
, "req_error = %ld\n", req_error
);
7308 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
7309 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
7310 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
7311 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
7312 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
7313 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
7314 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
7315 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
7316 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
7317 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
7319 test_request_flags(req
, 0);
7320 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
7321 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
7323 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
7324 ok(res
, "InternetReadFile failed: %lu\n", GetLastError());
7325 ok(size
, "size = 0\n");
7327 close_async_handle(ses
, 2);
7329 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
7330 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
7331 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
7334 static void test_secure_connection(void)
7336 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
7337 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
7338 static const WCHAR get
[] = {'G','E','T',0};
7339 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
7340 HINTERNET ses
, con
, req
;
7341 DWORD size
, size2
, flags
, err
;
7342 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
7343 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
7344 char certstr1
[512], certstr2
[512];
7346 PCCERT_CHAIN_CONTEXT chain
;
7348 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
7349 ok(ses
!= NULL
, "InternetOpen failed\n");
7351 con
= InternetConnectA(ses
, "test.winehq.org",
7352 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
7353 INTERNET_SERVICE_HTTP
, 0, 0);
7354 ok(con
!= NULL
, "InternetConnect failed\n");
7356 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
7357 INTERNET_FLAG_SECURE
| INTERNET_FLAG_RELOAD
, 0);
7358 ok(req
!= NULL
, "HttpOpenRequest failed\n");
7360 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
7361 err
= GetLastError();
7362 ok(ret
|| broken(err
== ERROR_INTERNET_CANNOT_CONNECT
) ||
7363 broken(err
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
), "HttpSendRequest failed: %lu\n", err
);
7366 win_skip("Cannot connect to https.\n");
7367 if (err
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
) https_support
= FALSE
;
7371 size
= sizeof(flags
);
7372 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
7373 ok(ret
, "InternetQueryOption failed: %ld\n", GetLastError());
7374 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
7376 test_cert_struct(req
, &test_winehq_org_cert
);
7378 size
= sizeof(chain
);
7379 SetLastError(0xdeadbeef);
7380 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SERVER_CERT_CHAIN_CONTEXT
, &chain
, &size
);
7381 ok(ret
|| GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE
/* < IE8 */,
7382 "InternetQueryOption failed: %lu\n", GetLastError());
7383 if (ret
) CertFreeCertificateChain(chain
);
7385 /* Querying the same option through InternetQueryOptionW still results in
7386 * ANSI strings being returned.
7389 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
7391 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %ld\n", GetLastError());
7392 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %ld\n", size
);
7393 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
7394 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
7395 certificate_structW
, &size
);
7396 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
7397 ok(ret
, "InternetQueryOption failed: %ld\n", GetLastError());
7400 ok(certificate_structA
->lpszSubjectInfo
&&
7401 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
7402 "expected a non-empty subject name\n");
7403 ok(certificate_structA
->lpszIssuerInfo
&&
7404 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
7405 "expected a non-empty issuer name\n");
7406 ok(!certificate_structA
->lpszSignatureAlgName
,
7407 "unexpected signature algorithm name\n");
7408 ok(!certificate_structA
->lpszEncryptionAlgName
,
7409 "unexpected encryption algorithm name\n");
7410 ok(!certificate_structA
->lpszProtocolName
,
7411 "unexpected protocol name\n");
7412 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
7413 release_cert_info(certificate_structA
);
7415 HeapFree(GetProcessHeap(), 0, certificate_structW
);
7417 SetLastError(0xdeadbeef);
7418 size
= sizeof(certstr1
);
7419 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, certstr1
, &size
);
7420 ok(ret
&& GetLastError() == ERROR_SUCCESS
, "InternetQueryOption failed: %ld\n", GetLastError());
7422 SetLastError(0xdeadbeef);
7423 size2
= sizeof(certstr2
);
7424 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, certstr2
, &size2
);
7425 ok(ret
&& GetLastError() == ERROR_SUCCESS
, "InternetQueryOption failed: %ld\n", GetLastError());
7427 ok(size
== size2
, "expected same size\n");
7428 ok(!strcmp(certstr1
, certstr2
), "expected same string\n");
7430 InternetCloseHandle(req
);
7431 InternetCloseHandle(con
);
7432 InternetCloseHandle(ses
);
7434 /* Repeating the tests with the W functions has the same result: */
7435 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
7436 ok(ses
!= NULL
, "InternetOpen failed\n");
7438 con
= InternetConnectW(ses
, testsite
,
7439 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
7440 INTERNET_SERVICE_HTTP
, 0, 0);
7441 ok(con
!= NULL
, "InternetConnect failed\n");
7443 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
7444 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
7445 ok(req
!= NULL
, "HttpOpenRequest failed\n");
7447 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
7448 ok(ret
, "HttpSendRequest failed: %ld\n", GetLastError());
7450 size
= sizeof(flags
);
7451 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
7452 ok(ret
, "InternetQueryOption failed: %ld\n", GetLastError());
7453 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %lx\n", flags
);
7455 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
7457 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %ld\n", GetLastError());
7458 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %ld\n", size
);
7459 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
7460 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
7461 certificate_structA
, &size
);
7462 ok(ret
, "InternetQueryOption failed: %ld\n", GetLastError());
7465 ok(certificate_structA
->lpszSubjectInfo
&&
7466 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
7467 "expected a non-empty subject name\n");
7468 ok(certificate_structA
->lpszIssuerInfo
&&
7469 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
7470 "expected a non-empty issuer name\n");
7471 ok(!certificate_structA
->lpszSignatureAlgName
,
7472 "unexpected signature algorithm name\n");
7473 ok(!certificate_structA
->lpszEncryptionAlgName
,
7474 "unexpected encryption algorithm name\n");
7475 ok(!certificate_structA
->lpszProtocolName
,
7476 "unexpected protocol name\n");
7477 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
7478 release_cert_info(certificate_structA
);
7480 HeapFree(GetProcessHeap(), 0, certificate_structA
);
7482 /* Again, querying the same option through InternetQueryOptionW still
7483 * results in ASCII strings being returned.
7486 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
7488 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %ld\n", GetLastError());
7489 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %ld\n", size
);
7490 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
7491 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
7492 certificate_structW
, &size
);
7493 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
7494 ok(ret
, "InternetQueryOption failed: %ld\n", GetLastError());
7497 ok(certificate_structA
->lpszSubjectInfo
&&
7498 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
7499 "expected a non-empty subject name\n");
7500 ok(certificate_structA
->lpszIssuerInfo
&&
7501 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
7502 "expected a non-empty issuer name\n");
7503 ok(!certificate_structA
->lpszSignatureAlgName
,
7504 "unexpected signature algorithm name\n");
7505 ok(!certificate_structA
->lpszEncryptionAlgName
,
7506 "unexpected encryption algorithm name\n");
7507 ok(!certificate_structA
->lpszProtocolName
,
7508 "unexpected protocol name\n");
7509 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
7510 release_cert_info(certificate_structA
);
7512 HeapFree(GetProcessHeap(), 0, certificate_structW
);
7515 InternetCloseHandle(req
);
7516 InternetCloseHandle(con
);
7517 InternetCloseHandle(ses
);
7520 static void test_user_agent_header(void)
7522 HINTERNET ses
, con
, req
;
7527 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
7528 ok(ses
!= NULL
, "InternetOpen failed\n");
7530 con
= InternetConnectA(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
7531 ok(con
!= NULL
, "InternetConnect failed\n");
7533 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
7534 ok(req
!= NULL
, "HttpOpenRequest failed\n");
7536 size
= sizeof(buffer
);
7537 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
7538 err
= GetLastError();
7539 ok(!ret
, "HttpQueryInfo succeeded\n");
7540 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %lu\n", err
);
7542 ret
= HttpAddRequestHeadersA(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
7543 ok(ret
, "HttpAddRequestHeaders succeeded\n");
7545 size
= sizeof(buffer
);
7546 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
7547 err
= GetLastError();
7548 ok(ret
, "HttpQueryInfo failed\n");
7550 InternetCloseHandle(req
);
7552 req
= HttpOpenRequestA(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
7553 ok(req
!= NULL
, "HttpOpenRequest failed\n");
7555 size
= sizeof(buffer
);
7556 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
7557 err
= GetLastError();
7558 ok(!ret
, "HttpQueryInfo succeeded\n");
7559 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %lu\n", err
);
7561 ret
= HttpAddRequestHeadersA(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
7562 ok(ret
, "HttpAddRequestHeaders failed\n");
7565 size
= sizeof(buffer
);
7566 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
7567 ok(ret
, "HttpQueryInfo failed: %lu\n", GetLastError());
7568 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
7570 InternetCloseHandle(req
);
7571 InternetCloseHandle(con
);
7572 InternetCloseHandle(ses
);
7575 static void test_bogus_accept_types_array(void)
7577 HINTERNET ses
, con
, req
;
7578 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
7583 ses
= InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
7584 con
= InternetConnectA(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
7585 req
= HttpOpenRequestA(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
7587 ok(req
!= NULL
, "HttpOpenRequest failed: %lu\n", GetLastError());
7590 size
= sizeof(buffer
);
7591 SetLastError(0xdeadbeef);
7592 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
7593 error
= GetLastError();
7594 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
7595 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %lu\n", error
);
7596 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
7597 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
7598 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
7600 InternetCloseHandle(req
);
7601 InternetCloseHandle(con
);
7602 InternetCloseHandle(ses
);
7611 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
7613 INTERNET_ASYNC_RESULT
*result
= info
;
7614 struct context
*ctx
= (struct context
*)context
;
7616 if(winetest_debug
> 1)
7617 trace("%p 0x%08Ix %lu %p 0x%08lx\n", handle
, context
, status
, info
, size
);
7620 case INTERNET_STATUS_REQUEST_COMPLETE
:
7621 trace("request handle: 0x%08Ix\n", result
->dwResult
);
7622 ctx
->req
= (HINTERNET
)result
->dwResult
;
7623 SetEvent(ctx
->event
);
7625 case INTERNET_STATUS_HANDLE_CLOSING
: {
7626 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
7628 if (InternetQueryOptionA(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
7629 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
7630 SetEvent(ctx
->event
);
7633 case INTERNET_STATUS_NAME_RESOLVED
:
7634 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
7635 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
7637 ok(str
[0] && str
[1], "Got string: %s\n", str
);
7638 ok(size
== strlen(str
)+1, "unexpected size %lu\n", size
);
7643 static void test_open_url_async(void)
7651 /* Collect all existing persistent connections */
7652 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
7653 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %lu\n", GetLastError());
7656 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
7657 * other versions never do. They also hang of following tests. We disable it for everything older
7664 ctx
.event
= CreateEventA(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
7666 ses
= InternetOpenA("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
7667 ok(ses
!= NULL
, "InternetOpen failed\n");
7669 SetLastError(0xdeadbeef);
7670 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
7671 error
= GetLastError();
7672 ok(!ret
, "InternetSetOptionA succeeded\n");
7673 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %lu expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
7675 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
7676 error
= GetLastError();
7677 ok(!ret
, "InternetSetOptionA failed\n");
7678 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %lu expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
7680 pInternetSetStatusCallbackW(ses
, cb
);
7681 ResetEvent(ctx
.event
);
7683 req
= InternetOpenUrlA(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
7684 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
7686 WaitForSingleObject(ctx
.event
, INFINITE
);
7689 size
= sizeof(type
);
7690 ret
= InternetQueryOptionA(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
7691 ok(ret
, "InternetQueryOption failed: %lu\n", GetLastError());
7692 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
7693 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %lu\n", type
);
7696 ret
= HttpQueryInfoA(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
7697 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
7698 ok(size
> 0, "expected size > 0\n");
7700 ResetEvent(ctx
.event
);
7701 InternetCloseHandle(ctx
.req
);
7702 WaitForSingleObject(ctx
.event
, INFINITE
);
7704 InternetCloseHandle(ses
);
7705 CloseHandle(ctx
.event
);
7710 internet_connect
= 1,
7712 http_send_request_ex
,
7715 internet_close_handle
7720 enum api function
; /* api responsible for notification */
7721 unsigned int status
; /* status received */
7722 BOOL async
; /* delivered from another thread? */
7730 const struct notification
*test
;
7736 DWORD expect_result
;
7740 static CRITICAL_SECTION notification_cs
;
7742 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
7744 BOOL status_ok
, function_ok
;
7745 struct info
*info
= (struct info
*)context
;
7748 EnterCriticalSection( ¬ification_cs
);
7750 if(info
->is_aborted
) {
7751 LeaveCriticalSection(¬ification_cs
);
7755 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
7757 DWORD size
= sizeof(struct info
*);
7758 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
7759 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
7760 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
7762 ok(buflen
== sizeof(*ar
), "unexpected buflen = %ld\n", buflen
);
7763 if(info
->expect_result
== ERROR_SUCCESS
) {
7764 ok(ar
->dwResult
== 1, "ar->dwResult = %Id, expected 1\n", ar
->dwResult
);
7766 ok(!ar
->dwResult
, "ar->dwResult = %Id, expected 1\n", ar
->dwResult
);
7767 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %ld, expected %ld\n", ar
->dwError
, info
->expect_result
);
7772 if (i
>= info
->count
)
7774 LeaveCriticalSection( ¬ification_cs
);
7778 while (info
->test
[i
].status
!= status
&&
7779 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
7780 i
< info
->count
- 1 &&
7781 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
7786 status_ok
= (info
->test
[i
].status
== status
);
7787 function_ok
= (info
->test
[i
].function
== info
->function
);
7789 if (!info
->test
[i
].todo
)
7791 ok( status_ok
, "%u: expected status %u got %lu\n", info
->line
, info
->test
[i
].status
, status
);
7792 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
7794 if (info
->test
[i
].async
)
7795 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %lu got %lu\n",
7796 info
->line
, info
->thread
, GetCurrentThreadId());
7800 todo_wine
ok( status_ok
, "%u: expected status %u got %lu\n", info
->line
, info
->test
[i
].status
, status
);
7802 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
7804 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
7807 LeaveCriticalSection( ¬ification_cs
);
7810 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
7812 info
->function
= function
;
7814 info
->expect_result
= expect_result
;
7817 struct notification_data
7819 const struct notification
*test
;
7820 const unsigned int count
;
7825 BOOL expect_conn_failure
;
7828 static const struct notification async_send_request_ex_test
[] =
7830 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
7831 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
7832 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
7833 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
7834 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
7835 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
7836 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
7837 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
7838 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
7839 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
7840 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7841 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, FALSE
},
7842 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, FALSE
},
7843 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
7844 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
7845 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7846 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
7847 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
7848 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
7849 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
7852 static const struct notification async_send_request_ex_test2
[] =
7854 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
7855 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
7856 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
7857 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
7858 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
7859 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
7860 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
7861 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
7862 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
7863 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
7864 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7865 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
7866 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
7867 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7868 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
7869 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
7870 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
7871 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
7874 static const struct notification async_send_request_ex_resolve_failure_test
[] =
7876 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
7877 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
7878 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
7879 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
},
7880 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
7881 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7882 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7883 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
7884 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
7885 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
7886 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
7889 static const struct notification async_send_request_ex_chunked_test
[] =
7891 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
},
7892 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
},
7893 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
7894 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
7895 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
7896 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
7897 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
7898 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
7899 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
7900 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
7901 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7902 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
7903 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
7904 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
7905 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
7906 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
7907 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
},
7908 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
}
7911 static const struct notification_data notification_data
[] = {
7913 async_send_request_ex_chunked_test
,
7914 ARRAY_SIZE(async_send_request_ex_chunked_test
),
7920 async_send_request_ex_test
,
7921 ARRAY_SIZE(async_send_request_ex_test
),
7925 "Public ID=codeweavers"
7928 async_send_request_ex_test2
,
7929 ARRAY_SIZE(async_send_request_ex_test2
),
7935 async_send_request_ex_resolve_failure_test
,
7936 ARRAY_SIZE(async_send_request_ex_resolve_failure_test
),
7945 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
7948 HINTERNET ses
, req
, con
;
7950 DWORD size
, written
, error
;
7951 INTERNET_BUFFERSA b
;
7952 static const char *accept
[2] = {"*/*", NULL
};
7955 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
7957 /* Collect all existing persistent connections */
7958 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
7959 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %lu\n", GetLastError());
7961 InitializeCriticalSection( ¬ification_cs
);
7963 info
.test
= nd
->test
;
7964 info
.count
= nd
->count
;
7966 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
7967 info
.thread
= GetCurrentThreadId();
7968 info
.is_aborted
= FALSE
;
7970 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
7971 ok( ses
!= NULL
, "InternetOpen failed\n" );
7973 pInternetSetStatusCallbackA( ses
, check_notification
);
7975 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
7976 con
= InternetConnectA( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
7977 ok( con
!= NULL
, "InternetConnect failed %lu\n", GetLastError() );
7979 WaitForSingleObject( info
.wait
, 10000 );
7981 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
7982 req
= HttpOpenRequestA( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
7983 ok( req
!= NULL
, "HttpOpenRequest failed %lu\n", GetLastError() );
7985 WaitForSingleObject( info
.wait
, 10000 );
7988 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
7989 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
7990 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
7991 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
7992 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
7995 setup_test( &info
, http_send_request_ex
, __LINE__
,
7996 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
7997 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
7998 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %lu\n", ret
, GetLastError() );
8000 error
= WaitForSingleObject( info
.wait
, 10000 );
8001 if(error
!= WAIT_OBJECT_0
) {
8002 skip("WaitForSingleObject returned %ld, assuming DNS problem\n", error
);
8003 info
.is_aborted
= TRUE
;
8007 size
= sizeof(buffer
);
8008 SetLastError( 0xdeadbeef );
8009 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
8010 error
= GetLastError();
8011 ok( !ret
, "HttpQueryInfoA failed %lu\n", GetLastError() );
8012 if(nd
->expect_conn_failure
) {
8013 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %lu\n", error
);
8016 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
8017 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %lu\n", error
);
8023 size
= strlen( nd
->data
);
8024 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
8025 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
8026 ok( ret
, "InternetWriteFile failed %lu\n", GetLastError() );
8027 ok( written
== size
, "expected %lu got %lu\n", written
, size
);
8029 WaitForSingleObject( info
.wait
, 10000 );
8031 SetLastError( 0xdeadbeef );
8032 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
8033 error
= GetLastError();
8034 ok( !ret
, "HttpEndRequestA succeeded\n" );
8035 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %lu\n", error
);
8038 SetLastError( 0xdeadbeef );
8039 setup_test( &info
, http_end_request
, __LINE__
,
8040 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
8041 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
8042 error
= GetLastError();
8043 ok( !ret
, "HttpEndRequestA succeeded\n" );
8044 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %lu\n", error
);
8046 WaitForSingleObject( info
.wait
, 10000 );
8048 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
8050 InternetCloseHandle( req
);
8051 InternetCloseHandle( con
);
8052 InternetCloseHandle( ses
);
8054 WaitForSingleObject( info
.wait
, 10000 );
8056 CloseHandle( info
.wait
);
8057 DeleteCriticalSection( ¬ification_cs
);
8060 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
8061 static BOOL closetest_closed
;
8063 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
8064 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
8069 if(winetest_debug
> 1)
8070 trace("closetest_callback %p: %ld\n", hInternet
, dwInternetStatus
);
8072 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
8073 "Unexpected hInternet %p\n", hInternet
);
8074 if(!closetest_closed
)
8078 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
8079 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
8080 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %lu, expected TRUE ERROR_INVALID_HANDLE\n",
8081 closetest_req
, res
, GetLastError());
8084 static void test_InternetCloseHandle(void)
8089 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
8090 ok(closetest_session
!= NULL
,"InternetOpen failed with error %lu\n", GetLastError());
8092 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
8094 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
8095 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
8096 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %lu\n", GetLastError());
8098 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
8099 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
8101 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
8102 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
8103 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
8105 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
8107 res
= InternetCloseHandle(closetest_session
);
8108 ok(res
, "InternetCloseHandle failed: %lu\n", GetLastError());
8109 closetest_closed
= TRUE
;
8110 trace("Closed session handle\n");
8112 res
= InternetCloseHandle(closetest_conn
);
8113 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %lu\n",
8114 res
, GetLastError());
8116 res
= InternetCloseHandle(closetest_req
);
8117 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %lu\n",
8118 res
, GetLastError());
8120 len
= sizeof(flags
);
8121 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
8122 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
8123 "InternetQueryOptionA(%p INTERNET_OPTION_REQUEST_FLAGS) failed: %x %lu, expected TRUE ERROR_INVALID_HANDLE\n",
8124 closetest_req
, res
, GetLastError());
8127 static void test_connection_failure(void)
8133 open_simple_request(&req
, "localhost", 1, NULL
, "/");
8135 SetLastError(0xdeadbeef);
8136 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
8137 error
= GetLastError();
8138 ok(!ret
, "unexpected success\n");
8139 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %lu\n", error
);
8141 close_request(&req
);
8144 static void test_default_service_port(void)
8146 HINTERNET session
, connect
, request
;
8154 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
8155 ok(session
!= NULL
, "InternetOpen failed\n");
8157 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
8158 INTERNET_SERVICE_HTTP
, 0, 0);
8159 ok(connect
!= NULL
, "InternetConnect failed\n");
8161 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
8162 ok(request
!= NULL
, "HttpOpenRequest failed\n");
8164 SetLastError(0xdeadbeef);
8165 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
8166 error
= GetLastError();
8167 ok(!ret
, "HttpSendRequest succeeded\n");
8168 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
8169 "got %lu\n", error
);
8171 size
= sizeof(buffer
);
8172 memset(buffer
, 0, sizeof(buffer
));
8173 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
8174 ok(ret
, "HttpQueryInfo failed with error %lu\n", GetLastError());
8175 ok(!strcmp(buffer
, "test.winehq.org:80"), "Expected test.winehg.org:80, got '%s'\n", buffer
);
8177 InternetCloseHandle(request
);
8178 InternetCloseHandle(connect
);
8180 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
8181 INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
8182 ok(connect
!= NULL
, "InternetConnect failed\n");
8184 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
8185 ok(request
!= NULL
, "HttpOpenRequest failed\n");
8187 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
8188 if (!ret
&& GetLastError() == ERROR_INTERNET_SECURITY_CHANNEL_ERROR
)
8190 win_skip("Can't make https connection\n");
8193 ok(ret
, "HttpSendRequest failed with error %lu\n", GetLastError());
8195 size
= sizeof(buffer
);
8196 memset(buffer
, 0, sizeof(buffer
));
8197 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
8198 ok(ret
, "HttpQueryInfo failed with error %lu\n", GetLastError());
8199 ok(!strcmp(buffer
, "test.winehq.org"), "Expected test.winehg.org, got '%s'\n", buffer
);
8201 InternetCloseHandle(request
);
8202 InternetCloseHandle(connect
);
8204 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
8205 INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
8206 ok(connect
!= NULL
, "InternetConnect failed\n");
8208 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
8209 ok(request
!= NULL
, "HttpOpenRequest failed\n");
8211 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
8212 ok(ret
, "HttpSendRequest failed with error %lu\n", GetLastError());
8214 size
= sizeof(buffer
);
8215 memset(buffer
, 0, sizeof(buffer
));
8216 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
8217 ok(ret
, "HttpQueryInfo failed with error %lu\n", GetLastError());
8218 ok(!strcmp(buffer
, "test.winehq.org:443"), "Expected test.winehg.org:443, got '%s'\n", buffer
);
8221 InternetCloseHandle(request
);
8222 InternetCloseHandle(connect
);
8223 InternetCloseHandle(session
);
8226 static void init_status_tests(void)
8228 memset(expect
, 0, sizeof(expect
));
8229 memset(optional
, 0, sizeof(optional
));
8230 memset(wine_allow
, 0, sizeof(wine_allow
));
8231 memset(notified
, 0, sizeof(notified
));
8232 memset(status_string
, 0, sizeof(status_string
));
8234 #define STATUS_STRING(status) status_string[status] = #status
8235 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
8236 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
8237 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
8238 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
8239 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
8240 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
8241 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
8242 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
8243 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
8244 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
8245 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
8246 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
8247 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
8248 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
8249 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
8250 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
8251 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
8252 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
8253 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
8254 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
8255 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
8256 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
8257 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
8258 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
8259 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
8260 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
8261 #undef STATUS_STRING
8264 static void WINAPI
header_cb( HINTERNET handle
, DWORD_PTR ctx
, DWORD status
, LPVOID info
, DWORD len
)
8270 if (status
== INTERNET_STATUS_SENDING_REQUEST
)
8272 ret
= HttpAddRequestHeadersA( handle
, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD
);
8273 ok( ret
, "HttpAddRequestHeadersA failed %lu\n", GetLastError() );
8274 SetEvent( (HANDLE
)ctx
);
8276 else if (status
== INTERNET_STATUS_REQUEST_SENT
)
8280 ret
= HttpQueryInfoA( handle
, HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
8281 buf
, &size
, &index
);
8282 ok( ret
, "HttpQueryInfoA failed %lu\n", GetLastError() );
8283 ok( strstr( buf
, "winetest: winetest" ) != NULL
, "header missing\n" );
8284 SetEvent( (HANDLE
)ctx
);
8288 static void test_concurrent_header_access(void)
8290 HINTERNET ses
, con
, req
;
8293 HANDLE wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
8295 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
8296 ok( ses
!= NULL
, "InternetOpenA failed\n" );
8298 con
= InternetConnectA( ses
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
8299 INTERNET_SERVICE_HTTP
, 0, 0 );
8300 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
8302 req
= HttpOpenRequestA( con
, NULL
, "/", NULL
, NULL
, NULL
, 0, (DWORD_PTR
)wait
);
8303 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
8305 pInternetSetStatusCallbackA( req
, header_cb
);
8307 SetLastError( 0xdeadbeef );
8308 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
8309 err
= GetLastError();
8310 ok( !ret
, "HttpSendRequestA succeeded\n" );
8311 ok( err
== ERROR_IO_PENDING
, "got %u\n", ERROR_IO_PENDING
);
8313 WaitForSingleObject( wait
, 5000 );
8314 WaitForSingleObject( wait
, 5000 );
8316 InternetCloseHandle( req
);
8317 InternetCloseHandle( con
);
8318 InternetCloseHandle( ses
);
8319 CloseHandle( wait
);
8322 static void test_cert_string(void)
8324 HINTERNET ses
, con
, req
;
8328 PCCERT_CHAIN_CONTEXT chain
;
8330 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, 0 );
8331 ok( ses
!= NULL
, "InternetOpenA failed\n" );
8333 con
= InternetConnectA( ses
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
8334 INTERNET_SERVICE_HTTP
, 0, 0 );
8335 ok( con
!= NULL
, "InternetConnectA failed %lu\n", GetLastError() );
8337 req
= HttpOpenRequestA( con
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0 );
8338 ok( req
!= NULL
, "HttpOpenRequestA failed %lu\n", GetLastError() );
8340 size
= sizeof(actual
);
8341 SetLastError( 0xdeadbeef );
8342 memset( actual
, 0x55, sizeof(actual
) );
8343 res
= InternetQueryOptionA( req
, INTERNET_OPTION_SECURITY_CERTIFICATE
, actual
, &size
);
8344 ok( !res
&& GetLastError() == ERROR_INTERNET_INVALID_OPERATION
,
8345 "InternetQueryOption failed: %lu\n", GetLastError() );
8346 ok( size
== 0, "unexpected size: %lu\n", size
);
8347 ok( actual
[0] == 0x55, "unexpected byte: %02x\n", actual
[0] );
8349 size
= sizeof(chain
);
8350 SetLastError(0xdeadbeef);
8351 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SERVER_CERT_CHAIN_CONTEXT
, &chain
, &size
);
8352 ok(!res
&& (GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_STATE
),
8353 "InternetQueryOption failed: %lu\n", GetLastError());
8355 InternetCloseHandle( req
);
8356 InternetCloseHandle( con
);
8357 InternetCloseHandle( ses
);
8363 hdll
= GetModuleHandleA("wininet.dll");
8365 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
8366 win_skip("Too old IE (older than 6.0)\n");
8370 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
8371 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
8372 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
8374 if(!pInternetGetSecurityInfoByURLA
) {
8376 win_skip("IE6 found. It's too old for some tests.\n");
8380 init_status_tests();
8381 test_InternetCloseHandle();
8382 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
8383 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
8384 InternetReadFile_test(0, &test_data
[1]);
8385 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
8386 test_secure_connection();
8387 test_security_flags();
8388 InternetReadFile_test(0, &test_data
[2]);
8389 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
8390 test_open_url_async();
8391 test_async_HttpSendRequestEx(¬ification_data
[0]);
8392 test_async_HttpSendRequestEx(¬ification_data
[1]);
8393 test_async_HttpSendRequestEx(¬ification_data
[2]);
8394 test_async_HttpSendRequestEx(¬ification_data
[3]);
8395 InternetOpenRequest_test();
8397 InternetLockRequestFile_test();
8398 InternetOpenUrlA_test();
8400 test_http_connection();
8401 test_user_agent_header();
8402 test_bogus_accept_types_array();
8403 InternetReadFile_chunked_test();
8404 HttpSendRequestEx_test();
8405 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
8406 InternetSetFilePointer_test("test.winehq.org", "/tests/hello.html");
8407 test_connection_failure();
8408 test_default_service_port();
8409 test_concurrent_header_access();