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
;
46 /* Adapted from dlls/urlmon/tests/protocol.c */
48 #define SET_EXPECT2(status, num) \
51 #define SET_EXPECT(status) \
52 SET_EXPECT2(status, 1)
54 #define SET_OPTIONAL2(status, num) \
55 optional[status] = num
57 #define SET_OPTIONAL(status) \
58 SET_OPTIONAL2(status, 1)
60 /* SET_WINE_ALLOW's should be used with an appropriate
61 * todo_wine CHECK_NOTIFIED at a later point in the code */
62 #define SET_WINE_ALLOW2(status, num) \
63 wine_allow[status] = num
65 #define SET_WINE_ALLOW(status) \
66 SET_WINE_ALLOW2(status, 1)
68 #define CHECK_EXPECT(status) \
70 if (!expect[status] && !optional[status] && wine_allow[status]) \
72 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
73 status < MAX_INTERNET_STATUS && status_string[status] ? \
74 status_string[status] : "unknown"); \
75 wine_allow[status]--; \
79 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
80 status < MAX_INTERNET_STATUS && status_string[status] ? \
81 status_string[status] : "unknown"); \
82 if (expect[status]) expect[status]--; \
83 else if(optional[status]) optional[status]--; \
88 /* CLEAR_NOTIFIED used in cases when notification behavior
89 * differs between Windows versions */
90 #define CLEAR_NOTIFIED(status) \
91 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
93 #define CHECK_NOTIFIED2(status, num) \
95 ok(notified[status] + optional[status] == (num), \
96 "expected status %d (%s) %d times, received %d times\n", \
97 status, status < MAX_INTERNET_STATUS && status_string[status] ? \
98 status_string[status] : "unknown", (num), notified[status]); \
99 CLEAR_NOTIFIED(status); \
102 #define CHECK_NOTIFIED(status) \
103 CHECK_NOTIFIED2(status, 1)
105 #define CHECK_NOT_NOTIFIED(status) \
106 CHECK_NOTIFIED2(status, 0)
108 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
109 static int expect
[MAX_INTERNET_STATUS
], optional
[MAX_INTERNET_STATUS
],
110 wine_allow
[MAX_INTERNET_STATUS
], notified
[MAX_INTERNET_STATUS
];
111 static const char *status_string
[MAX_INTERNET_STATUS
];
113 static HANDLE complete_event
, conn_close_event
, conn_wait_event
, server_req_rec_event
, request_sent_event
;
114 static DWORD req_error
;
115 static BOOL is_ie7plus
= TRUE
;
117 #define TESTF_REDIRECT 0x01
118 #define TESTF_COMPRESSED 0x02
119 #define TESTF_CHUNKED 0x04
123 const char *redirected_url
;
128 const char *post_data
;
132 static const test_data_t test_data
[] = {
134 "http://test.winehq.org/tests/data.php",
135 "http://test.winehq.org/tests/data.php",
142 "http://test.winehq.org/tests/redirect",
143 "http://test.winehq.org/tests/hello.html",
150 "http://test.winehq.org/tests/gzip.php",
151 "http://test.winehq.org/tests/gzip.php",
154 "Accept-Encoding: gzip, deflate",
158 "http://test.winehq.org/tests/post.php",
159 "http://test.winehq.org/tests/post.php",
162 "Content-Type: application/x-www-form-urlencoded",
169 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackA
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
170 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackW
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
171 static BOOL (WINAPI
*pInternetGetSecurityInfoByURLA
)(LPSTR
,PCCERT_CHAIN_CONTEXT
*,DWORD
*);
173 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
176 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, ARRAY_SIZE(buf
));
177 return lstrcmpW(strw
, buf
);
180 static BOOL
proxy_active(void)
182 HKEY internet_settings
;
186 if (RegOpenKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
187 0, KEY_QUERY_VALUE
, &internet_settings
) != ERROR_SUCCESS
)
190 size
= sizeof(DWORD
);
191 if (RegQueryValueExA(internet_settings
, "ProxyEnable", NULL
, NULL
, (LPBYTE
) &proxy_enable
, &size
) != ERROR_SUCCESS
)
194 RegCloseKey(internet_settings
);
196 return proxy_enable
!= 0;
199 static void init_events(void)
201 complete_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
202 conn_close_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
203 conn_wait_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
204 server_req_rec_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
205 request_sent_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
208 static void free_events(void)
210 CloseHandle(complete_event
);
211 CloseHandle(conn_close_event
);
212 CloseHandle(conn_wait_event
);
213 CloseHandle(server_req_rec_event
);
214 CloseHandle(request_sent_event
);
217 static void reset_events(void)
219 ResetEvent(complete_event
);
220 ResetEvent(conn_close_event
);
221 ResetEvent(conn_wait_event
);
222 ResetEvent(server_req_rec_event
);
223 ResetEvent(request_sent_event
);
226 #define test_status_code(a,b) _test_status_code(__LINE__,a,b, FALSE)
227 #define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)
228 static void _test_status_code(unsigned line
, HINTERNET req
, DWORD excode
, BOOL is_todo
)
230 DWORD code
, size
, index
;
231 char exbuf
[12], bufa
[10];
237 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, NULL
);
238 ok_(__FILE__
,line
)(res
, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
239 todo_wine_if (is_todo
)
240 ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
241 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
246 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
247 ok_(__FILE__
,line
)(res
, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
248 ok_(__FILE__
,line
)(!index
, "index = %d, expected 0\n", index
);
249 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
251 sprintf(exbuf
, "%u", excode
);
254 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, bufa
, &size
, NULL
);
255 ok_(__FILE__
,line
)(res
, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
256 todo_wine_if (is_todo
)
257 ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
258 ok_(__FILE__
,line
)(size
== strlen(exbuf
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
261 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
262 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
263 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
264 ok_(__FILE__
,line
)(size
== strlen(exbuf
)+1, "unexpected size %d for \"%s\"\n", size
, exbuf
);
267 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
268 ok_(__FILE__
,line
)(res
, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
269 todo_wine_if (is_todo
)
270 ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
271 ok_(__FILE__
,line
)(size
== strlen(exbuf
)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
274 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
275 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
276 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
277 ok_(__FILE__
,line
)(size
== (strlen(exbuf
)+1)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
281 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
282 ok(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
283 ok(size
== sizeof(bufw
), "unexpected size %d\n", size
);
289 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
290 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
291 "[7] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
295 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, &code
, &size
, NULL
);
296 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST
,
297 "[8] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
300 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
301 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
302 static void _test_request_flags(unsigned line
, HINTERNET req
, DWORD exflags
, BOOL is_todo
)
308 size
= sizeof(flags
);
309 res
= InternetQueryOptionW(req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &size
);
310 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
312 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
313 flags
&= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED
;
314 todo_wine_if (is_todo
)
315 ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
318 #define test_request_url(a,b) _test_request_url(__LINE__,a,b)
319 static void _test_request_url(unsigned line
, HINTERNET req
, const char *expected_url
)
321 char buf
[INTERNET_MAX_URL_LENGTH
];
322 DWORD size
= sizeof(buf
);
325 res
= InternetQueryOptionA(req
, INTERNET_OPTION_URL
, buf
, &size
);
326 ok_(__FILE__
,line
)(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
327 ok_(__FILE__
,line
)(size
== strlen(expected_url
), "size = %u\n", size
);
328 ok_(__FILE__
,line
)(!strcmp(buf
, expected_url
), "unexpected URL %s, expected %s\n", buf
, expected_url
);
331 #define test_http_version(a) _test_http_version(__LINE__,a)
332 static void _test_http_version(unsigned line
, HINTERNET req
)
334 HTTP_VERSION_INFO v
= {0xdeadbeef, 0xdeadbeef};
339 res
= InternetQueryOptionW(req
, INTERNET_OPTION_HTTP_VERSION
, &v
, &size
);
340 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
341 ok_(__FILE__
,line
)(v
.dwMajorVersion
== 1, "dwMajorVersion = %d\n", v
.dwMajorVersion
);
342 ok_(__FILE__
,line
)(v
.dwMinorVersion
== 1, "dwMinorVersion = %d\n", v
.dwMinorVersion
);
345 static int close_handle_cnt
;
347 static VOID WINAPI
callback(
350 DWORD dwInternetStatus
,
351 LPVOID lpvStatusInformation
,
352 DWORD dwStatusInformationLength
355 CHECK_EXPECT(dwInternetStatus
);
356 switch (dwInternetStatus
)
358 case INTERNET_STATUS_RESOLVING_NAME
:
359 if(winetest_debug
> 1)
360 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
361 GetCurrentThreadId(), hInternet
, dwContext
,
362 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
363 *(LPSTR
)lpvStatusInformation
= '\0';
365 case INTERNET_STATUS_NAME_RESOLVED
:
366 if(winetest_debug
> 1)
367 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
368 GetCurrentThreadId(), hInternet
, dwContext
,
369 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
370 *(LPSTR
)lpvStatusInformation
= '\0';
372 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
373 if(winetest_debug
> 1)
374 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
375 GetCurrentThreadId(), hInternet
, dwContext
,
376 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
377 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
378 dwStatusInformationLength
);
379 *(LPSTR
)lpvStatusInformation
= '\0';
381 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
382 if(winetest_debug
> 1)
383 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
384 GetCurrentThreadId(), hInternet
, dwContext
,
385 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
386 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
387 dwStatusInformationLength
);
388 *(LPSTR
)lpvStatusInformation
= '\0';
390 case INTERNET_STATUS_SENDING_REQUEST
:
391 if(winetest_debug
> 1)
392 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
393 GetCurrentThreadId(), hInternet
, dwContext
,
394 lpvStatusInformation
,dwStatusInformationLength
);
396 case INTERNET_STATUS_REQUEST_SENT
:
397 ok(dwStatusInformationLength
== sizeof(DWORD
),
398 "info length should be sizeof(DWORD) instead of %d\n",
399 dwStatusInformationLength
);
400 if(winetest_debug
> 1)
401 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
402 GetCurrentThreadId(), hInternet
, dwContext
,
403 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
405 case INTERNET_STATUS_RECEIVING_RESPONSE
:
406 if(winetest_debug
> 1)
407 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
408 GetCurrentThreadId(), hInternet
, dwContext
,
409 lpvStatusInformation
,dwStatusInformationLength
);
411 case INTERNET_STATUS_RESPONSE_RECEIVED
:
412 ok(dwStatusInformationLength
== sizeof(DWORD
),
413 "info length should be sizeof(DWORD) instead of %d\n",
414 dwStatusInformationLength
);
415 if(winetest_debug
> 1)
416 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
417 GetCurrentThreadId(), hInternet
, dwContext
,
418 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
420 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
421 if(winetest_debug
> 1)
422 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
423 GetCurrentThreadId(), hInternet
,dwContext
,
424 lpvStatusInformation
,dwStatusInformationLength
);
426 case INTERNET_STATUS_PREFETCH
:
427 if(winetest_debug
> 1)
428 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
429 GetCurrentThreadId(), hInternet
, dwContext
,
430 lpvStatusInformation
,dwStatusInformationLength
);
432 case INTERNET_STATUS_CLOSING_CONNECTION
:
433 if(winetest_debug
> 1)
434 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
435 GetCurrentThreadId(), hInternet
, dwContext
,
436 lpvStatusInformation
,dwStatusInformationLength
);
438 case INTERNET_STATUS_CONNECTION_CLOSED
:
439 if(winetest_debug
> 1)
440 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
441 GetCurrentThreadId(), hInternet
, dwContext
,
442 lpvStatusInformation
,dwStatusInformationLength
);
444 case INTERNET_STATUS_HANDLE_CREATED
:
445 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
446 "info length should be sizeof(HINTERNET) instead of %d\n",
447 dwStatusInformationLength
);
448 if(winetest_debug
> 1)
449 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
450 GetCurrentThreadId(), hInternet
, dwContext
,
451 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
452 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
453 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
455 case INTERNET_STATUS_HANDLE_CLOSING
:
456 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
457 "info length should be sizeof(HINTERNET) instead of %d\n",
458 dwStatusInformationLength
);
459 if(winetest_debug
> 1)
460 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
461 GetCurrentThreadId(), hInternet
, dwContext
,
462 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
463 if(!InterlockedDecrement(&close_handle_cnt
))
464 SetEvent(complete_event
);
466 case INTERNET_STATUS_REQUEST_COMPLETE
:
468 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
469 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
470 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
471 dwStatusInformationLength
);
472 ok(iar
->dwResult
== 1 || iar
->dwResult
== 0, "iar->dwResult = %ld\n", iar
->dwResult
);
473 if(winetest_debug
> 1)
474 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
475 GetCurrentThreadId(), hInternet
, dwContext
,
476 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
477 req_error
= iar
->dwError
;
478 if(!close_handle_cnt
)
479 SetEvent(complete_event
);
482 case INTERNET_STATUS_REDIRECT
:
483 if(winetest_debug
> 1)
484 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
485 GetCurrentThreadId(), hInternet
, dwContext
,
486 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
487 *(LPSTR
)lpvStatusInformation
= '\0';
488 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
489 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
491 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
492 if(winetest_debug
> 1)
493 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
494 GetCurrentThreadId(), hInternet
, dwContext
,
495 lpvStatusInformation
, dwStatusInformationLength
);
498 if(winetest_debug
> 1)
499 trace("%04x:Callback %p 0x%lx %d %p %d\n",
500 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
501 lpvStatusInformation
, dwStatusInformationLength
);
507 HINTERNET connection
;
511 #define open_simple_request(a,b,c,d,e) _open_simple_request(__LINE__,a,b,c,d,e)
512 static void _open_simple_request(unsigned line
, test_request_t
*req
, const char *host
,
513 int port
, const char *verb
, const char *url
)
515 req
->session
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
516 ok_(__FILE__
,line
)(req
->session
!= NULL
, "InternetOpenA failed: %u\n", GetLastError());
518 req
->connection
= InternetConnectA(req
->session
, host
, port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
519 ok_(__FILE__
,line
)(req
->connection
!= NULL
, "InternetConnectA failed: %u\n", GetLastError());
521 req
->request
= HttpOpenRequestA(req
->connection
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
522 ok_(__FILE__
,line
)(req
->request
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
525 #define close_request(a) _close_request(__LINE__,a)
526 static void _close_request(unsigned line
, test_request_t
*req
)
530 ret
= InternetCloseHandle(req
->request
);
531 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(request) failed: %u\n", GetLastError());
532 ret
= InternetCloseHandle(req
->connection
);
533 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(connection) failed: %u\n", GetLastError());
534 ret
= InternetCloseHandle(req
->session
);
535 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(session) failed: %u\n", GetLastError());
538 #define receive_simple_request(a,b,c) _receive_simple_request(__LINE__,a,b,c)
539 static DWORD
_receive_simple_request(unsigned line
, HINTERNET req
, char *buf
, size_t buf_size
)
544 ret
= InternetReadFile(req
, buf
, buf_size
, &read
);
545 ok_(__FILE__
,line
)(ret
, "InternetReadFile failed: %u\n", GetLastError());
550 static void close_async_handle(HINTERNET handle
, int handle_cnt
)
554 close_handle_cnt
= handle_cnt
;
556 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
557 res
= InternetCloseHandle(handle
);
558 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
559 WaitForSingleObject(complete_event
, INFINITE
);
560 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
563 static void InternetReadFile_test(int flags
, const test_data_t
*test
)
565 char *post_data
= NULL
;
566 BOOL res
, on_async
= TRUE
;
569 DWORD length
, length2
, index
, exlen
= 0, post_len
= 0;
570 const char *types
[2] = { "*", NULL
};
571 HINTERNET hi
, hic
= 0, hor
= 0;
573 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags
,test
->url
);
576 trace("InternetOpenA <--\n");
577 hi
= InternetOpenA((test
->flags
& TESTF_COMPRESSED
) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
578 INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
579 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
580 trace("InternetOpenA -->\n");
582 if (hi
== 0x0) goto abort
;
584 pInternetSetStatusCallbackA(hi
,&callback
);
586 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
588 trace("InternetConnectA <--\n");
589 hic
=InternetConnectA(hi
, test
->host
, INTERNET_INVALID_PORT_NUMBER
,
590 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
591 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
592 trace("InternetConnectA -->\n");
594 if (hic
== 0x0) goto abort
;
596 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
597 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
599 trace("HttpOpenRequestA <--\n");
600 hor
= HttpOpenRequestA(hic
, test
->post_data
? "POST" : "GET", test
->path
, NULL
, NULL
, types
,
601 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
603 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
605 * If the internet name can't be resolved we are probably behind
606 * a firewall or in some other way not directly connected to the
607 * Internet. Not enough reason to fail the test. Just ignore and
611 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
613 trace("HttpOpenRequestA -->\n");
615 if (hor
== 0x0) goto abort
;
617 test_request_flags(hor
, INTERNET_REQFLAG_NO_HEADERS
);
618 test_request_url(hor
, test
->url
);
620 length
= sizeof(buffer
);
621 res
= HttpQueryInfoA(hor
, HTTP_QUERY_RAW_HEADERS
, buffer
, &length
, 0x0);
622 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
623 ok(length
== 0 || (length
== 1 && !*buffer
) /* win10 */, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length
);
624 ok(!strcmp(buffer
, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer
);
626 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
627 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
628 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
629 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
,2);
630 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED
,2);
631 if (first_connection_to_test_url
)
633 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
634 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
636 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
637 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
638 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
639 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
640 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
641 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
642 if(test
->flags
& TESTF_REDIRECT
) {
643 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
644 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
646 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
647 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
648 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
649 if (flags
& INTERNET_FLAG_ASYNC
)
650 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
652 if(test
->flags
& TESTF_COMPRESSED
) {
655 res
= InternetSetOptionA(hor
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
656 ok(res
|| broken(!res
&& GetLastError() == ERROR_INTERNET_INVALID_OPTION
),
657 "InternetSetOption failed: %u\n", GetLastError());
662 test_status_code(hor
, 0);
664 trace("HttpSendRequestA -->\n");
665 if(test
->post_data
) {
666 post_len
= strlen(test
->post_data
);
667 post_data
= HeapAlloc(GetProcessHeap(), 0, post_len
);
668 memcpy(post_data
, test
->post_data
, post_len
);
670 SetLastError(0xdeadbeef);
671 res
= HttpSendRequestA(hor
, test
->headers
, -1, post_data
, post_len
);
672 if (flags
& INTERNET_FLAG_ASYNC
)
673 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
674 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
676 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
677 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
678 trace("HttpSendRequestA <--\n");
680 if (flags
& INTERNET_FLAG_ASYNC
) {
681 WaitForSingleObject(complete_event
, INFINITE
);
682 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
684 HeapFree(GetProcessHeap(), 0, post_data
);
686 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
687 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED
);
688 if (first_connection_to_test_url
)
690 if (! proxy_active())
692 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
693 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
697 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
698 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
703 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
704 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
706 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
707 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
708 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
709 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
710 if(test
->flags
& TESTF_REDIRECT
)
711 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
712 if (flags
& INTERNET_FLAG_ASYNC
)
713 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
714 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
715 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
716 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
718 test_request_flags(hor
, 0);
721 res
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
722 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
724 length
= sizeof(buffer
)-2;
725 memset(buffer
, 0x77, sizeof(buffer
));
726 SetLastError(0xdeadbeef);
727 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
728 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
729 ok(GetLastError() == 0 ||
730 broken(GetLastError() == 0xdeadbeef /* XP/W2K3 */), "Last Error not reset %u\n", GetLastError());
731 /* show that the function writes data past the length returned */
732 ok(buffer
[length
-2], "Expected any header character, got 0x00\n");
733 ok(!buffer
[length
-1], "Expected 0x00, got %02X\n", buffer
[length
-1]);
734 ok(!buffer
[length
], "Expected 0x00, got %02X\n", buffer
[length
]);
735 ok(buffer
[length
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length
+1]);
738 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
739 ok(!res
, "Expected 0x00, got %d\n", res
);
740 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
741 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
742 /* the in length of the buffer must be +1 but the length returned does not count this */
744 memset(buffer
, 0x77, sizeof(buffer
));
745 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
746 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
747 ok(buffer
[length2
] == 0x00, "Expected 0x00, got %02X\n", buffer
[length2
]);
748 ok(buffer
[length2
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length2
+1]);
749 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
751 length
= sizeof(wbuffer
)-2*sizeof(WCHAR
);
752 memset(wbuffer
, 0x77, sizeof(wbuffer
));
753 res
= HttpQueryInfoW(hor
, HTTP_QUERY_RAW_HEADERS
, wbuffer
, &length
, 0x0);
754 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
755 ok(length
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length
);
756 length
/= sizeof(WCHAR
);
757 /* show that the function writes data past the length returned */
758 ok(wbuffer
[length
-2], "Expected any header character, got 0x0000\n");
759 ok(!wbuffer
[length
-1], "Expected 0x0000, got %04X\n", wbuffer
[length
-1]);
760 ok(!wbuffer
[length
], "Expected 0x0000, got %04X\n", wbuffer
[length
]);
761 ok(wbuffer
[length
+1] == 0x7777 || broken(wbuffer
[length
+1] != 0x7777),
762 "Expected 0x7777, got %04X\n", wbuffer
[length
+1]);
764 length2
= length
*sizeof(WCHAR
);
765 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
766 ok(!res
, "Expected 0x00, got %d\n", res
);
767 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
768 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
769 length2
/= sizeof(WCHAR
);
770 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
771 /* the in length of the buffer must be +1 but the length returned does not count this */
772 length2
= (length
+1)*sizeof(WCHAR
);
773 memset(wbuffer
, 0x77, sizeof(wbuffer
));
774 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
775 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
776 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
777 length2
/= sizeof(WCHAR
);
778 ok(!wbuffer
[length2
], "Expected 0x0000, got %04X\n", wbuffer
[length2
]);
779 ok(wbuffer
[length2
+1] == 0x7777, "Expected 0x7777, got %04X\n", wbuffer
[length2
+1]);
780 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
782 test_request_url(hor
, test
->redirected_url
);
786 SetLastError(0xdeadbeef);
787 ok(HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,NULL
,&length
,&index
) == FALSE
,"Query worked\n");
788 if(test
->flags
& TESTF_COMPRESSED
)
789 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
790 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
791 ok(index
== 0, "Index was incremented\n");
795 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,&index
);
796 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res
,buffer
,GetLastError());
797 if(test
->flags
& TESTF_COMPRESSED
)
798 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
799 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res
, GetLastError());
800 ok(!res
|| index
== 1, "Index was not incremented although result is %x (index = %u)\n", res
, index
);
803 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
805 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res
,buffer
);
808 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_ENCODING
,buffer
,&length
,0x0);
810 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res
,buffer
);
812 SetLastError(0xdeadbeef);
813 res
= InternetReadFile(NULL
, buffer
, 100, &length
);
814 ok(!res
, "InternetReadFile should have failed\n");
815 ok(GetLastError() == ERROR_INVALID_HANDLE
,
816 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
820 if(winetest_debug
> 1)
821 trace("Entering Query loop\n");
825 if (flags
& INTERNET_FLAG_ASYNC
)
826 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
828 /* IE11 calls those in InternetQueryDataAvailable call. */
829 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
830 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
833 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
835 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
837 if (flags
& INTERNET_FLAG_ASYNC
)
841 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
843 ok(length
>= exlen
, "length %u < exlen %u\n", length
, exlen
);
847 else if (GetLastError() == ERROR_IO_PENDING
)
849 if(winetest_debug
> 1)
851 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
852 if(!(test
->flags
& TESTF_CHUNKED
))
853 ok(!length
, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length
);
854 WaitForSingleObject(complete_event
, INFINITE
);
856 ok(exlen
, "length = 0\n");
857 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
858 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
859 ok(req_error
, "req_error = 0\n");
862 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
865 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
867 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
869 if(winetest_debug
> 1)
870 trace("length %u\n", length
);
871 if(test
->flags
& TESTF_CHUNKED
)
872 ok(length
<= 8192, "length = %d, expected <= 8192\n", length
);
876 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
878 res
= InternetReadFile(hor
,buffer
,length
,&length
);
882 if(winetest_debug
> 1)
883 trace("ReadFile -> %s %i\n", res
? "TRUE" : "FALSE", length
);
886 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
887 HeapFree(GetProcessHeap(),0,buffer
);
889 ok(!on_async
, "Returned zero size in response to request complete\n");
894 if(test
->flags
& TESTF_REDIRECT
) {
895 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
896 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
899 if(winetest_debug
> 1)
901 close_async_handle(hi
, 2);
902 first_connection_to_test_url
= FALSE
;
905 static void InternetReadFile_chunked_test(void)
910 const char *types
[2] = { "*", NULL
};
911 HINTERNET hi
, hic
= 0, hor
= 0;
913 trace("Starting InternetReadFile chunked test\n");
915 trace("InternetOpenA <--\n");
916 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
917 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
918 trace("InternetOpenA -->\n");
920 if (hi
== 0x0) goto abort
;
922 trace("InternetConnectA <--\n");
923 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
924 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
925 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
926 trace("InternetConnectA -->\n");
928 if (hic
== 0x0) goto abort
;
930 trace("HttpOpenRequestA <--\n");
931 hor
= HttpOpenRequestA(hic
, "GET", "/tests/chunked", NULL
, NULL
, types
,
932 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
934 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
936 * If the internet name can't be resolved we are probably behind
937 * a firewall or in some other way not directly connected to the
938 * Internet. Not enough reason to fail the test. Just ignore and
942 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
944 trace("HttpOpenRequestA -->\n");
946 if (hor
== 0x0) goto abort
;
948 trace("HttpSendRequestA -->\n");
949 SetLastError(0xdeadbeef);
950 res
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
951 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
952 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
953 trace("HttpSendRequestA <--\n");
955 test_request_flags(hor
, 0);
958 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
960 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
962 SetLastError( 0xdeadbeef );
964 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
966 trace("Option TRANSFER_ENCODING -> %i %s\n",res
,buffer
);
967 ok( res
|| ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
968 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
969 ok( !strcmp( buffer
, "chunked" ) || ( ! res
&& proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
970 "Wrong transfer encoding '%s'\n", buffer
);
972 SetLastError( 0xdeadbeef );
974 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
975 ok( !res
, "Found CONTENT_LENGTH option '%s'\n", buffer
);
976 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Wrong error %u\n", GetLastError() );
979 trace("Entering Query loop\n");
983 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
984 ok(!(!res
&& length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
985 ok(res
, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
986 trace("got %u available\n",length
);
989 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
991 SetLastError(0xdeadbeef);
992 res
= InternetReadFile(hor
,buffer
,length
,&got
);
993 ok(GetLastError() == 0 ||
994 broken(GetLastError() == 0xdeadbeef /* XP/W2K3 */), "Last Error not reset %u\n", GetLastError());
997 trace("ReadFile -> %i %i\n",res
,got
);
998 ok( length
== got
, "only got %u of %u available\n", got
, length
);
999 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
1001 HeapFree(GetProcessHeap(),0,buffer
);
1007 SetLastError(0xdeadbeef);
1008 res
= InternetReadFile( hor
, buffer
, 1, &got
);
1009 ok( res
, "InternetReadFile failed: %u\n", GetLastError() );
1010 ok(GetLastError() == 0 ||
1011 broken(GetLastError() == 0xdeadbeef /* XP/W2K3 */), "Last Error not reset %u\n", GetLastError());
1012 ok( !got
, "got %u\n", got
);
1017 trace("aborting\n");
1019 res
= InternetCloseHandle(hor
);
1020 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
1023 res
= InternetCloseHandle(hi
);
1024 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
1028 static void InternetReadFileExA_test(int flags
)
1032 const char *types
[2] = { "*", NULL
};
1033 HINTERNET hi
, hic
= 0, hor
= 0;
1034 INTERNET_BUFFERSA inetbuffers
;
1036 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
1039 trace("InternetOpenA <--\n");
1040 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
1041 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
1042 trace("InternetOpenA -->\n");
1044 if (hi
== 0x0) goto abort
;
1046 pInternetSetStatusCallbackA(hi
,&callback
);
1048 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1050 trace("InternetConnectA <--\n");
1051 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
1052 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1053 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
1054 trace("InternetConnectA -->\n");
1056 if (hic
== 0x0) goto abort
;
1058 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1059 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1061 trace("HttpOpenRequestA <--\n");
1062 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
1063 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
1065 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
1067 * If the internet name can't be resolved we are probably behind
1068 * a firewall or in some other way not directly connected to the
1069 * Internet. Not enough reason to fail the test. Just ignore and
1073 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
1075 trace("HttpOpenRequestA -->\n");
1077 if (hor
== 0x0) goto abort
;
1079 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1080 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1081 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1082 if (first_connection_to_test_url
)
1084 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
1085 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
1087 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
, 2);
1088 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1089 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1090 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1091 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
1092 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1093 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1094 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1095 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1096 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
1097 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1098 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1099 if (flags
& INTERNET_FLAG_ASYNC
)
1100 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1102 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1104 trace("HttpSendRequestA -->\n");
1105 SetLastError(0xdeadbeef);
1106 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
1107 if (flags
& INTERNET_FLAG_ASYNC
)
1108 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
1109 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
1111 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
1112 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
1113 trace("HttpSendRequestA <--\n");
1115 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
1116 WaitForSingleObject(complete_event
, INFINITE
);
1117 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1120 if (first_connection_to_test_url
)
1122 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1123 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1127 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1128 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1130 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1131 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
1132 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1133 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1134 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1135 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1136 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
1137 if (flags
& INTERNET_FLAG_ASYNC
)
1138 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1140 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1141 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
1142 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
1143 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1144 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1147 rc
= InternetReadFileExW(hor
, NULL
, 0, 0xdeadcafe);
1148 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1149 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1150 rc
? "TRUE" : "FALSE", GetLastError());
1153 /* tests invalid dwStructSize */
1154 inetbuffers
.dwStructSize
= sizeof(inetbuffers
)+1;
1155 inetbuffers
.lpcszHeader
= NULL
;
1156 inetbuffers
.dwHeadersLength
= 0;
1157 inetbuffers
.dwBufferLength
= 10;
1158 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
1159 inetbuffers
.dwOffsetHigh
= 1234;
1160 inetbuffers
.dwOffsetLow
= 5678;
1161 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1162 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1163 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1164 rc
? "TRUE" : "FALSE", GetLastError());
1165 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1167 test_request_flags(hor
, 0);
1169 /* tests to see whether lpcszHeader is used - it isn't */
1170 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1171 inetbuffers
.lpcszHeader
= (LPCSTR
)0xdeadbeef;
1172 inetbuffers
.dwHeadersLength
= 255;
1173 inetbuffers
.dwBufferLength
= 0;
1174 inetbuffers
.lpvBuffer
= NULL
;
1175 inetbuffers
.dwOffsetHigh
= 1234;
1176 inetbuffers
.dwOffsetLow
= 5678;
1177 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1178 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
1179 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1181 rc
= InternetReadFileExA(NULL
, &inetbuffers
, 0, 0xdeadcafe);
1182 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
1183 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1184 rc
? "TRUE" : "FALSE", GetLastError());
1187 trace("Entering Query loop\n");
1191 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1192 inetbuffers
.dwBufferLength
= 1024;
1193 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
1194 inetbuffers
.dwOffsetHigh
= 1234;
1195 inetbuffers
.dwOffsetLow
= 5678;
1197 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1198 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1199 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1200 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
1203 if (GetLastError() == ERROR_IO_PENDING
)
1205 trace("InternetReadFileEx -> PENDING\n");
1206 ok(flags
& INTERNET_FLAG_ASYNC
,
1207 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1208 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1209 WaitForSingleObject(complete_event
, INFINITE
);
1210 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1211 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1212 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1216 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1222 trace("InternetReadFileEx -> SUCCEEDED\n");
1223 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1224 if (inetbuffers
.dwBufferLength
)
1226 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1227 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1231 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1232 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1233 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1237 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1238 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
1240 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
1241 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1242 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
1244 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1246 if (!inetbuffers
.dwBufferLength
)
1249 length
+= inetbuffers
.dwBufferLength
;
1251 ok(length
> 0, "failed to read any of the document\n");
1252 trace("Finished. Read %d bytes\n", length
);
1255 close_async_handle(hi
, 2);
1256 first_connection_to_test_url
= FALSE
;
1259 static void InternetOpenUrlA_test(void)
1261 HINTERNET myhinternet
, myhttp
;
1263 DWORD size
, readbytes
, totalbytes
=0;
1266 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1267 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
1268 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret
, GetLastError());
1270 myhinternet
= InternetOpenA("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
1271 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
1273 ret
= InternetCanonicalizeUrlA(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1274 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1277 myhttp
= InternetOpenUrlA(myhinternet
, TEST_URL
, 0, 0,
1278 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
1279 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1280 return; /* WinXP returns this when not connected to the net */
1281 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1282 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
1283 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
1284 totalbytes
+= readbytes
;
1285 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
1286 totalbytes
+= readbytes
;
1287 trace("read 0x%08x bytes\n",totalbytes
);
1289 InternetCloseHandle(myhttp
);
1290 InternetCloseHandle(myhinternet
);
1292 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1293 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1296 static void HttpSendRequestEx_test(void)
1302 INTERNET_BUFFERSA BufferIn
;
1303 DWORD dwBytesWritten
, dwBytesRead
, error
;
1308 static char szPostData
[] = "mode=Test";
1309 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
1311 hSession
= InternetOpenA("Wine Regression Test",
1312 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1313 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1314 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1315 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1317 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1318 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1319 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1320 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1322 skip( "Network unreachable, skipping test\n" );
1325 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1327 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1329 BufferIn
.dwStructSize
= sizeof(BufferIn
);
1330 BufferIn
.Next
= (INTERNET_BUFFERSA
*)0xdeadcab;
1331 BufferIn
.lpcszHeader
= szContentType
;
1332 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1333 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1334 BufferIn
.lpvBuffer
= szPostData
;
1335 BufferIn
.dwBufferLength
= 3;
1336 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1337 BufferIn
.dwOffsetLow
= 0;
1338 BufferIn
.dwOffsetHigh
= 0;
1340 SetLastError(0xdeadbeef);
1341 ret
= HttpSendRequestExA(hRequest
, &BufferIn
, NULL
, 0 ,0);
1342 error
= GetLastError();
1343 ok(ret
, "HttpSendRequestEx Failed with error %u\n", error
);
1344 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", error
);
1346 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1348 for (i
= 3; szPostData
[i
]; i
++)
1349 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1350 "InternetWriteFile failed\n");
1352 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1354 ok(HttpEndRequestA(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1356 test_request_flags(hRequest
, 0);
1358 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1359 "Unable to read response\n");
1360 szBuffer
[dwBytesRead
] = 0;
1362 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
1363 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1365 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1367 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1368 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1371 static void InternetOpenRequest_test(void)
1373 HINTERNET session
, connect
, request
;
1374 static const char *types
[] = { "*", "", NULL
};
1375 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1376 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1379 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1380 ok(session
!= NULL
,"Unable to open Internet session\n");
1382 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1383 INTERNET_SERVICE_HTTP
, 0, 0);
1384 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1385 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1387 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1388 INTERNET_SERVICE_HTTP
, 0, 0);
1389 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1390 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1392 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1393 INTERNET_SERVICE_HTTP
, 0, 0);
1394 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1396 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1397 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1399 skip( "Network unreachable, skipping test\n" );
1402 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1404 ret
= HttpSendRequestW(request
, NULL
, 0, NULL
, 0);
1405 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1406 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1408 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1409 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1411 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1412 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1413 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1416 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1417 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1420 static void test_cache_read(void)
1422 HINTERNET session
, connection
, req
;
1423 FILETIME now
, tomorrow
, yesterday
;
1424 BYTE content
[1000], buf
[2000];
1425 char file_path
[MAX_PATH
];
1432 static const char cache_only_url
[] = "http://test.winehq.org/tests/cache-only";
1433 BYTE cache_headers
[] = "HTTP/1.1 200 OK\r\n\r\n";
1435 trace("Testing cache read...\n");
1438 for(i
= 0; i
< sizeof(content
); i
++)
1439 content
[i
] = '0' + (i
%10);
1441 GetSystemTimeAsFileTime(&now
);
1442 li
.u
.HighPart
= now
.dwHighDateTime
;
1443 li
.u
.LowPart
= now
.dwLowDateTime
;
1444 li
.QuadPart
+= (LONGLONG
)10000000 * 3600 * 24;
1445 tomorrow
.dwHighDateTime
= li
.u
.HighPart
;
1446 tomorrow
.dwLowDateTime
= li
.u
.LowPart
;
1447 li
.QuadPart
-= (LONGLONG
)10000000 * 3600 * 24 * 2;
1448 yesterday
.dwHighDateTime
= li
.u
.HighPart
;
1449 yesterday
.dwLowDateTime
= li
.u
.LowPart
;
1451 res
= CreateUrlCacheEntryA(cache_only_url
, sizeof(content
), "", file_path
, 0);
1452 ok(res
, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1454 file
= CreateFileA(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1455 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
1457 WriteFile(file
, content
, sizeof(content
), &size
, NULL
);
1460 res
= CommitUrlCacheEntryA(cache_only_url
, file_path
, tomorrow
, yesterday
, NORMAL_CACHE_ENTRY
,
1461 cache_headers
, sizeof(cache_headers
)-1, "", 0);
1462 ok(res
, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1464 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
1465 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
1467 pInternetSetStatusCallbackA(session
, callback
);
1469 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1470 connection
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
,
1471 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1472 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
1473 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1475 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1476 req
= HttpOpenRequestA(connection
, "GET", "/tests/cache-only", NULL
, NULL
, NULL
, 0, 0xdeadbead);
1477 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
1478 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1480 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1481 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1482 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST
);
1483 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT
);
1484 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1485 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1486 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1488 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
1490 ok(res
, "HttpSendRequest failed: %u\n", GetLastError());
1494 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
1495 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1496 ok(size
== sizeof(content
), "size = %u\n", size
);
1499 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
1500 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
1501 ok(size
== sizeof(content
), "size = %u\n", size
);
1502 ok(!memcmp(content
, buf
, sizeof(content
)), "unexpected content\n");
1505 close_async_handle(session
, 2);
1507 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1508 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1509 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
1510 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
1511 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1512 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1513 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1515 res
= DeleteUrlCacheEntryA(cache_only_url
);
1516 ok(res
, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1519 static void test_http_cache(void)
1521 HINTERNET session
, connect
, request
;
1522 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1523 DWORD size
, file_size
;
1527 FILETIME filetime_zero
= {0};
1529 static const char cached_content
[] = "data read from cache";
1530 static const char *types
[] = { "*", "", NULL
};
1532 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1533 ok(session
!= NULL
,"Unable to open Internet session\n");
1535 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1536 INTERNET_SERVICE_HTTP
, 0, 0);
1537 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1539 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1540 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1542 skip( "Network unreachable, skipping test\n" );
1544 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1545 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1549 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1552 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1553 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1554 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1556 size
= sizeof(file_name
);
1557 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1558 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1559 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1560 ok(!size
, "size = %d\n", size
);
1562 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1563 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1565 size
= sizeof(file_name
);
1566 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1567 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1569 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1570 FILE_ATTRIBUTE_NORMAL
, NULL
);
1571 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1572 file_size
= GetFileSize(file
, NULL
);
1573 ok(file_size
== 106, "file size = %u\n", file_size
);
1576 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1577 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1578 ok(size
== 100, "size = %u\n", size
);
1580 file_size
= GetFileSize(file
, NULL
);
1581 ok(file_size
== 106, "file size = %u\n", file_size
);
1584 ret
= DeleteFileA(file_name
);
1585 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1587 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1589 file
= CreateFileA(file_name
, GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1590 FILE_ATTRIBUTE_NORMAL
, NULL
);
1591 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1592 ret
= WriteFile(file
, cached_content
, sizeof(cached_content
), &size
, NULL
);
1593 ok(ret
&& size
, "WriteFile failed: %d, %d\n", ret
, size
);
1594 ret
= CommitUrlCacheEntryA(url
, file_name
, filetime_zero
, filetime_zero
, NORMAL_CACHE_ENTRY
, NULL
, 0, NULL
, 0);
1595 ok(ret
, "CommitUrlCacheEntry failed: %d\n", GetLastError());
1598 /* Send the same request, requiring it to be retrieved from the cache */
1599 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1601 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1602 ok(ret
, "HttpSendRequest failed\n");
1605 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1606 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1607 ok(size
== 100, "size = %u\n", size
);
1609 todo_wine
ok(!strcmp((char*)buf
, cached_content
), "incorrect page data: %s\n", (char*)buf
);
1611 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1613 DeleteUrlCacheEntryA(url
);
1614 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1615 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1616 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
1618 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError() = %d\n", GetLastError());
1619 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1621 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1622 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1624 size
= sizeof(file_name
);
1625 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1626 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1627 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1628 ok(!size
, "size = %d\n", size
);
1630 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1631 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1633 size
= sizeof(file_name
);
1635 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1638 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1639 FILE_ATTRIBUTE_NORMAL
, NULL
);
1640 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1646 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1649 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1650 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1651 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1656 static void InternetLockRequestFile_test(void)
1658 char file_name
[MAX_PATH
];
1664 open_simple_request(&req
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, "/tests/hello.html");
1666 size
= sizeof(file_name
);
1667 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1668 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1669 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1670 ok(!size
, "size = %d\n", size
);
1673 ret
= InternetLockRequestFile(req
.request
, &lock
);
1674 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1676 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
1677 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1679 size
= sizeof(file_name
);
1680 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1681 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1683 ret
= InternetLockRequestFile(req
.request
, &lock
);
1684 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1685 ok(lock
!= NULL
, "lock == NULL\n");
1687 ret
= InternetLockRequestFile(req
.request
, &lock2
);
1688 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1689 ok(lock
== lock2
, "lock != lock2\n");
1691 ret
= InternetUnlockRequestFile(lock2
);
1692 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1694 ret
= DeleteFileA(file_name
);
1695 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1697 ok(InternetCloseHandle(req
.request
), "Close request handle failed\n");
1699 ret
= DeleteFileA(file_name
);
1700 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1702 ret
= InternetUnlockRequestFile(lock
);
1703 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1705 ret
= DeleteFileA(file_name
);
1706 ok(ret
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1709 static void HttpHeaders_test(void)
1721 hSession
= InternetOpenA("Wine Regression Test",
1722 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1723 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1724 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1725 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1727 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1728 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1729 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1730 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1732 skip( "Network unreachable, skipping test\n" );
1735 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1738 len
= sizeof(buffer
);
1739 strcpy(buffer
,"Warning");
1740 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1741 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1743 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1744 "Failed to add new header\n");
1747 len
= sizeof(buffer
);
1748 strcpy(buffer
,"Warning");
1749 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1750 buffer
,&len
,&index
),"Unable to query header\n");
1751 ok(index
== 1, "Index was not incremented\n");
1752 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1753 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1754 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1755 len
= sizeof(buffer
);
1756 strcpy(buffer
,"Warning");
1757 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1758 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1761 len
= 5; /* could store the string but not the NULL terminator */
1762 strcpy(buffer
,"Warning");
1763 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1764 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1765 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1766 ok(index
== 0, "Index was incremented\n");
1767 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1768 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1770 /* a call with NULL will fail but will return the length */
1772 len
= sizeof(buffer
);
1773 SetLastError(0xdeadbeef);
1774 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1775 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1776 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1777 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1778 ok(index
== 0, "Index was incremented\n");
1780 /* even for a len that is too small */
1783 SetLastError(0xdeadbeef);
1784 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1785 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1786 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1787 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1788 ok(index
== 0, "Index was incremented\n");
1792 SetLastError(0xdeadbeef);
1793 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1794 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1795 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1796 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1797 ok(index
== 0, "Index was incremented\n");
1798 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1801 /* a working query */
1803 len
= sizeof(buffer
);
1804 memset(buffer
, 'x', sizeof(buffer
));
1805 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1806 buffer
,&len
,&index
),"Unable to query header\n");
1807 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1808 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1809 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1810 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1811 ok(strncmp(buffer
, "POST /tests/post.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1812 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1813 ok(index
== 0, "Index was incremented\n");
1815 /* Like above two tests, but for W version */
1819 SetLastError(0xdeadbeef);
1820 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1821 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1822 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1823 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1824 ok(index
== 0, "Index was incremented\n");
1825 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1827 /* a working query */
1829 len
= sizeof(wbuffer
);
1830 memset(wbuffer
, 'x', sizeof(wbuffer
));
1831 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1832 wbuffer
,&len
,&index
),"Unable to query header\n");
1833 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1834 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1835 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1836 ok(index
== 0, "Index was incremented\n");
1838 /* end of W version tests */
1840 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1842 len
= sizeof(buffer
);
1843 memset(buffer
, 'x', sizeof(buffer
));
1844 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1845 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1846 ok(len
== 2 || len
== 4 /* win10 */, "Expected 2 or 4, got %d\n", len
);
1847 ok(memcmp(buffer
, "\r\n\r\n", len
) == 0, "Expected CRLF, got '%s'\n", buffer
);
1848 ok(index
== 0, "Index was incremented\n");
1850 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1851 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1854 len
= sizeof(buffer
);
1855 strcpy(buffer
,"Warning");
1856 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1857 buffer
,&len
,&index
),"Unable to query header\n");
1858 ok(index
== 1, "Index was not incremented\n");
1859 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1860 len
= sizeof(buffer
);
1861 strcpy(buffer
,"Warning");
1862 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1863 buffer
,&len
,&index
),"Failed to get second header\n");
1864 ok(index
== 2, "Index was not incremented\n");
1865 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1866 len
= sizeof(buffer
);
1867 strcpy(buffer
,"Warning");
1868 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1869 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1871 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1874 len
= sizeof(buffer
);
1875 strcpy(buffer
,"Warning");
1876 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1877 buffer
,&len
,&index
),"Unable to query header\n");
1878 ok(index
== 1, "Index was not incremented\n");
1879 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1880 len
= sizeof(buffer
);
1881 strcpy(buffer
,"Warning");
1882 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1883 buffer
,&len
,&index
),"Failed to get second header\n");
1884 ok(index
== 2, "Index was not incremented\n");
1885 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1886 len
= sizeof(buffer
);
1887 strcpy(buffer
,"Warning");
1888 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1889 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1891 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1894 len
= sizeof(buffer
);
1895 strcpy(buffer
,"Warning");
1896 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1897 buffer
,&len
,&index
),"Unable to query header\n");
1898 ok(index
== 1, "Index was not incremented\n");
1899 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1900 len
= sizeof(buffer
);
1901 strcpy(buffer
,"Warning");
1902 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1903 buffer
,&len
,&index
),"Failed to get second header\n");
1904 ok(index
== 2, "Index was not incremented\n");
1905 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1906 len
= sizeof(buffer
);
1907 strcpy(buffer
,"Warning");
1908 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1909 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1911 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1914 len
= sizeof(buffer
);
1915 strcpy(buffer
,"Warning");
1916 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1917 buffer
,&len
,&index
),"Unable to query header\n");
1918 ok(index
== 1, "Index was not incremented\n");
1919 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1920 len
= sizeof(buffer
);
1921 strcpy(buffer
,"Warning");
1922 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1923 ok(index
== 2, "Index was not incremented\n");
1924 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1925 len
= sizeof(buffer
);
1926 strcpy(buffer
,"Warning");
1927 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1929 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1932 len
= sizeof(buffer
);
1933 strcpy(buffer
,"Warning");
1934 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1935 ok(index
== 1, "Index was not incremented\n");
1936 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1937 len
= sizeof(buffer
);
1938 strcpy(buffer
,"Warning");
1939 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1940 ok(index
== 2, "Index was not incremented\n");
1941 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1942 len
= sizeof(buffer
);
1943 strcpy(buffer
,"Warning");
1944 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1946 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1949 len
= sizeof(buffer
);
1950 strcpy(buffer
,"Warning");
1951 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1952 ok(index
== 1, "Index was not incremented\n");
1953 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1954 len
= sizeof(buffer
);
1955 strcpy(buffer
,"Warning");
1956 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1957 ok(index
== 2, "Index was not incremented\n");
1958 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1959 len
= sizeof(buffer
);
1960 strcpy(buffer
,"Warning");
1961 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1963 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");
1966 len
= sizeof(buffer
);
1967 strcpy(buffer
,"Warning");
1968 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1969 ok(index
== 1, "Index was not incremented\n");
1970 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1971 len
= sizeof(buffer
);
1972 strcpy(buffer
,"Warning");
1973 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1974 ok(index
== 2, "Index was not incremented\n");
1975 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1976 len
= sizeof(buffer
);
1977 strcpy(buffer
,"Warning");
1978 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1980 /* Ensure that blank headers are ignored and don't cause a failure */
1981 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");
1984 len
= sizeof(buffer
);
1985 strcpy(buffer
,"BlankTest");
1986 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1987 ok(index
== 1, "Index was not incremented\n");
1988 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1990 /* Ensure that malformed header separators are ignored and don't cause a failure */
1991 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
),
1992 "Failed to add header with malformed entries in list\n");
1995 len
= sizeof(buffer
);
1996 strcpy(buffer
,"MalformedTest");
1997 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1998 ok(index
== 1, "Index was not incremented\n");
1999 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
2001 len
= sizeof(buffer
);
2002 strcpy(buffer
,"MalformedTestTwo");
2003 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2004 ok(index
== 1, "Index was not incremented\n");
2005 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
2007 len
= sizeof(buffer
);
2008 strcpy(buffer
,"MalformedTestThree");
2009 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2010 ok(index
== 1, "Index was not incremented\n");
2011 ok(strcmp(buffer
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
2013 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD
);
2014 ok(ret
, "unable to add header %u\n", GetLastError());
2018 len
= sizeof(buffer
);
2019 ret
= HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
);
2020 ok(ret
, "unable to query header %u\n", GetLastError());
2021 ok(index
== 1, "index was not incremented\n");
2022 ok(!strcmp(buffer
, "Basic"), "incorrect string was returned (%s)\n", buffer
);
2024 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE
);
2025 ok(ret
, "unable to remove header %u\n", GetLastError());
2028 len
= sizeof(buffer
);
2029 SetLastError(0xdeadbeef);
2030 ok(!HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
),
2031 "header still present\n");
2032 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "got %u\n", GetLastError());
2034 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
2036 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
2037 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
2040 static const char garbagemsg
[] =
2041 "Garbage: Header\r\n";
2043 static const char contmsg
[] =
2044 "HTTP/1.1 100 Continue\r\n";
2046 static const char expandcontmsg
[] =
2047 "HTTP/1.1 100 Continue\r\n"
2048 "Server: winecontinue\r\n"
2049 "Tag: something witty\r\n";
2051 static const char okmsg
[] =
2052 "HTTP/1.1 200 OK\r\n"
2053 "Server: winetest\r\n"
2056 static const char okmsg2
[] =
2057 "HTTP/1.1 200 OK\r\n"
2058 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
2059 "Server: winetest\r\n"
2060 "Content-Length: 0\r\n"
2061 "Set-Cookie: one\r\n"
2062 "Set-Cookie: two\r\n"
2065 static DWORD64 content_length
;
2066 static const char largemsg
[] =
2067 "HTTP/1.1 200 OK\r\n"
2068 "Content-Length: %I64u\r\n"
2071 static const char notokmsg
[] =
2072 "HTTP/1.1 400 Bad Request\r\n"
2073 "Server: winetest\r\n"
2076 static const char noauthmsg
[] =
2077 "HTTP/1.1 401 Unauthorized\r\n"
2078 "Server: winetest\r\n"
2079 "Connection: close\r\n"
2080 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
2083 static const char noauthmsg2
[] =
2084 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
2085 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
2087 "Server: winetest\r\n";
2089 static const char proxymsg
[] =
2090 "HTTP/1.1 407 Proxy Authentication Required\r\n"
2091 "Server: winetest\r\n"
2092 "Proxy-Connection: close\r\n"
2093 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
2096 static const char page1
[] =
2098 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
2099 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
2102 static const char ok_with_length
[] =
2103 "HTTP/1.1 200 OK\r\n"
2104 "Connection: Keep-Alive\r\n"
2105 "Content-Length: 18\r\n\r\n"
2106 "HTTP/1.1 211 OK\r\n\r\n";
2108 static const char ok_with_length2
[] =
2109 "HTTP/1.1 210 OK\r\n"
2110 "Connection: Keep-Alive\r\n"
2111 "Content-Length: 19\r\n\r\n"
2112 "HTTP/1.1 211 OK\r\n\r\n";
2114 struct server_info
{
2119 static int test_cache_gzip
;
2120 static const char *send_buffer
;
2121 static int server_socket
;
2123 static DWORD CALLBACK
server_thread(LPVOID param
)
2125 struct server_info
*si
= param
;
2126 int r
, c
= -1, i
, on
, count
= 0;
2128 struct sockaddr_in sa
;
2132 int last_request
= 0;
2133 char host_header
[22];
2134 char host_header_override
[30];
2135 static int test_no_cache
= 0;
2137 WSAStartup(MAKEWORD(1,1), &wsaData
);
2139 s
= socket(AF_INET
, SOCK_STREAM
, 0);
2140 if (s
== INVALID_SOCKET
)
2144 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
2146 memset(&sa
, 0, sizeof sa
);
2147 sa
.sin_family
= AF_INET
;
2148 sa
.sin_port
= htons(si
->port
);
2149 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
2151 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
2157 SetEvent(si
->hEvent
);
2159 sprintf(host_header
, "Host: localhost:%d", si
->port
);
2160 sprintf(host_header_override
, "Host: test.local:%d\r\n", si
->port
);
2161 buffer
= HeapAlloc(GetProcessHeap(), 0, buffer_size
= 1000);
2166 c
= accept(s
, NULL
, NULL
);
2168 memset(buffer
, 0, buffer_size
);
2171 if(i
== buffer_size
)
2172 buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, buffer_size
*= 2);
2174 r
= recv(c
, buffer
+i
, 1, 0);
2178 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
2179 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
2182 if (strstr(buffer
, "GET /test1"))
2184 if (!strstr(buffer
, "Content-Length: 0"))
2186 send(c
, okmsg
, sizeof okmsg
-1, 0);
2187 send(c
, page1
, sizeof page1
-1, 0);
2190 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2192 if (strstr(buffer
, "CONNECT "))
2194 if (!strstr(buffer
, "Content-Length: 0"))
2195 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2197 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2199 if (strstr(buffer
, "/test2"))
2201 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2203 send(c
, okmsg
, sizeof okmsg
-1, 0);
2204 send(c
, page1
, sizeof page1
-1, 0);
2207 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2209 if (strstr(buffer
, "/test3"))
2211 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2212 send(c
, okmsg
, sizeof okmsg
-1, 0);
2214 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2216 if (strstr(buffer
, "/test4"))
2218 if (strstr(buffer
, "Connection: Close"))
2219 send(c
, okmsg
, sizeof okmsg
-1, 0);
2221 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2223 if (strstr(buffer
, "POST /test5") ||
2224 strstr(buffer
, "RPC_IN_DATA /test5") ||
2225 strstr(buffer
, "RPC_OUT_DATA /test5"))
2227 if (strstr(buffer
, "Content-Length: 0"))
2229 send(c
, okmsg
, sizeof okmsg
-1, 0);
2230 send(c
, page1
, sizeof page1
-1, 0);
2233 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2235 if (strstr(buffer
, "GET /test6"))
2237 send(c
, contmsg
, sizeof contmsg
-1, 0);
2238 send(c
, contmsg
, sizeof contmsg
-1, 0);
2239 send(c
, okmsg
, sizeof okmsg
-1, 0);
2240 send(c
, page1
, sizeof page1
-1, 0);
2242 if (strstr(buffer
, "POST /test7"))
2244 if (strstr(buffer
, "Content-Length: 100"))
2246 if (strstr(buffer
, "POST /test7b"))
2247 recvfrom(c
, buffer
, buffer_size
, 0, NULL
, NULL
);
2248 send(c
, okmsg
, sizeof okmsg
-1, 0);
2249 send(c
, page1
, sizeof page1
-1, 0);
2252 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2254 if (strstr(buffer
, "/test8"))
2256 if (!strstr(buffer
, "Connection: Close") &&
2257 strstr(buffer
, "Connection: Keep-Alive") &&
2258 !strstr(buffer
, "Cache-Control: no-cache") &&
2259 !strstr(buffer
, "Pragma: no-cache") &&
2260 strstr(buffer
, host_header
))
2261 send(c
, okmsg
, sizeof okmsg
-1, 0);
2263 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2265 if (strstr(buffer
, "/test9"))
2267 if (!strstr(buffer
, "Connection: Close") &&
2268 !strstr(buffer
, "Connection: Keep-Alive") &&
2269 !strstr(buffer
, "Cache-Control: no-cache") &&
2270 !strstr(buffer
, "Pragma: no-cache") &&
2271 strstr(buffer
, host_header
))
2272 send(c
, okmsg
, sizeof okmsg
-1, 0);
2274 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2276 if (strstr(buffer
, "/testA"))
2278 if (!strstr(buffer
, "Connection: Close") &&
2279 !strstr(buffer
, "Connection: Keep-Alive") &&
2280 (strstr(buffer
, "Cache-Control: no-cache") ||
2281 strstr(buffer
, "Pragma: no-cache")) &&
2282 strstr(buffer
, host_header
))
2283 send(c
, okmsg
, sizeof okmsg
-1, 0);
2285 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2287 if (strstr(buffer
, "/testC"))
2289 if (strstr(buffer
, "Cookie: cookie=biscuit"))
2290 send(c
, okmsg
, sizeof okmsg
-1, 0);
2292 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2294 if (strstr(buffer
, "/testD"))
2296 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
2298 if (strstr(buffer
, "/testE"))
2300 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
2302 if (strstr(buffer
, "GET /quit"))
2304 send(c
, okmsg
, sizeof okmsg
-1, 0);
2305 send(c
, page1
, sizeof page1
-1, 0);
2308 if (strstr(buffer
, "GET /testF"))
2310 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
2311 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2312 send(c
, contmsg
, sizeof contmsg
-1, 0);
2313 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2314 send(c
, okmsg
, sizeof okmsg
-1, 0);
2315 send(c
, page1
, sizeof page1
-1, 0);
2317 if (strstr(buffer
, "GET /testG"))
2319 send(c
, page1
, sizeof page1
-1, 0);
2322 if (strstr(buffer
, "GET /testJ"))
2327 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2331 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2335 if (strstr(buffer
, "GET /testH"))
2337 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2338 recvfrom(c
, buffer
, buffer_size
, 0, NULL
, NULL
);
2339 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2342 if (strstr(buffer
, "GET /test_no_content"))
2344 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2345 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2347 if (strstr(buffer
, "GET /test_conn_close"))
2349 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2350 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
2351 WaitForSingleObject(conn_close_event
, INFINITE
);
2352 trace("closing connection\n");
2354 if (strstr(buffer
, "GET /test_cache_control_no_cache"))
2356 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2357 if(!test_no_cache
++)
2358 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2360 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2362 if (strstr(buffer
, "GET /test_cache_control_no_store"))
2364 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2365 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2367 if (strstr(buffer
, "GET /test_cache_gzip"))
2369 static const char gzip_response
[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2370 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2371 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2372 if(!test_cache_gzip
++)
2373 send(c
, gzip_response
, sizeof(gzip_response
), 0);
2375 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2377 if (strstr(buffer
, "HEAD /test_head")) {
2378 static const char head_response
[] =
2379 "HTTP/1.1 200 OK\r\n"
2380 "Connection: Keep-Alive\r\n"
2381 "Content-Length: 100\r\n"
2384 send(c
, head_response
, sizeof(head_response
), 0);
2387 if (strstr(buffer
, "GET /send_from_buffer"))
2388 send(c
, send_buffer
, strlen(send_buffer
), 0);
2389 if (strstr(buffer
, "/test_cache_control_verb"))
2391 if (!memcmp(buffer
, "GET ", sizeof("GET ")-1) &&
2392 !strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2393 else if (strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2394 else send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2396 if (strstr(buffer
, "/test_request_content_length"))
2398 static char msg
[] = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\n\r\n";
2399 static int seen_content_length
;
2401 if (!seen_content_length
)
2403 if (strstr(buffer
, "Content-Length: 0"))
2405 seen_content_length
= 1;
2406 send(c
, msg
, sizeof msg
-1, 0);
2408 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2409 WaitForSingleObject(complete_event
, 5000);
2413 if (strstr(buffer
, "Content-Length: 0")) send(c
, msg
, sizeof msg
-1, 0);
2414 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2415 WaitForSingleObject(complete_event
, 5000);
2418 if (strstr(buffer
, "GET /test_premature_disconnect"))
2419 trace("closing connection\n");
2420 if (strstr(buffer
, "HEAD /upload.txt"))
2422 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2423 send(c
, okmsg
, sizeof okmsg
-1, 0);
2425 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2427 if (strstr(buffer
, "PUT /upload2.txt"))
2429 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2430 send(c
, okmsg
, sizeof okmsg
-1, 0);
2432 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2434 if (strstr(buffer
, "/test_host_override"))
2436 if (strstr(buffer
, host_header_override
))
2437 send(c
, okmsg
, sizeof okmsg
-1, 0);
2439 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2441 if (strstr(buffer
, "/async_read"))
2443 const char *page1_mid
= page1
+ (sizeof page1
- 1)/2;
2444 const char *page1_end
= page1
+ sizeof page1
- 1;
2445 send(c
, okmsg
, sizeof okmsg
-1, 0);
2446 send(c
, page1
, page1_mid
- page1
, 0);
2447 WaitForSingleObject(conn_wait_event
, INFINITE
);
2448 send(c
, page1_mid
, page1_end
- page1_mid
, 0);
2450 if (strstr(buffer
, "/socket"))
2453 SetEvent(server_req_rec_event
);
2454 WaitForSingleObject(conn_wait_event
, INFINITE
);
2456 if (strstr(buffer
, "/echo_request"))
2458 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2459 send(c
, buffer
, strlen(buffer
), 0);
2461 if (strstr(buffer
, "GET /test_remove_dot_segments"))
2463 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2465 if (strstr(buffer
, "HEAD /test_large_content"))
2467 char msg
[sizeof(largemsg
) + 16];
2468 sprintf(msg
, largemsg
, content_length
);
2469 send(c
, msg
, strlen(msg
), 0);
2474 } while (!last_request
);
2477 HeapFree(GetProcessHeap(), 0, buffer
);
2482 static void test_basic_request(int port
, const char *verb
, const char *url
)
2485 DWORD r
, count
, error
;
2488 trace("basic request %s %s\n", verb
, url
);
2490 open_simple_request(&req
, "localhost", port
, verb
, url
);
2492 SetLastError(0xdeadbeef);
2493 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
2494 error
= GetLastError();
2495 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
2496 ok(r
, "HttpSendRequest failed: %u\n", GetLastError());
2499 memset(buffer
, 0, sizeof buffer
);
2500 SetLastError(0xdeadbeef);
2501 r
= InternetReadFile(req
.request
, buffer
, sizeof buffer
, &count
);
2502 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2503 ok(count
== sizeof page1
- 1, "count was wrong\n");
2504 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2506 close_request(&req
);
2509 static void test_proxy_indirect(int port
)
2515 open_simple_request(&req
, "localhost", port
, NULL
, "/test2");
2517 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
2518 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2521 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2522 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
2525 skip("missing proxy header, not testing remaining proxy headers\n");
2528 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2530 test_status_code(req
.request
, 407);
2531 test_request_flags(req
.request
, 0);
2534 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2535 ok(r
, "HttpQueryInfo failed\n");
2536 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2539 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2540 ok(r
, "HttpQueryInfo failed\n");
2541 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2544 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2545 ok(r
, "HttpQueryInfo failed\n");
2546 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2549 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2550 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2551 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2554 close_request(&req
);
2557 static void test_proxy_direct(int port
)
2559 HINTERNET hi
, hc
, hr
;
2561 char buffer
[0x40], *url
;
2562 WCHAR bufferW
[0x40];
2563 static const char url_fmt
[] = "http://test.winehq.org:%u/test2";
2564 static CHAR username
[] = "mike",
2565 password
[] = "1101",
2566 useragent
[] = "winetest";
2567 static const WCHAR usernameW
[] = {'m','i','k','e',0},
2568 passwordW
[] = {'1','1','0','1',0},
2569 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2571 /* specify proxy type without the proxy and bypass */
2572 SetLastError(0xdeadbeef);
2573 hi
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2574 error
= GetLastError();
2575 ok(error
== ERROR_INVALID_PARAMETER
||
2576 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %u\n", error
);
2577 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2579 sprintf(buffer
, "localhost:%d\n", port
);
2580 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2581 ok(hi
!= NULL
, "open failed\n");
2583 /* try connect without authorization */
2584 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2585 ok(hc
!= NULL
, "connect failed\n");
2587 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2588 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2591 SetLastError(0xdeadbeef);
2592 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
2593 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2594 ok(!r
, "unexpected success\n");
2595 ok(sz
== 1, "got %u\n", sz
);
2598 SetLastError(0xdeadbeef);
2599 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
2600 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2601 ok(!r
, "unexpected success\n");
2602 ok(sz
== 1, "got %u\n", sz
);
2604 sz
= sizeof(buffer
);
2605 SetLastError(0xdeadbeef);
2606 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2607 ok(r
, "unexpected failure %u\n", GetLastError());
2608 ok(!sz
, "got %u\n", sz
);
2610 sz
= sizeof(buffer
);
2611 SetLastError(0xdeadbeef);
2612 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2613 ok(r
, "unexpected failure %u\n", GetLastError());
2614 ok(!sz
, "got %u\n", sz
);
2617 SetLastError(0xdeadbeef);
2618 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
2619 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2620 ok(!r
, "unexpected success\n");
2621 ok(sz
== 1, "got %u\n", sz
);
2624 SetLastError(0xdeadbeef);
2625 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
2626 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2627 ok(!r
, "unexpected success\n");
2628 ok(sz
== 1, "got %u\n", sz
);
2630 sz
= sizeof(buffer
);
2631 SetLastError(0xdeadbeef);
2632 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2633 ok(r
, "unexpected failure %u\n", GetLastError());
2634 ok(!sz
, "got %u\n", sz
);
2636 sz
= sizeof(buffer
);
2637 SetLastError(0xdeadbeef);
2638 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2639 ok(r
, "unexpected failure %u\n", GetLastError());
2640 ok(!sz
, "got %u\n", sz
);
2643 SetLastError(0xdeadbeef);
2644 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
2645 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2646 ok(!r
, "unexpected success\n");
2647 ok(sz
== 34, "got %u\n", sz
);
2649 sz
= sizeof(buffer
);
2650 SetLastError(0xdeadbeef);
2651 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2652 ok(r
, "unexpected failure %u\n", GetLastError());
2653 ok(sz
== 33, "got %u\n", sz
);
2655 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2656 ok(r
|| broken(!r
), "HttpSendRequest failed %u\n", GetLastError());
2659 win_skip("skipping proxy tests on broken wininet\n");
2663 test_status_code(hr
, 407);
2665 /* set the user + password then try again */
2666 r
= InternetSetOptionA(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2667 ok(!r
, "unexpected success\n");
2669 r
= InternetSetOptionA(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2670 ok(r
, "failed to set user\n");
2672 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2673 ok(r
, "failed to set user\n");
2677 SetLastError(0xdeadbeef);
2678 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2679 ok(!r
, "unexpected failure %u\n", GetLastError());
2680 ok(!buffer
[0], "got %s\n", buffer
);
2681 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2685 SetLastError(0xdeadbeef);
2686 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2687 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2688 ok(!r
, "unexpected success\n");
2689 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2693 SetLastError(0xdeadbeef);
2694 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2695 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2696 ok(!r
, "unexpected success\n");
2697 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2700 sz
= sizeof(buffer
);
2701 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2702 ok(r
, "failed to get username\n");
2703 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2704 ok(sz
== strlen(username
), "got %u\n", sz
);
2707 sz
= sizeof(bufferW
);
2708 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2709 ok(r
, "failed to get username\n");
2710 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
2711 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2713 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
2714 ok(r
, "failed to set user\n");
2717 sz
= sizeof(buffer
);
2718 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2719 ok(r
, "failed to get username\n");
2720 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2721 ok(sz
== strlen(username
), "got %u\n", sz
);
2723 r
= InternetSetOptionA(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
2724 ok(r
, "failed to set useragent\n");
2728 SetLastError(0xdeadbeef);
2729 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2730 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2731 ok(!r
, "unexpected success\n");
2732 ok(sz
== strlen(useragent
) + 1, "got %u\n", sz
);
2735 sz
= sizeof(buffer
);
2736 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2737 ok(r
, "failed to get user agent\n");
2738 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
2739 ok(sz
== strlen(useragent
), "got %u\n", sz
);
2743 SetLastError(0xdeadbeef);
2744 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2745 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2746 ok(!r
, "unexpected success\n");
2747 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2750 sz
= sizeof(bufferW
);
2751 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2752 ok(r
, "failed to get user agent\n");
2753 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
2754 ok(sz
== lstrlenW(useragentW
), "got %u\n", sz
);
2756 r
= InternetSetOptionA(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
2757 ok(r
, "failed to set user\n");
2761 SetLastError(0xdeadbeef);
2762 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2763 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2764 ok(!r
, "unexpected success\n");
2765 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2768 sz
= sizeof(buffer
);
2769 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2770 ok(r
, "failed to get user\n");
2771 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2772 ok(sz
== strlen(username
), "got %u\n", sz
);
2776 SetLastError(0xdeadbeef);
2777 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2778 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2779 ok(!r
, "unexpected success\n");
2780 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2783 sz
= sizeof(bufferW
);
2784 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2785 ok(r
, "failed to get user\n");
2786 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
2787 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2789 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
2790 ok(r
, "failed to set password\n");
2794 SetLastError(0xdeadbeef);
2795 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2796 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2797 ok(!r
, "unexpected success\n");
2798 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2801 sz
= sizeof(buffer
);
2802 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2803 ok(r
, "failed to get password\n");
2804 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2805 ok(sz
== strlen(password
), "got %u\n", sz
);
2809 SetLastError(0xdeadbeef);
2810 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2811 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2812 ok(!r
, "unexpected success\n");
2813 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2816 sz
= sizeof(bufferW
);
2817 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2818 ok(r
, "failed to get password\n");
2819 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2820 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2822 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
2823 sprintf(url
, url_fmt
, port
);
2826 SetLastError(0xdeadbeef);
2827 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2828 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2829 ok(!r
, "unexpected success\n");
2830 ok(sz
== strlen(url
) + 1, "got %u\n", sz
);
2833 sz
= sizeof(buffer
);
2834 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2835 ok(r
, "failed to get url\n");
2836 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
2837 ok(sz
== strlen(url
), "got %u\n", sz
);
2841 SetLastError(0xdeadbeef);
2842 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2843 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2844 ok(!r
, "unexpected success\n");
2845 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2848 sz
= sizeof(bufferW
);
2849 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2850 ok(r
, "failed to get url\n");
2851 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
2852 ok(sz
== strlen(url
), "got %u\n", sz
);
2853 HeapFree(GetProcessHeap(), 0, url
);
2855 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2856 ok(r
, "failed to set password\n");
2860 SetLastError(0xdeadbeef);
2861 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2862 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2863 ok(!r
, "unexpected success\n");
2864 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2867 sz
= sizeof(buffer
);
2868 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2869 ok(r
, "failed to get password\n");
2870 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2871 ok(sz
== strlen(password
), "got %u\n", sz
);
2875 SetLastError(0xdeadbeef);
2876 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2877 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2878 ok(!r
, "unexpected success\n");
2879 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2882 sz
= sizeof(bufferW
);
2883 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2884 ok(r
, "failed to get password\n");
2885 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2886 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2888 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2891 win_skip("skipping proxy tests on broken wininet\n");
2894 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2896 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2897 ok(r
, "HttpQueryInfo failed\n");
2898 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2900 InternetCloseHandle(hr
);
2901 InternetCloseHandle(hc
);
2902 InternetCloseHandle(hi
);
2904 sprintf(buffer
, "localhost:%d\n", port
);
2905 hi
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2906 ok(hi
!= NULL
, "InternetOpen failed\n");
2908 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2909 ok(hc
!= NULL
, "InternetConnect failed\n");
2911 hr
= HttpOpenRequestA(hc
, "POST", "/test2", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
2912 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2914 r
= HttpSendRequestA(hr
, NULL
, 0, (char *)"data", sizeof("data"));
2915 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2917 test_status_code(hr
, 407);
2920 InternetCloseHandle(hr
);
2921 InternetCloseHandle(hc
);
2922 InternetCloseHandle(hi
);
2925 static void test_header_handling_order(int port
)
2927 static const char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
2928 static const char connection
[] = "Connection: Close";
2929 static const char *types
[2] = { "*", NULL
};
2931 HINTERNET session
, connect
, request
;
2932 DWORD size
, status
, data_len
;
2935 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2936 ok(session
!= NULL
, "InternetOpen failed\n");
2938 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2939 ok(connect
!= NULL
, "InternetConnect failed\n");
2941 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2942 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2944 ret
= HttpAddRequestHeadersA(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
2945 ok(ret
, "HttpAddRequestHeaders failed\n");
2947 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
2948 ok(ret
, "HttpSendRequest failed\n");
2950 test_status_code(request
, 200);
2951 test_request_flags(request
, 0);
2953 InternetCloseHandle(request
);
2955 request
= HttpOpenRequestA(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2956 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2958 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2959 ok(ret
, "HttpSendRequest failed\n");
2962 size
= sizeof(status
);
2963 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2964 ok(ret
, "HttpQueryInfo failed\n");
2965 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2967 InternetCloseHandle(request
);
2968 InternetCloseHandle(connect
);
2970 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2971 ok(connect
!= NULL
, "InternetConnect failed\n");
2973 request
= HttpOpenRequestA(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2974 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2976 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2977 ok(ret
, "HttpAddRequestHeaders failed\n");
2979 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2980 ok(ret
, "HttpSendRequest failed\n");
2983 size
= sizeof(status
);
2984 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2985 ok(ret
, "HttpQueryInfo failed\n");
2986 ok(status
== 200, "got status %u, expected 200\n", status
);
2988 InternetCloseHandle(request
);
2989 InternetCloseHandle(connect
);
2991 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2992 ok(connect
!= NULL
, "InternetConnect failed\n");
2994 request
= HttpOpenRequestA(connect
, "POST", "/test7b", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2995 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2997 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2998 ok(ret
, "HttpAddRequestHeaders failed\n");
3000 data_len
= sizeof(data
);
3001 memset(data
, 'a', sizeof(data
));
3002 ret
= HttpSendRequestA(request
, NULL
, 0, data
, data_len
);
3003 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3006 size
= sizeof(status
);
3007 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
3008 ok(ret
, "HttpQueryInfo failed\n");
3009 ok(status
== 200, "got status %u, expected 200\n", status
);
3011 InternetCloseHandle(request
);
3012 InternetCloseHandle(connect
);
3013 InternetCloseHandle(session
);
3016 static void test_connection_header(int port
)
3018 HINTERNET ses
, con
, req
;
3021 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3022 ok(ses
!= NULL
, "InternetOpen failed\n");
3024 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3025 ok(con
!= NULL
, "InternetConnect failed\n");
3027 req
= HttpOpenRequestA(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3028 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3030 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3031 ok(ret
, "HttpSendRequest failed\n");
3033 test_status_code(req
, 200);
3035 InternetCloseHandle(req
);
3037 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
3038 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3040 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3041 ok(ret
, "HttpSendRequest failed\n");
3043 test_status_code(req
, 200);
3045 InternetCloseHandle(req
);
3047 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3048 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3050 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3051 ok(ret
, "HttpSendRequest failed\n");
3053 test_status_code(req
, 200);
3055 InternetCloseHandle(req
);
3057 req
= HttpOpenRequestA(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3058 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3060 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3061 ok(ret
, "HttpSendRequest failed\n");
3063 test_status_code(req
, 200);
3065 InternetCloseHandle(req
);
3066 InternetCloseHandle(con
);
3067 InternetCloseHandle(ses
);
3070 static void test_header_override(int port
)
3072 char buffer
[128], host_header_override
[30], full_url
[128];
3073 HINTERNET ses
, con
, req
;
3074 DWORD size
, count
, err
;
3077 sprintf(host_header_override
, "Host: test.local:%d\r\n", port
);
3078 sprintf(full_url
, "http://localhost:%d/test_host_override", port
);
3080 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3081 ok(ses
!= NULL
, "InternetOpen failed\n");
3083 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3084 ok(con
!= NULL
, "InternetConnect failed\n");
3086 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3087 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3089 size
= sizeof(buffer
) - 1;
3091 memset(buffer
, 0, sizeof(buffer
));
3092 ret
= HttpQueryInfoA(req
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &count
);
3093 err
= GetLastError();
3094 ok(!ret
, "HttpQueryInfo succeeded\n");
3095 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err
);
3097 test_request_url(req
, full_url
);
3099 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3100 ok(ret
, "HttpAddRequestHeaders failed\n");
3102 size
= sizeof(buffer
) - 1;
3104 memset(buffer
, 0, sizeof(buffer
));
3105 ret
= HttpQueryInfoA(req
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &count
);
3106 ok(ret
, "HttpQueryInfo failed\n");
3108 test_request_url(req
, full_url
);
3110 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3111 ok(ret
, "HttpSendRequest failed\n");
3113 test_status_code(req
, 200);
3115 InternetCloseHandle(req
);
3116 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3117 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3119 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3120 ok(ret
, "HttpAddRequestHeaders failed\n");
3122 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3123 ok(ret
, "HttpAddRequestHeaders failed\n");
3125 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3126 ok(ret
, "HttpSendRequest failed\n");
3128 test_status_code(req
, 400);
3130 InternetCloseHandle(req
);
3131 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3132 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3134 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3135 ok(ret
, "HttpAddRequestHeaders failed\n");
3137 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3138 ok(ret
, "HttpSendRequest failed\n");
3140 test_status_code(req
, 200);
3142 InternetCloseHandle(req
);
3143 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3144 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3146 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_REPLACE
);
3147 if(ret
) { /* win10 returns success */
3148 trace("replacing host header is supported.\n");
3150 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3151 ok(ret
, "HttpSendRequest failed\n");
3153 test_status_code(req
, 200);
3155 trace("replacing host header is not supported.\n");
3157 err
= GetLastError();
3158 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err
);
3160 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3161 ok(ret
, "HttpSendRequest failed\n");
3163 test_status_code(req
, 400);
3166 InternetCloseHandle(req
);
3167 InternetCloseHandle(con
);
3168 InternetCloseHandle(ses
);
3171 static void test_connection_closing(int port
)
3173 HINTERNET session
, connection
, req
;
3178 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3179 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3181 pInternetSetStatusCallbackA(session
, callback
);
3183 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3184 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3185 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3186 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3188 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3189 req
= HttpOpenRequestA(connection
, "GET", "/testJ", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3190 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3191 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3193 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3194 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3195 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3196 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3197 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3198 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3199 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3200 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3201 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3202 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3203 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3205 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3206 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3207 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3208 WaitForSingleObject(complete_event
, INFINITE
);
3209 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3211 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3212 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3213 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3214 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3215 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3216 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3217 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3218 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3219 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3220 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3221 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3223 test_status_code(req
, 200);
3225 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3226 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3227 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3228 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3229 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3230 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3231 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3232 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3233 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3235 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3236 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3237 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3238 WaitForSingleObject(complete_event
, INFINITE
);
3239 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3241 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3242 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3243 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3244 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3245 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3246 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3247 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3248 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3249 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3251 test_status_code(req
, 210);
3253 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3254 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3255 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3256 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3257 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3258 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3259 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3260 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3261 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3262 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3263 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3265 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3266 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3267 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3268 WaitForSingleObject(complete_event
, INFINITE
);
3269 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3271 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3272 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3273 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3274 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3275 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3276 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3277 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3278 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3279 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3280 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3281 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3283 test_status_code(req
, 200);
3285 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3286 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3288 close_async_handle(session
, 2);
3291 static void test_successive_HttpSendRequest(int port
)
3293 HINTERNET session
, connection
, req
;
3298 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3299 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3301 pInternetSetStatusCallbackA(session
, callback
);
3303 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3304 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3305 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3306 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3308 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3309 req
= HttpOpenRequestA(connection
, "GET", "/testH", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3310 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3311 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3313 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3314 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3315 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3316 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3317 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3318 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3319 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3320 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3321 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3323 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3324 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3325 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3326 WaitForSingleObject(complete_event
, INFINITE
);
3327 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3329 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3330 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3331 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3332 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3333 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3334 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3335 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3336 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3337 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3339 test_status_code(req
, 210);
3341 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3342 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3343 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3344 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3345 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3346 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3347 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3348 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3349 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3351 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3352 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3353 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3354 WaitForSingleObject(complete_event
, INFINITE
);
3355 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3357 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3358 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3359 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3360 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3361 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3362 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3363 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3364 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3365 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3367 test_status_code(req
, 200);
3369 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3370 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3372 close_async_handle(session
, 2);
3375 static void test_no_content(int port
)
3377 HINTERNET session
, connection
, req
;
3380 trace("Testing 204 no content response...\n");
3384 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3385 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3387 pInternetSetStatusCallbackA(session
, callback
);
3389 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3390 connection
= InternetConnectA(session
, "localhost", port
,
3391 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3392 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3393 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3395 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3396 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
3397 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3398 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3399 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3401 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3402 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3403 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3404 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3405 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3406 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3407 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3408 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3409 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3410 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3412 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3413 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3414 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3415 WaitForSingleObject(complete_event
, INFINITE
);
3416 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3418 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3419 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3420 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3421 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3422 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3423 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3424 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3425 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3427 close_async_handle(session
, 2);
3430 * The connection should be closed before closing handle. This is true for most
3431 * wininet versions (including Wine), but some old win2k versions fail to do that.
3433 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3434 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3437 static void test_conn_close(int port
)
3439 HINTERNET session
, connection
, req
;
3440 DWORD res
, avail
, size
;
3443 trace("Testing connection close connection...\n");
3447 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3448 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3450 pInternetSetStatusCallbackA(session
, callback
);
3452 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3453 connection
= InternetConnectA(session
, "localhost", port
,
3454 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3455 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3456 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3458 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3459 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
3460 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3461 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3462 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3464 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3465 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3466 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3467 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3468 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3469 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3470 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3471 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3473 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3474 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3475 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3476 WaitForSingleObject(complete_event
, INFINITE
);
3477 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3479 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3480 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3481 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3482 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3483 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3484 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3485 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3486 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3489 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3490 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3491 ok(avail
!= 0, "avail = 0\n");
3494 res
= InternetReadFile(req
, buf
, avail
, &size
);
3495 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3497 /* IE11 calls those in InternetQueryDataAvailable call. */
3498 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
3499 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
3501 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3502 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3503 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3504 ok(!avail
, "avail = %u, expected 0\n", avail
);
3506 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3508 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3509 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3510 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3511 SetEvent(conn_close_event
);
3512 WaitForSingleObject(complete_event
, INFINITE
);
3513 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3514 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3515 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3516 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3517 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3519 close_async_handle(session
, 2);
3522 static void test_no_cache(int port
)
3524 static const char cache_control_no_cache
[] = "/test_cache_control_no_cache";
3525 static const char cache_control_no_store
[] = "/test_cache_control_no_store";
3526 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3528 char cache_url
[256], buf
[256];
3529 HINTERNET ses
, con
, req
;
3533 trace("Testing no-cache header\n");
3535 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3536 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3538 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3539 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3541 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3542 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3544 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_cache
);
3545 DeleteUrlCacheEntryA(cache_url
);
3547 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3548 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3550 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3552 ok(size
== 12, "read %d bytes of data\n", size
);
3553 InternetCloseHandle(req
);
3555 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3556 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3558 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3559 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3561 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3563 ok(size
== 0, "read %d bytes of data\n", size
);
3564 InternetCloseHandle(req
);
3565 DeleteUrlCacheEntryA(cache_url
);
3567 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_store
, NULL
, NULL
, NULL
, 0, 0);
3568 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3570 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_store
);
3571 DeleteUrlCacheEntryA(cache_url
);
3573 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3574 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3576 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3578 ok(size
== 12, "read %d bytes of data\n", size
);
3579 InternetCloseHandle(req
);
3581 ret
= DeleteUrlCacheEntryA(cache_url
);
3582 ok(!ret
&& GetLastError()==ERROR_FILE_NOT_FOUND
, "cache entry should not exist\n");
3584 InternetCloseHandle(con
);
3585 InternetCloseHandle(ses
);
3588 static void test_cache_read_gzipped(int port
)
3590 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3591 static const char get_gzip
[] = "/test_cache_gzip";
3592 static const char content
[] = "gzip test\n";
3593 static const char text_html
[] = "text/html";
3594 static const char raw_header
[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3596 HINTERNET ses
, con
, req
;
3598 char cache_url
[256], buf
[256];
3601 trace("Testing reading compressed content from cache\n");
3603 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3604 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3606 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3607 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3609 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3610 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3613 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3614 if(!ret
&& GetLastError()==ERROR_INTERNET_INVALID_OPTION
) {
3615 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3616 InternetCloseHandle(req
);
3617 InternetCloseHandle(con
);
3618 InternetCloseHandle(ses
);
3621 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3623 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3624 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3626 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-size
, &read
) && read
)
3628 ok(size
== 10, "read %d bytes of data\n", size
);
3630 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3632 size
= sizeof(buf
)-1;
3633 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3634 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3636 ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3638 size
= sizeof(buf
)-1;
3639 ret
= HttpQueryInfoA(req
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &size
, 0);
3640 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3642 ok(!strncmp(raw_header
, buf
, size
), "buf = %s\n", buf
);
3643 InternetCloseHandle(req
);
3645 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3646 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3649 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3650 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3652 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3653 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3655 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3657 todo_wine
ok(size
== 10, "read %d bytes of data\n", size
);
3659 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3662 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3663 ok(!ret
&& GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND
,
3664 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3665 ret
, GetLastError());
3667 size
= sizeof(buf
)-1;
3668 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3669 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3671 todo_wine
ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3672 InternetCloseHandle(req
);
3674 /* Decompression doesn't work while reading from cache */
3675 test_cache_gzip
= 0;
3676 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3677 DeleteUrlCacheEntryA(cache_url
);
3679 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3680 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3682 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3683 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3685 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3687 ok(size
== 31, "read %d bytes of data\n", size
);
3688 InternetCloseHandle(req
);
3690 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3691 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3694 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3695 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3697 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3698 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3700 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3702 todo_wine
ok(size
== 31, "read %d bytes of data\n", size
);
3705 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3706 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3707 InternetCloseHandle(req
);
3709 InternetCloseHandle(con
);
3710 InternetCloseHandle(ses
);
3712 /* Decompression doesn't work while reading from cache */
3713 test_cache_gzip
= 0;
3714 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3715 DeleteUrlCacheEntryA(cache_url
);
3717 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3718 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3721 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3722 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3724 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3725 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3727 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3728 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3730 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3731 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3733 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3735 ok(size
== 10, "read %d bytes of data\n", size
);
3737 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3738 InternetCloseHandle(req
);
3740 InternetCloseHandle(con
);
3741 InternetCloseHandle(ses
);
3743 /* Decompression doesn't work while reading from cache */
3744 test_cache_gzip
= 0;
3745 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3746 DeleteUrlCacheEntryA(cache_url
);
3748 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3749 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3751 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3752 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3755 ret
= InternetSetOptionA(con
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3756 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3758 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3759 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3761 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3762 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3764 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3766 ok(size
== 10, "read %d bytes of data\n", size
);
3768 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3769 InternetCloseHandle(req
);
3771 InternetCloseHandle(con
);
3772 InternetCloseHandle(ses
);
3774 DeleteUrlCacheEntryA(cache_url
);
3777 static void test_HttpSendRequestW(int port
)
3779 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3780 HINTERNET ses
, con
, req
;
3784 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3785 ok(ses
!= NULL
, "InternetOpen failed\n");
3787 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3788 ok(con
!= NULL
, "InternetConnect failed\n");
3790 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3791 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3793 SetLastError(0xdeadbeef);
3794 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
3795 error
= GetLastError();
3796 ok(!ret
, "HttpSendRequestW succeeded\n");
3797 ok(error
== ERROR_IO_PENDING
||
3798 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
3799 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
3800 "got %u expected ERROR_IO_PENDING\n", error
);
3802 InternetCloseHandle(req
);
3803 InternetCloseHandle(con
);
3804 InternetCloseHandle(ses
);
3807 static void test_cookie_header(int port
)
3809 HINTERNET ses
, con
, req
;
3814 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3815 ok(ses
!= NULL
, "InternetOpen failed\n");
3817 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3818 ok(con
!= NULL
, "InternetConnect failed\n");
3820 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3822 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3823 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3826 size
= sizeof(buffer
);
3827 SetLastError(0xdeadbeef);
3828 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3829 error
= GetLastError();
3830 ok(!ret
, "HttpQueryInfo succeeded\n");
3831 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3833 ret
= HttpAddRequestHeadersA(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
3834 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3837 size
= sizeof(buffer
);
3838 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3839 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3840 ok(!strcmp(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
3842 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3843 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3845 test_status_code(req
, 200);
3848 size
= sizeof(buffer
);
3849 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3850 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3851 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
3853 InternetCloseHandle(req
);
3854 InternetCloseHandle(con
);
3855 InternetCloseHandle(ses
);
3858 static void test_basic_authentication(int port
)
3860 HINTERNET session
, connect
, request
;
3863 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3864 ok(session
!= NULL
, "InternetOpen failed\n");
3866 connect
= InternetConnectA(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
3867 ok(connect
!= NULL
, "InternetConnect failed\n");
3869 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
3870 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3872 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3873 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3875 test_status_code(request
, 200);
3876 test_request_flags(request
, 0);
3878 InternetCloseHandle(request
);
3879 InternetCloseHandle(connect
);
3880 InternetCloseHandle(session
);
3883 static void test_premature_disconnect(int port
)
3889 open_simple_request(&req
, "localhost", port
, NULL
, "/premature_disconnect");
3891 SetLastError(0xdeadbeef);
3892 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
3893 err
= GetLastError();
3894 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
3895 todo_wine
ok(err
== ERROR_HTTP_INVALID_SERVER_RESPONSE
, "got %u\n", err
);
3897 close_request(&req
);
3900 static void test_invalid_response_headers(int port
)
3907 open_simple_request(&req
, "localhost", port
, NULL
, "/testE");
3909 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
3910 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3912 test_status_code(req
.request
, 401);
3913 test_request_flags(req
.request
, 0);
3916 size
= sizeof(buffer
);
3917 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3918 ok(ret
, "HttpQueryInfo failed\n");
3919 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
3920 "headers wrong \"%s\"\n", buffer
);
3923 size
= sizeof(buffer
);
3924 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
3925 ok(ret
, "HttpQueryInfo failed\n");
3926 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
3928 close_request(&req
);
3931 static void test_response_without_headers(int port
)
3934 DWORD r
, count
, size
;
3937 open_simple_request(&req
, "localhost", port
, NULL
, "/testG");
3939 test_request_flags(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
3941 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
3942 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
3944 test_request_flags_todo(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
3947 memset(buffer
, 0, sizeof buffer
);
3948 r
= InternetReadFile(req
.request
, buffer
, sizeof buffer
, &count
);
3949 ok(r
, "InternetReadFile failed %u\n", GetLastError());
3950 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
3951 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
3953 test_status_code(req
.request
, 200);
3954 test_request_flags_todo(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
3957 size
= sizeof(buffer
);
3958 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
3959 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3960 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
3963 size
= sizeof(buffer
);
3964 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
3965 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3966 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
3969 size
= sizeof(buffer
);
3970 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3971 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3972 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
3974 close_request(&req
);
3977 static void test_head_request(int port
)
3979 DWORD len
, content_length
;
3984 open_simple_request(&req
, "localhost", port
, "HEAD", "/test_head");
3986 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
3987 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3989 len
= sizeof(content_length
);
3990 content_length
= -1;
3991 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
, &content_length
, &len
, 0);
3992 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3993 ok(len
== sizeof(DWORD
), "len = %u\n", len
);
3994 ok(content_length
== 100, "content_length = %u\n", content_length
);
3997 ret
= InternetReadFile(req
.request
, buf
, sizeof(buf
), &len
);
3998 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
4001 ret
= InternetReadFile(req
.request
, buf
, sizeof(buf
), &len
);
4002 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
4004 close_request(&req
);
4007 static void test_HttpQueryInfo(int port
)
4010 DWORD size
, index
, error
;
4014 open_simple_request(&req
, "localhost", port
, NULL
, "/testD");
4016 size
= sizeof(buffer
);
4017 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
4018 error
= GetLastError();
4019 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
4020 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
4022 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4023 ok(ret
, "HttpSendRequest failed\n");
4026 size
= sizeof(buffer
);
4027 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
4028 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4029 ok(index
== 1, "expected 1 got %u\n", index
);
4032 size
= sizeof(buffer
);
4033 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
4034 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4035 ok(index
== 1, "expected 1 got %u\n", index
);
4038 size
= sizeof(buffer
);
4039 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4040 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4041 ok(index
== 0, "expected 0 got %u\n", index
);
4043 size
= sizeof(buffer
);
4044 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4045 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4046 ok(index
== 0, "expected 0 got %u\n", index
);
4048 index
= 0xdeadbeef; /* invalid start index */
4049 size
= sizeof(buffer
);
4050 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4051 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
4052 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
4053 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
4056 size
= sizeof(buffer
);
4057 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
4058 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4059 ok(index
== 0, "expected 0 got %u\n", index
);
4061 size
= sizeof(buffer
);
4062 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
4063 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4064 ok(index
== 0, "expected 0 got %u\n", index
);
4066 size
= sizeof(buffer
);
4067 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
4068 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4069 ok(index
== 0, "expected 0 got %u\n", index
);
4071 test_status_code(req
.request
, 200);
4074 size
= sizeof(buffer
);
4075 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
4076 ok(!ret
, "HttpQueryInfo succeeded\n");
4077 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
4080 size
= sizeof(buffer
);
4081 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
4082 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4083 ok(index
== 1, "expected 1 got %u\n", index
);
4086 size
= sizeof(buffer
);
4087 strcpy(buffer
, "Server");
4088 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
4089 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4090 ok(index
== 1, "expected 1 got %u\n", index
);
4093 size
= sizeof(buffer
);
4094 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
4095 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4096 ok(index
== 1, "expected 1 got %u\n", index
);
4098 size
= sizeof(buffer
);
4099 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
4100 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4101 ok(index
== 2, "expected 2 got %u\n", index
);
4103 close_request(&req
);
4106 static void test_options(int port
)
4108 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi
;
4109 HINTERNET ses
, con
, req
;
4114 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4115 ok(ses
!= NULL
, "InternetOpen failed\n");
4117 SetLastError(0xdeadbeef);
4118 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
4119 error
= GetLastError();
4120 ok(!ret
, "InternetSetOption succeeded\n");
4121 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4123 SetLastError(0xdeadbeef);
4124 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
4125 ok(!ret
, "InternetSetOption succeeded\n");
4126 error
= GetLastError();
4127 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4129 SetLastError(0xdeadbeef);
4130 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
4131 ok(!ret
, "InternetSetOption succeeded\n");
4132 error
= GetLastError();
4133 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4136 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4137 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4139 SetLastError(0xdeadbeef);
4140 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
4141 error
= GetLastError();
4142 ok(!ret
, "InternetQueryOption succeeded\n");
4143 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4145 SetLastError(0xdeadbeef);
4146 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
4147 error
= GetLastError();
4148 ok(!ret
, "InternetQueryOption succeeded\n");
4149 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4152 SetLastError(0xdeadbeef);
4153 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
4154 error
= GetLastError();
4155 ok(!ret
, "InternetQueryOption succeeded\n");
4156 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
4159 SetLastError(0xdeadbeef);
4160 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4161 error
= GetLastError();
4162 ok(!ret
, "InternetQueryOption succeeded\n");
4163 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
4167 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4168 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4169 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
4171 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4172 ok(con
!= NULL
, "InternetConnect failed\n");
4176 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4177 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4178 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
4181 ret
= InternetSetOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4182 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4186 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4187 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4188 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
4190 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
4191 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4195 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4196 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4197 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
4200 ret
= InternetSetOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4201 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4205 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4206 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4207 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
4209 size
= sizeof(idsi
);
4210 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO
, &idsi
, &size
);
4211 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4214 SetLastError(0xdeadbeef);
4215 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
4216 error
= GetLastError();
4217 ok(!ret
, "InternetQueryOption succeeded\n");
4218 ok(error
== ERROR_INTERNET_INVALID_OPERATION
, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error
);
4220 /* INTERNET_OPTION_PROXY */
4221 SetLastError(0xdeadbeef);
4222 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
4223 error
= GetLastError();
4224 ok(!ret
, "InternetQueryOption succeeded\n");
4225 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4227 SetLastError(0xdeadbeef);
4228 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
4229 error
= GetLastError();
4230 ok(!ret
, "InternetQueryOption succeeded\n");
4231 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4234 SetLastError(0xdeadbeef);
4235 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
4236 error
= GetLastError();
4237 ok(!ret
, "InternetQueryOption succeeded\n");
4238 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
4239 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
4241 InternetCloseHandle(req
);
4242 InternetCloseHandle(con
);
4243 InternetCloseHandle(ses
);
4247 const char *response_text
;
4249 const char *status_text
;
4250 const char *raw_headers
;
4251 } http_status_test_t
;
4253 static const http_status_test_t http_status_tests
[] = {
4255 "HTTP/1.1 200 OK\r\n"
4256 "Content-Length: 1\r\n"
4262 "HTTP/1.1 404 Fail\r\n"
4263 "Content-Length: 1\r\n"
4270 "Content-Length: 1\r\n"
4277 "Content-Length: 1\r\n"
4284 static void test_http_status(int port
)
4291 for(i
= 0; i
< ARRAY_SIZE(http_status_tests
); i
++) {
4292 send_buffer
= http_status_tests
[i
].response_text
;
4294 open_simple_request(&req
, "localhost", port
, NULL
, "/send_from_buffer");
4296 res
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4297 ok(res
, "HttpSendRequest failed\n");
4299 test_status_code(req
.request
, http_status_tests
[i
].status_code
);
4302 res
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buf
, &size
, NULL
);
4303 ok(res
, "HttpQueryInfo failed: %u\n", GetLastError());
4304 ok(!strcmp(buf
, http_status_tests
[i
].status_text
), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
4305 i
, buf
, http_status_tests
[i
].status_text
);
4307 close_request(&req
);
4311 static void test_cache_control_verb(int port
)
4313 HINTERNET session
, connect
, request
;
4316 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4317 ok(session
!= NULL
, "InternetOpen failed\n");
4319 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4320 ok(connect
!= NULL
, "InternetConnect failed\n");
4322 request
= HttpOpenRequestA(connect
, "RPC_OUT_DATA", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4323 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4324 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4325 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4326 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4327 test_status_code(request
, 200);
4328 InternetCloseHandle(request
);
4330 request
= HttpOpenRequestA(connect
, "POST", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4331 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4332 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4333 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4334 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4335 test_status_code(request
, 200);
4336 InternetCloseHandle(request
);
4338 request
= HttpOpenRequestA(connect
, "HEAD", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4339 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4340 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4341 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4342 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4343 test_status_code(request
, 200);
4344 InternetCloseHandle(request
);
4346 request
= HttpOpenRequestA(connect
, "GET", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4347 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4348 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4349 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4350 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4351 test_status_code(request
, 200);
4352 InternetCloseHandle(request
);
4354 InternetCloseHandle(connect
);
4355 InternetCloseHandle(session
);
4358 static void test_request_content_length(int port
)
4360 char data
[] = {'t','e','s','t'};
4365 open_simple_request(&req
, "localhost", port
, "POST", "/test_request_content_length");
4367 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4368 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4369 test_status_code(req
.request
, 200);
4371 SetEvent(complete_event
);
4373 ret
= HttpSendRequestA(req
.request
, NULL
, 0, data
, sizeof(data
));
4374 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4375 test_status_code(req
.request
, 200);
4377 SetEvent(complete_event
);
4378 close_request(&req
);
4381 static void test_accept_encoding(int port
)
4383 HINTERNET ses
, con
, req
;
4387 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4388 ok(ses
!= NULL
, "InternetOpen failed\n");
4390 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4391 ok(con
!= NULL
, "InternetConnect failed\n");
4393 req
= HttpOpenRequestA(con
, "GET", "/echo_request", "HTTP/1.0", NULL
, NULL
, 0, 0);
4394 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4396 ret
= HttpAddRequestHeadersA(req
, "Accept-Encoding: gzip\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDREQ_FLAG_ADD
);
4397 ok(ret
, "HttpAddRequestHeaders failed\n");
4399 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4400 ok(ret
, "HttpSendRequestA failed\n");
4402 test_status_code(req
, 200);
4403 receive_simple_request(req
, buf
, sizeof(buf
));
4404 ok(strstr(buf
, "Accept-Encoding: gzip") != NULL
, "Accept-Encoding header not found in %s\n", buf
);
4406 InternetCloseHandle(req
);
4408 req
= HttpOpenRequestA(con
, "GET", "/echo_request", "HTTP/1.0", NULL
, NULL
, 0, 0);
4409 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4411 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", ~0u, NULL
, 0);
4412 ok(ret
, "HttpSendRequestA failed\n");
4414 test_status_code(req
, 200);
4415 receive_simple_request(req
, buf
, sizeof(buf
));
4416 ok(strstr(buf
, "Accept-Encoding: gzip") != NULL
, "Accept-Encoding header not found in %s\n", buf
);
4418 InternetCloseHandle(req
);
4419 InternetCloseHandle(con
);
4420 InternetCloseHandle(ses
);
4423 static void test_basic_auth_credentials_reuse(int port
)
4425 HINTERNET ses
, con
, req
;
4429 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4430 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4432 con
= InternetConnectA( ses
, "localhost", port
, "user", "pwd",
4433 INTERNET_SERVICE_HTTP
, 0, 0 );
4434 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4436 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
4437 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4439 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4440 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4442 status
= 0xdeadbeef;
4443 size
= sizeof(status
);
4444 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4445 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4446 ok( status
== 200, "got %u\n", status
);
4448 InternetCloseHandle( req
);
4449 InternetCloseHandle( con
);
4450 InternetCloseHandle( ses
);
4452 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4453 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4455 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
,
4456 INTERNET_SERVICE_HTTP
, 0, 0 );
4457 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4459 req
= HttpOpenRequestA( con
, "PUT", "/upload2.txt", NULL
, NULL
, NULL
, 0, 0 );
4460 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4462 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4463 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4465 status
= 0xdeadbeef;
4466 size
= sizeof(status
);
4467 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4468 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4469 ok( status
== 200, "got %u\n", status
);
4471 InternetCloseHandle( req
);
4472 InternetCloseHandle( con
);
4473 InternetCloseHandle( ses
);
4476 static void test_async_read(int port
)
4478 HINTERNET ses
, con
, req
;
4479 INTERNET_BUFFERSA ib
;
4481 DWORD pending_reads
;
4482 DWORD res
, count
, bytes
;
4487 /* test asynchronous InternetReadFileEx */
4488 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4489 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4490 pInternetSetStatusCallbackA( ses
, &callback
);
4492 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4493 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef );
4494 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4495 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4497 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4498 req
= HttpOpenRequestA( con
, "GET", "/async_read", NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef );
4499 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4500 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4502 SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT
);
4503 SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY
);
4504 SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4505 SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4506 SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST
);
4507 SET_EXPECT( INTERNET_STATUS_REQUEST_SENT
);
4508 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4509 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4510 SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION
);
4511 SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED
);
4512 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4514 SetLastError( 0xdeadbeef );
4515 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4516 ok( !ret
, "HttpSendRequestA unexpectedly succeeded\n" );
4517 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4518 WaitForSingleObject( complete_event
, INFINITE
);
4519 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4521 CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT
);
4522 CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY
);
4523 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4524 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4525 CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST
);
4526 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT
);
4527 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4528 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4529 CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION
);
4530 CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED
);
4531 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4534 memset( &ib
, 0, sizeof(ib
) );
4535 memset( buffer
, 0, sizeof(buffer
) );
4536 ib
.dwStructSize
= sizeof(ib
);
4537 for (count
= 0; count
< sizeof(buffer
); count
+= ib
.dwBufferLength
)
4539 ib
.lpvBuffer
= buffer
+ count
;
4540 ib
.dwBufferLength
= min(16, sizeof(buffer
) - count
);
4542 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4543 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4545 ret
= InternetReadFileExA( req
, &ib
, 0, 0xdeadbeef );
4546 if (!count
) /* the first part should arrive immediately */
4547 ok( ret
, "InternetReadFileExA failed %u\n", GetLastError() );
4550 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4551 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4552 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4553 if (!pending_reads
++)
4555 res
= WaitForSingleObject( complete_event
, 0 );
4556 ok( res
== WAIT_TIMEOUT
, "expected WAIT_TIMEOUT, got %u\n", res
);
4557 SetEvent( conn_wait_event
);
4559 res
= WaitForSingleObject( complete_event
, INFINITE
);
4560 ok( res
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", res
);
4561 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4562 todo_wine_if( pending_reads
> 1 )
4563 ok( ib
.dwBufferLength
!= 0, "expected ib.dwBufferLength != 0\n" );
4564 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4565 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4568 CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4569 CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4570 if (!ib
.dwBufferLength
) break;
4573 ok( pending_reads
== 1, "expected 1 pending read, got %u\n", pending_reads
);
4574 ok( !strcmp(buffer
, page1
), "unexpected buffer content\n" );
4575 close_async_handle( ses
, 2 );
4576 ResetEvent( conn_wait_event
);
4578 /* test asynchronous InternetReadFile */
4579 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4580 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4581 pInternetSetStatusCallbackA( ses
, &callback
);
4583 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4584 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef );
4585 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4586 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4588 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4589 req
= HttpOpenRequestA( con
, "GET", "/async_read", NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef );
4590 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4591 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4593 SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT
);
4594 SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY
);
4595 SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4596 SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4597 SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST
);
4598 SET_EXPECT( INTERNET_STATUS_REQUEST_SENT
);
4599 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4600 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4601 SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION
);
4602 SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED
);
4603 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4605 SetLastError( 0xdeadbeef );
4606 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4607 ok( !ret
, "HttpSendRequestA unexpectedly succeeded\n" );
4608 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4609 WaitForSingleObject( complete_event
, INFINITE
);
4610 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4612 CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT
);
4613 CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY
);
4614 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4615 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4616 CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST
);
4617 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT
);
4618 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4619 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4620 CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION
);
4621 CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED
);
4622 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4625 memset( buffer
, 0, sizeof(buffer
) );
4626 for (count
= 0; count
< sizeof(buffer
); count
+= bytes
)
4628 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4629 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4632 ret
= InternetReadFile( req
, buffer
+ count
, min(16, sizeof(buffer
) - count
), &bytes
);
4633 if (!count
) /* the first part should arrive immediately */
4634 ok( ret
, "InternetReadFile failed %u\n", GetLastError() );
4637 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4638 ok( bytes
== 0, "expected 0, got %u\n", bytes
);
4639 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4640 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4641 if (!pending_reads
++)
4643 res
= WaitForSingleObject( complete_event
, 0 );
4644 ok( res
== WAIT_TIMEOUT
, "expected WAIT_TIMEOUT, got %u\n", res
);
4645 SetEvent( conn_wait_event
);
4647 res
= WaitForSingleObject( complete_event
, INFINITE
);
4648 ok( res
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", res
);
4649 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4650 todo_wine_if( pending_reads
> 1 )
4651 ok( bytes
!= 0, "expected bytes != 0\n" );
4652 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4653 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4656 CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4657 CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4661 ok( pending_reads
== 1, "expected 1 pending read, got %u\n", pending_reads
);
4662 ok( !strcmp(buffer
, page1
), "unexpected buffer content\n" );
4663 close_async_handle( ses
, 2 );
4666 static void server_send_string(const char *msg
)
4668 send(server_socket
, msg
, strlen(msg
), 0);
4671 static size_t server_read_data(char *buf
, size_t buf_size
)
4673 return recv(server_socket
, buf
, buf_size
, 0);
4676 #define server_read_request(a) _server_read_request(__LINE__,a)
4677 static void _server_read_request(unsigned line
, const char *expected_request
)
4682 size
= server_read_data(buf
, sizeof(buf
) - 1);
4684 p
= strstr(buf
, "\r\n");
4686 ok_(__FILE__
,line
)(p
&& !strcmp(buf
, expected_request
), "unexpected request %s\n", buf
);
4689 static BOOL skip_receive_notification_tests
;
4690 static DWORD received_response_size
;
4692 static void WINAPI
readex_callback(HINTERNET handle
, DWORD_PTR context
, DWORD status
, void *info
, DWORD info_size
)
4695 case INTERNET_STATUS_RECEIVING_RESPONSE
:
4696 if(!skip_receive_notification_tests
)
4697 callback(handle
, context
, status
, info
, info_size
);
4699 case INTERNET_STATUS_RESPONSE_RECEIVED
:
4700 if(!skip_receive_notification_tests
)
4701 callback(handle
, context
, status
, info
, info_size
);
4702 received_response_size
= *(DWORD
*)info
;
4704 case INTERNET_STATUS_REQUEST_SENT
:
4705 callback(handle
, context
, status
, info
, info_size
);
4706 SetEvent(request_sent_event
);
4709 callback(handle
, context
, status
, info
, info_size
);
4713 static void send_socket_request(test_request_t
*req
, BOOL new_connection
)
4717 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4718 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4719 if(new_connection
) {
4720 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4721 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4723 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4724 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4725 if(!skip_receive_notification_tests
)
4726 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4728 SetLastError(0xdeadbeef);
4729 ret
= HttpSendRequestA(req
->request
, NULL
, 0, NULL
, 0);
4730 ok(!ret
, "HttpSendRequestA unexpectedly succeeded\n");
4731 ok(GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError());
4734 WaitForSingleObject(server_req_rec_event
, INFINITE
);
4735 WaitForSingleObject(request_sent_event
, INFINITE
);
4737 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4738 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4739 if(new_connection
) {
4740 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4741 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4743 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4744 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4747 static void open_socket_request(int port
, test_request_t
*req
, const char *verb
)
4749 /* We're connecting to new socket */
4753 req
->session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4754 ok(req
->session
!= NULL
, "InternetOpenA failed\n");
4755 pInternetSetStatusCallbackA(req
->session
, readex_callback
);
4757 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4758 req
->connection
= InternetConnectA(req
->session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef);
4759 ok(req
->connection
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
4760 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4762 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4763 req
->request
= HttpOpenRequestA(req
->connection
, "GET", verb
? verb
: "/socket",
4764 NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef);
4765 ok(req
->request
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
4766 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4768 send_socket_request(req
, !verb
);
4771 static void open_read_test_request(int port
, test_request_t
*req
, const char *response
)
4773 if(!skip_receive_notification_tests
)
4774 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4776 open_socket_request(port
, req
, NULL
);
4778 if(!skip_receive_notification_tests
) {
4779 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4780 received_response_size
= 0xdeadbeef;
4782 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4784 server_send_string(response
);
4785 WaitForSingleObject(complete_event
, INFINITE
);
4787 if(!skip_receive_notification_tests
) {
4788 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4789 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4791 ok(received_response_size
== strlen(response
), "received_response_size = %u\n", received_response_size
);
4793 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4794 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4797 #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)
4798 static void _readex_expect_sync_data_len(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
4799 DWORD buf_size
, const char *exdata
, DWORD len
, DWORD expect_receive
)
4803 if(!skip_receive_notification_tests
&& expect_receive
) {
4804 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4805 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4806 received_response_size
= 0xdeadbeef;
4809 memset(buf
->lpvBuffer
, 0xff, buf_size
);
4810 buf
->dwBufferLength
= buf_size
;
4811 ret
= InternetReadFileExW(req
, buf
, flags
, 0xdeadbeef);
4812 ok_(__FILE__
,line
)(ret
, "InternetReadFileExW failed: %u\n", GetLastError());
4813 ok_(__FILE__
,line
)(buf
->dwBufferLength
== len
, "dwBufferLength = %u, expected %u\n", buf
->dwBufferLength
, len
);
4815 ok_(__FILE__
,line
)(!memcmp(buf
->lpvBuffer
, exdata
, len
), "Unexpected data\n");
4817 if(!skip_receive_notification_tests
&& expect_receive
) {
4818 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4819 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4820 ok_(__FILE__
,line
)(received_response_size
== len
, "received_response_size = %u\n", received_response_size
);
4824 #define readex_expect_sync_data(a,b,c,d,e,f) _readex_expect_sync_data(__LINE__,a,b,c,d,e,f)
4825 static void _readex_expect_sync_data(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
4826 DWORD buf_size
, const char *exdata
, DWORD expect_receive
)
4828 _readex_expect_sync_data_len(line
, req
, flags
, buf
, buf_size
, exdata
, strlen(exdata
), expect_receive
);
4831 #define read_expect_sync_data_len(a,b,c,d,e) _read_expect_sync_data_len(__LINE__,a,b,c,d,e)
4832 static void _read_expect_sync_data_len(unsigned line
, HINTERNET req
, void *buf
, DWORD buf_size
,
4833 const char *exdata
, DWORD len
)
4835 DWORD ret_size
= 0xdeadbeef;
4838 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4839 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4840 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4841 received_response_size
= 0xdeadbeef;
4843 memset(buf
, 0xff, buf_size
);
4844 ret
= InternetReadFile(req
, buf
, buf_size
, &ret_size
);
4845 ok_(__FILE__
,line
)(ret
, "InternetReadFileExW failed: %u\n", GetLastError());
4846 ok_(__FILE__
,line
)(ret_size
== len
, "dwBufferLength = %u, expected %u\n", ret_size
, len
);
4848 ok_(__FILE__
,line
)(!memcmp(buf
, exdata
, len
), "Unexpected data\n");
4850 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4851 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4852 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4853 ok_(__FILE__
,line
)(received_response_size
== len
, "received_response_size = %u\n", received_response_size
);
4854 ok_(__FILE__
,line
)(!req_error
, "req_error = %u\n", req_error
);
4857 #define read_expect_sync_data(a,b,c,d) _read_expect_sync_data(__LINE__,a,b,c,d)
4858 static void _read_expect_sync_data(unsigned line
, HINTERNET req
, void *buf
,
4859 DWORD buf_size
, const char *exdata
)
4861 _read_expect_sync_data_len(line
, req
, buf
, buf_size
, exdata
, strlen(exdata
));
4864 static void close_connection(void)
4867 SetEvent(conn_wait_event
);
4868 recv(server_socket
, &c
, 1, 0);
4871 #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)
4872 static void _send_response_and_wait(unsigned line
, const char *response
, BOOL do_close_connection
,
4873 void *buf
, DWORD
*ret_size
, const char *exdata
,
4874 DWORD expected_size
, DWORD expected_req_error
, DWORD expected_receive_size
)
4876 if(!skip_receive_notification_tests
)
4877 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4878 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4881 server_send_string(response
);
4883 if(do_close_connection
)
4886 WaitForSingleObject(complete_event
, INFINITE
);
4888 if(!skip_receive_notification_tests
)
4889 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4890 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4891 if(!skip_receive_notification_tests
&& expected_receive_size
!= -1)
4892 todo_wine_if(received_response_size
!= expected_receive_size
) /* FIXME! remove when wine is fixed */
4893 ok_(__FILE__
,line
)(received_response_size
== expected_receive_size
,
4894 "received_response_size = %u\n", received_response_size
);
4895 ok_(__FILE__
,line
)(req_error
== expected_req_error
, "req_error = %u, expected %u\n", req_error
, expected_req_error
);
4897 /* If IRF_NO_WAIT is used, buffer is not changed. */
4898 ok_(__FILE__
,line
)(*ret_size
== expected_size
, "dwBufferLength = %u\n", *ret_size
);
4900 ok_(__FILE__
,line
)(!memcmp(buf
, exdata
, strlen(exdata
)), "unexpected buffer data\n");
4902 ok_(__FILE__
,line
)(!*(DWORD
*)buf
, "buffer data changed\n");
4905 #define send_response_ex_and_wait(a,b,c,d,e,f) _send_response_ex_and_wait(__LINE__,a,b,c,d,e,f)
4906 static void _send_response_ex_and_wait(unsigned line
, const char *response
, BOOL close_connection
,
4907 INTERNET_BUFFERSW
*buf
, const char *exdata
, DWORD expected_req_error
,
4908 DWORD expected_receive_size
)
4910 _send_response_and_wait(line
, response
, close_connection
, buf
->lpvBuffer
, &buf
->dwBufferLength
,
4911 exdata
, exdata
? strlen(exdata
) : buf
->dwBufferLength
, expected_req_error
,
4912 expected_receive_size
);
4915 static void send_response_len_and_wait(unsigned len
, BOOL close_connection
, INTERNET_BUFFERSW
*buf
)
4919 response
= HeapAlloc(GetProcessHeap(), 0, len
+1);
4920 memset(response
, 'x', len
);
4922 send_response_ex_and_wait(response
, close_connection
, buf
, NULL
, 0, -1);
4923 HeapFree(GetProcessHeap(), 0, response
);
4926 #define readex_expect_async(a,b,c,d,e) _readex_expect_async(__LINE__,a,b,c,d,e)
4927 static void _readex_expect_async(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
4928 DWORD buf_size
, const char *exdata
)
4933 if(!skip_receive_notification_tests
)
4934 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4936 memset(buf
->lpvBuffer
, 0, max(buf_size
, sizeof(DWORD
)));
4937 buf
->dwBufferLength
= buf_size
;
4938 ret
= InternetReadFileExW(req
, buf
, flags
, 0xdeadbeef);
4939 ok_(__FILE__
,line
)(!ret
&& GetLastError() == ERROR_IO_PENDING
, "InternetReadFileExW returned %x (%u)\n", ret
, GetLastError());
4940 ok_(__FILE__
,line
)(buf
->dwBufferLength
== buf_size
, "dwBufferLength = %u, expected %u\n", buf
->dwBufferLength
, buf_size
);
4942 len
= strlen(exdata
);
4943 ok_(__FILE__
,line
)(!memcmp(buf
->lpvBuffer
, exdata
, len
), "unexpected buffer data\n");
4945 ok_(__FILE__
,line
)(!*(DWORD
*)buf
->lpvBuffer
, "buffer data changed\n");
4948 if(!skip_receive_notification_tests
)
4949 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4952 static void read_expect_async(HINTERNET req
, void *buf
, DWORD buf_size
, DWORD
*ret_size
, const char *exdata
)
4958 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4960 *ret_size
= 0xdeadbeef;
4961 memset(buf
, 0, buf_size
);
4962 ret
= InternetReadFile(req
, buf
, buf_size
, ret_size
);
4963 ok(!ret
&& GetLastError() == ERROR_IO_PENDING
, "InternetReadFileExW returned %x (%u)\n", ret
, GetLastError());
4964 ok(*ret_size
== 0, "dwBufferLength = %u\n", *ret_size
);
4966 len
= strlen(exdata
);
4967 ok(!memcmp(buf
, exdata
, len
), "unexpected buffer data\n");
4969 for(p
= (const char*)buf
+ len
; p
< (const char*)buf
+ buf_size
; p
++) {
4971 ok(0, "buffer data changed\n");
4974 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4977 #define expect_data_available(a,b) _expect_data_available(__LINE__,a,b)
4978 static DWORD
_expect_data_available(unsigned line
, HINTERNET req
, int exsize
)
4983 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
4984 ok_(__FILE__
,line
)(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
4986 ok_(__FILE__
,line
)(size
== exsize
, "size = %u, expected %u\n", size
, exsize
);
4991 #define async_query_data_available(a,b) _async_query_data_available(__LINE__,a,b)
4992 static void _async_query_data_available(unsigned line
, HINTERNET req
, DWORD
*size
)
4996 if(!skip_receive_notification_tests
)
4997 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5000 res
= InternetQueryDataAvailable(req
, size
, 0, 0);
5001 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_IO_PENDING
,
5002 "InternetQueryDataAvailable returned: %x(%u)\n", res
, GetLastError());
5003 ok_(__FILE__
,line
)(!*size
, "size = %u\n", *size
);
5005 if(!skip_receive_notification_tests
)
5006 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5009 static void test_http_read(int port
)
5011 INTERNET_BUFFERSW ib
;
5020 memset(&ib
, 0, sizeof(ib
));
5021 ib
.dwStructSize
= sizeof(ib
);
5024 trace("Testing InternetReadFileExW with IRF_ASYNC flag...\n");
5026 open_read_test_request(port
, &req
,
5027 "HTTP/1.1 200 OK\r\n"
5028 "Server: winetest\r\n"
5032 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, 4, "xx");
5034 send_response_ex_and_wait("yy1234567890", FALSE
, &ib
, "xxyy", 0, 2);
5035 readex_expect_sync_data(req
.request
, IRF_ASYNC
, &ib
, 4, "1234", 4);
5036 readex_expect_sync_data(req
.request
, IRF_ASYNC
, &ib
, 5, "56789", 5);
5038 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, sizeof(buf
), "0");
5039 send_response_ex_and_wait("123", TRUE
, &ib
, "0123", 0, 4);
5041 close_async_handle(req
.session
, 2);
5043 trace("Testing InternetReadFileExW with no flags...\n");
5045 open_read_test_request(port
, &req
,
5046 "HTTP/1.1 200 OK\r\n"
5047 "Server: winetest\r\n"
5051 readex_expect_async(req
.request
, 0, &ib
, 4, "xx");
5053 send_response_ex_and_wait("yy1234567890", FALSE
, &ib
, "xxyy", 0, 2);
5054 readex_expect_sync_data(req
.request
, 0, &ib
, 4, "1234", 4);
5055 readex_expect_sync_data(req
.request
, 0, &ib
, 5, "56789", 5);
5057 readex_expect_async(req
.request
, 0, &ib
, sizeof(buf
), "0");
5058 send_response_ex_and_wait("123", TRUE
, &ib
, "0123", 0, 4);
5060 close_async_handle(req
.session
, 2);
5062 trace("Testing InternetReadFile...\n");
5064 open_read_test_request(port
, &req
,
5065 "HTTP/1.1 200 OK\r\n"
5066 "Server: winetest\r\n"
5070 read_expect_async(req
.request
, buf
, 4, &read_size
, "xx");
5072 send_response_and_wait("yy1234567890", FALSE
, buf
, &read_size
, "xxyy", 4, 0, 2);
5073 read_expect_sync_data(req
.request
, buf
, 4, "1234");
5074 read_expect_sync_data(req
.request
, buf
, 5, "56789");
5076 read_expect_async(req
.request
, buf
, sizeof(buf
), &read_size
, "0");
5077 send_response_and_wait("123", TRUE
, buf
, &read_size
, "0123", 4, 0, 4);
5079 close_async_handle(req
.session
, 2);
5081 trace("Testing InternetReadFileExW with IRF_NO_WAIT flag...\n");
5083 open_read_test_request(port
, &req
,
5084 "HTTP/1.1 200 OK\r\n"
5085 "Server: winetest\r\n"
5089 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
5091 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "xx", 0);
5093 if(notified
[INTERNET_STATUS_RECEIVING_RESPONSE
]) {
5094 win_skip("Skipping receive notification tests on too old Windows.\n");
5095 skip_receive_notification_tests
= TRUE
;
5097 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5099 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5100 send_response_ex_and_wait("1234567890", FALSE
, &ib
, NULL
, 0, 10);
5101 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, 5, "12345", 0);
5102 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "67890", 0);
5104 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5105 send_response_ex_and_wait("12345", TRUE
, &ib
, NULL
, 0, 5);
5107 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "12345", 0);
5108 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "", TRUE
);
5110 close_async_handle(req
.session
, 2);
5112 open_read_test_request(port
, &req
,
5113 "HTTP/1.1 200 OK\r\n"
5114 "Server: winetest\r\n"
5115 "Transfer-Encoding: chunked\r\n"
5118 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123456789", 0);
5119 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5121 send_response_ex_and_wait("\r\n1\r\na\r\n1\r\nb\r", FALSE
, &ib
, NULL
, 0, 13);
5122 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
5123 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5125 send_response_ex_and_wait("\n3\r\nab", FALSE
, &ib
, NULL
, 0, 6);
5126 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
5127 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5129 send_response_ex_and_wait("c", FALSE
, &ib
, NULL
, 0, 1);
5130 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "c", 0);
5131 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5133 send_response_ex_and_wait("\r\n1\r\nx\r\n0\r\n\r\n", TRUE
, &ib
, NULL
, 0, 13);
5134 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "x", 0);
5135 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "", 0);
5137 close_async_handle(req
.session
, 2);
5139 open_read_test_request(port
, &req
,
5140 "HTTP/1.1 200 OK\r\n"
5141 "Server: winetest\r\n"
5142 "Transfer-Encoding: chunked\r\n"
5145 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123", 0);
5146 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5148 send_response_ex_and_wait("0\r\n\r\n", TRUE
, &ib
, NULL
, 0, 5);
5149 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "", 0);
5151 close_async_handle(req
.session
, 2);
5153 open_read_test_request(port
, &req
,
5154 "HTTP/1.1 200 OK\r\n"
5155 "Server: winetest\r\n"
5156 "Connection: close\r\n"
5158 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5159 send_response_ex_and_wait("123", TRUE
, &ib
, NULL
, 0, 3);
5160 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123", 0);
5162 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5163 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5164 close_async_handle(req
.session
, 2);
5165 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5166 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5168 trace("Testing InternetQueryDataAvailable...\n");
5170 open_read_test_request(port
, &req
,
5171 "HTTP/1.1 200 OK\r\n"
5172 "Server: winetest\r\n"
5175 expect_data_available(req
.request
, 3);
5176 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123", 0);
5177 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5179 send_response_len_and_wait(20000, TRUE
, &ib
);
5180 avail
= expect_data_available(req
.request
, -1);
5181 ok(avail
< 17000, "avail = %u\n", avail
);
5183 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
5184 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
5185 close_async_handle(req
.session
, 2);
5186 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5187 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5189 open_read_test_request(port
, &req
,
5190 "HTTP/1.1 200 OK\r\n"
5191 "Server: winetest\r\n"
5192 "Connection: close\r\n"
5196 expect_data_available(req
.request
, 3);
5197 readex_expect_sync_data(req
.request
, 0, &ib
, 3, "123", 0);
5199 async_query_data_available(req
.request
, &read_size
);
5200 send_response_and_wait("1234567890", FALSE
, NULL
, &read_size
, NULL
, 10, 10, 10);
5202 readex_expect_sync_data(req
.request
, 0, &ib
, 9, "123456789", 0);
5203 expect_data_available(req
.request
, 1);
5204 readex_expect_sync_data(req
.request
, 0, &ib
, 1, "0", 0);
5206 async_query_data_available(req
.request
, &read_size
);
5207 send_response_and_wait("1234567890", FALSE
, NULL
, &read_size
, NULL
, 10, 10, 10);
5208 expect_data_available(req
.request
, 10);
5209 for(i
= 0; i
< 10; i
++)
5210 server_send_string("x");
5211 expect_data_available(req
.request
, 10);
5213 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, 21, "1234567890");
5214 send_response_ex_and_wait("X", FALSE
, &ib
, "1234567890xxxxxxxxxxX", 0, 11);
5215 async_query_data_available(req
.request
, &read_size
);
5217 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5218 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5219 send_response_and_wait(NULL
, TRUE
, NULL
, &read_size
, NULL
, 0, 0, 0);
5220 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5221 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5223 close_async_handle(req
.session
, 2);
5225 skip_receive_notification_tests
= FALSE
;
5228 static void test_connection_break(int port
)
5230 INTERNET_BUFFERSW ib
;
5237 memset(&ib
, 0, sizeof(ib
));
5238 ib
.dwStructSize
= sizeof(ib
);
5241 trace("Testing InternetReadFileExW on broken connection...\n");
5243 open_read_test_request(port
, &req
,
5244 "HTTP/1.1 200 OK\r\n"
5245 "Server: winetest\r\n"
5246 "Content-Length: 10000\r\n"
5250 /* close connection and make sure that it's closed on handle release. */
5252 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5253 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5254 close_async_handle(req
.session
, 2);
5255 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5256 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5259 static void test_long_url(int port
)
5261 char long_path
[INTERNET_MAX_PATH_LENGTH
*2] = "/echo_request?";
5262 char buf
[sizeof(long_path
)*2], url
[sizeof(buf
)];
5270 memset(long_path
+strlen(long_path
), 'x', sizeof(long_path
)-strlen(long_path
));
5271 long_path
[sizeof(long_path
)-1] = 0;
5272 open_simple_request(&req
, "localhost", port
, NULL
, long_path
);
5274 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
5275 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
5276 test_status_code(req
.request
, 200);
5278 receive_simple_request(req
.request
, buf
, sizeof(buf
));
5279 ok(strstr(buf
, long_path
) != NULL
, "long pathnot found in %s\n", buf
);
5281 sprintf(url
, "http://localhost:%u%s", port
, long_path
);
5284 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_URL
, buf
, &size
);
5285 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
5287 ok(size
== len
, "size = %u, expected %u\n", size
, len
);
5288 ok(!strcmp(buf
, url
), "Wrong URL %s, expected %s\n", buf
, url
);
5290 close_request(&req
);
5293 static void test_persistent_connection(int port
)
5295 INTERNET_BUFFERSW ib
;
5302 memset(&ib
, 0, sizeof(ib
));
5303 ib
.dwStructSize
= sizeof(ib
);
5306 skip_receive_notification_tests
= TRUE
;
5308 trace("Testing persistent connection...\n");
5310 open_read_test_request(port
, &req
,
5311 "HTTP/1.1 200 OK\r\n"
5312 "Server: winetest\r\n"
5313 "Content-Length: 2\r\n"
5316 readex_expect_sync_data(req
.request
, IRF_ASYNC
, &ib
, 4, "xx", 0);
5317 close_async_handle(req
.session
, 2);
5319 open_socket_request(port
, &req
, "/test_simple_chunked");
5320 server_read_request("GET /test_simple_chunked HTTP/1.1");
5322 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5323 server_send_string("HTTP/1.1 200 OK\r\n"
5324 "Server: winetest\r\n"
5325 "Transfer-Encoding: chunked\r\n"
5328 WaitForSingleObject(complete_event
, INFINITE
);
5329 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5330 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5332 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
5333 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, sizeof(buf
), NULL
);
5334 send_response_ex_and_wait("3\r\nabc\r\n0\r\n\r\n", FALSE
, &ib
, "abc", 0, 13);
5335 close_async_handle(req
.session
, 2);
5337 open_socket_request(port
, &req
, "/chunked");
5338 server_read_request("GET /chunked HTTP/1.1");
5340 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5341 server_send_string("HTTP/1.1 200 OK\r\n"
5342 "Server: winetest\r\n"
5343 "Transfer-Encoding: chunked\r\n"
5346 WaitForSingleObject(complete_event
, INFINITE
);
5347 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5348 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5350 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, 3, "ab", 0);
5351 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, 3, NULL
);
5352 send_response_ex_and_wait("3\r\nabc\r\n", FALSE
, &ib
, "abc", 0, 13);
5354 /* send another request on the same request handle, it must drain remaining last chunk marker */
5355 server_send_string("0\r\n\r\n");
5357 send_socket_request(&req
, FALSE
);
5358 server_read_request("GET /chunked HTTP/1.1");
5360 ResetEvent(complete_event
);
5361 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5362 server_send_string("HTTP/1.1 201 OK\r\n"
5363 "Server: winetest\r\n"
5364 "Content-Length: 0\r\n"
5365 "Connection: keep-alive\r\n"
5367 WaitForSingleObject(complete_event
, INFINITE
);
5368 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5369 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5371 test_status_code(req
.request
, 201);
5372 close_async_handle(req
.session
, 2);
5374 /* the connection is still valid */
5375 open_socket_request(port
, &req
, "/another_chunked");
5376 server_read_request("GET /another_chunked HTTP/1.1");
5378 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5379 server_send_string("HTTP/1.1 200 OK\r\n"
5380 "Server: winetest\r\n"
5381 "Transfer-Encoding: chunked\r\n"
5384 WaitForSingleObject(complete_event
, INFINITE
);
5385 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5386 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5388 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
5389 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, sizeof(buf
), NULL
);
5391 /* we're missing trailing '\n'; the connection can't be drained without blocking,
5392 * so it will be closed */
5393 send_response_ex_and_wait("3\r\nabc\r\n0\r\n\r", FALSE
, &ib
, "abc", 0, 13);
5395 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5396 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5397 close_async_handle(req
.session
, 2);
5398 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5399 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5402 skip_receive_notification_tests
= FALSE
;
5405 static void test_redirect(int port
)
5407 char buf
[4000], expect_url
[INTERNET_MAX_URL_LENGTH
];
5408 INTERNET_BUFFERSW ib
;
5414 skip_receive_notification_tests
= TRUE
;
5416 memset(&ib
, 0, sizeof(ib
));
5417 ib
.dwStructSize
= sizeof(ib
);
5420 trace("Testing redirection...\n");
5422 open_socket_request(port
, &req
, NULL
);
5424 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5425 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
5426 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5427 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5429 server_send_string("HTTP/1.1 302 Found\r\n"
5430 "Server: winetest\r\n"
5431 "Location: test_redirection\r\n"
5432 "Connection: keep-alive\r\n"
5433 "Content-Length: 0\r\n"
5436 server_read_request("GET /test_redirection HTTP/1.1");
5438 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5440 sprintf(expect_url
, "http://localhost:%u/test_redirection", port
);
5441 test_request_url(req
.request
, expect_url
);
5443 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5445 server_send_string("HTTP/1.1 200 OK\r\n"
5446 "Server: winetest\r\n"
5447 "Content-Length: 3\r\n"
5451 WaitForSingleObject(complete_event
, INFINITE
);
5453 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5454 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5455 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
5456 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5457 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5459 test_status_code(req
.request
, 200);
5462 close_async_handle(req
.session
, 2);
5464 trace("Test redirect to non-http URL...\n");
5466 open_socket_request(port
, &req
, NULL
);
5468 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5470 server_send_string("HTTP/1.1 302 Found\r\n"
5471 "Server: winetest\r\n"
5472 "Location: test:non:http/url\r\n"
5473 "Connection: keep-alive\r\n"
5474 "Content-Length: 0\r\n"
5477 WaitForSingleObject(complete_event
, INFINITE
);
5479 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5480 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5482 sprintf(expect_url
, "http://localhost:%u/socket", port
);
5483 test_request_url(req
.request
, expect_url
);
5484 test_status_code(req
.request
, 302);
5487 close_async_handle(req
.session
, 2);
5489 trace("Test redirect to http URL with no host name...\n");
5491 open_socket_request(port
, &req
, NULL
);
5493 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5495 server_send_string("HTTP/1.1 302 Found\r\n"
5496 "Server: winetest\r\n"
5497 "Location: http:///nohost\r\n"
5498 "Connection: keep-alive\r\n"
5499 "Content-Length: 0\r\n"
5502 WaitForSingleObject(complete_event
, INFINITE
);
5504 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5505 ok(req_error
== ERROR_INTERNET_INVALID_URL
, "expected ERROR_INTERNET_INVALID_URL, got %u\n", req_error
);
5507 sprintf(expect_url
, "http://localhost:%u/socket", port
);
5508 test_request_url(req
.request
, expect_url
);
5509 test_status_code(req
.request
, 302);
5512 close_async_handle(req
.session
, 2);
5514 skip_receive_notification_tests
= FALSE
;
5517 static void test_remove_dot_segments(int port
)
5522 open_simple_request(&req
, "localhost", port
, NULL
, "/A/../B/./C/../../test_remove_dot_segments");
5524 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
5525 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
5526 test_status_code(req
.request
, 200);
5528 close_request(&req
);
5533 DWORD64 content_length
;
5537 static void test_large_content(int port
)
5539 struct large_test tests
[] = {
5541 { UINT_MAX
-1, TRUE
},
5543 { (DWORD64
)UINT_MAX
+1, FALSE
},
5552 open_simple_request(&req
, "localhost", port
, "HEAD", "/test_large_content");
5554 for (i
= 0; i
< ARRAY_SIZE(tests
); i
++)
5556 content_length
= tests
[i
].content_length
;
5557 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
5558 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
5561 sizelen
= sizeof(len
);
5562 SetLastError(0xdeadbeef);
5563 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
,
5567 ok(ret
, "HttpQueryInfo should have succeeded\n");
5568 ok(GetLastError() == ERROR_SUCCESS
||
5569 broken(GetLastError() == 0xdeadbeef), /* xp, 2k8, vista */
5570 "expected ERROR_SUCCESS, got %x\n", GetLastError());
5571 ok(len
== (DWORD
)tests
[i
].content_length
, "expected %u, got %u\n",
5572 (DWORD
)tests
[i
].content_length
, len
);
5576 ok(!ret
, "HttpQueryInfo should have failed\n");
5577 ok(GetLastError() == ERROR_HTTP_INVALID_HEADER
,
5578 "expected ERROR_HTTP_INVALID_HEADER, got %x\n", GetLastError());
5579 ok(len
== ~0, "expected ~0, got %u\n", len
);
5581 ok(sizelen
== sizeof(DWORD
), "sizelen %u\n", sizelen
);
5584 /* test argument size */
5586 sizelen
= sizeof(len64
);
5587 SetLastError(0xdeadbeef);
5588 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
,
5590 ok(!ret
, "HttpQueryInfo should have failed\n");
5591 ok(GetLastError() == ERROR_HTTP_INVALID_HEADER
,
5592 "expected ERROR_HTTP_INVALID_HEADER, got %x\n", GetLastError());
5593 ok(sizelen
== sizeof(DWORD64
), "sizelen %u\n", sizelen
);
5594 ok(len64
== ~0, "len64 %x%08x\n", (DWORD
)(len64
>> 32), (DWORD
)len64
);
5596 close_request(&req
);
5599 static void test_http_connection(void)
5601 struct server_info si
;
5605 si
.hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
5608 hThread
= CreateThread(NULL
, 0, server_thread
, &si
, 0, &id
);
5609 ok( hThread
!= NULL
, "create thread failed\n");
5611 r
= WaitForSingleObject(si
.hEvent
, 10000);
5612 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
5613 if (r
!= WAIT_OBJECT_0
)
5615 CloseHandle(hThread
);
5619 test_basic_request(si
.port
, "GET", "/test1");
5620 test_proxy_indirect(si
.port
);
5621 test_proxy_direct(si
.port
);
5622 test_header_handling_order(si
.port
);
5623 test_basic_request(si
.port
, "POST", "/test5");
5624 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
5625 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
5626 test_basic_request(si
.port
, "GET", "/test6");
5627 test_basic_request(si
.port
, "GET", "/testF");
5628 test_connection_header(si
.port
);
5629 test_header_override(si
.port
);
5630 test_cookie_header(si
.port
);
5631 test_basic_authentication(si
.port
);
5632 test_invalid_response_headers(si
.port
);
5633 test_response_without_headers(si
.port
);
5634 test_HttpQueryInfo(si
.port
);
5635 test_HttpSendRequestW(si
.port
);
5636 test_options(si
.port
);
5637 test_no_content(si
.port
);
5638 test_conn_close(si
.port
);
5639 test_no_cache(si
.port
);
5640 test_cache_read_gzipped(si
.port
);
5641 test_http_status(si
.port
);
5642 test_premature_disconnect(si
.port
);
5643 test_connection_closing(si
.port
);
5644 test_cache_control_verb(si
.port
);
5645 test_successive_HttpSendRequest(si
.port
);
5646 test_head_request(si
.port
);
5647 test_request_content_length(si
.port
);
5648 test_accept_encoding(si
.port
);
5649 test_basic_auth_credentials_reuse(si
.port
);
5650 test_async_read(si
.port
);
5651 test_http_read(si
.port
);
5652 test_connection_break(si
.port
);
5653 test_long_url(si
.port
);
5654 test_redirect(si
.port
);
5655 test_persistent_connection(si
.port
);
5656 test_remove_dot_segments(si
.port
);
5657 test_large_content(si
.port
);
5659 /* send the basic request again to shutdown the server thread */
5660 test_basic_request(si
.port
, "GET", "/quit");
5662 r
= WaitForSingleObject(hThread
, 3000);
5663 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
5664 CloseHandle(hThread
);
5667 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
5669 LocalFree(info
->lpszSubjectInfo
);
5670 LocalFree(info
->lpszIssuerInfo
);
5671 LocalFree(info
->lpszProtocolName
);
5672 LocalFree(info
->lpszSignatureAlgName
);
5673 LocalFree(info
->lpszEncryptionAlgName
);
5677 const char *ex_subject
;
5678 const char *ex_issuer
;
5679 } cert_struct_test_t
;
5681 static const cert_struct_test_t test_winehq_org_cert
= {
5687 "700 Raymond Ave\r\n"
5690 "Secure Link SSL Wildcard\r\n"
5696 "Network Solutions L.L.C.\r\n"
5697 "Network Solutions OV Server CA 2"
5700 static const cert_struct_test_t test_winehq_com_cert
= {
5705 "test.winehq.com\r\n"
5706 "webmaster@winehq.org",
5711 "test.winehq.com\r\n"
5712 "webmaster@winehq.org"
5715 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
5717 INTERNET_CERTIFICATE_INFOA info
;
5721 memset(&info
, 0x5, sizeof(info
));
5723 size
= sizeof(info
);
5724 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
5727 win_skip("Querying INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT failed, skipping tests\n");
5731 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
5732 ok(size
== sizeof(info
), "size = %u\n", size
);
5734 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
5735 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
5736 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
5737 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
5738 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
5739 ok(info
.dwKeySize
>= 128 && info
.dwKeySize
<= 256, "dwKeySize = %u\n", info
.dwKeySize
);
5741 release_cert_info(&info
);
5744 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
5745 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
5747 char url
[INTERNET_MAX_URL_LENGTH
];
5748 const CERT_CHAIN_CONTEXT
*chain
;
5752 if(!pInternetGetSecurityInfoByURLA
) {
5753 win_skip("pInternetGetSecurityInfoByURLA not available\n");
5758 chain
= (void*)0xdeadbeef;
5760 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
5761 if(error
== ERROR_SUCCESS
) {
5762 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
5763 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
5764 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
5765 CertFreeCertificateChain(chain
);
5767 SetLastError(0xdeadbeef);
5768 res
= pInternetGetSecurityInfoByURLA(url
, NULL
, NULL
);
5769 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
,
5770 "InternetGetSecurityInfoByURLA returned: %x(%u)\n", res
, GetLastError());
5772 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, NULL
);
5773 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
5774 CertFreeCertificateChain(chain
);
5776 res
= pInternetGetSecurityInfoByURLA(url
, NULL
, &flags
);
5777 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
5779 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
5780 "InternetGetSecurityInfoByURLA returned: %x(%u), expected %u\n", res
, GetLastError(), error
);
5784 #define test_secflags_option(a,b,c) _test_secflags_option(__LINE__,a,b,c)
5785 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
, DWORD opt_flags
)
5791 size
= sizeof(flags
);
5792 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
5793 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
5794 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n",
5797 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
5799 size
= sizeof(flags
);
5800 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
5801 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
5802 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n",
5806 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
5807 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
5811 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
5812 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
5815 static void test_security_flags(void)
5817 INTERNET_CERTIFICATE_INFOA
*cert
;
5818 HINTERNET ses
, conn
, req
;
5823 trace("Testing security flags...\n");
5826 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5827 ok(ses
!= NULL
, "InternetOpen failed\n");
5829 pInternetSetStatusCallbackA(ses
, &callback
);
5831 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5832 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
5833 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
5834 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
5835 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5837 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5838 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5839 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5841 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5842 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5845 size
= sizeof(flags
);
5846 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
5847 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
5848 win_skip("Incomplete security flags support, skipping\n");
5850 close_async_handle(ses
, 2);
5854 test_secflags_option(req
, 0, 0);
5855 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5857 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
5858 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
, 0);
5860 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
5861 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
5863 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
5864 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
5866 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
5867 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
5868 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
5870 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
5871 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
5872 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5873 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5874 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5875 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5876 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5877 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5878 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5879 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5880 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5881 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5882 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5883 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5884 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5886 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5887 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5889 WaitForSingleObject(complete_event
, INFINITE
);
5890 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5892 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
5893 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
5894 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5895 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5896 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5897 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5898 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5899 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5900 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5901 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5902 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5903 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5904 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5906 test_request_flags(req
, 0);
5907 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
5908 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
, 0);
5910 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5911 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5912 ok(size
, "size = 0\n");
5914 /* Collect all existing persistent connections */
5915 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5916 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5918 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5919 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5920 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5922 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5923 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5925 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
5926 res
= InternetSetOptionA(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
5927 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
5929 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5930 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5931 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5932 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5933 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5934 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5935 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5936 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5937 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5938 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5939 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5941 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5942 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5944 WaitForSingleObject(complete_event
, INFINITE
);
5945 ok(req_error
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| broken(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
),
5946 "req_error = %d\n", req_error
);
5949 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
5950 ok(res
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5951 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %u\n", size
);
5952 cert
= HeapAlloc(GetProcessHeap(), 0, size
);
5953 cert
->lpszSubjectInfo
= NULL
;
5954 cert
->lpszIssuerInfo
= NULL
;
5955 cert
->lpszSignatureAlgName
= (char *)0xdeadbeef;
5956 cert
->lpszEncryptionAlgName
= (char *)0xdeadbeef;
5957 cert
->lpszProtocolName
= (char *)0xdeadbeef;
5958 cert
->dwKeySize
= 0xdeadbeef;
5959 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, cert
, &size
);
5960 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
5963 ok(cert
->lpszSubjectInfo
&& strlen(cert
->lpszSubjectInfo
) > 1, "expected a non-empty subject name\n");
5964 ok(cert
->lpszIssuerInfo
&& strlen(cert
->lpszIssuerInfo
) > 1, "expected a non-empty issuer name\n");
5965 ok(!cert
->lpszSignatureAlgName
, "unexpected signature algorithm name\n");
5966 ok(!cert
->lpszEncryptionAlgName
, "unexpected encryption algorithm name\n");
5967 ok(!cert
->lpszProtocolName
, "unexpected protocol name\n");
5968 ok(cert
->dwKeySize
!= 0xdeadbeef, "unexpected key size\n");
5970 LocalFree(cert
->lpszSubjectInfo
);
5971 LocalFree(cert
->lpszIssuerInfo
);
5973 HeapFree(GetProcessHeap(), 0, cert
);
5975 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5976 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5977 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
5978 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
5979 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5980 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5981 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5983 if(req_error
!= ERROR_INTERNET_SEC_CERT_REV_FAILED
) {
5984 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error
);
5986 close_async_handle(ses
, 3);
5991 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
5992 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
5994 test_request_flags(req
, 8);
5995 /* IE11 finds both rev failure and invalid CA. Previous versions required rev failure
5996 to be ignored before invalid CA was reported. */
5997 test_secflags_option(req
, _SECURITY_FLAG_CERT_REV_FAILED
, _SECURITY_FLAG_CERT_INVALID_CA
);
5999 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
6000 test_secflags_option(req
, _SECURITY_FLAG_CERT_REV_FAILED
|SECURITY_FLAG_IGNORE_REVOCATION
, _SECURITY_FLAG_CERT_INVALID_CA
);
6002 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6003 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6004 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
6005 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
6006 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6007 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
6008 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
6010 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
6011 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
6013 WaitForSingleObject(complete_event
, INFINITE
);
6014 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
6016 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6017 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6018 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6019 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6020 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6021 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
6022 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
6024 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
6025 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
6026 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
6028 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
6029 test_secflags_option(req
, _SECURITY_FLAG_CERT_INVALID_CA
|_SECURITY_FLAG_CERT_REV_FAILED
6030 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
, 0);
6031 test_http_version(req
);
6033 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6034 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6035 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
6036 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
6037 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
6038 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
6039 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
6040 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
6041 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
6042 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
6043 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6044 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
6045 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
6047 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
6048 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
6050 WaitForSingleObject(complete_event
, INFINITE
);
6051 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
6053 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
6054 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
6055 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6056 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6057 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
6058 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
6059 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
6060 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
6061 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6062 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
6063 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
6065 test_request_flags(req
, 0);
6066 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
6067 |SECURITY_FLAG_STRENGTH_STRONG
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
6069 test_cert_struct(req
, &test_winehq_com_cert
);
6070 test_security_info("https://test.winehq.com/data/some_file.html?q", 0,
6071 _SECURITY_FLAG_CERT_INVALID_CA
|_SECURITY_FLAG_CERT_REV_FAILED
);
6073 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
6074 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
6075 ok(size
, "size = 0\n");
6077 close_async_handle(ses
, 3);
6079 /* Collect all existing persistent connections */
6080 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
6081 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
6083 /* Make another request, without setting security flags */
6085 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6086 ok(ses
!= NULL
, "InternetOpen failed\n");
6088 pInternetSetStatusCallbackA(ses
, &callback
);
6090 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
6091 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
6092 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
6093 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
6094 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
6096 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
6097 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
6098 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
6100 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6101 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
6103 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
6104 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
6105 test_http_version(req
);
6107 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6108 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6109 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
6110 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
6111 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
6112 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
6113 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
6114 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
6115 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
6116 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
6117 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
6118 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
6120 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
6121 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
6123 WaitForSingleObject(complete_event
, INFINITE
);
6124 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
6126 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
6127 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
6128 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
6129 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
6130 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
6131 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
6132 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
6133 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
6134 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
6135 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
6137 test_request_flags(req
, 0);
6138 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
6139 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
6141 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
6142 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
6143 ok(size
, "size = 0\n");
6145 close_async_handle(ses
, 2);
6147 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
6148 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
6149 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
6152 static void test_secure_connection(void)
6154 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
6155 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
6156 static const WCHAR get
[] = {'G','E','T',0};
6157 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
6158 HINTERNET ses
, con
, req
;
6160 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
6161 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
6164 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
6165 ok(ses
!= NULL
, "InternetOpen failed\n");
6167 con
= InternetConnectA(ses
, "test.winehq.org",
6168 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
6169 INTERNET_SERVICE_HTTP
, 0, 0);
6170 ok(con
!= NULL
, "InternetConnect failed\n");
6172 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
6173 INTERNET_FLAG_SECURE
, 0);
6174 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6176 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
6177 ok(ret
|| broken(GetLastError() == ERROR_INTERNET_CANNOT_CONNECT
),
6178 "HttpSendRequest failed: %d\n", GetLastError());
6181 win_skip("Cannot connect to https.\n");
6185 size
= sizeof(flags
);
6186 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
6187 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6188 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
6190 test_cert_struct(req
, &test_winehq_org_cert
);
6192 /* Querying the same option through InternetQueryOptionW still results in
6193 * ASCII strings being returned.
6196 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6198 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
6199 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
6200 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
6201 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6202 certificate_structW
, &size
);
6203 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
6204 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6207 ok(certificate_structA
->lpszSubjectInfo
&&
6208 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
6209 "expected a non-empty subject name\n");
6210 ok(certificate_structA
->lpszIssuerInfo
&&
6211 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
6212 "expected a non-empty issuer name\n");
6213 ok(!certificate_structA
->lpszSignatureAlgName
,
6214 "unexpected signature algorithm name\n");
6215 ok(!certificate_structA
->lpszEncryptionAlgName
,
6216 "unexpected encryption algorithm name\n");
6217 ok(!certificate_structA
->lpszProtocolName
,
6218 "unexpected protocol name\n");
6219 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
6220 release_cert_info(certificate_structA
);
6222 HeapFree(GetProcessHeap(), 0, certificate_structW
);
6224 InternetCloseHandle(req
);
6225 InternetCloseHandle(con
);
6226 InternetCloseHandle(ses
);
6228 /* Repeating the tests with the W functions has the same result: */
6229 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
6230 ok(ses
!= NULL
, "InternetOpen failed\n");
6232 con
= InternetConnectW(ses
, testsite
,
6233 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
6234 INTERNET_SERVICE_HTTP
, 0, 0);
6235 ok(con
!= NULL
, "InternetConnect failed\n");
6237 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
6238 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
6239 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6241 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
6242 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
6244 size
= sizeof(flags
);
6245 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
6246 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6247 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %x\n", flags
);
6249 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6251 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
6252 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
6253 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
6254 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6255 certificate_structA
, &size
);
6256 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6259 ok(certificate_structA
->lpszSubjectInfo
&&
6260 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
6261 "expected a non-empty subject name\n");
6262 ok(certificate_structA
->lpszIssuerInfo
&&
6263 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
6264 "expected a non-empty issuer name\n");
6265 ok(!certificate_structA
->lpszSignatureAlgName
,
6266 "unexpected signature algorithm name\n");
6267 ok(!certificate_structA
->lpszEncryptionAlgName
,
6268 "unexpected encryption algorithm name\n");
6269 ok(!certificate_structA
->lpszProtocolName
,
6270 "unexpected protocol name\n");
6271 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
6272 release_cert_info(certificate_structA
);
6274 HeapFree(GetProcessHeap(), 0, certificate_structA
);
6276 /* Again, querying the same option through InternetQueryOptionW still
6277 * results in ASCII strings being returned.
6280 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6282 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
6283 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
6284 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
6285 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6286 certificate_structW
, &size
);
6287 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
6288 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6291 ok(certificate_structA
->lpszSubjectInfo
&&
6292 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
6293 "expected a non-empty subject name\n");
6294 ok(certificate_structA
->lpszIssuerInfo
&&
6295 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
6296 "expected a non-empty issuer name\n");
6297 ok(!certificate_structA
->lpszSignatureAlgName
,
6298 "unexpected signature algorithm name\n");
6299 ok(!certificate_structA
->lpszEncryptionAlgName
,
6300 "unexpected encryption algorithm name\n");
6301 ok(!certificate_structA
->lpszProtocolName
,
6302 "unexpected protocol name\n");
6303 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
6304 release_cert_info(certificate_structA
);
6306 HeapFree(GetProcessHeap(), 0, certificate_structW
);
6309 InternetCloseHandle(req
);
6310 InternetCloseHandle(con
);
6311 InternetCloseHandle(ses
);
6314 static void test_user_agent_header(void)
6316 HINTERNET ses
, con
, req
;
6321 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
6322 ok(ses
!= NULL
, "InternetOpen failed\n");
6324 con
= InternetConnectA(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
6325 ok(con
!= NULL
, "InternetConnect failed\n");
6327 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
6328 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6330 size
= sizeof(buffer
);
6331 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6332 err
= GetLastError();
6333 ok(!ret
, "HttpQueryInfo succeeded\n");
6334 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
6336 ret
= HttpAddRequestHeadersA(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
6337 ok(ret
, "HttpAddRequestHeaders succeeded\n");
6339 size
= sizeof(buffer
);
6340 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6341 err
= GetLastError();
6342 ok(ret
, "HttpQueryInfo failed\n");
6344 InternetCloseHandle(req
);
6346 req
= HttpOpenRequestA(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
6347 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6349 size
= sizeof(buffer
);
6350 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6351 err
= GetLastError();
6352 ok(!ret
, "HttpQueryInfo succeeded\n");
6353 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
6355 ret
= HttpAddRequestHeadersA(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
6356 ok(ret
, "HttpAddRequestHeaders failed\n");
6359 size
= sizeof(buffer
);
6360 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6361 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
6362 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
6364 InternetCloseHandle(req
);
6365 InternetCloseHandle(con
);
6366 InternetCloseHandle(ses
);
6369 static void test_bogus_accept_types_array(void)
6371 HINTERNET ses
, con
, req
;
6372 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
6377 ses
= InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
6378 con
= InternetConnectA(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
6379 req
= HttpOpenRequestA(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
6381 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
6384 size
= sizeof(buffer
);
6385 SetLastError(0xdeadbeef);
6386 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6387 error
= GetLastError();
6388 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
6389 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
6390 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
6391 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
6392 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
6394 InternetCloseHandle(req
);
6395 InternetCloseHandle(con
);
6396 InternetCloseHandle(ses
);
6405 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
6407 INTERNET_ASYNC_RESULT
*result
= info
;
6408 struct context
*ctx
= (struct context
*)context
;
6410 if(winetest_debug
> 1)
6411 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
6414 case INTERNET_STATUS_REQUEST_COMPLETE
:
6415 trace("request handle: 0x%08lx\n", result
->dwResult
);
6416 ctx
->req
= (HINTERNET
)result
->dwResult
;
6417 SetEvent(ctx
->event
);
6419 case INTERNET_STATUS_HANDLE_CLOSING
: {
6420 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
6422 if (InternetQueryOptionA(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
6423 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
6424 SetEvent(ctx
->event
);
6427 case INTERNET_STATUS_NAME_RESOLVED
:
6428 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
6429 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
6431 ok(str
[0] && str
[1], "Got string: %s\n", str
);
6432 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
6437 static void test_open_url_async(void)
6445 /* Collect all existing persistent connections */
6446 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
6447 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
6450 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
6451 * other versions never do. They also hang of following tests. We disable it for everything older
6458 ctx
.event
= CreateEventA(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
6460 ses
= InternetOpenA("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6461 ok(ses
!= NULL
, "InternetOpen failed\n");
6463 SetLastError(0xdeadbeef);
6464 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
6465 error
= GetLastError();
6466 ok(!ret
, "InternetSetOptionA succeeded\n");
6467 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
6469 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
6470 error
= GetLastError();
6471 ok(!ret
, "InternetSetOptionA failed\n");
6472 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
6474 pInternetSetStatusCallbackW(ses
, cb
);
6475 ResetEvent(ctx
.event
);
6477 req
= InternetOpenUrlA(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
6478 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
6480 WaitForSingleObject(ctx
.event
, INFINITE
);
6483 size
= sizeof(type
);
6484 ret
= InternetQueryOptionA(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
6485 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
6486 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
6487 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
6490 ret
= HttpQueryInfoA(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
6491 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
6492 ok(size
> 0, "expected size > 0\n");
6494 ResetEvent(ctx
.event
);
6495 InternetCloseHandle(ctx
.req
);
6496 WaitForSingleObject(ctx
.event
, INFINITE
);
6498 InternetCloseHandle(ses
);
6499 CloseHandle(ctx
.event
);
6504 internet_connect
= 1,
6506 http_send_request_ex
,
6509 internet_close_handle
6514 enum api function
; /* api responsible for notification */
6515 unsigned int status
; /* status received */
6516 BOOL async
; /* delivered from another thread? */
6524 const struct notification
*test
;
6530 DWORD expect_result
;
6534 static CRITICAL_SECTION notification_cs
;
6536 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
6538 BOOL status_ok
, function_ok
;
6539 struct info
*info
= (struct info
*)context
;
6542 EnterCriticalSection( ¬ification_cs
);
6544 if(info
->is_aborted
) {
6545 LeaveCriticalSection(¬ification_cs
);
6549 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
6551 DWORD size
= sizeof(struct info
*);
6552 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
6553 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
6554 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
6556 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
6557 if(info
->expect_result
== ERROR_SUCCESS
) {
6558 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
6560 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
6561 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
6566 if (i
>= info
->count
)
6568 LeaveCriticalSection( ¬ification_cs
);
6572 while (info
->test
[i
].status
!= status
&&
6573 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
6574 i
< info
->count
- 1 &&
6575 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
6580 status_ok
= (info
->test
[i
].status
== status
);
6581 function_ok
= (info
->test
[i
].function
== info
->function
);
6583 if (!info
->test
[i
].todo
)
6585 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
6586 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
6588 if (info
->test
[i
].async
)
6589 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
6590 info
->line
, info
->thread
, GetCurrentThreadId());
6594 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
6596 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
6598 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
6601 LeaveCriticalSection( ¬ification_cs
);
6604 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
6606 info
->function
= function
;
6608 info
->expect_result
= expect_result
;
6611 struct notification_data
6613 const struct notification
*test
;
6614 const unsigned int count
;
6619 BOOL expect_conn_failure
;
6622 static const struct notification async_send_request_ex_test
[] =
6624 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6625 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6626 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6627 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6628 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6629 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6630 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
6631 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
6632 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6633 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6634 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6635 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, FALSE
},
6636 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, FALSE
},
6637 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6638 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6639 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6640 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6641 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6642 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6643 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6646 static const struct notification async_send_request_ex_test2
[] =
6648 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6649 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6650 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6651 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6652 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6653 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6654 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
, TRUE
},
6655 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
, TRUE
},
6656 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6657 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6658 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6659 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6660 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6661 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6662 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6663 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6664 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6665 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6668 static const struct notification async_send_request_ex_resolve_failure_test
[] =
6670 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6671 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6672 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6673 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
},
6674 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6675 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6676 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6677 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6678 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6679 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6680 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6683 static const struct notification async_send_request_ex_chunked_test
[] =
6685 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
},
6686 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
},
6687 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6688 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6689 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6690 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6691 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
6692 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
6693 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6694 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6695 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6696 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6697 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6698 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6699 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
},
6700 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
},
6701 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
},
6702 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
}
6705 static const struct notification_data notification_data
[] = {
6707 async_send_request_ex_chunked_test
,
6708 ARRAY_SIZE(async_send_request_ex_chunked_test
),
6714 async_send_request_ex_test
,
6715 ARRAY_SIZE(async_send_request_ex_test
),
6719 "Public ID=codeweavers"
6722 async_send_request_ex_test2
,
6723 ARRAY_SIZE(async_send_request_ex_test2
),
6729 async_send_request_ex_resolve_failure_test
,
6730 ARRAY_SIZE(async_send_request_ex_resolve_failure_test
),
6739 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
6742 HINTERNET ses
, req
, con
;
6744 DWORD size
, written
, error
;
6745 INTERNET_BUFFERSA b
;
6746 static const char *accept
[2] = {"*/*", NULL
};
6749 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
6751 InitializeCriticalSection( ¬ification_cs
);
6753 info
.test
= nd
->test
;
6754 info
.count
= nd
->count
;
6756 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
6757 info
.thread
= GetCurrentThreadId();
6758 info
.is_aborted
= FALSE
;
6760 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6761 ok( ses
!= NULL
, "InternetOpen failed\n" );
6763 pInternetSetStatusCallbackA( ses
, check_notification
);
6765 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
6766 con
= InternetConnectA( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
6767 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
6769 WaitForSingleObject( info
.wait
, 10000 );
6771 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
6772 req
= HttpOpenRequestA( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
6773 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
6775 WaitForSingleObject( info
.wait
, 10000 );
6778 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
6779 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
6780 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
6781 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
6782 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
6785 setup_test( &info
, http_send_request_ex
, __LINE__
,
6786 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
6787 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
6788 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
6790 error
= WaitForSingleObject( info
.wait
, 10000 );
6791 if(error
!= WAIT_OBJECT_0
) {
6792 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
6793 info
.is_aborted
= TRUE
;
6797 size
= sizeof(buffer
);
6798 SetLastError( 0xdeadbeef );
6799 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
6800 error
= GetLastError();
6801 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
6802 if(nd
->expect_conn_failure
) {
6803 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
6806 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
6807 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
6813 size
= strlen( nd
->data
);
6814 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
6815 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
6816 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
6817 ok( written
== size
, "expected %u got %u\n", written
, size
);
6819 WaitForSingleObject( info
.wait
, 10000 );
6821 SetLastError( 0xdeadbeef );
6822 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
6823 error
= GetLastError();
6824 ok( !ret
, "HttpEndRequestA succeeded\n" );
6825 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
6828 SetLastError( 0xdeadbeef );
6829 setup_test( &info
, http_end_request
, __LINE__
,
6830 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
6831 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
6832 error
= GetLastError();
6833 ok( !ret
, "HttpEndRequestA succeeded\n" );
6834 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
6836 WaitForSingleObject( info
.wait
, 10000 );
6838 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
6840 InternetCloseHandle( req
);
6841 InternetCloseHandle( con
);
6842 InternetCloseHandle( ses
);
6844 WaitForSingleObject( info
.wait
, 10000 );
6846 CloseHandle( info
.wait
);
6847 DeleteCriticalSection( ¬ification_cs
);
6850 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
6851 static BOOL closetest_closed
;
6853 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
6854 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
6859 if(winetest_debug
> 1)
6860 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
6862 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
6863 "Unexpected hInternet %p\n", hInternet
);
6864 if(!closetest_closed
)
6868 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
6869 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
6870 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
6871 closetest_req
, res
, GetLastError());
6874 static void test_InternetCloseHandle(void)
6879 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6880 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
6882 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
6884 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
6885 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
6886 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
6888 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
6889 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
6891 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
6892 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
6893 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
6895 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
6897 res
= InternetCloseHandle(closetest_session
);
6898 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
6899 closetest_closed
= TRUE
;
6900 trace("Closed session handle\n");
6902 res
= InternetCloseHandle(closetest_conn
);
6903 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
6904 res
, GetLastError());
6906 res
= InternetCloseHandle(closetest_req
);
6907 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
6908 res
, GetLastError());
6910 len
= sizeof(flags
);
6911 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
6912 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
6913 "InternetQueryOptionA(%p INTERNET_OPTION_REQUEST_FLAGS) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
6914 closetest_req
, res
, GetLastError());
6917 static void test_connection_failure(void)
6923 open_simple_request(&req
, "localhost", 1, NULL
, "/");
6925 SetLastError(0xdeadbeef);
6926 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
6927 error
= GetLastError();
6928 ok(!ret
, "unexpected success\n");
6929 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
6931 close_request(&req
);
6934 static void test_default_service_port(void)
6936 HINTERNET session
, connect
, request
;
6944 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
6945 ok(session
!= NULL
, "InternetOpen failed\n");
6947 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6948 INTERNET_SERVICE_HTTP
, 0, 0);
6949 ok(connect
!= NULL
, "InternetConnect failed\n");
6951 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
6952 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6954 SetLastError(0xdeadbeef);
6955 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6956 error
= GetLastError();
6957 ok(!ret
, "HttpSendRequest succeeded\n");
6958 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
6961 size
= sizeof(buffer
);
6962 memset(buffer
, 0, sizeof(buffer
));
6963 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6964 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
6965 ok(!strcmp(buffer
, "test.winehq.org:80"), "Expected test.winehg.org:80, got '%s'\n", buffer
);
6967 InternetCloseHandle(request
);
6968 InternetCloseHandle(connect
);
6970 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6971 INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
6972 ok(connect
!= NULL
, "InternetConnect failed\n");
6974 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
6975 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6977 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6978 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
6980 size
= sizeof(buffer
);
6981 memset(buffer
, 0, sizeof(buffer
));
6982 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6983 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
6984 ok(!strcmp(buffer
, "test.winehq.org"), "Expected test.winehg.org, got '%s'\n", buffer
);
6986 InternetCloseHandle(request
);
6987 InternetCloseHandle(connect
);
6989 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6990 INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
6991 ok(connect
!= NULL
, "InternetConnect failed\n");
6993 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
6994 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6996 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6997 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
6999 size
= sizeof(buffer
);
7000 memset(buffer
, 0, sizeof(buffer
));
7001 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
7002 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
7003 ok(!strcmp(buffer
, "test.winehq.org:443"), "Expected test.winehg.org:443, got '%s'\n", buffer
);
7005 InternetCloseHandle(request
);
7006 InternetCloseHandle(connect
);
7007 InternetCloseHandle(session
);
7010 static void init_status_tests(void)
7012 memset(expect
, 0, sizeof(expect
));
7013 memset(optional
, 0, sizeof(optional
));
7014 memset(wine_allow
, 0, sizeof(wine_allow
));
7015 memset(notified
, 0, sizeof(notified
));
7016 memset(status_string
, 0, sizeof(status_string
));
7018 #define STATUS_STRING(status) status_string[status] = #status
7019 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
7020 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
7021 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
7022 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
7023 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
7024 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
7025 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
7026 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
7027 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
7028 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
7029 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
7030 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
7031 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
7032 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
7033 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
7034 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
7035 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
7036 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
7037 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
7038 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
7039 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
7040 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
7041 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
7042 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
7043 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
7044 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
7045 #undef STATUS_STRING
7048 static void WINAPI
header_cb( HINTERNET handle
, DWORD_PTR ctx
, DWORD status
, LPVOID info
, DWORD len
)
7054 if (status
== INTERNET_STATUS_SENDING_REQUEST
)
7056 ret
= HttpAddRequestHeadersA( handle
, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD
);
7057 ok( ret
, "HttpAddRequestHeadersA failed %u\n", GetLastError() );
7058 SetEvent( (HANDLE
)ctx
);
7060 else if (status
== INTERNET_STATUS_REQUEST_SENT
)
7064 ret
= HttpQueryInfoA( handle
, HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
7065 buf
, &size
, &index
);
7066 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
7067 ok( strstr( buf
, "winetest: winetest" ) != NULL
, "header missing\n" );
7068 SetEvent( (HANDLE
)ctx
);
7072 static void test_concurrent_header_access(void)
7074 HINTERNET ses
, con
, req
;
7077 HANDLE wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
7079 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
7080 ok( ses
!= NULL
, "InternetOpenA failed\n" );
7082 con
= InternetConnectA( ses
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
7083 INTERNET_SERVICE_HTTP
, 0, 0 );
7084 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
7086 req
= HttpOpenRequestA( con
, NULL
, "/", NULL
, NULL
, NULL
, 0, (DWORD_PTR
)wait
);
7087 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
7089 pInternetSetStatusCallbackA( req
, header_cb
);
7091 SetLastError( 0xdeadbeef );
7092 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
7093 err
= GetLastError();
7094 ok( !ret
, "HttpSendRequestA succeeded\n" );
7095 ok( err
== ERROR_IO_PENDING
, "got %u\n", ERROR_IO_PENDING
);
7097 WaitForSingleObject( wait
, 5000 );
7098 WaitForSingleObject( wait
, 5000 );
7100 InternetCloseHandle( req
);
7101 InternetCloseHandle( con
);
7102 InternetCloseHandle( ses
);
7103 CloseHandle( wait
);
7109 hdll
= GetModuleHandleA("wininet.dll");
7111 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
7112 win_skip("Too old IE (older than 6.0)\n");
7116 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
7117 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
7118 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
7120 if(!pInternetGetSecurityInfoByURLA
) {
7122 win_skip("IE6 found. It's too old for some tests.\n");
7126 init_status_tests();
7127 test_InternetCloseHandle();
7128 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
7129 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
7130 InternetReadFile_test(0, &test_data
[1]);
7131 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
7132 test_security_flags();
7133 InternetReadFile_test(0, &test_data
[2]);
7134 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
7135 test_open_url_async();
7136 test_async_HttpSendRequestEx(¬ification_data
[0]);
7137 test_async_HttpSendRequestEx(¬ification_data
[1]);
7138 test_async_HttpSendRequestEx(¬ification_data
[2]);
7139 test_async_HttpSendRequestEx(¬ification_data
[3]);
7140 InternetOpenRequest_test();
7142 InternetLockRequestFile_test();
7143 InternetOpenUrlA_test();
7145 test_http_connection();
7146 test_secure_connection();
7147 test_user_agent_header();
7148 test_bogus_accept_types_array();
7149 InternetReadFile_chunked_test();
7150 HttpSendRequestEx_test();
7151 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
7152 test_connection_failure();
7153 test_default_service_port();
7154 test_concurrent_header_access();