4 * Copyright 2002 Aric Stewart
5 * Copyright 2004 Mike McCormack
6 * Copyright 2005 Hans Leidekker
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/test.h"
35 /* Undocumented security flags */
36 #define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
37 #define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
38 #define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
39 #define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
41 #define TEST_URL "http://test.winehq.org/tests/hello.html"
43 static BOOL first_connection_to_test_url
= TRUE
;
45 /* Adapted from dlls/urlmon/tests/protocol.c */
47 #define SET_EXPECT2(status, num) \
50 #define SET_EXPECT(status) \
51 SET_EXPECT2(status, 1)
53 #define SET_OPTIONAL2(status, num) \
54 optional[status] = num
56 #define SET_OPTIONAL(status) \
57 SET_OPTIONAL2(status, 1)
59 /* SET_WINE_ALLOW's should be used with an appropriate
60 * todo_wine CHECK_NOTIFIED at a later point in the code */
61 #define SET_WINE_ALLOW2(status, num) \
62 wine_allow[status] = num
64 #define SET_WINE_ALLOW(status) \
65 SET_WINE_ALLOW2(status, 1)
67 #define CHECK_EXPECT(status) \
69 if (!expect[status] && !optional[status] && wine_allow[status]) \
71 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
72 status < MAX_INTERNET_STATUS && status_string[status] ? \
73 status_string[status] : "unknown"); \
74 wine_allow[status]--; \
78 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
79 status < MAX_INTERNET_STATUS && status_string[status] ? \
80 status_string[status] : "unknown"); \
81 if (expect[status]) expect[status]--; \
82 else if(optional[status]) optional[status]--; \
87 /* CLEAR_NOTIFIED used in cases when notification behavior
88 * differs between Windows versions */
89 #define CLEAR_NOTIFIED(status) \
90 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
92 #define CHECK_NOTIFIED2(status, num) \
94 ok(notified[status] + optional[status] == (num), \
95 "expected status %d (%s) %d times, received %d times\n", \
96 status, status < MAX_INTERNET_STATUS && status_string[status] ? \
97 status_string[status] : "unknown", (num), notified[status]); \
98 CLEAR_NOTIFIED(status); \
101 #define CHECK_NOTIFIED(status) \
102 CHECK_NOTIFIED2(status, 1)
104 #define CHECK_NOT_NOTIFIED(status) \
105 CHECK_NOTIFIED2(status, 0)
107 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
108 static int expect
[MAX_INTERNET_STATUS
], optional
[MAX_INTERNET_STATUS
],
109 wine_allow
[MAX_INTERNET_STATUS
], notified
[MAX_INTERNET_STATUS
];
110 static const char *status_string
[MAX_INTERNET_STATUS
];
112 static HANDLE complete_event
, conn_close_event
, conn_wait_event
, server_req_rec_event
, request_sent_event
;
113 static DWORD req_error
;
114 static BOOL is_ie7plus
= TRUE
;
116 #define TESTF_REDIRECT 0x01
117 #define TESTF_COMPRESSED 0x02
118 #define TESTF_CHUNKED 0x04
122 const char *redirected_url
;
127 const char *post_data
;
131 static const test_data_t test_data
[] = {
133 "http://test.winehq.org/tests/data.php",
134 "http://test.winehq.org/tests/data.php",
141 "http://test.winehq.org/tests/redirect",
142 "http://test.winehq.org/tests/hello.html",
149 "http://test.winehq.org/tests/gzip.php",
150 "http://test.winehq.org/tests/gzip.php",
153 "Accept-Encoding: gzip, deflate",
157 "http://test.winehq.org/tests/post.php",
158 "http://test.winehq.org/tests/post.php",
161 "Content-Type: application/x-www-form-urlencoded",
168 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackA
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
169 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackW
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
170 static BOOL (WINAPI
*pInternetGetSecurityInfoByURLA
)(LPSTR
,PCCERT_CHAIN_CONTEXT
*,DWORD
*);
172 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
175 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
176 return lstrcmpW(strw
, buf
);
179 static BOOL
proxy_active(void)
181 HKEY internet_settings
;
185 if (RegOpenKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
186 0, KEY_QUERY_VALUE
, &internet_settings
) != ERROR_SUCCESS
)
189 size
= sizeof(DWORD
);
190 if (RegQueryValueExA(internet_settings
, "ProxyEnable", NULL
, NULL
, (LPBYTE
) &proxy_enable
, &size
) != ERROR_SUCCESS
)
193 RegCloseKey(internet_settings
);
195 return proxy_enable
!= 0;
198 static void init_events(void)
200 complete_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
201 conn_close_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
202 conn_wait_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
203 server_req_rec_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
204 request_sent_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
207 static void free_events(void)
209 CloseHandle(complete_event
);
210 CloseHandle(conn_close_event
);
211 CloseHandle(conn_wait_event
);
212 CloseHandle(server_req_rec_event
);
213 CloseHandle(request_sent_event
);
216 static void reset_events(void)
218 ResetEvent(complete_event
);
219 ResetEvent(conn_close_event
);
220 ResetEvent(conn_wait_event
);
221 ResetEvent(server_req_rec_event
);
222 ResetEvent(request_sent_event
);
225 #define test_status_code(a,b) _test_status_code(__LINE__,a,b, FALSE)
226 #define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)
227 static void _test_status_code(unsigned line
, HINTERNET req
, DWORD excode
, BOOL is_todo
)
229 DWORD code
, size
, index
;
230 char exbuf
[12], bufa
[10];
236 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, NULL
);
237 ok_(__FILE__
,line
)(res
, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
238 todo_wine_if (is_todo
)
239 ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
240 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
245 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
246 ok_(__FILE__
,line
)(res
, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
247 ok_(__FILE__
,line
)(!index
, "index = %d, expected 0\n", index
);
248 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
250 sprintf(exbuf
, "%u", excode
);
253 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, bufa
, &size
, NULL
);
254 ok_(__FILE__
,line
)(res
, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
255 todo_wine_if (is_todo
)
256 ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
257 ok_(__FILE__
,line
)(size
== strlen(exbuf
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
260 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
261 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
262 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
263 ok_(__FILE__
,line
)(size
== strlen(exbuf
)+1, "unexpected size %d for \"%s\"\n", size
, exbuf
);
266 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
267 ok_(__FILE__
,line
)(res
, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
268 todo_wine_if (is_todo
)
269 ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
270 ok_(__FILE__
,line
)(size
== strlen(exbuf
)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
273 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
274 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
275 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
276 ok_(__FILE__
,line
)(size
== (strlen(exbuf
)+1)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
280 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
281 ok(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
282 ok(size
== sizeof(bufw
), "unexpected size %d\n", size
);
288 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
289 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
290 "[7] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
294 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, &code
, &size
, NULL
);
295 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST
,
296 "[8] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
299 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
300 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
301 static void _test_request_flags(unsigned line
, HINTERNET req
, DWORD exflags
, BOOL is_todo
)
307 size
= sizeof(flags
);
308 res
= InternetQueryOptionW(req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &size
);
309 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
311 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
312 flags
&= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED
;
313 todo_wine_if (is_todo
)
314 ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
317 #define test_request_url(a,b) _test_request_url(__LINE__,a,b)
318 static void _test_request_url(unsigned line
, HINTERNET req
, const char *expected_url
)
320 char buf
[INTERNET_MAX_URL_LENGTH
];
321 DWORD size
= sizeof(buf
);
324 res
= InternetQueryOptionA(req
, INTERNET_OPTION_URL
, buf
, &size
);
325 ok_(__FILE__
,line
)(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
326 ok_(__FILE__
,line
)(size
== strlen(expected_url
), "size = %u\n", size
);
327 ok_(__FILE__
,line
)(!strcmp(buf
, expected_url
), "unexpected URL %s, expected %s\n", buf
, expected_url
);
330 #define test_http_version(a) _test_http_version(__LINE__,a)
331 static void _test_http_version(unsigned line
, HINTERNET req
)
333 HTTP_VERSION_INFO v
= {0xdeadbeef, 0xdeadbeef};
338 res
= InternetQueryOptionW(req
, INTERNET_OPTION_HTTP_VERSION
, &v
, &size
);
339 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
340 ok_(__FILE__
,line
)(v
.dwMajorVersion
== 1, "dwMajorVersion = %d\n", v
.dwMajorVersion
);
341 ok_(__FILE__
,line
)(v
.dwMinorVersion
== 1, "dwMinorVersion = %d\n", v
.dwMinorVersion
);
344 static int close_handle_cnt
;
346 static VOID WINAPI
callback(
349 DWORD dwInternetStatus
,
350 LPVOID lpvStatusInformation
,
351 DWORD dwStatusInformationLength
354 CHECK_EXPECT(dwInternetStatus
);
355 switch (dwInternetStatus
)
357 case INTERNET_STATUS_RESOLVING_NAME
:
358 if(winetest_debug
> 1)
359 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
360 GetCurrentThreadId(), hInternet
, dwContext
,
361 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
362 *(LPSTR
)lpvStatusInformation
= '\0';
364 case INTERNET_STATUS_NAME_RESOLVED
:
365 if(winetest_debug
> 1)
366 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
367 GetCurrentThreadId(), hInternet
, dwContext
,
368 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
369 *(LPSTR
)lpvStatusInformation
= '\0';
371 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
372 if(winetest_debug
> 1)
373 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
374 GetCurrentThreadId(), hInternet
, dwContext
,
375 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
376 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
377 dwStatusInformationLength
);
378 *(LPSTR
)lpvStatusInformation
= '\0';
380 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
381 if(winetest_debug
> 1)
382 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
383 GetCurrentThreadId(), hInternet
, dwContext
,
384 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
385 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
386 dwStatusInformationLength
);
387 *(LPSTR
)lpvStatusInformation
= '\0';
389 case INTERNET_STATUS_SENDING_REQUEST
:
390 if(winetest_debug
> 1)
391 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
392 GetCurrentThreadId(), hInternet
, dwContext
,
393 lpvStatusInformation
,dwStatusInformationLength
);
395 case INTERNET_STATUS_REQUEST_SENT
:
396 ok(dwStatusInformationLength
== sizeof(DWORD
),
397 "info length should be sizeof(DWORD) instead of %d\n",
398 dwStatusInformationLength
);
399 if(winetest_debug
> 1)
400 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
401 GetCurrentThreadId(), hInternet
, dwContext
,
402 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
404 case INTERNET_STATUS_RECEIVING_RESPONSE
:
405 if(winetest_debug
> 1)
406 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
407 GetCurrentThreadId(), hInternet
, dwContext
,
408 lpvStatusInformation
,dwStatusInformationLength
);
410 case INTERNET_STATUS_RESPONSE_RECEIVED
:
411 ok(dwStatusInformationLength
== sizeof(DWORD
),
412 "info length should be sizeof(DWORD) instead of %d\n",
413 dwStatusInformationLength
);
414 if(winetest_debug
> 1)
415 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
416 GetCurrentThreadId(), hInternet
, dwContext
,
417 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
419 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
420 if(winetest_debug
> 1)
421 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
422 GetCurrentThreadId(), hInternet
,dwContext
,
423 lpvStatusInformation
,dwStatusInformationLength
);
425 case INTERNET_STATUS_PREFETCH
:
426 if(winetest_debug
> 1)
427 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
428 GetCurrentThreadId(), hInternet
, dwContext
,
429 lpvStatusInformation
,dwStatusInformationLength
);
431 case INTERNET_STATUS_CLOSING_CONNECTION
:
432 if(winetest_debug
> 1)
433 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
434 GetCurrentThreadId(), hInternet
, dwContext
,
435 lpvStatusInformation
,dwStatusInformationLength
);
437 case INTERNET_STATUS_CONNECTION_CLOSED
:
438 if(winetest_debug
> 1)
439 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
440 GetCurrentThreadId(), hInternet
, dwContext
,
441 lpvStatusInformation
,dwStatusInformationLength
);
443 case INTERNET_STATUS_HANDLE_CREATED
:
444 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
445 "info length should be sizeof(HINTERNET) instead of %d\n",
446 dwStatusInformationLength
);
447 if(winetest_debug
> 1)
448 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
449 GetCurrentThreadId(), hInternet
, dwContext
,
450 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
451 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
452 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
454 case INTERNET_STATUS_HANDLE_CLOSING
:
455 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
456 "info length should be sizeof(HINTERNET) instead of %d\n",
457 dwStatusInformationLength
);
458 if(winetest_debug
> 1)
459 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
460 GetCurrentThreadId(), hInternet
, dwContext
,
461 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
462 if(!InterlockedDecrement(&close_handle_cnt
))
463 SetEvent(complete_event
);
465 case INTERNET_STATUS_REQUEST_COMPLETE
:
467 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
468 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
469 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
470 dwStatusInformationLength
);
471 ok(iar
->dwResult
== 1 || iar
->dwResult
== 0, "iar->dwResult = %ld\n", iar
->dwResult
);
472 if(winetest_debug
> 1)
473 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
474 GetCurrentThreadId(), hInternet
, dwContext
,
475 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
476 req_error
= iar
->dwError
;
477 if(!close_handle_cnt
)
478 SetEvent(complete_event
);
481 case INTERNET_STATUS_REDIRECT
:
482 if(winetest_debug
> 1)
483 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
484 GetCurrentThreadId(), hInternet
, dwContext
,
485 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
486 *(LPSTR
)lpvStatusInformation
= '\0';
487 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
488 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
490 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
491 if(winetest_debug
> 1)
492 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
493 GetCurrentThreadId(), hInternet
, dwContext
,
494 lpvStatusInformation
, dwStatusInformationLength
);
497 if(winetest_debug
> 1)
498 trace("%04x:Callback %p 0x%lx %d %p %d\n",
499 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
500 lpvStatusInformation
, dwStatusInformationLength
);
506 HINTERNET connection
;
510 #define open_simple_request(a,b,c,d,e) _open_simple_request(__LINE__,a,b,c,d,e)
511 static void _open_simple_request(unsigned line
, test_request_t
*req
, const char *host
,
512 int port
, const char *verb
, const char *url
)
514 req
->session
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
515 ok_(__FILE__
,line
)(req
->session
!= NULL
, "InternetOpenA failed: %u\n", GetLastError());
517 req
->connection
= InternetConnectA(req
->session
, host
, port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
518 ok_(__FILE__
,line
)(req
->connection
!= NULL
, "InternetConnectA failed: %u\n", GetLastError());
520 req
->request
= HttpOpenRequestA(req
->connection
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
521 ok_(__FILE__
,line
)(req
->request
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
524 #define close_request(a) _close_request(__LINE__,a)
525 static void _close_request(unsigned line
, test_request_t
*req
)
529 ret
= InternetCloseHandle(req
->request
);
530 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(request) failed: %u\n", GetLastError());
531 ret
= InternetCloseHandle(req
->connection
);
532 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(connection) failed: %u\n", GetLastError());
533 ret
= InternetCloseHandle(req
->session
);
534 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(session) failed: %u\n", GetLastError());
537 #define receive_simple_request(a,b,c) _receive_simple_request(__LINE__,a,b,c)
538 static DWORD
_receive_simple_request(unsigned line
, HINTERNET req
, char *buf
, size_t buf_size
)
543 ret
= InternetReadFile(req
, buf
, buf_size
, &read
);
544 ok_(__FILE__
,line
)(ret
, "InternetReadFile failed: %u\n", GetLastError());
549 static void close_async_handle(HINTERNET handle
, int handle_cnt
)
553 close_handle_cnt
= handle_cnt
;
555 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
556 res
= InternetCloseHandle(handle
);
557 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
558 WaitForSingleObject(complete_event
, INFINITE
);
559 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
562 static void InternetReadFile_test(int flags
, const test_data_t
*test
)
564 char *post_data
= NULL
;
565 BOOL res
, on_async
= TRUE
;
568 DWORD length
, length2
, index
, exlen
= 0, post_len
= 0;
569 const char *types
[2] = { "*", NULL
};
570 HINTERNET hi
, hic
= 0, hor
= 0;
572 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags
,test
->url
);
575 trace("InternetOpenA <--\n");
576 hi
= InternetOpenA((test
->flags
& TESTF_COMPRESSED
) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
577 INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
578 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
579 trace("InternetOpenA -->\n");
581 if (hi
== 0x0) goto abort
;
583 pInternetSetStatusCallbackA(hi
,&callback
);
585 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
587 trace("InternetConnectA <--\n");
588 hic
=InternetConnectA(hi
, test
->host
, INTERNET_INVALID_PORT_NUMBER
,
589 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
590 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
591 trace("InternetConnectA -->\n");
593 if (hic
== 0x0) goto abort
;
595 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
596 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
598 trace("HttpOpenRequestA <--\n");
599 hor
= HttpOpenRequestA(hic
, test
->post_data
? "POST" : "GET", test
->path
, NULL
, NULL
, types
,
600 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
602 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
604 * If the internet name can't be resolved we are probably behind
605 * a firewall or in some other way not directly connected to the
606 * Internet. Not enough reason to fail the test. Just ignore and
610 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
612 trace("HttpOpenRequestA -->\n");
614 if (hor
== 0x0) goto abort
;
616 test_request_flags(hor
, INTERNET_REQFLAG_NO_HEADERS
);
617 test_request_url(hor
, test
->url
);
619 length
= sizeof(buffer
);
620 res
= HttpQueryInfoA(hor
, HTTP_QUERY_RAW_HEADERS
, buffer
, &length
, 0x0);
621 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
622 ok(length
== 0 || (length
== 1 && !*buffer
) /* win10 */, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length
);
623 ok(!strcmp(buffer
, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer
);
625 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
626 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
627 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
628 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
,2);
629 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED
,2);
630 if (first_connection_to_test_url
)
632 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
633 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
635 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
636 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
637 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
638 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
639 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
640 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
641 if(test
->flags
& TESTF_REDIRECT
) {
642 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
643 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
645 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
646 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
647 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
648 if (flags
& INTERNET_FLAG_ASYNC
)
649 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
651 if(test
->flags
& TESTF_COMPRESSED
) {
654 res
= InternetSetOptionA(hor
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
655 ok(res
|| broken(!res
&& GetLastError() == ERROR_INTERNET_INVALID_OPTION
),
656 "InternetSetOption failed: %u\n", GetLastError());
661 test_status_code(hor
, 0);
663 trace("HttpSendRequestA -->\n");
664 if(test
->post_data
) {
665 post_len
= strlen(test
->post_data
);
666 post_data
= HeapAlloc(GetProcessHeap(), 0, post_len
);
667 memcpy(post_data
, test
->post_data
, post_len
);
669 SetLastError(0xdeadbeef);
670 res
= HttpSendRequestA(hor
, test
->headers
, -1, post_data
, post_len
);
671 if (flags
& INTERNET_FLAG_ASYNC
)
672 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
673 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
675 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
676 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
677 trace("HttpSendRequestA <--\n");
679 if (flags
& INTERNET_FLAG_ASYNC
) {
680 WaitForSingleObject(complete_event
, INFINITE
);
681 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
683 HeapFree(GetProcessHeap(), 0, post_data
);
685 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
686 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED
);
687 if (first_connection_to_test_url
)
689 if (! proxy_active())
691 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
692 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
696 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
697 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
702 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
703 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
705 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
706 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
707 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
708 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
709 if(test
->flags
& TESTF_REDIRECT
)
710 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
711 if (flags
& INTERNET_FLAG_ASYNC
)
712 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
713 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
714 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
715 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
717 test_request_flags(hor
, 0);
720 res
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
721 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
723 length
= sizeof(buffer
)-2;
724 memset(buffer
, 0x77, sizeof(buffer
));
725 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
726 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
727 /* show that the function writes data past the length returned */
728 ok(buffer
[length
-2], "Expected any header character, got 0x00\n");
729 ok(!buffer
[length
-1], "Expected 0x00, got %02X\n", buffer
[length
-1]);
730 ok(!buffer
[length
], "Expected 0x00, got %02X\n", buffer
[length
]);
731 ok(buffer
[length
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length
+1]);
734 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
735 ok(!res
, "Expected 0x00, got %d\n", res
);
736 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
737 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
738 /* the in length of the buffer must be +1 but the length returned does not count this */
740 memset(buffer
, 0x77, sizeof(buffer
));
741 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
742 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
743 ok(buffer
[length2
] == 0x00, "Expected 0x00, got %02X\n", buffer
[length2
]);
744 ok(buffer
[length2
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length2
+1]);
745 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
747 length
= sizeof(wbuffer
)-2*sizeof(WCHAR
);
748 memset(wbuffer
, 0x77, sizeof(wbuffer
));
749 res
= HttpQueryInfoW(hor
, HTTP_QUERY_RAW_HEADERS
, wbuffer
, &length
, 0x0);
750 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
751 ok(length
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length
);
752 length
/= sizeof(WCHAR
);
753 /* show that the function writes data past the length returned */
754 ok(wbuffer
[length
-2], "Expected any header character, got 0x0000\n");
755 ok(!wbuffer
[length
-1], "Expected 0x0000, got %04X\n", wbuffer
[length
-1]);
756 ok(!wbuffer
[length
], "Expected 0x0000, got %04X\n", wbuffer
[length
]);
757 ok(wbuffer
[length
+1] == 0x7777 || broken(wbuffer
[length
+1] != 0x7777),
758 "Expected 0x7777, got %04X\n", wbuffer
[length
+1]);
760 length2
= length
*sizeof(WCHAR
);
761 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
762 ok(!res
, "Expected 0x00, got %d\n", res
);
763 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
764 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
765 length2
/= sizeof(WCHAR
);
766 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
767 /* the in length of the buffer must be +1 but the length returned does not count this */
768 length2
= (length
+1)*sizeof(WCHAR
);
769 memset(wbuffer
, 0x77, sizeof(wbuffer
));
770 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
771 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
772 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
773 length2
/= sizeof(WCHAR
);
774 ok(!wbuffer
[length2
], "Expected 0x0000, got %04X\n", wbuffer
[length2
]);
775 ok(wbuffer
[length2
+1] == 0x7777, "Expected 0x7777, got %04X\n", wbuffer
[length2
+1]);
776 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
778 test_request_url(hor
, test
->redirected_url
);
782 SetLastError(0xdeadbeef);
783 ok(HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,NULL
,&length
,&index
) == FALSE
,"Query worked\n");
784 if(test
->flags
& TESTF_COMPRESSED
)
785 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
786 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
787 ok(index
== 0, "Index was incremented\n");
791 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,&index
);
792 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res
,buffer
,GetLastError());
793 if(test
->flags
& TESTF_COMPRESSED
)
794 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
795 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res
, GetLastError());
796 ok(!res
|| index
== 1, "Index was not incremented although result is %x (index = %u)\n", res
, index
);
799 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
801 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res
,buffer
);
804 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_ENCODING
,buffer
,&length
,0x0);
806 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res
,buffer
);
808 SetLastError(0xdeadbeef);
809 res
= InternetReadFile(NULL
, buffer
, 100, &length
);
810 ok(!res
, "InternetReadFile should have failed\n");
811 ok(GetLastError() == ERROR_INVALID_HANDLE
,
812 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
816 if(winetest_debug
> 1)
817 trace("Entering Query loop\n");
821 if (flags
& INTERNET_FLAG_ASYNC
)
822 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
824 /* IE11 calls those in InternetQueryDataAvailable call. */
825 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
826 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
829 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
831 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
833 if (flags
& INTERNET_FLAG_ASYNC
)
837 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
839 ok(length
>= exlen
, "length %u < exlen %u\n", length
, exlen
);
843 else if (GetLastError() == ERROR_IO_PENDING
)
845 if(winetest_debug
> 1)
847 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
848 if(!(test
->flags
& TESTF_CHUNKED
))
849 ok(!length
, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length
);
850 WaitForSingleObject(complete_event
, INFINITE
);
852 ok(exlen
, "length = 0\n");
853 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
854 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
855 ok(req_error
, "req_error = 0\n");
858 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
861 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
863 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
865 if(winetest_debug
> 1)
866 trace("length %u\n", length
);
867 if(test
->flags
& TESTF_CHUNKED
)
868 ok(length
<= 8192, "length = %d, expected <= 8192\n", length
);
872 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
874 res
= InternetReadFile(hor
,buffer
,length
,&length
);
878 if(winetest_debug
> 1)
879 trace("ReadFile -> %s %i\n", res
? "TRUE" : "FALSE", length
);
882 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
883 HeapFree(GetProcessHeap(),0,buffer
);
885 ok(!on_async
, "Returned zero size in response to request complete\n");
890 if(test
->flags
& TESTF_REDIRECT
) {
891 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
892 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
895 if(winetest_debug
> 1)
897 close_async_handle(hi
, 2);
898 first_connection_to_test_url
= FALSE
;
901 static void InternetReadFile_chunked_test(void)
906 const char *types
[2] = { "*", NULL
};
907 HINTERNET hi
, hic
= 0, hor
= 0;
909 trace("Starting InternetReadFile chunked test\n");
911 trace("InternetOpenA <--\n");
912 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
913 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
914 trace("InternetOpenA -->\n");
916 if (hi
== 0x0) goto abort
;
918 trace("InternetConnectA <--\n");
919 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
920 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
921 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
922 trace("InternetConnectA -->\n");
924 if (hic
== 0x0) goto abort
;
926 trace("HttpOpenRequestA <--\n");
927 hor
= HttpOpenRequestA(hic
, "GET", "/tests/chunked", NULL
, NULL
, types
,
928 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
930 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
932 * If the internet name can't be resolved we are probably behind
933 * a firewall or in some other way not directly connected to the
934 * Internet. Not enough reason to fail the test. Just ignore and
938 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
940 trace("HttpOpenRequestA -->\n");
942 if (hor
== 0x0) goto abort
;
944 trace("HttpSendRequestA -->\n");
945 SetLastError(0xdeadbeef);
946 res
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
947 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
948 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
949 trace("HttpSendRequestA <--\n");
951 test_request_flags(hor
, 0);
954 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
956 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
958 SetLastError( 0xdeadbeef );
960 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
962 trace("Option TRANSFER_ENCODING -> %i %s\n",res
,buffer
);
963 ok( res
|| ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
964 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
965 ok( !strcmp( buffer
, "chunked" ) || ( ! res
&& proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
966 "Wrong transfer encoding '%s'\n", buffer
);
968 SetLastError( 0xdeadbeef );
970 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
971 ok( !res
, "Found CONTENT_LENGTH option '%s'\n", buffer
);
972 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Wrong error %u\n", GetLastError() );
975 trace("Entering Query loop\n");
979 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
980 ok(!(!res
&& length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
981 ok(res
, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
982 trace("got %u available\n",length
);
985 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
987 res
= InternetReadFile(hor
,buffer
,length
,&got
);
990 trace("ReadFile -> %i %i\n",res
,got
);
991 ok( length
== got
, "only got %u of %u available\n", got
, length
);
992 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
994 HeapFree(GetProcessHeap(),0,buffer
);
1000 res
= InternetReadFile( hor
, buffer
, 1, &got
);
1001 ok( res
, "InternetReadFile failed: %u\n", GetLastError() );
1002 ok( !got
, "got %u\n", got
);
1007 trace("aborting\n");
1009 res
= InternetCloseHandle(hor
);
1010 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
1013 res
= InternetCloseHandle(hi
);
1014 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
1018 static void InternetReadFileExA_test(int flags
)
1022 const char *types
[2] = { "*", NULL
};
1023 HINTERNET hi
, hic
= 0, hor
= 0;
1024 INTERNET_BUFFERSA inetbuffers
;
1026 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
1029 trace("InternetOpenA <--\n");
1030 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
1031 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
1032 trace("InternetOpenA -->\n");
1034 if (hi
== 0x0) goto abort
;
1036 pInternetSetStatusCallbackA(hi
,&callback
);
1038 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1040 trace("InternetConnectA <--\n");
1041 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
1042 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1043 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
1044 trace("InternetConnectA -->\n");
1046 if (hic
== 0x0) goto abort
;
1048 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1049 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1051 trace("HttpOpenRequestA <--\n");
1052 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
1053 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
1055 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
1057 * If the internet name can't be resolved we are probably behind
1058 * a firewall or in some other way not directly connected to the
1059 * Internet. Not enough reason to fail the test. Just ignore and
1063 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
1065 trace("HttpOpenRequestA -->\n");
1067 if (hor
== 0x0) goto abort
;
1069 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1070 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1071 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1072 if (first_connection_to_test_url
)
1074 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
1075 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
1077 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
, 2);
1078 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1079 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1080 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1081 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
1082 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1083 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1084 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1085 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1086 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
1087 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1088 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1089 if (flags
& INTERNET_FLAG_ASYNC
)
1090 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1092 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1094 trace("HttpSendRequestA -->\n");
1095 SetLastError(0xdeadbeef);
1096 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
1097 if (flags
& INTERNET_FLAG_ASYNC
)
1098 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
1099 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
1101 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
1102 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
1103 trace("HttpSendRequestA <--\n");
1105 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
1106 WaitForSingleObject(complete_event
, INFINITE
);
1107 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1110 if (first_connection_to_test_url
)
1112 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1113 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1117 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1118 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1120 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1121 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
1122 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1123 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1124 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1125 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1126 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
1127 if (flags
& INTERNET_FLAG_ASYNC
)
1128 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1130 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1131 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
1132 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
1133 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1134 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1137 rc
= InternetReadFileExW(hor
, NULL
, 0, 0xdeadcafe);
1138 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1139 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1140 rc
? "TRUE" : "FALSE", GetLastError());
1143 /* tests invalid dwStructSize */
1144 inetbuffers
.dwStructSize
= sizeof(inetbuffers
)+1;
1145 inetbuffers
.lpcszHeader
= NULL
;
1146 inetbuffers
.dwHeadersLength
= 0;
1147 inetbuffers
.dwBufferLength
= 10;
1148 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
1149 inetbuffers
.dwOffsetHigh
= 1234;
1150 inetbuffers
.dwOffsetLow
= 5678;
1151 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1152 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1153 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1154 rc
? "TRUE" : "FALSE", GetLastError());
1155 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1157 test_request_flags(hor
, 0);
1159 /* tests to see whether lpcszHeader is used - it isn't */
1160 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1161 inetbuffers
.lpcszHeader
= (LPCSTR
)0xdeadbeef;
1162 inetbuffers
.dwHeadersLength
= 255;
1163 inetbuffers
.dwBufferLength
= 0;
1164 inetbuffers
.lpvBuffer
= NULL
;
1165 inetbuffers
.dwOffsetHigh
= 1234;
1166 inetbuffers
.dwOffsetLow
= 5678;
1167 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1168 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
1169 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1171 rc
= InternetReadFileExA(NULL
, &inetbuffers
, 0, 0xdeadcafe);
1172 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
1173 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1174 rc
? "TRUE" : "FALSE", GetLastError());
1177 trace("Entering Query loop\n");
1181 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1182 inetbuffers
.dwBufferLength
= 1024;
1183 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
1184 inetbuffers
.dwOffsetHigh
= 1234;
1185 inetbuffers
.dwOffsetLow
= 5678;
1187 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1188 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1189 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1190 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
1193 if (GetLastError() == ERROR_IO_PENDING
)
1195 trace("InternetReadFileEx -> PENDING\n");
1196 ok(flags
& INTERNET_FLAG_ASYNC
,
1197 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1198 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1199 WaitForSingleObject(complete_event
, INFINITE
);
1200 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1201 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1202 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1206 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1212 trace("InternetReadFileEx -> SUCCEEDED\n");
1213 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1214 if (inetbuffers
.dwBufferLength
)
1216 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1217 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1221 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1222 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1223 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1227 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1228 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
1230 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
1231 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1232 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
1234 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1236 if (!inetbuffers
.dwBufferLength
)
1239 length
+= inetbuffers
.dwBufferLength
;
1241 ok(length
> 0, "failed to read any of the document\n");
1242 trace("Finished. Read %d bytes\n", length
);
1245 close_async_handle(hi
, 2);
1246 first_connection_to_test_url
= FALSE
;
1249 static void InternetOpenUrlA_test(void)
1251 HINTERNET myhinternet
, myhttp
;
1253 DWORD size
, readbytes
, totalbytes
=0;
1256 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1257 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
1258 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret
, GetLastError());
1260 myhinternet
= InternetOpenA("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
1261 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
1263 ret
= InternetCanonicalizeUrlA(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1264 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1267 myhttp
= InternetOpenUrlA(myhinternet
, TEST_URL
, 0, 0,
1268 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
1269 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1270 return; /* WinXP returns this when not connected to the net */
1271 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1272 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
1273 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
1274 totalbytes
+= readbytes
;
1275 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
1276 totalbytes
+= readbytes
;
1277 trace("read 0x%08x bytes\n",totalbytes
);
1279 InternetCloseHandle(myhttp
);
1280 InternetCloseHandle(myhinternet
);
1282 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1283 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1286 static void HttpSendRequestEx_test(void)
1292 INTERNET_BUFFERSA BufferIn
;
1293 DWORD dwBytesWritten
, dwBytesRead
, error
;
1298 static char szPostData
[] = "mode=Test";
1299 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
1301 hSession
= InternetOpenA("Wine Regression Test",
1302 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1303 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1304 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1305 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1307 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1308 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1309 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1310 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1312 skip( "Network unreachable, skipping test\n" );
1315 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1317 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1319 BufferIn
.dwStructSize
= sizeof(BufferIn
);
1320 BufferIn
.Next
= (INTERNET_BUFFERSA
*)0xdeadcab;
1321 BufferIn
.lpcszHeader
= szContentType
;
1322 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1323 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1324 BufferIn
.lpvBuffer
= szPostData
;
1325 BufferIn
.dwBufferLength
= 3;
1326 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1327 BufferIn
.dwOffsetLow
= 0;
1328 BufferIn
.dwOffsetHigh
= 0;
1330 SetLastError(0xdeadbeef);
1331 ret
= HttpSendRequestExA(hRequest
, &BufferIn
, NULL
, 0 ,0);
1332 error
= GetLastError();
1333 ok(ret
, "HttpSendRequestEx Failed with error %u\n", error
);
1334 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", error
);
1336 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1338 for (i
= 3; szPostData
[i
]; i
++)
1339 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1340 "InternetWriteFile failed\n");
1342 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1344 ok(HttpEndRequestA(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1346 test_request_flags(hRequest
, 0);
1348 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1349 "Unable to read response\n");
1350 szBuffer
[dwBytesRead
] = 0;
1352 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
1353 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1355 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1357 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1358 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1361 static void InternetOpenRequest_test(void)
1363 HINTERNET session
, connect
, request
;
1364 static const char *types
[] = { "*", "", NULL
};
1365 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1366 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1369 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1370 ok(session
!= NULL
,"Unable to open Internet session\n");
1372 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1373 INTERNET_SERVICE_HTTP
, 0, 0);
1374 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1375 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1377 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1378 INTERNET_SERVICE_HTTP
, 0, 0);
1379 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1380 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1382 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1383 INTERNET_SERVICE_HTTP
, 0, 0);
1384 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1386 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1387 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1389 skip( "Network unreachable, skipping test\n" );
1392 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1394 ret
= HttpSendRequestW(request
, NULL
, 0, NULL
, 0);
1395 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1396 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1398 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1399 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1401 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1402 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1403 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1406 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1407 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1410 static void test_cache_read(void)
1412 HINTERNET session
, connection
, req
;
1413 FILETIME now
, tomorrow
, yesterday
;
1414 BYTE content
[1000], buf
[2000];
1415 char file_path
[MAX_PATH
];
1422 static const char cache_only_url
[] = "http://test.winehq.org/tests/cache-only";
1423 BYTE cache_headers
[] = "HTTP/1.1 200 OK\r\n\r\n";
1425 trace("Testing cache read...\n");
1428 for(i
= 0; i
< sizeof(content
); i
++)
1429 content
[i
] = '0' + (i
%10);
1431 GetSystemTimeAsFileTime(&now
);
1432 li
.u
.HighPart
= now
.dwHighDateTime
;
1433 li
.u
.LowPart
= now
.dwLowDateTime
;
1434 li
.QuadPart
+= (LONGLONG
)10000000 * 3600 * 24;
1435 tomorrow
.dwHighDateTime
= li
.u
.HighPart
;
1436 tomorrow
.dwLowDateTime
= li
.u
.LowPart
;
1437 li
.QuadPart
-= (LONGLONG
)10000000 * 3600 * 24 * 2;
1438 yesterday
.dwHighDateTime
= li
.u
.HighPart
;
1439 yesterday
.dwLowDateTime
= li
.u
.LowPart
;
1441 res
= CreateUrlCacheEntryA(cache_only_url
, sizeof(content
), "", file_path
, 0);
1442 ok(res
, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1444 file
= CreateFileA(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1445 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
1447 WriteFile(file
, content
, sizeof(content
), &size
, NULL
);
1450 res
= CommitUrlCacheEntryA(cache_only_url
, file_path
, tomorrow
, yesterday
, NORMAL_CACHE_ENTRY
,
1451 cache_headers
, sizeof(cache_headers
)-1, "", 0);
1452 ok(res
, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1454 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
1455 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
1457 pInternetSetStatusCallbackA(session
, callback
);
1459 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1460 connection
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
,
1461 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1462 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
1463 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1465 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1466 req
= HttpOpenRequestA(connection
, "GET", "/tests/cache-only", NULL
, NULL
, NULL
, 0, 0xdeadbead);
1467 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
1468 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1470 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1471 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1472 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST
);
1473 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT
);
1474 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1475 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1476 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1478 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
1480 ok(res
, "HttpSendRequest failed: %u\n", GetLastError());
1484 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
1485 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1486 ok(size
== sizeof(content
), "size = %u\n", size
);
1489 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
1490 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
1491 ok(size
== sizeof(content
), "size = %u\n", size
);
1492 ok(!memcmp(content
, buf
, sizeof(content
)), "unexpected content\n");
1495 close_async_handle(session
, 2);
1497 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1498 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1499 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
1500 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
1501 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1502 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1503 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1505 res
= DeleteUrlCacheEntryA(cache_only_url
);
1506 ok(res
, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1509 static void test_http_cache(void)
1511 HINTERNET session
, connect
, request
;
1512 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1513 DWORD size
, file_size
;
1517 FILETIME filetime_zero
= {0};
1519 static const char cached_content
[] = "data read from cache";
1520 static const char *types
[] = { "*", "", NULL
};
1522 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1523 ok(session
!= NULL
,"Unable to open Internet session\n");
1525 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1526 INTERNET_SERVICE_HTTP
, 0, 0);
1527 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1529 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1530 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1532 skip( "Network unreachable, skipping test\n" );
1534 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1535 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1539 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1542 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1543 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1544 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1546 size
= sizeof(file_name
);
1547 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1548 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1549 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1550 ok(!size
, "size = %d\n", size
);
1552 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1553 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1555 size
= sizeof(file_name
);
1556 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1557 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1559 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1560 FILE_ATTRIBUTE_NORMAL
, NULL
);
1561 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1562 file_size
= GetFileSize(file
, NULL
);
1563 ok(file_size
== 106, "file size = %u\n", file_size
);
1566 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1567 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1568 ok(size
== 100, "size = %u\n", size
);
1570 file_size
= GetFileSize(file
, NULL
);
1571 ok(file_size
== 106, "file size = %u\n", file_size
);
1574 ret
= DeleteFileA(file_name
);
1575 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1577 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1579 file
= CreateFileA(file_name
, GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1580 FILE_ATTRIBUTE_NORMAL
, NULL
);
1581 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1582 ret
= WriteFile(file
, cached_content
, sizeof(cached_content
), &size
, NULL
);
1583 ok(ret
&& size
, "WriteFile failed: %d, %d\n", ret
, size
);
1584 ret
= CommitUrlCacheEntryA(url
, file_name
, filetime_zero
, filetime_zero
, NORMAL_CACHE_ENTRY
, NULL
, 0, NULL
, 0);
1585 ok(ret
, "CommitUrlCacheEntry failed: %d\n", GetLastError());
1588 /* Send the same request, requiring it to be retrieved from the cache */
1589 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1591 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1592 ok(ret
, "HttpSendRequest failed\n");
1595 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1596 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1597 ok(size
== 100, "size = %u\n", size
);
1599 todo_wine
ok(!strcmp((char*)buf
, cached_content
), "incorrect page data: %s\n", (char*)buf
);
1601 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1603 DeleteUrlCacheEntryA(url
);
1604 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1605 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1606 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
1608 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError() = %d\n", GetLastError());
1609 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1611 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1612 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1614 size
= sizeof(file_name
);
1615 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1616 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1617 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1618 ok(!size
, "size = %d\n", size
);
1620 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1621 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1623 size
= sizeof(file_name
);
1625 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1628 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1629 FILE_ATTRIBUTE_NORMAL
, NULL
);
1630 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1636 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1639 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1640 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1641 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1646 static void InternetLockRequestFile_test(void)
1648 char file_name
[MAX_PATH
];
1654 open_simple_request(&req
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, "/tests/hello.html");
1656 size
= sizeof(file_name
);
1657 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1658 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1659 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1660 ok(!size
, "size = %d\n", size
);
1663 ret
= InternetLockRequestFile(req
.request
, &lock
);
1664 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1666 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
1667 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1669 size
= sizeof(file_name
);
1670 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1671 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1673 ret
= InternetLockRequestFile(req
.request
, &lock
);
1674 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1675 ok(lock
!= NULL
, "lock == NULL\n");
1677 ret
= InternetLockRequestFile(req
.request
, &lock2
);
1678 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1679 ok(lock
== lock2
, "lock != lock2\n");
1681 ret
= InternetUnlockRequestFile(lock2
);
1682 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1684 ret
= DeleteFileA(file_name
);
1685 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1687 ok(InternetCloseHandle(req
.request
), "Close request handle failed\n");
1689 ret
= DeleteFileA(file_name
);
1690 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1692 ret
= InternetUnlockRequestFile(lock
);
1693 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1695 ret
= DeleteFileA(file_name
);
1696 ok(ret
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1699 static void HttpHeaders_test(void)
1711 hSession
= InternetOpenA("Wine Regression Test",
1712 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1713 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1714 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1715 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1717 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1718 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1719 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1720 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1722 skip( "Network unreachable, skipping test\n" );
1725 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1728 len
= sizeof(buffer
);
1729 strcpy(buffer
,"Warning");
1730 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1731 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1733 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1734 "Failed to add new header\n");
1737 len
= sizeof(buffer
);
1738 strcpy(buffer
,"Warning");
1739 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1740 buffer
,&len
,&index
),"Unable to query header\n");
1741 ok(index
== 1, "Index was not incremented\n");
1742 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1743 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1744 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1745 len
= sizeof(buffer
);
1746 strcpy(buffer
,"Warning");
1747 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1748 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1751 len
= 5; /* could store the string but not the NULL terminator */
1752 strcpy(buffer
,"Warning");
1753 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1754 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1755 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1756 ok(index
== 0, "Index was incremented\n");
1757 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1758 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1760 /* a call with NULL will fail but will return the length */
1762 len
= sizeof(buffer
);
1763 SetLastError(0xdeadbeef);
1764 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1765 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1766 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1767 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1768 ok(index
== 0, "Index was incremented\n");
1770 /* even for a len that is too small */
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");
1782 SetLastError(0xdeadbeef);
1783 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1784 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1785 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1786 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1787 ok(index
== 0, "Index was incremented\n");
1788 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1791 /* a working query */
1793 len
= sizeof(buffer
);
1794 memset(buffer
, 'x', sizeof(buffer
));
1795 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1796 buffer
,&len
,&index
),"Unable to query header\n");
1797 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1798 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1799 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1800 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1801 ok(strncmp(buffer
, "POST /tests/post.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1802 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1803 ok(index
== 0, "Index was incremented\n");
1805 /* Like above two tests, but for W version */
1809 SetLastError(0xdeadbeef);
1810 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1811 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1812 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1813 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1814 ok(index
== 0, "Index was incremented\n");
1815 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1817 /* a working query */
1819 len
= sizeof(wbuffer
);
1820 memset(wbuffer
, 'x', sizeof(wbuffer
));
1821 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1822 wbuffer
,&len
,&index
),"Unable to query header\n");
1823 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1824 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1825 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1826 ok(index
== 0, "Index was incremented\n");
1828 /* end of W version tests */
1830 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1832 len
= sizeof(buffer
);
1833 memset(buffer
, 'x', sizeof(buffer
));
1834 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1835 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1836 ok(len
== 2 || len
== 4 /* win10 */, "Expected 2 or 4, got %d\n", len
);
1837 ok(memcmp(buffer
, "\r\n\r\n", len
) == 0, "Expected CRLF, got '%s'\n", buffer
);
1838 ok(index
== 0, "Index was incremented\n");
1840 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1841 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1844 len
= sizeof(buffer
);
1845 strcpy(buffer
,"Warning");
1846 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1847 buffer
,&len
,&index
),"Unable to query header\n");
1848 ok(index
== 1, "Index was not incremented\n");
1849 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1850 len
= sizeof(buffer
);
1851 strcpy(buffer
,"Warning");
1852 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1853 buffer
,&len
,&index
),"Failed to get second header\n");
1854 ok(index
== 2, "Index was not incremented\n");
1855 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1856 len
= sizeof(buffer
);
1857 strcpy(buffer
,"Warning");
1858 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1859 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1861 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1864 len
= sizeof(buffer
);
1865 strcpy(buffer
,"Warning");
1866 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1867 buffer
,&len
,&index
),"Unable to query header\n");
1868 ok(index
== 1, "Index was not incremented\n");
1869 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1870 len
= sizeof(buffer
);
1871 strcpy(buffer
,"Warning");
1872 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1873 buffer
,&len
,&index
),"Failed to get second header\n");
1874 ok(index
== 2, "Index was not incremented\n");
1875 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1876 len
= sizeof(buffer
);
1877 strcpy(buffer
,"Warning");
1878 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1879 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1881 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1884 len
= sizeof(buffer
);
1885 strcpy(buffer
,"Warning");
1886 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1887 buffer
,&len
,&index
),"Unable to query header\n");
1888 ok(index
== 1, "Index was not incremented\n");
1889 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1890 len
= sizeof(buffer
);
1891 strcpy(buffer
,"Warning");
1892 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1893 buffer
,&len
,&index
),"Failed to get second header\n");
1894 ok(index
== 2, "Index was not incremented\n");
1895 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1896 len
= sizeof(buffer
);
1897 strcpy(buffer
,"Warning");
1898 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1899 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1901 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1904 len
= sizeof(buffer
);
1905 strcpy(buffer
,"Warning");
1906 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1907 buffer
,&len
,&index
),"Unable to query header\n");
1908 ok(index
== 1, "Index was not incremented\n");
1909 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1910 len
= sizeof(buffer
);
1911 strcpy(buffer
,"Warning");
1912 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1913 ok(index
== 2, "Index was not incremented\n");
1914 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1915 len
= sizeof(buffer
);
1916 strcpy(buffer
,"Warning");
1917 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1919 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1922 len
= sizeof(buffer
);
1923 strcpy(buffer
,"Warning");
1924 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1925 ok(index
== 1, "Index was not incremented\n");
1926 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1927 len
= sizeof(buffer
);
1928 strcpy(buffer
,"Warning");
1929 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1930 ok(index
== 2, "Index was not incremented\n");
1931 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1932 len
= sizeof(buffer
);
1933 strcpy(buffer
,"Warning");
1934 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1936 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1939 len
= sizeof(buffer
);
1940 strcpy(buffer
,"Warning");
1941 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1942 ok(index
== 1, "Index was not incremented\n");
1943 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1944 len
= sizeof(buffer
);
1945 strcpy(buffer
,"Warning");
1946 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1947 ok(index
== 2, "Index was not incremented\n");
1948 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1949 len
= sizeof(buffer
);
1950 strcpy(buffer
,"Warning");
1951 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1953 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");
1956 len
= sizeof(buffer
);
1957 strcpy(buffer
,"Warning");
1958 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1959 ok(index
== 1, "Index was not incremented\n");
1960 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1961 len
= sizeof(buffer
);
1962 strcpy(buffer
,"Warning");
1963 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1964 ok(index
== 2, "Index was not incremented\n");
1965 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1966 len
= sizeof(buffer
);
1967 strcpy(buffer
,"Warning");
1968 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1970 /* Ensure that blank headers are ignored and don't cause a failure */
1971 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");
1974 len
= sizeof(buffer
);
1975 strcpy(buffer
,"BlankTest");
1976 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1977 ok(index
== 1, "Index was not incremented\n");
1978 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1980 /* Ensure that malformed header separators are ignored and don't cause a failure */
1981 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
),
1982 "Failed to add header with malformed entries in list\n");
1985 len
= sizeof(buffer
);
1986 strcpy(buffer
,"MalformedTest");
1987 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1988 ok(index
== 1, "Index was not incremented\n");
1989 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1991 len
= sizeof(buffer
);
1992 strcpy(buffer
,"MalformedTestTwo");
1993 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1994 ok(index
== 1, "Index was not incremented\n");
1995 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
1997 len
= sizeof(buffer
);
1998 strcpy(buffer
,"MalformedTestThree");
1999 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
2000 ok(index
== 1, "Index was not incremented\n");
2001 ok(strcmp(buffer
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
2003 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD
);
2004 ok(ret
, "unable to add header %u\n", GetLastError());
2008 len
= sizeof(buffer
);
2009 ret
= HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
);
2010 ok(ret
, "unable to query header %u\n", GetLastError());
2011 ok(index
== 1, "index was not incremented\n");
2012 ok(!strcmp(buffer
, "Basic"), "incorrect string was returned (%s)\n", buffer
);
2014 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE
);
2015 ok(ret
, "unable to remove header %u\n", GetLastError());
2018 len
= sizeof(buffer
);
2019 SetLastError(0xdeadbeef);
2020 ok(!HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
),
2021 "header still present\n");
2022 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "got %u\n", GetLastError());
2024 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
2026 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
2027 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
2030 static const char garbagemsg
[] =
2031 "Garbage: Header\r\n";
2033 static const char contmsg
[] =
2034 "HTTP/1.1 100 Continue\r\n";
2036 static const char expandcontmsg
[] =
2037 "HTTP/1.1 100 Continue\r\n"
2038 "Server: winecontinue\r\n"
2039 "Tag: something witty\r\n";
2041 static const char okmsg
[] =
2042 "HTTP/1.1 200 OK\r\n"
2043 "Server: winetest\r\n"
2046 static const char okmsg2
[] =
2047 "HTTP/1.1 200 OK\r\n"
2048 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
2049 "Server: winetest\r\n"
2050 "Content-Length: 0\r\n"
2051 "Set-Cookie: one\r\n"
2052 "Set-Cookie: two\r\n"
2055 static const char notokmsg
[] =
2056 "HTTP/1.1 400 Bad Request\r\n"
2057 "Server: winetest\r\n"
2060 static const char noauthmsg
[] =
2061 "HTTP/1.1 401 Unauthorized\r\n"
2062 "Server: winetest\r\n"
2063 "Connection: close\r\n"
2064 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
2067 static const char noauthmsg2
[] =
2068 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
2069 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
2071 "Server: winetest\r\n";
2073 static const char proxymsg
[] =
2074 "HTTP/1.1 407 Proxy Authentication Required\r\n"
2075 "Server: winetest\r\n"
2076 "Proxy-Connection: close\r\n"
2077 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
2080 static const char page1
[] =
2082 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
2083 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
2086 static const char ok_with_length
[] =
2087 "HTTP/1.1 200 OK\r\n"
2088 "Connection: Keep-Alive\r\n"
2089 "Content-Length: 18\r\n\r\n"
2090 "HTTP/1.1 211 OK\r\n\r\n";
2092 static const char ok_with_length2
[] =
2093 "HTTP/1.1 210 OK\r\n"
2094 "Connection: Keep-Alive\r\n"
2095 "Content-Length: 19\r\n\r\n"
2096 "HTTP/1.1 211 OK\r\n\r\n";
2098 struct server_info
{
2103 static int test_cache_gzip
;
2104 static const char *send_buffer
;
2105 static int server_socket
;
2107 static DWORD CALLBACK
server_thread(LPVOID param
)
2109 struct server_info
*si
= param
;
2110 int r
, c
= -1, i
, on
, count
= 0;
2112 struct sockaddr_in sa
;
2116 int last_request
= 0;
2117 char host_header
[22];
2118 char host_header_override
[30];
2119 static int test_no_cache
= 0;
2121 WSAStartup(MAKEWORD(1,1), &wsaData
);
2123 s
= socket(AF_INET
, SOCK_STREAM
, 0);
2124 if (s
== INVALID_SOCKET
)
2128 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
2130 memset(&sa
, 0, sizeof sa
);
2131 sa
.sin_family
= AF_INET
;
2132 sa
.sin_port
= htons(si
->port
);
2133 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
2135 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
2141 SetEvent(si
->hEvent
);
2143 sprintf(host_header
, "Host: localhost:%d", si
->port
);
2144 sprintf(host_header_override
, "Host: test.local:%d\r\n", si
->port
);
2145 buffer
= HeapAlloc(GetProcessHeap(), 0, buffer_size
= 1000);
2150 c
= accept(s
, NULL
, NULL
);
2152 memset(buffer
, 0, buffer_size
);
2155 if(i
== buffer_size
)
2156 buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, buffer_size
*= 2);
2158 r
= recv(c
, buffer
+i
, 1, 0);
2162 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
2163 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
2166 if (strstr(buffer
, "GET /test1"))
2168 if (!strstr(buffer
, "Content-Length: 0"))
2170 send(c
, okmsg
, sizeof okmsg
-1, 0);
2171 send(c
, page1
, sizeof page1
-1, 0);
2174 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2176 if (strstr(buffer
, "CONNECT "))
2178 if (!strstr(buffer
, "Content-Length: 0"))
2179 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2181 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2183 if (strstr(buffer
, "/test2"))
2185 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2187 send(c
, okmsg
, sizeof okmsg
-1, 0);
2188 send(c
, page1
, sizeof page1
-1, 0);
2191 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2193 if (strstr(buffer
, "/test3"))
2195 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2196 send(c
, okmsg
, sizeof okmsg
-1, 0);
2198 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2200 if (strstr(buffer
, "/test4"))
2202 if (strstr(buffer
, "Connection: Close"))
2203 send(c
, okmsg
, sizeof okmsg
-1, 0);
2205 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2207 if (strstr(buffer
, "POST /test5") ||
2208 strstr(buffer
, "RPC_IN_DATA /test5") ||
2209 strstr(buffer
, "RPC_OUT_DATA /test5"))
2211 if (strstr(buffer
, "Content-Length: 0"))
2213 send(c
, okmsg
, sizeof okmsg
-1, 0);
2214 send(c
, page1
, sizeof page1
-1, 0);
2217 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2219 if (strstr(buffer
, "GET /test6"))
2221 send(c
, contmsg
, sizeof contmsg
-1, 0);
2222 send(c
, contmsg
, sizeof contmsg
-1, 0);
2223 send(c
, okmsg
, sizeof okmsg
-1, 0);
2224 send(c
, page1
, sizeof page1
-1, 0);
2226 if (strstr(buffer
, "POST /test7"))
2228 if (strstr(buffer
, "Content-Length: 100"))
2230 if (strstr(buffer
, "POST /test7b"))
2231 recvfrom(c
, buffer
, buffer_size
, 0, NULL
, NULL
);
2232 send(c
, okmsg
, sizeof okmsg
-1, 0);
2233 send(c
, page1
, sizeof page1
-1, 0);
2236 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2238 if (strstr(buffer
, "/test8"))
2240 if (!strstr(buffer
, "Connection: Close") &&
2241 strstr(buffer
, "Connection: Keep-Alive") &&
2242 !strstr(buffer
, "Cache-Control: no-cache") &&
2243 !strstr(buffer
, "Pragma: no-cache") &&
2244 strstr(buffer
, host_header
))
2245 send(c
, okmsg
, sizeof okmsg
-1, 0);
2247 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2249 if (strstr(buffer
, "/test9"))
2251 if (!strstr(buffer
, "Connection: Close") &&
2252 !strstr(buffer
, "Connection: Keep-Alive") &&
2253 !strstr(buffer
, "Cache-Control: no-cache") &&
2254 !strstr(buffer
, "Pragma: no-cache") &&
2255 strstr(buffer
, host_header
))
2256 send(c
, okmsg
, sizeof okmsg
-1, 0);
2258 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2260 if (strstr(buffer
, "/testA"))
2262 if (!strstr(buffer
, "Connection: Close") &&
2263 !strstr(buffer
, "Connection: Keep-Alive") &&
2264 (strstr(buffer
, "Cache-Control: no-cache") ||
2265 strstr(buffer
, "Pragma: no-cache")) &&
2266 strstr(buffer
, host_header
))
2267 send(c
, okmsg
, sizeof okmsg
-1, 0);
2269 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2271 if (strstr(buffer
, "/testC"))
2273 if (strstr(buffer
, "Cookie: cookie=biscuit"))
2274 send(c
, okmsg
, sizeof okmsg
-1, 0);
2276 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2278 if (strstr(buffer
, "/testD"))
2280 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
2282 if (strstr(buffer
, "/testE"))
2284 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
2286 if (strstr(buffer
, "GET /quit"))
2288 send(c
, okmsg
, sizeof okmsg
-1, 0);
2289 send(c
, page1
, sizeof page1
-1, 0);
2292 if (strstr(buffer
, "GET /testF"))
2294 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
2295 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2296 send(c
, contmsg
, sizeof contmsg
-1, 0);
2297 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2298 send(c
, okmsg
, sizeof okmsg
-1, 0);
2299 send(c
, page1
, sizeof page1
-1, 0);
2301 if (strstr(buffer
, "GET /testG"))
2303 send(c
, page1
, sizeof page1
-1, 0);
2306 if (strstr(buffer
, "GET /testJ"))
2311 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2315 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2319 if (strstr(buffer
, "GET /testH"))
2321 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2322 recvfrom(c
, buffer
, buffer_size
, 0, NULL
, NULL
);
2323 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2326 if (strstr(buffer
, "GET /test_no_content"))
2328 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2329 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2331 if (strstr(buffer
, "GET /test_conn_close"))
2333 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2334 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
2335 WaitForSingleObject(conn_close_event
, INFINITE
);
2336 trace("closing connection\n");
2338 if (strstr(buffer
, "GET /test_cache_control_no_cache"))
2340 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2341 if(!test_no_cache
++)
2342 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2344 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2346 if (strstr(buffer
, "GET /test_cache_control_no_store"))
2348 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2349 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2351 if (strstr(buffer
, "GET /test_cache_gzip"))
2353 static const char gzip_response
[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2354 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2355 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2356 if(!test_cache_gzip
++)
2357 send(c
, gzip_response
, sizeof(gzip_response
), 0);
2359 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2361 if (strstr(buffer
, "HEAD /test_head")) {
2362 static const char head_response
[] =
2363 "HTTP/1.1 200 OK\r\n"
2364 "Connection: Keep-Alive\r\n"
2365 "Content-Length: 100\r\n"
2368 send(c
, head_response
, sizeof(head_response
), 0);
2371 if (strstr(buffer
, "GET /send_from_buffer"))
2372 send(c
, send_buffer
, strlen(send_buffer
), 0);
2373 if (strstr(buffer
, "/test_cache_control_verb"))
2375 if (!memcmp(buffer
, "GET ", sizeof("GET ")-1) &&
2376 !strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2377 else if (strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2378 else send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2380 if (strstr(buffer
, "/test_request_content_length"))
2382 static char msg
[] = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\n\r\n";
2383 static int seen_content_length
;
2385 if (!seen_content_length
)
2387 if (strstr(buffer
, "Content-Length: 0"))
2389 seen_content_length
= 1;
2390 send(c
, msg
, sizeof msg
-1, 0);
2392 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2393 WaitForSingleObject(complete_event
, 5000);
2397 if (strstr(buffer
, "Content-Length: 0")) send(c
, msg
, sizeof msg
-1, 0);
2398 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2399 WaitForSingleObject(complete_event
, 5000);
2402 if (strstr(buffer
, "GET /test_premature_disconnect"))
2403 trace("closing connection\n");
2404 if (strstr(buffer
, "HEAD /upload.txt"))
2406 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2407 send(c
, okmsg
, sizeof okmsg
-1, 0);
2409 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2411 if (strstr(buffer
, "PUT /upload2.txt"))
2413 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2414 send(c
, okmsg
, sizeof okmsg
-1, 0);
2416 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2418 if (strstr(buffer
, "/test_host_override"))
2420 if (strstr(buffer
, host_header_override
))
2421 send(c
, okmsg
, sizeof okmsg
-1, 0);
2423 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2425 if (strstr(buffer
, "/async_read"))
2427 const char *page1_mid
= page1
+ (sizeof page1
- 1)/2;
2428 const char *page1_end
= page1
+ sizeof page1
- 1;
2429 send(c
, okmsg
, sizeof okmsg
-1, 0);
2430 send(c
, page1
, page1_mid
- page1
, 0);
2431 WaitForSingleObject(conn_wait_event
, INFINITE
);
2432 send(c
, page1_mid
, page1_end
- page1_mid
, 0);
2434 if (strstr(buffer
, "/socket"))
2437 SetEvent(server_req_rec_event
);
2438 WaitForSingleObject(conn_wait_event
, INFINITE
);
2440 if (strstr(buffer
, "/echo_request"))
2442 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2443 send(c
, buffer
, strlen(buffer
), 0);
2445 if (strstr(buffer
, "GET /test_remove_dot_segments"))
2447 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2452 } while (!last_request
);
2455 HeapFree(GetProcessHeap(), 0, buffer
);
2460 static void test_basic_request(int port
, const char *verb
, const char *url
)
2463 DWORD r
, count
, error
;
2466 trace("basic request %s %s\n", verb
, url
);
2468 open_simple_request(&req
, "localhost", port
, verb
, url
);
2470 SetLastError(0xdeadbeef);
2471 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
2472 error
= GetLastError();
2473 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
2474 ok(r
, "HttpSendRequest failed: %u\n", GetLastError());
2477 memset(buffer
, 0, sizeof buffer
);
2478 SetLastError(0xdeadbeef);
2479 r
= InternetReadFile(req
.request
, buffer
, sizeof buffer
, &count
);
2480 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2481 ok(count
== sizeof page1
- 1, "count was wrong\n");
2482 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2484 close_request(&req
);
2487 static void test_proxy_indirect(int port
)
2493 open_simple_request(&req
, "localhost", port
, NULL
, "/test2");
2495 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
2496 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2499 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2500 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
2503 skip("missing proxy header, not testing remaining proxy headers\n");
2506 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2508 test_status_code(req
.request
, 407);
2509 test_request_flags(req
.request
, 0);
2512 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2513 ok(r
, "HttpQueryInfo failed\n");
2514 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2517 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2518 ok(r
, "HttpQueryInfo failed\n");
2519 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2522 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2523 ok(r
, "HttpQueryInfo failed\n");
2524 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2527 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2528 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2529 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2532 close_request(&req
);
2535 static void test_proxy_direct(int port
)
2537 HINTERNET hi
, hc
, hr
;
2539 char buffer
[0x40], *url
;
2540 WCHAR bufferW
[0x40];
2541 static const char url_fmt
[] = "http://test.winehq.org:%u/test2";
2542 static CHAR username
[] = "mike",
2543 password
[] = "1101",
2544 useragent
[] = "winetest";
2545 static const WCHAR usernameW
[] = {'m','i','k','e',0},
2546 passwordW
[] = {'1','1','0','1',0},
2547 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2549 /* specify proxy type without the proxy and bypass */
2550 SetLastError(0xdeadbeef);
2551 hi
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2552 error
= GetLastError();
2553 ok(error
== ERROR_INVALID_PARAMETER
||
2554 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %u\n", error
);
2555 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2557 sprintf(buffer
, "localhost:%d\n", port
);
2558 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2559 ok(hi
!= NULL
, "open failed\n");
2561 /* try connect without authorization */
2562 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2563 ok(hc
!= NULL
, "connect failed\n");
2565 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2566 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2569 SetLastError(0xdeadbeef);
2570 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
2571 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2572 ok(!r
, "unexpected success\n");
2573 ok(sz
== 1, "got %u\n", sz
);
2576 SetLastError(0xdeadbeef);
2577 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
2578 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2579 ok(!r
, "unexpected success\n");
2580 ok(sz
== 1, "got %u\n", sz
);
2582 sz
= sizeof(buffer
);
2583 SetLastError(0xdeadbeef);
2584 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2585 ok(r
, "unexpected failure %u\n", GetLastError());
2586 ok(!sz
, "got %u\n", sz
);
2588 sz
= sizeof(buffer
);
2589 SetLastError(0xdeadbeef);
2590 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2591 ok(r
, "unexpected failure %u\n", GetLastError());
2592 ok(!sz
, "got %u\n", sz
);
2595 SetLastError(0xdeadbeef);
2596 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
2597 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2598 ok(!r
, "unexpected success\n");
2599 ok(sz
== 1, "got %u\n", sz
);
2602 SetLastError(0xdeadbeef);
2603 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
2604 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2605 ok(!r
, "unexpected success\n");
2606 ok(sz
== 1, "got %u\n", sz
);
2608 sz
= sizeof(buffer
);
2609 SetLastError(0xdeadbeef);
2610 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2611 ok(r
, "unexpected failure %u\n", GetLastError());
2612 ok(!sz
, "got %u\n", sz
);
2614 sz
= sizeof(buffer
);
2615 SetLastError(0xdeadbeef);
2616 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2617 ok(r
, "unexpected failure %u\n", GetLastError());
2618 ok(!sz
, "got %u\n", sz
);
2621 SetLastError(0xdeadbeef);
2622 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
2623 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2624 ok(!r
, "unexpected success\n");
2625 ok(sz
== 34, "got %u\n", sz
);
2627 sz
= sizeof(buffer
);
2628 SetLastError(0xdeadbeef);
2629 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2630 ok(r
, "unexpected failure %u\n", GetLastError());
2631 ok(sz
== 33, "got %u\n", sz
);
2633 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2634 ok(r
|| broken(!r
), "HttpSendRequest failed %u\n", GetLastError());
2637 win_skip("skipping proxy tests on broken wininet\n");
2641 test_status_code(hr
, 407);
2643 /* set the user + password then try again */
2644 r
= InternetSetOptionA(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2645 ok(!r
, "unexpected success\n");
2647 r
= InternetSetOptionA(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2648 ok(r
, "failed to set user\n");
2650 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2651 ok(r
, "failed to set user\n");
2655 SetLastError(0xdeadbeef);
2656 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2657 ok(!r
, "unexpected failure %u\n", GetLastError());
2658 ok(!buffer
[0], "got %s\n", buffer
);
2659 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2663 SetLastError(0xdeadbeef);
2664 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2665 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2666 ok(!r
, "unexpected success\n");
2667 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2671 SetLastError(0xdeadbeef);
2672 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2673 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2674 ok(!r
, "unexpected success\n");
2675 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2678 sz
= sizeof(buffer
);
2679 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2680 ok(r
, "failed to get username\n");
2681 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2682 ok(sz
== strlen(username
), "got %u\n", sz
);
2685 sz
= sizeof(bufferW
);
2686 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2687 ok(r
, "failed to get username\n");
2688 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
2689 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2691 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
2692 ok(r
, "failed to set user\n");
2695 sz
= sizeof(buffer
);
2696 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2697 ok(r
, "failed to get username\n");
2698 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2699 ok(sz
== strlen(username
), "got %u\n", sz
);
2701 r
= InternetSetOptionA(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
2702 ok(r
, "failed to set useragent\n");
2706 SetLastError(0xdeadbeef);
2707 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2708 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2709 ok(!r
, "unexpected success\n");
2710 ok(sz
== strlen(useragent
) + 1, "got %u\n", sz
);
2713 sz
= sizeof(buffer
);
2714 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2715 ok(r
, "failed to get user agent\n");
2716 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
2717 ok(sz
== strlen(useragent
), "got %u\n", sz
);
2721 SetLastError(0xdeadbeef);
2722 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2723 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2724 ok(!r
, "unexpected success\n");
2725 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2728 sz
= sizeof(bufferW
);
2729 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2730 ok(r
, "failed to get user agent\n");
2731 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
2732 ok(sz
== lstrlenW(useragentW
), "got %u\n", sz
);
2734 r
= InternetSetOptionA(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
2735 ok(r
, "failed to set user\n");
2739 SetLastError(0xdeadbeef);
2740 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2741 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2742 ok(!r
, "unexpected success\n");
2743 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2746 sz
= sizeof(buffer
);
2747 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2748 ok(r
, "failed to get user\n");
2749 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2750 ok(sz
== strlen(username
), "got %u\n", sz
);
2754 SetLastError(0xdeadbeef);
2755 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2756 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2757 ok(!r
, "unexpected success\n");
2758 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2761 sz
= sizeof(bufferW
);
2762 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2763 ok(r
, "failed to get user\n");
2764 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
2765 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2767 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
2768 ok(r
, "failed to set password\n");
2772 SetLastError(0xdeadbeef);
2773 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2774 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2775 ok(!r
, "unexpected success\n");
2776 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2779 sz
= sizeof(buffer
);
2780 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2781 ok(r
, "failed to get password\n");
2782 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2783 ok(sz
== strlen(password
), "got %u\n", sz
);
2787 SetLastError(0xdeadbeef);
2788 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2789 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2790 ok(!r
, "unexpected success\n");
2791 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2794 sz
= sizeof(bufferW
);
2795 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2796 ok(r
, "failed to get password\n");
2797 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2798 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2800 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
2801 sprintf(url
, url_fmt
, port
);
2804 SetLastError(0xdeadbeef);
2805 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2806 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2807 ok(!r
, "unexpected success\n");
2808 ok(sz
== strlen(url
) + 1, "got %u\n", sz
);
2811 sz
= sizeof(buffer
);
2812 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2813 ok(r
, "failed to get url\n");
2814 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
2815 ok(sz
== strlen(url
), "got %u\n", sz
);
2819 SetLastError(0xdeadbeef);
2820 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2821 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2822 ok(!r
, "unexpected success\n");
2823 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2826 sz
= sizeof(bufferW
);
2827 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2828 ok(r
, "failed to get url\n");
2829 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
2830 ok(sz
== strlen(url
), "got %u\n", sz
);
2831 HeapFree(GetProcessHeap(), 0, url
);
2833 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2834 ok(r
, "failed to set password\n");
2838 SetLastError(0xdeadbeef);
2839 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2840 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2841 ok(!r
, "unexpected success\n");
2842 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2845 sz
= sizeof(buffer
);
2846 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2847 ok(r
, "failed to get password\n");
2848 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2849 ok(sz
== strlen(password
), "got %u\n", sz
);
2853 SetLastError(0xdeadbeef);
2854 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2855 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2856 ok(!r
, "unexpected success\n");
2857 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2860 sz
= sizeof(bufferW
);
2861 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2862 ok(r
, "failed to get password\n");
2863 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2864 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2866 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2869 win_skip("skipping proxy tests on broken wininet\n");
2872 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2874 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2875 ok(r
, "HttpQueryInfo failed\n");
2876 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2878 InternetCloseHandle(hr
);
2879 InternetCloseHandle(hc
);
2880 InternetCloseHandle(hi
);
2882 sprintf(buffer
, "localhost:%d\n", port
);
2883 hi
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2884 ok(hi
!= NULL
, "InternetOpen failed\n");
2886 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2887 ok(hc
!= NULL
, "InternetConnect failed\n");
2889 hr
= HttpOpenRequestA(hc
, "POST", "/test2", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
2890 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2892 r
= HttpSendRequestA(hr
, NULL
, 0, (char *)"data", sizeof("data"));
2893 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2895 test_status_code(hr
, 407);
2898 InternetCloseHandle(hr
);
2899 InternetCloseHandle(hc
);
2900 InternetCloseHandle(hi
);
2903 static void test_header_handling_order(int port
)
2905 static const char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
2906 static const char connection
[] = "Connection: Close";
2907 static const char *types
[2] = { "*", NULL
};
2909 HINTERNET session
, connect
, request
;
2910 DWORD size
, status
, data_len
;
2913 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2914 ok(session
!= NULL
, "InternetOpen failed\n");
2916 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2917 ok(connect
!= NULL
, "InternetConnect failed\n");
2919 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2920 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2922 ret
= HttpAddRequestHeadersA(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
2923 ok(ret
, "HttpAddRequestHeaders failed\n");
2925 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
2926 ok(ret
, "HttpSendRequest failed\n");
2928 test_status_code(request
, 200);
2929 test_request_flags(request
, 0);
2931 InternetCloseHandle(request
);
2933 request
= HttpOpenRequestA(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2934 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2936 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2937 ok(ret
, "HttpSendRequest failed\n");
2940 size
= sizeof(status
);
2941 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2942 ok(ret
, "HttpQueryInfo failed\n");
2943 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2945 InternetCloseHandle(request
);
2946 InternetCloseHandle(connect
);
2948 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2949 ok(connect
!= NULL
, "InternetConnect failed\n");
2951 request
= HttpOpenRequestA(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2952 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2954 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2955 ok(ret
, "HttpAddRequestHeaders failed\n");
2957 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2958 ok(ret
, "HttpSendRequest failed\n");
2961 size
= sizeof(status
);
2962 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2963 ok(ret
, "HttpQueryInfo failed\n");
2964 ok(status
== 200, "got status %u, expected 200\n", status
);
2966 InternetCloseHandle(request
);
2967 InternetCloseHandle(connect
);
2969 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2970 ok(connect
!= NULL
, "InternetConnect failed\n");
2972 request
= HttpOpenRequestA(connect
, "POST", "/test7b", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2973 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2975 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2976 ok(ret
, "HttpAddRequestHeaders failed\n");
2978 data_len
= sizeof(data
);
2979 memset(data
, 'a', sizeof(data
));
2980 ret
= HttpSendRequestA(request
, NULL
, 0, data
, data_len
);
2981 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
2984 size
= sizeof(status
);
2985 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2986 ok(ret
, "HttpQueryInfo failed\n");
2987 ok(status
== 200, "got status %u, expected 200\n", status
);
2989 InternetCloseHandle(request
);
2990 InternetCloseHandle(connect
);
2991 InternetCloseHandle(session
);
2994 static void test_connection_header(int port
)
2996 HINTERNET ses
, con
, req
;
2999 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3000 ok(ses
!= NULL
, "InternetOpen failed\n");
3002 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3003 ok(con
!= NULL
, "InternetConnect failed\n");
3005 req
= HttpOpenRequestA(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3006 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3008 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3009 ok(ret
, "HttpSendRequest failed\n");
3011 test_status_code(req
, 200);
3013 InternetCloseHandle(req
);
3015 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
3016 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3018 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3019 ok(ret
, "HttpSendRequest failed\n");
3021 test_status_code(req
, 200);
3023 InternetCloseHandle(req
);
3025 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3026 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3028 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3029 ok(ret
, "HttpSendRequest failed\n");
3031 test_status_code(req
, 200);
3033 InternetCloseHandle(req
);
3035 req
= HttpOpenRequestA(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3036 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3038 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3039 ok(ret
, "HttpSendRequest failed\n");
3041 test_status_code(req
, 200);
3043 InternetCloseHandle(req
);
3044 InternetCloseHandle(con
);
3045 InternetCloseHandle(ses
);
3048 static void test_header_override(int port
)
3050 char buffer
[128], host_header_override
[30], full_url
[128];
3051 HINTERNET ses
, con
, req
;
3052 DWORD size
, count
, err
;
3055 sprintf(host_header_override
, "Host: test.local:%d\r\n", port
);
3056 sprintf(full_url
, "http://localhost:%d/test_host_override", port
);
3058 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3059 ok(ses
!= NULL
, "InternetOpen failed\n");
3061 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3062 ok(con
!= NULL
, "InternetConnect failed\n");
3064 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3065 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3067 size
= sizeof(buffer
) - 1;
3069 memset(buffer
, 0, sizeof(buffer
));
3070 ret
= HttpQueryInfoA(req
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &count
);
3071 err
= GetLastError();
3072 ok(!ret
, "HttpQueryInfo succeeded\n");
3073 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err
);
3075 test_request_url(req
, full_url
);
3077 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3078 ok(ret
, "HttpAddRequestHeaders failed\n");
3080 size
= sizeof(buffer
) - 1;
3082 memset(buffer
, 0, sizeof(buffer
));
3083 ret
= HttpQueryInfoA(req
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &count
);
3084 ok(ret
, "HttpQueryInfo failed\n");
3086 test_request_url(req
, full_url
);
3088 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3089 ok(ret
, "HttpSendRequest failed\n");
3091 test_status_code(req
, 200);
3093 InternetCloseHandle(req
);
3094 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3095 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3097 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3098 ok(ret
, "HttpAddRequestHeaders failed\n");
3100 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3101 ok(ret
, "HttpAddRequestHeaders failed\n");
3103 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3104 ok(ret
, "HttpSendRequest failed\n");
3106 test_status_code(req
, 400);
3108 InternetCloseHandle(req
);
3109 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3110 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3112 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3113 ok(ret
, "HttpAddRequestHeaders failed\n");
3115 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3116 ok(ret
, "HttpSendRequest failed\n");
3118 test_status_code(req
, 200);
3120 InternetCloseHandle(req
);
3121 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3122 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3124 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_REPLACE
);
3125 if(ret
) { /* win10 returns success */
3126 trace("replacing host header is supported.\n");
3128 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3129 ok(ret
, "HttpSendRequest failed\n");
3131 test_status_code(req
, 200);
3133 trace("replacing host header is not supported.\n");
3135 err
= GetLastError();
3136 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err
);
3138 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3139 ok(ret
, "HttpSendRequest failed\n");
3141 test_status_code(req
, 400);
3144 InternetCloseHandle(req
);
3145 InternetCloseHandle(con
);
3146 InternetCloseHandle(ses
);
3149 static void test_connection_closing(int port
)
3151 HINTERNET session
, connection
, req
;
3156 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3157 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3159 pInternetSetStatusCallbackA(session
, callback
);
3161 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3162 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3163 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3164 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3166 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3167 req
= HttpOpenRequestA(connection
, "GET", "/testJ", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3168 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3169 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3171 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3172 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3173 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3174 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3175 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3176 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3177 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3178 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3179 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3180 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3181 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3183 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3184 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3185 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3186 WaitForSingleObject(complete_event
, INFINITE
);
3187 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3189 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3190 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3191 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3192 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3193 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3194 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3195 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3196 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3197 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3198 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3199 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3201 test_status_code(req
, 200);
3203 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3204 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3205 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3206 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3207 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3208 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3209 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3210 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3211 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3213 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3214 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3215 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3216 WaitForSingleObject(complete_event
, INFINITE
);
3217 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3219 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3220 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3221 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3222 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3223 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3224 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3225 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3226 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3227 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3229 test_status_code(req
, 210);
3231 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3232 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3233 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3234 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3235 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3236 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3237 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3238 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3239 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3240 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3241 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3243 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3244 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3245 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3246 WaitForSingleObject(complete_event
, INFINITE
);
3247 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3249 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3250 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3251 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3252 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3253 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3254 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3255 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3256 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3257 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3258 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3259 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3261 test_status_code(req
, 200);
3263 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3264 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3266 close_async_handle(session
, 2);
3269 static void test_successive_HttpSendRequest(int port
)
3271 HINTERNET session
, connection
, req
;
3276 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3277 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3279 pInternetSetStatusCallbackA(session
, callback
);
3281 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3282 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3283 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3284 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3286 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3287 req
= HttpOpenRequestA(connection
, "GET", "/testH", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3288 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3289 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3291 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3292 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3293 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3294 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3295 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3296 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3297 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3298 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3299 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3301 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3302 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3303 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3304 WaitForSingleObject(complete_event
, INFINITE
);
3305 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3307 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3308 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3309 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3310 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3311 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3312 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3313 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3314 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3315 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3317 test_status_code(req
, 210);
3319 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3320 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3321 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3322 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3323 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3324 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3325 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3326 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3327 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3329 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3330 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3331 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3332 WaitForSingleObject(complete_event
, INFINITE
);
3333 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3335 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3336 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3337 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3338 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3339 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3340 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3341 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3342 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3343 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3345 test_status_code(req
, 200);
3347 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3348 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3350 close_async_handle(session
, 2);
3353 static void test_no_content(int port
)
3355 HINTERNET session
, connection
, req
;
3358 trace("Testing 204 no content response...\n");
3362 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3363 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3365 pInternetSetStatusCallbackA(session
, callback
);
3367 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3368 connection
= InternetConnectA(session
, "localhost", port
,
3369 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3370 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3371 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3373 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3374 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
3375 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3376 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3377 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3379 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3380 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3381 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3382 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3383 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3384 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3385 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3386 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3387 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3388 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3390 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3391 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3392 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3393 WaitForSingleObject(complete_event
, INFINITE
);
3394 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3396 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3397 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3398 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3399 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3400 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3401 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3402 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3403 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3405 close_async_handle(session
, 2);
3408 * The connection should be closed before closing handle. This is true for most
3409 * wininet versions (including Wine), but some old win2k versions fail to do that.
3411 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3412 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3415 static void test_conn_close(int port
)
3417 HINTERNET session
, connection
, req
;
3418 DWORD res
, avail
, size
;
3421 trace("Testing connection close connection...\n");
3425 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3426 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3428 pInternetSetStatusCallbackA(session
, callback
);
3430 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3431 connection
= InternetConnectA(session
, "localhost", port
,
3432 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3433 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3434 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3436 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3437 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
3438 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3439 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3440 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3442 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3443 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3444 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3445 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3446 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3447 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3448 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3449 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3451 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3452 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3453 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3454 WaitForSingleObject(complete_event
, INFINITE
);
3455 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3457 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3458 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3459 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3460 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3461 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3462 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3463 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3464 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3467 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3468 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3469 ok(avail
!= 0, "avail = 0\n");
3472 res
= InternetReadFile(req
, buf
, avail
, &size
);
3473 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3475 /* IE11 calls those in InternetQueryDataAvailable call. */
3476 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
3477 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
3479 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3480 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3481 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3482 ok(!avail
, "avail = %u, expected 0\n", avail
);
3484 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3486 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3487 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3488 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3489 SetEvent(conn_close_event
);
3490 WaitForSingleObject(complete_event
, INFINITE
);
3491 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3492 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3493 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3494 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3495 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3497 close_async_handle(session
, 2);
3500 static void test_no_cache(int port
)
3502 static const char cache_control_no_cache
[] = "/test_cache_control_no_cache";
3503 static const char cache_control_no_store
[] = "/test_cache_control_no_store";
3504 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3506 char cache_url
[256], buf
[256];
3507 HINTERNET ses
, con
, req
;
3511 trace("Testing no-cache header\n");
3513 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3514 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3516 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3517 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3519 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3520 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3522 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_cache
);
3523 DeleteUrlCacheEntryA(cache_url
);
3525 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3526 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3528 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3530 ok(size
== 12, "read %d bytes of data\n", size
);
3531 InternetCloseHandle(req
);
3533 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3534 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3536 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3537 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3539 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3541 ok(size
== 0, "read %d bytes of data\n", size
);
3542 InternetCloseHandle(req
);
3543 DeleteUrlCacheEntryA(cache_url
);
3545 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_store
, NULL
, NULL
, NULL
, 0, 0);
3546 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3548 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_store
);
3549 DeleteUrlCacheEntryA(cache_url
);
3551 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3552 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3554 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3556 ok(size
== 12, "read %d bytes of data\n", size
);
3557 InternetCloseHandle(req
);
3559 ret
= DeleteUrlCacheEntryA(cache_url
);
3560 ok(!ret
&& GetLastError()==ERROR_FILE_NOT_FOUND
, "cache entry should not exist\n");
3562 InternetCloseHandle(con
);
3563 InternetCloseHandle(ses
);
3566 static void test_cache_read_gzipped(int port
)
3568 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3569 static const char get_gzip
[] = "/test_cache_gzip";
3570 static const char content
[] = "gzip test\n";
3571 static const char text_html
[] = "text/html";
3572 static const char raw_header
[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3574 HINTERNET ses
, con
, req
;
3576 char cache_url
[256], buf
[256];
3579 trace("Testing reading compressed content from cache\n");
3581 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3582 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3584 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3585 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3587 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3588 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3591 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3592 if(!ret
&& GetLastError()==ERROR_INTERNET_INVALID_OPTION
) {
3593 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3594 InternetCloseHandle(req
);
3595 InternetCloseHandle(con
);
3596 InternetCloseHandle(ses
);
3599 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3601 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3602 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3604 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-size
, &read
) && read
)
3606 ok(size
== 10, "read %d bytes of data\n", size
);
3608 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3610 size
= sizeof(buf
)-1;
3611 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3612 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3614 ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3616 size
= sizeof(buf
)-1;
3617 ret
= HttpQueryInfoA(req
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &size
, 0);
3618 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3620 ok(!strncmp(raw_header
, buf
, size
), "buf = %s\n", buf
);
3621 InternetCloseHandle(req
);
3623 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3624 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3627 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3628 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3630 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3631 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3633 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3635 todo_wine
ok(size
== 10, "read %d bytes of data\n", size
);
3637 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3640 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3641 ok(!ret
&& GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND
,
3642 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3643 ret
, GetLastError());
3645 size
= sizeof(buf
)-1;
3646 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3647 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3649 todo_wine
ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3650 InternetCloseHandle(req
);
3652 /* Decompression doesn't work while reading from cache */
3653 test_cache_gzip
= 0;
3654 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3655 DeleteUrlCacheEntryA(cache_url
);
3657 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3658 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3660 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3661 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3663 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3665 ok(size
== 31, "read %d bytes of data\n", size
);
3666 InternetCloseHandle(req
);
3668 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3669 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3672 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3673 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3675 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3676 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3678 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3680 todo_wine
ok(size
== 31, "read %d bytes of data\n", size
);
3683 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3684 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3685 InternetCloseHandle(req
);
3687 InternetCloseHandle(con
);
3688 InternetCloseHandle(ses
);
3690 DeleteUrlCacheEntryA(cache_url
);
3693 static void test_HttpSendRequestW(int port
)
3695 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3696 HINTERNET ses
, con
, req
;
3700 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3701 ok(ses
!= NULL
, "InternetOpen failed\n");
3703 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3704 ok(con
!= NULL
, "InternetConnect failed\n");
3706 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3707 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3709 SetLastError(0xdeadbeef);
3710 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
3711 error
= GetLastError();
3712 ok(!ret
, "HttpSendRequestW succeeded\n");
3713 ok(error
== ERROR_IO_PENDING
||
3714 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
3715 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
3716 "got %u expected ERROR_IO_PENDING\n", error
);
3718 InternetCloseHandle(req
);
3719 InternetCloseHandle(con
);
3720 InternetCloseHandle(ses
);
3723 static void test_cookie_header(int port
)
3725 HINTERNET ses
, con
, req
;
3730 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3731 ok(ses
!= NULL
, "InternetOpen failed\n");
3733 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3734 ok(con
!= NULL
, "InternetConnect failed\n");
3736 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3738 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3739 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3742 size
= sizeof(buffer
);
3743 SetLastError(0xdeadbeef);
3744 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3745 error
= GetLastError();
3746 ok(!ret
, "HttpQueryInfo succeeded\n");
3747 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3749 ret
= HttpAddRequestHeadersA(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
3750 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3753 size
= sizeof(buffer
);
3754 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3755 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3756 ok(!strcmp(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
3758 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3759 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3761 test_status_code(req
, 200);
3764 size
= sizeof(buffer
);
3765 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3766 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3767 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
3769 InternetCloseHandle(req
);
3770 InternetCloseHandle(con
);
3771 InternetCloseHandle(ses
);
3774 static void test_basic_authentication(int port
)
3776 HINTERNET session
, connect
, request
;
3779 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3780 ok(session
!= NULL
, "InternetOpen failed\n");
3782 connect
= InternetConnectA(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
3783 ok(connect
!= NULL
, "InternetConnect failed\n");
3785 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
3786 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3788 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3789 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3791 test_status_code(request
, 200);
3792 test_request_flags(request
, 0);
3794 InternetCloseHandle(request
);
3795 InternetCloseHandle(connect
);
3796 InternetCloseHandle(session
);
3799 static void test_premature_disconnect(int port
)
3805 open_simple_request(&req
, "localhost", port
, NULL
, "/premature_disconnect");
3807 SetLastError(0xdeadbeef);
3808 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
3809 err
= GetLastError();
3810 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
3811 todo_wine
ok(err
== ERROR_HTTP_INVALID_SERVER_RESPONSE
, "got %u\n", err
);
3813 close_request(&req
);
3816 static void test_invalid_response_headers(int port
)
3823 open_simple_request(&req
, "localhost", port
, NULL
, "/testE");
3825 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
3826 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3828 test_status_code(req
.request
, 401);
3829 test_request_flags(req
.request
, 0);
3832 size
= sizeof(buffer
);
3833 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3834 ok(ret
, "HttpQueryInfo failed\n");
3835 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
3836 "headers wrong \"%s\"\n", buffer
);
3839 size
= sizeof(buffer
);
3840 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
3841 ok(ret
, "HttpQueryInfo failed\n");
3842 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
3844 close_request(&req
);
3847 static void test_response_without_headers(int port
)
3850 DWORD r
, count
, size
;
3853 open_simple_request(&req
, "localhost", port
, NULL
, "/testG");
3855 test_request_flags(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
3857 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
3858 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
3860 test_request_flags_todo(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
3863 memset(buffer
, 0, sizeof buffer
);
3864 r
= InternetReadFile(req
.request
, buffer
, sizeof buffer
, &count
);
3865 ok(r
, "InternetReadFile failed %u\n", GetLastError());
3866 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
3867 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
3869 test_status_code(req
.request
, 200);
3870 test_request_flags_todo(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
3873 size
= sizeof(buffer
);
3874 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
3875 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3876 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
3879 size
= sizeof(buffer
);
3880 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
3881 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3882 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
3885 size
= sizeof(buffer
);
3886 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3887 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3888 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
3890 close_request(&req
);
3893 static void test_head_request(int port
)
3895 DWORD len
, content_length
;
3900 open_simple_request(&req
, "localhost", port
, "HEAD", "/test_head");
3902 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
3903 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3905 len
= sizeof(content_length
);
3906 content_length
= -1;
3907 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
, &content_length
, &len
, 0);
3908 ok(ret
, "HttpQueryInfo dailed: %u\n", GetLastError());
3909 ok(len
== sizeof(DWORD
), "len = %u\n", len
);
3910 ok(content_length
== 100, "content_length = %u\n", content_length
);
3913 ret
= InternetReadFile(req
.request
, buf
, sizeof(buf
), &len
);
3914 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
3917 ret
= InternetReadFile(req
.request
, buf
, sizeof(buf
), &len
);
3918 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
3920 close_request(&req
);
3923 static void test_HttpQueryInfo(int port
)
3926 DWORD size
, index
, error
;
3930 open_simple_request(&req
, "localhost", port
, NULL
, "/testD");
3932 size
= sizeof(buffer
);
3933 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3934 error
= GetLastError();
3935 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
3936 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3938 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
3939 ok(ret
, "HttpSendRequest failed\n");
3942 size
= sizeof(buffer
);
3943 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
3944 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3945 ok(index
== 1, "expected 1 got %u\n", index
);
3948 size
= sizeof(buffer
);
3949 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
3950 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3951 ok(index
== 1, "expected 1 got %u\n", index
);
3954 size
= sizeof(buffer
);
3955 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3956 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3957 ok(index
== 0, "expected 0 got %u\n", index
);
3959 size
= sizeof(buffer
);
3960 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3961 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3962 ok(index
== 0, "expected 0 got %u\n", index
);
3964 index
= 0xdeadbeef; /* invalid start index */
3965 size
= sizeof(buffer
);
3966 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3967 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
3968 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
3969 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
3972 size
= sizeof(buffer
);
3973 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
3974 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3975 ok(index
== 0, "expected 0 got %u\n", index
);
3977 size
= sizeof(buffer
);
3978 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3979 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3980 ok(index
== 0, "expected 0 got %u\n", index
);
3982 size
= sizeof(buffer
);
3983 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
3984 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3985 ok(index
== 0, "expected 0 got %u\n", index
);
3987 test_status_code(req
.request
, 200);
3990 size
= sizeof(buffer
);
3991 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
3992 ok(!ret
, "HttpQueryInfo succeeded\n");
3993 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
3996 size
= sizeof(buffer
);
3997 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
3998 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3999 ok(index
== 1, "expected 1 got %u\n", index
);
4002 size
= sizeof(buffer
);
4003 strcpy(buffer
, "Server");
4004 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
4005 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4006 ok(index
== 1, "expected 1 got %u\n", index
);
4009 size
= sizeof(buffer
);
4010 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
4011 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4012 ok(index
== 1, "expected 1 got %u\n", index
);
4014 size
= sizeof(buffer
);
4015 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
4016 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4017 ok(index
== 2, "expected 2 got %u\n", index
);
4019 close_request(&req
);
4022 static void test_options(int port
)
4024 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi
;
4025 HINTERNET ses
, con
, req
;
4030 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4031 ok(ses
!= NULL
, "InternetOpen failed\n");
4033 SetLastError(0xdeadbeef);
4034 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
4035 error
= GetLastError();
4036 ok(!ret
, "InternetSetOption succeeded\n");
4037 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4039 SetLastError(0xdeadbeef);
4040 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
4041 ok(!ret
, "InternetSetOption succeeded\n");
4042 error
= GetLastError();
4043 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4045 SetLastError(0xdeadbeef);
4046 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
4047 ok(!ret
, "InternetSetOption succeeded\n");
4048 error
= GetLastError();
4049 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4052 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4053 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4055 SetLastError(0xdeadbeef);
4056 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
4057 error
= GetLastError();
4058 ok(!ret
, "InternetQueryOption succeeded\n");
4059 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4061 SetLastError(0xdeadbeef);
4062 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
4063 error
= GetLastError();
4064 ok(!ret
, "InternetQueryOption succeeded\n");
4065 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4068 SetLastError(0xdeadbeef);
4069 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
4070 error
= GetLastError();
4071 ok(!ret
, "InternetQueryOption succeeded\n");
4072 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
4075 SetLastError(0xdeadbeef);
4076 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4077 error
= GetLastError();
4078 ok(!ret
, "InternetQueryOption succeeded\n");
4079 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
4083 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4084 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4085 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
4087 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4088 ok(con
!= NULL
, "InternetConnect failed\n");
4092 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4093 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4094 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
4097 ret
= InternetSetOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4098 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4102 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4103 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4104 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
4106 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
4107 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4111 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4112 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4113 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
4116 ret
= InternetSetOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4117 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4121 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4122 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4123 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
4125 size
= sizeof(idsi
);
4126 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO
, &idsi
, &size
);
4127 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4130 SetLastError(0xdeadbeef);
4131 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
4132 error
= GetLastError();
4133 ok(!ret
, "InternetQueryOption succeeded\n");
4134 ok(error
== ERROR_INTERNET_INVALID_OPERATION
, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error
);
4136 /* INTERNET_OPTION_PROXY */
4137 SetLastError(0xdeadbeef);
4138 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
4139 error
= GetLastError();
4140 ok(!ret
, "InternetQueryOption succeeded\n");
4141 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4143 SetLastError(0xdeadbeef);
4144 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
4145 error
= GetLastError();
4146 ok(!ret
, "InternetQueryOption succeeded\n");
4147 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4150 SetLastError(0xdeadbeef);
4151 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
4152 error
= GetLastError();
4153 ok(!ret
, "InternetQueryOption succeeded\n");
4154 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
4155 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
4157 InternetCloseHandle(req
);
4158 InternetCloseHandle(con
);
4159 InternetCloseHandle(ses
);
4163 const char *response_text
;
4165 const char *status_text
;
4166 const char *raw_headers
;
4167 } http_status_test_t
;
4169 static const http_status_test_t http_status_tests
[] = {
4171 "HTTP/1.1 200 OK\r\n"
4172 "Content-Length: 1\r\n"
4178 "HTTP/1.1 404 Fail\r\n"
4179 "Content-Length: 1\r\n"
4186 "Content-Length: 1\r\n"
4193 "Content-Length: 1\r\n"
4200 static void test_http_status(int port
)
4207 for(i
=0; i
< sizeof(http_status_tests
)/sizeof(*http_status_tests
); i
++) {
4208 send_buffer
= http_status_tests
[i
].response_text
;
4210 open_simple_request(&req
, "localhost", port
, NULL
, "/send_from_buffer");
4212 res
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4213 ok(res
, "HttpSendRequest failed\n");
4215 test_status_code(req
.request
, http_status_tests
[i
].status_code
);
4218 res
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buf
, &size
, NULL
);
4219 ok(res
, "HttpQueryInfo failed: %u\n", GetLastError());
4220 ok(!strcmp(buf
, http_status_tests
[i
].status_text
), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
4221 i
, buf
, http_status_tests
[i
].status_text
);
4223 close_request(&req
);
4227 static void test_cache_control_verb(int port
)
4229 HINTERNET session
, connect
, request
;
4232 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4233 ok(session
!= NULL
, "InternetOpen failed\n");
4235 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4236 ok(connect
!= NULL
, "InternetConnect failed\n");
4238 request
= HttpOpenRequestA(connect
, "RPC_OUT_DATA", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4239 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4240 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4241 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4242 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4243 test_status_code(request
, 200);
4244 InternetCloseHandle(request
);
4246 request
= HttpOpenRequestA(connect
, "POST", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4247 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4248 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4249 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4250 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4251 test_status_code(request
, 200);
4252 InternetCloseHandle(request
);
4254 request
= HttpOpenRequestA(connect
, "HEAD", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4255 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4256 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4257 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4258 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4259 test_status_code(request
, 200);
4260 InternetCloseHandle(request
);
4262 request
= HttpOpenRequestA(connect
, "GET", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4263 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4264 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4265 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4266 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4267 test_status_code(request
, 200);
4268 InternetCloseHandle(request
);
4270 InternetCloseHandle(connect
);
4271 InternetCloseHandle(session
);
4274 static void test_request_content_length(int port
)
4276 char data
[] = {'t','e','s','t'};
4281 open_simple_request(&req
, "localhost", port
, "POST", "/test_request_content_length");
4283 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4284 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4285 test_status_code(req
.request
, 200);
4287 SetEvent(complete_event
);
4289 ret
= HttpSendRequestA(req
.request
, NULL
, 0, data
, sizeof(data
));
4290 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4291 test_status_code(req
.request
, 200);
4293 SetEvent(complete_event
);
4294 close_request(&req
);
4297 static void test_accept_encoding(int port
)
4299 HINTERNET ses
, con
, req
;
4303 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4304 ok(ses
!= NULL
, "InternetOpen failed\n");
4306 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4307 ok(con
!= NULL
, "InternetConnect failed\n");
4309 req
= HttpOpenRequestA(con
, "GET", "/echo_request", "HTTP/1.0", NULL
, NULL
, 0, 0);
4310 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4312 ret
= HttpAddRequestHeadersA(req
, "Accept-Encoding: gzip\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDREQ_FLAG_ADD
);
4313 ok(ret
, "HttpAddRequestHeaders failed\n");
4315 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4316 ok(ret
, "HttpSendRequestA failed\n");
4318 test_status_code(req
, 200);
4319 receive_simple_request(req
, buf
, sizeof(buf
));
4320 ok(strstr(buf
, "Accept-Encoding: gzip") != NULL
, "Accept-Encoding header not found in %s\n", buf
);
4322 InternetCloseHandle(req
);
4324 req
= HttpOpenRequestA(con
, "GET", "/echo_request", "HTTP/1.0", NULL
, NULL
, 0, 0);
4325 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4327 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", ~0u, NULL
, 0);
4328 ok(ret
, "HttpSendRequestA failed\n");
4330 test_status_code(req
, 200);
4331 receive_simple_request(req
, buf
, sizeof(buf
));
4332 ok(strstr(buf
, "Accept-Encoding: gzip") != NULL
, "Accept-Encoding header not found in %s\n", buf
);
4334 InternetCloseHandle(req
);
4335 InternetCloseHandle(con
);
4336 InternetCloseHandle(ses
);
4339 static void test_basic_auth_credentials_reuse(int port
)
4341 HINTERNET ses
, con
, req
;
4345 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4346 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4348 con
= InternetConnectA( ses
, "localhost", port
, "user", "pwd",
4349 INTERNET_SERVICE_HTTP
, 0, 0 );
4350 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4352 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
4353 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4355 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4356 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4358 status
= 0xdeadbeef;
4359 size
= sizeof(status
);
4360 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4361 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4362 ok( status
== 200, "got %u\n", status
);
4364 InternetCloseHandle( req
);
4365 InternetCloseHandle( con
);
4366 InternetCloseHandle( ses
);
4368 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4369 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4371 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
,
4372 INTERNET_SERVICE_HTTP
, 0, 0 );
4373 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4375 req
= HttpOpenRequestA( con
, "PUT", "/upload2.txt", NULL
, NULL
, NULL
, 0, 0 );
4376 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4378 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4379 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4381 status
= 0xdeadbeef;
4382 size
= sizeof(status
);
4383 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4384 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4385 ok( status
== 200, "got %u\n", status
);
4387 InternetCloseHandle( req
);
4388 InternetCloseHandle( con
);
4389 InternetCloseHandle( ses
);
4392 static void test_async_read(int port
)
4394 HINTERNET ses
, con
, req
;
4395 INTERNET_BUFFERSA ib
;
4397 DWORD pending_reads
;
4398 DWORD res
, count
, bytes
;
4403 /* test asynchronous InternetReadFileEx */
4404 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4405 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4406 pInternetSetStatusCallbackA( ses
, &callback
);
4408 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4409 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef );
4410 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4411 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4413 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4414 req
= HttpOpenRequestA( con
, "GET", "/async_read", NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef );
4415 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4416 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4418 SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT
);
4419 SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY
);
4420 SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4421 SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4422 SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST
);
4423 SET_EXPECT( INTERNET_STATUS_REQUEST_SENT
);
4424 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4425 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4426 SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION
);
4427 SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED
);
4428 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4430 SetLastError( 0xdeadbeef );
4431 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4432 ok( !ret
, "HttpSendRequestA unexpectedly succeeded\n" );
4433 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4434 WaitForSingleObject( complete_event
, INFINITE
);
4435 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4437 CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT
);
4438 CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY
);
4439 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4440 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4441 CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST
);
4442 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT
);
4443 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4444 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4445 CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION
);
4446 CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED
);
4447 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4450 memset( &ib
, 0, sizeof(ib
) );
4451 memset( buffer
, 0, sizeof(buffer
) );
4452 ib
.dwStructSize
= sizeof(ib
);
4453 for (count
= 0; count
< sizeof(buffer
); count
+= ib
.dwBufferLength
)
4455 ib
.lpvBuffer
= buffer
+ count
;
4456 ib
.dwBufferLength
= min(16, sizeof(buffer
) - count
);
4458 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4459 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4461 ret
= InternetReadFileExA( req
, &ib
, 0, 0xdeadbeef );
4462 if (!count
) /* the first part should arrive immediately */
4463 ok( ret
, "InternetReadFileExA failed %u\n", GetLastError() );
4466 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4467 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4468 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4469 if (!pending_reads
++)
4471 res
= WaitForSingleObject( complete_event
, 0 );
4472 ok( res
== WAIT_TIMEOUT
, "expected WAIT_TIMEOUT, got %u\n", res
);
4473 SetEvent( conn_wait_event
);
4475 res
= WaitForSingleObject( complete_event
, INFINITE
);
4476 ok( res
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", res
);
4477 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4478 todo_wine_if( pending_reads
> 1 )
4479 ok( ib
.dwBufferLength
!= 0, "expected ib.dwBufferLength != 0\n" );
4480 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4481 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4484 CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4485 CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4486 if (!ib
.dwBufferLength
) break;
4489 ok( pending_reads
== 1, "expected 1 pending read, got %u\n", pending_reads
);
4490 ok( !strcmp(buffer
, page1
), "unexpected buffer content\n" );
4491 close_async_handle( ses
, 2 );
4492 ResetEvent( conn_wait_event
);
4494 /* test asynchronous InternetReadFile */
4495 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4496 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4497 pInternetSetStatusCallbackA( ses
, &callback
);
4499 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4500 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef );
4501 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4502 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4504 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4505 req
= HttpOpenRequestA( con
, "GET", "/async_read", NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef );
4506 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4507 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4509 SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT
);
4510 SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY
);
4511 SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4512 SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4513 SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST
);
4514 SET_EXPECT( INTERNET_STATUS_REQUEST_SENT
);
4515 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4516 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4517 SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION
);
4518 SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED
);
4519 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4521 SetLastError( 0xdeadbeef );
4522 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4523 ok( !ret
, "HttpSendRequestA unexpectedly succeeded\n" );
4524 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4525 WaitForSingleObject( complete_event
, INFINITE
);
4526 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4528 CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT
);
4529 CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY
);
4530 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4531 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4532 CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST
);
4533 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT
);
4534 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4535 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4536 CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION
);
4537 CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED
);
4538 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4541 memset( buffer
, 0, sizeof(buffer
) );
4542 for (count
= 0; count
< sizeof(buffer
); count
+= bytes
)
4544 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4545 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4548 ret
= InternetReadFile( req
, buffer
+ count
, min(16, sizeof(buffer
) - count
), &bytes
);
4549 if (!count
) /* the first part should arrive immediately */
4550 ok( ret
, "InternetReadFile failed %u\n", GetLastError() );
4553 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4554 ok( bytes
== 0, "expected 0, got %u\n", bytes
);
4555 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4556 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4557 if (!pending_reads
++)
4559 res
= WaitForSingleObject( complete_event
, 0 );
4560 ok( res
== WAIT_TIMEOUT
, "expected WAIT_TIMEOUT, got %u\n", res
);
4561 SetEvent( conn_wait_event
);
4563 res
= WaitForSingleObject( complete_event
, INFINITE
);
4564 ok( res
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", res
);
4565 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4566 todo_wine_if( pending_reads
> 1 )
4567 ok( bytes
!= 0, "expected bytes != 0\n" );
4568 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4569 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4572 CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4573 CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4577 ok( pending_reads
== 1, "expected 1 pending read, got %u\n", pending_reads
);
4578 ok( !strcmp(buffer
, page1
), "unexpected buffer content\n" );
4579 close_async_handle( ses
, 2 );
4582 static void server_send_string(const char *msg
)
4584 send(server_socket
, msg
, strlen(msg
), 0);
4587 static size_t server_read_data(char *buf
, size_t buf_size
)
4589 return recv(server_socket
, buf
, buf_size
, 0);
4592 #define server_read_request(a) _server_read_request(__LINE__,a)
4593 static void _server_read_request(unsigned line
, const char *expected_request
)
4598 size
= server_read_data(buf
, sizeof(buf
) - 1);
4600 p
= strstr(buf
, "\r\n");
4602 ok_(__FILE__
,line
)(p
&& !strcmp(buf
, expected_request
), "unexpected request %s\n", buf
);
4605 static BOOL skip_receive_notification_tests
;
4606 static DWORD received_response_size
;
4608 static void WINAPI
readex_callback(HINTERNET handle
, DWORD_PTR context
, DWORD status
, void *info
, DWORD info_size
)
4611 case INTERNET_STATUS_RECEIVING_RESPONSE
:
4612 if(!skip_receive_notification_tests
)
4613 callback(handle
, context
, status
, info
, info_size
);
4615 case INTERNET_STATUS_RESPONSE_RECEIVED
:
4616 if(!skip_receive_notification_tests
)
4617 callback(handle
, context
, status
, info
, info_size
);
4618 received_response_size
= *(DWORD
*)info
;
4620 case INTERNET_STATUS_REQUEST_SENT
:
4621 callback(handle
, context
, status
, info
, info_size
);
4622 SetEvent(request_sent_event
);
4625 callback(handle
, context
, status
, info
, info_size
);
4629 static void send_socket_request(test_request_t
*req
, BOOL new_connection
)
4633 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4634 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4635 if(new_connection
) {
4636 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4637 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4639 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4640 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4641 if(!skip_receive_notification_tests
)
4642 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4644 SetLastError(0xdeadbeef);
4645 ret
= HttpSendRequestA(req
->request
, NULL
, 0, NULL
, 0);
4646 ok(!ret
, "HttpSendRequestA unexpectedly succeeded\n");
4647 ok(GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError());
4650 WaitForSingleObject(server_req_rec_event
, INFINITE
);
4651 WaitForSingleObject(request_sent_event
, INFINITE
);
4653 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4654 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4655 if(new_connection
) {
4656 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4657 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4659 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4660 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4663 static void open_socket_request(int port
, test_request_t
*req
, const char *verb
)
4665 /* We're connecting to new socket */
4669 req
->session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4670 ok(req
->session
!= NULL
, "InternetOpenA failed\n");
4671 pInternetSetStatusCallbackA(req
->session
, readex_callback
);
4673 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4674 req
->connection
= InternetConnectA(req
->session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef);
4675 ok(req
->connection
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
4676 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4678 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4679 req
->request
= HttpOpenRequestA(req
->connection
, "GET", verb
? verb
: "/socket",
4680 NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef);
4681 ok(req
->request
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
4682 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4684 send_socket_request(req
, !verb
);
4687 static void open_read_test_request(int port
, test_request_t
*req
, const char *response
)
4689 if(!skip_receive_notification_tests
)
4690 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4692 open_socket_request(port
, req
, NULL
);
4694 if(!skip_receive_notification_tests
) {
4695 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4696 received_response_size
= 0xdeadbeef;
4698 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4700 server_send_string(response
);
4701 WaitForSingleObject(complete_event
, INFINITE
);
4703 if(!skip_receive_notification_tests
) {
4704 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4705 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4707 ok(received_response_size
== strlen(response
), "received_response_size = %u\n", received_response_size
);
4709 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4710 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4713 #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)
4714 static void _readex_expect_sync_data_len(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
4715 DWORD buf_size
, const char *exdata
, DWORD len
, DWORD expect_receive
)
4719 if(!skip_receive_notification_tests
&& expect_receive
) {
4720 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4721 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4722 received_response_size
= 0xdeadbeef;
4725 memset(buf
->lpvBuffer
, 0xff, buf_size
);
4726 buf
->dwBufferLength
= buf_size
;
4727 ret
= InternetReadFileExW(req
, buf
, flags
, 0xdeadbeef);
4728 ok_(__FILE__
,line
)(ret
, "InternetReadFileExW failed: %u\n", GetLastError());
4729 ok_(__FILE__
,line
)(buf
->dwBufferLength
== len
, "dwBufferLength = %u, expected %u\n", buf
->dwBufferLength
, len
);
4731 ok_(__FILE__
,line
)(!memcmp(buf
->lpvBuffer
, exdata
, len
), "Unexpected data\n");
4733 if(!skip_receive_notification_tests
&& expect_receive
) {
4734 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4735 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4736 ok_(__FILE__
,line
)(received_response_size
== len
, "received_response_size = %u\n", received_response_size
);
4740 #define readex_expect_sync_data(a,b,c,d,e,f) _readex_expect_sync_data(__LINE__,a,b,c,d,e,f)
4741 static void _readex_expect_sync_data(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
4742 DWORD buf_size
, const char *exdata
, DWORD expect_receive
)
4744 _readex_expect_sync_data_len(line
, req
, flags
, buf
, buf_size
, exdata
, strlen(exdata
), expect_receive
);
4747 #define read_expect_sync_data_len(a,b,c,d,e) _read_expect_sync_data_len(__LINE__,a,b,c,d,e)
4748 static void _read_expect_sync_data_len(unsigned line
, HINTERNET req
, void *buf
, DWORD buf_size
,
4749 const char *exdata
, DWORD len
)
4751 DWORD ret_size
= 0xdeadbeef;
4754 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4755 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4756 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4757 received_response_size
= 0xdeadbeef;
4759 memset(buf
, 0xff, buf_size
);
4760 ret
= InternetReadFile(req
, buf
, buf_size
, &ret_size
);
4761 ok_(__FILE__
,line
)(ret
, "InternetReadFileExW failed: %u\n", GetLastError());
4762 ok_(__FILE__
,line
)(ret_size
== len
, "dwBufferLength = %u, expected %u\n", ret_size
, len
);
4764 ok_(__FILE__
,line
)(!memcmp(buf
, exdata
, len
), "Unexpected data\n");
4766 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4767 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4768 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4769 ok_(__FILE__
,line
)(received_response_size
== len
, "received_response_size = %u\n", received_response_size
);
4770 ok_(__FILE__
,line
)(!req_error
, "req_error = %u\n", req_error
);
4773 #define read_expect_sync_data(a,b,c,d) _read_expect_sync_data(__LINE__,a,b,c,d)
4774 static void _read_expect_sync_data(unsigned line
, HINTERNET req
, void *buf
,
4775 DWORD buf_size
, const char *exdata
)
4777 _read_expect_sync_data_len(line
, req
, buf
, buf_size
, exdata
, strlen(exdata
));
4780 static void close_connection(void)
4783 SetEvent(conn_wait_event
);
4784 recv(server_socket
, &c
, 1, 0);
4787 #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)
4788 static void _send_response_and_wait(unsigned line
, const char *response
, BOOL do_close_connection
,
4789 void *buf
, DWORD
*ret_size
, const char *exdata
,
4790 DWORD expected_size
, DWORD expected_req_error
, DWORD expected_receive_size
)
4792 if(!skip_receive_notification_tests
)
4793 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4794 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4797 server_send_string(response
);
4799 if(do_close_connection
)
4802 WaitForSingleObject(complete_event
, INFINITE
);
4804 if(!skip_receive_notification_tests
)
4805 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4806 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4807 if(!skip_receive_notification_tests
&& expected_receive_size
!= -1)
4808 todo_wine_if(received_response_size
!= expected_receive_size
) /* FIXME! remove when wine is fixed */
4809 ok_(__FILE__
,line
)(received_response_size
== expected_receive_size
,
4810 "received_response_size = %u\n", received_response_size
);
4811 ok_(__FILE__
,line
)(req_error
== expected_req_error
, "req_error = %u, expected %u\n", req_error
, expected_req_error
);
4813 /* If IRF_NO_WAIT is used, buffer is not changed. */
4814 ok_(__FILE__
,line
)(*ret_size
== expected_size
, "dwBufferLength = %u\n", *ret_size
);
4816 ok_(__FILE__
,line
)(!memcmp(buf
, exdata
, strlen(exdata
)), "unexpected buffer data\n");
4818 ok_(__FILE__
,line
)(!*(DWORD
*)buf
, "buffer data changed\n");
4821 #define send_response_ex_and_wait(a,b,c,d,e,f) _send_response_ex_and_wait(__LINE__,a,b,c,d,e,f)
4822 static void _send_response_ex_and_wait(unsigned line
, const char *response
, BOOL close_connection
,
4823 INTERNET_BUFFERSW
*buf
, const char *exdata
, DWORD expected_req_error
,
4824 DWORD expected_receive_size
)
4826 _send_response_and_wait(line
, response
, close_connection
, buf
->lpvBuffer
, &buf
->dwBufferLength
,
4827 exdata
, exdata
? strlen(exdata
) : buf
->dwBufferLength
, expected_req_error
,
4828 expected_receive_size
);
4831 static void send_response_len_and_wait(unsigned len
, BOOL close_connection
, INTERNET_BUFFERSW
*buf
)
4835 response
= HeapAlloc(GetProcessHeap(), 0, len
+1);
4836 memset(response
, 'x', len
);
4838 send_response_ex_and_wait(response
, close_connection
, buf
, NULL
, 0, -1);
4839 HeapFree(GetProcessHeap(), 0, response
);
4842 #define readex_expect_async(a,b,c,d,e) _readex_expect_async(__LINE__,a,b,c,d,e)
4843 static void _readex_expect_async(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
4844 DWORD buf_size
, const char *exdata
)
4849 if(!skip_receive_notification_tests
)
4850 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4852 memset(buf
->lpvBuffer
, 0, max(buf_size
, sizeof(DWORD
)));
4853 buf
->dwBufferLength
= buf_size
;
4854 ret
= InternetReadFileExW(req
, buf
, flags
, 0xdeadbeef);
4855 ok_(__FILE__
,line
)(!ret
&& GetLastError() == ERROR_IO_PENDING
, "InternetReadFileExW returned %x (%u)\n", ret
, GetLastError());
4856 ok_(__FILE__
,line
)(buf
->dwBufferLength
== buf_size
, "dwBufferLength = %u, expected %u\n", buf
->dwBufferLength
, buf_size
);
4858 len
= strlen(exdata
);
4859 ok_(__FILE__
,line
)(!memcmp(buf
->lpvBuffer
, exdata
, len
), "unexpected buffer data\n");
4861 ok_(__FILE__
,line
)(!*(DWORD
*)buf
->lpvBuffer
, "buffer data changed\n");
4864 if(!skip_receive_notification_tests
)
4865 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4868 static void read_expect_async(HINTERNET req
, void *buf
, DWORD buf_size
, DWORD
*ret_size
, const char *exdata
)
4874 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4876 *ret_size
= 0xdeadbeef;
4877 memset(buf
, 0, buf_size
);
4878 ret
= InternetReadFile(req
, buf
, buf_size
, ret_size
);
4879 ok(!ret
&& GetLastError() == ERROR_IO_PENDING
, "InternetReadFileExW returned %x (%u)\n", ret
, GetLastError());
4880 ok(*ret_size
== 0, "dwBufferLength = %u\n", *ret_size
);
4882 len
= strlen(exdata
);
4883 ok(!memcmp(buf
, exdata
, len
), "unexpected buffer data\n");
4885 for(p
= (const char*)buf
+ len
; p
< (const char*)buf
+ buf_size
; p
++) {
4887 ok(0, "buffer data changed\n");
4890 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4893 #define expect_data_available(a,b) _expect_data_available(__LINE__,a,b)
4894 static DWORD
_expect_data_available(unsigned line
, HINTERNET req
, int exsize
)
4899 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
4900 ok_(__FILE__
,line
)(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
4902 ok_(__FILE__
,line
)(size
== exsize
, "size = %u, expected %u\n", size
, exsize
);
4907 #define async_query_data_available(a,b) _async_query_data_available(__LINE__,a,b)
4908 static void _async_query_data_available(unsigned line
, HINTERNET req
, DWORD
*size
)
4912 if(!skip_receive_notification_tests
)
4913 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4916 res
= InternetQueryDataAvailable(req
, size
, 0, 0);
4917 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_IO_PENDING
,
4918 "InternetQueryDataAvailable returned: %x(%u)\n", res
, GetLastError());
4919 ok_(__FILE__
,line
)(!*size
, "size = %u\n", *size
);
4921 if(!skip_receive_notification_tests
)
4922 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4925 static void test_http_read(int port
)
4927 INTERNET_BUFFERSW ib
;
4936 memset(&ib
, 0, sizeof(ib
));
4937 ib
.dwStructSize
= sizeof(ib
);
4940 trace("Testing InternetReadFileExW with IRF_ASYNC flag...\n");
4942 open_read_test_request(port
, &req
,
4943 "HTTP/1.1 200 OK\r\n"
4944 "Server: winetest\r\n"
4948 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, 4, "xx");
4950 send_response_ex_and_wait("yy1234567890", FALSE
, &ib
, "xxyy", 0, 2);
4951 readex_expect_sync_data(req
.request
, IRF_ASYNC
, &ib
, 4, "1234", 4);
4952 readex_expect_sync_data(req
.request
, IRF_ASYNC
, &ib
, 5, "56789", 5);
4954 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, sizeof(buf
), "0");
4955 send_response_ex_and_wait("123", TRUE
, &ib
, "0123", 0, 4);
4957 close_async_handle(req
.session
, 2);
4959 trace("Testing InternetReadFileExW with no flags...\n");
4961 open_read_test_request(port
, &req
,
4962 "HTTP/1.1 200 OK\r\n"
4963 "Server: winetest\r\n"
4967 readex_expect_async(req
.request
, 0, &ib
, 4, "xx");
4969 send_response_ex_and_wait("yy1234567890", FALSE
, &ib
, "xxyy", 0, 2);
4970 readex_expect_sync_data(req
.request
, 0, &ib
, 4, "1234", 4);
4971 readex_expect_sync_data(req
.request
, 0, &ib
, 5, "56789", 5);
4973 readex_expect_async(req
.request
, 0, &ib
, sizeof(buf
), "0");
4974 send_response_ex_and_wait("123", TRUE
, &ib
, "0123", 0, 4);
4976 close_async_handle(req
.session
, 2);
4978 trace("Testing InternetReadFile...\n");
4980 open_read_test_request(port
, &req
,
4981 "HTTP/1.1 200 OK\r\n"
4982 "Server: winetest\r\n"
4986 read_expect_async(req
.request
, buf
, 4, &read_size
, "xx");
4988 send_response_and_wait("yy1234567890", FALSE
, buf
, &read_size
, "xxyy", 4, 0, 2);
4989 read_expect_sync_data(req
.request
, buf
, 4, "1234");
4990 read_expect_sync_data(req
.request
, buf
, 5, "56789");
4992 read_expect_async(req
.request
, buf
, sizeof(buf
), &read_size
, "0");
4993 send_response_and_wait("123", TRUE
, buf
, &read_size
, "0123", 4, 0, 4);
4995 close_async_handle(req
.session
, 2);
4997 trace("Testing InternetReadFileExW with IRF_NO_WAIT flag...\n");
4999 open_read_test_request(port
, &req
,
5000 "HTTP/1.1 200 OK\r\n"
5001 "Server: winetest\r\n"
5005 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
5007 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "xx", 0);
5009 if(notified
[INTERNET_STATUS_RECEIVING_RESPONSE
]) {
5010 win_skip("Skipping receive notification tests on too old Windows.\n");
5011 skip_receive_notification_tests
= TRUE
;
5013 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5015 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5016 send_response_ex_and_wait("1234567890", FALSE
, &ib
, NULL
, 0, 10);
5017 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, 5, "12345", 0);
5018 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "67890", 0);
5020 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5021 send_response_ex_and_wait("12345", TRUE
, &ib
, NULL
, 0, 5);
5023 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "12345", 0);
5024 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "", TRUE
);
5026 close_async_handle(req
.session
, 2);
5028 open_read_test_request(port
, &req
,
5029 "HTTP/1.1 200 OK\r\n"
5030 "Server: winetest\r\n"
5031 "Transfer-Encoding: chunked\r\n"
5034 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123456789", 0);
5035 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5037 send_response_ex_and_wait("\r\n1\r\na\r\n1\r\nb\r", FALSE
, &ib
, NULL
, 0, 13);
5038 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
5039 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5041 send_response_ex_and_wait("\n3\r\nab", FALSE
, &ib
, NULL
, 0, 6);
5042 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
5043 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5045 send_response_ex_and_wait("c", FALSE
, &ib
, NULL
, 0, 1);
5046 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "c", 0);
5047 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5049 send_response_ex_and_wait("\r\n1\r\nx\r\n0\r\n\r\n", TRUE
, &ib
, NULL
, 0, 13);
5050 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "x", 0);
5051 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "", 0);
5053 close_async_handle(req
.session
, 2);
5055 open_read_test_request(port
, &req
,
5056 "HTTP/1.1 200 OK\r\n"
5057 "Server: winetest\r\n"
5058 "Transfer-Encoding: chunked\r\n"
5061 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123", 0);
5062 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5064 send_response_ex_and_wait("0\r\n\r\n", TRUE
, &ib
, NULL
, 0, 5);
5065 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "", 0);
5067 close_async_handle(req
.session
, 2);
5069 open_read_test_request(port
, &req
,
5070 "HTTP/1.1 200 OK\r\n"
5071 "Server: winetest\r\n"
5072 "Connection: close\r\n"
5074 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5075 send_response_ex_and_wait("123", TRUE
, &ib
, NULL
, 0, 3);
5076 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123", 0);
5078 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5079 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5080 close_async_handle(req
.session
, 2);
5081 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5082 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5084 trace("Testing InternetQueryDataAvailable...\n");
5086 open_read_test_request(port
, &req
,
5087 "HTTP/1.1 200 OK\r\n"
5088 "Server: winetest\r\n"
5091 expect_data_available(req
.request
, 3);
5092 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123", 0);
5093 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), NULL
);
5095 send_response_len_and_wait(20000, TRUE
, &ib
);
5096 avail
= expect_data_available(req
.request
, -1);
5097 ok(avail
< 17000, "avail = %u\n", avail
);
5099 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
5100 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
5101 close_async_handle(req
.session
, 2);
5102 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5103 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5105 open_read_test_request(port
, &req
,
5106 "HTTP/1.1 200 OK\r\n"
5107 "Server: winetest\r\n"
5108 "Connection: close\r\n"
5112 expect_data_available(req
.request
, 3);
5113 readex_expect_sync_data(req
.request
, 0, &ib
, 3, "123", 0);
5115 async_query_data_available(req
.request
, &read_size
);
5116 send_response_and_wait("1234567890", FALSE
, NULL
, &read_size
, NULL
, 10, 10, 10);
5118 readex_expect_sync_data(req
.request
, 0, &ib
, 9, "123456789", 0);
5119 expect_data_available(req
.request
, 1);
5120 readex_expect_sync_data(req
.request
, 0, &ib
, 1, "0", 0);
5122 async_query_data_available(req
.request
, &read_size
);
5123 send_response_and_wait("1234567890", FALSE
, NULL
, &read_size
, NULL
, 10, 10, 10);
5124 expect_data_available(req
.request
, 10);
5125 for(i
= 0; i
< 10; i
++)
5126 server_send_string("x");
5127 expect_data_available(req
.request
, 10);
5129 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, 21, "1234567890");
5130 send_response_ex_and_wait("X", FALSE
, &ib
, "1234567890xxxxxxxxxxX", 0, 11);
5131 async_query_data_available(req
.request
, &read_size
);
5133 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5134 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5135 send_response_and_wait(NULL
, TRUE
, NULL
, &read_size
, NULL
, 0, 0, 0);
5136 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5137 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5139 close_async_handle(req
.session
, 2);
5141 skip_receive_notification_tests
= FALSE
;
5144 static void test_connection_break(int port
)
5146 INTERNET_BUFFERSW ib
;
5153 memset(&ib
, 0, sizeof(ib
));
5154 ib
.dwStructSize
= sizeof(ib
);
5157 trace("Testing InternetReadFileExW on broken connection...\n");
5159 open_read_test_request(port
, &req
,
5160 "HTTP/1.1 200 OK\r\n"
5161 "Server: winetest\r\n"
5162 "Content-Length: 10000\r\n"
5166 /* close connection and make sure that it's closed on handle release. */
5168 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5169 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5170 close_async_handle(req
.session
, 2);
5171 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5172 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5175 static void test_long_url(int port
)
5177 char long_path
[INTERNET_MAX_PATH_LENGTH
*2] = "/echo_request?";
5178 char buf
[sizeof(long_path
)*2], url
[sizeof(buf
)];
5186 memset(long_path
+strlen(long_path
), 'x', sizeof(long_path
)-strlen(long_path
));
5187 long_path
[sizeof(long_path
)-1] = 0;
5188 open_simple_request(&req
, "localhost", port
, NULL
, long_path
);
5190 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
5191 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
5192 test_status_code(req
.request
, 200);
5194 receive_simple_request(req
.request
, buf
, sizeof(buf
));
5195 ok(strstr(buf
, long_path
) != NULL
, "long pathnot found in %s\n", buf
);
5197 sprintf(url
, "http://localhost:%u%s", port
, long_path
);
5200 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_URL
, buf
, &size
);
5201 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
5203 ok(size
== len
, "size = %u, expected %u\n", size
, len
);
5204 ok(!strcmp(buf
, url
), "Wrong URL %s, expected %s\n", buf
, url
);
5206 close_request(&req
);
5209 static void test_persistent_connection(int port
)
5211 INTERNET_BUFFERSW ib
;
5218 memset(&ib
, 0, sizeof(ib
));
5219 ib
.dwStructSize
= sizeof(ib
);
5222 skip_receive_notification_tests
= TRUE
;
5224 trace("Testing persistent connection...\n");
5226 open_read_test_request(port
, &req
,
5227 "HTTP/1.1 200 OK\r\n"
5228 "Server: winetest\r\n"
5229 "Content-Length: 2\r\n"
5232 readex_expect_sync_data(req
.request
, IRF_ASYNC
, &ib
, 4, "xx", 0);
5233 close_async_handle(req
.session
, 2);
5235 open_socket_request(port
, &req
, "/test_simple_chunked");
5236 server_read_request("GET /test_simple_chunked HTTP/1.1");
5238 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5239 server_send_string("HTTP/1.1 200 OK\r\n"
5240 "Server: winetest\r\n"
5241 "Transfer-Encoding: chunked\r\n"
5244 WaitForSingleObject(complete_event
, INFINITE
);
5245 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5246 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5248 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
5249 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, sizeof(buf
), NULL
);
5250 send_response_ex_and_wait("3\r\nabc\r\n0\r\n\r\n", FALSE
, &ib
, "abc", 0, 13);
5251 close_async_handle(req
.session
, 2);
5253 open_socket_request(port
, &req
, "/chunked");
5254 server_read_request("GET /chunked HTTP/1.1");
5256 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5257 server_send_string("HTTP/1.1 200 OK\r\n"
5258 "Server: winetest\r\n"
5259 "Transfer-Encoding: chunked\r\n"
5262 WaitForSingleObject(complete_event
, INFINITE
);
5263 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5264 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5266 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, 3, "ab", 0);
5267 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, 3, NULL
);
5268 send_response_ex_and_wait("3\r\nabc\r\n", FALSE
, &ib
, "abc", 0, 13);
5270 /* send another request on the same request handle, it must drain remaining last chunk marker */
5271 server_send_string("0\r\n\r\n");
5273 send_socket_request(&req
, FALSE
);
5274 server_read_request("GET /chunked HTTP/1.1");
5276 ResetEvent(complete_event
);
5277 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5278 server_send_string("HTTP/1.1 201 OK\r\n"
5279 "Server: winetest\r\n"
5280 "Content-Length: 0\r\n"
5281 "Connection: keep-alive\r\n"
5283 WaitForSingleObject(complete_event
, INFINITE
);
5284 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5285 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5287 test_status_code(req
.request
, 201);
5288 close_async_handle(req
.session
, 2);
5290 /* the connection is still valid */
5291 open_socket_request(port
, &req
, "/another_chunked");
5292 server_read_request("GET /another_chunked HTTP/1.1");
5294 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5295 server_send_string("HTTP/1.1 200 OK\r\n"
5296 "Server: winetest\r\n"
5297 "Transfer-Encoding: chunked\r\n"
5300 WaitForSingleObject(complete_event
, INFINITE
);
5301 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5302 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5304 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab", 0);
5305 readex_expect_async(req
.request
, IRF_ASYNC
, &ib
, sizeof(buf
), NULL
);
5307 /* we're missing trailing '\n'; the connection can't be drained without blocking,
5308 * so it will be closed */
5309 send_response_ex_and_wait("3\r\nabc\r\n0\r\n\r", FALSE
, &ib
, "abc", 0, 13);
5311 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5312 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5313 close_async_handle(req
.session
, 2);
5314 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5315 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5318 skip_receive_notification_tests
= FALSE
;
5321 static void test_redirect(int port
)
5323 char buf
[4000], expect_url
[INTERNET_MAX_URL_LENGTH
];
5324 INTERNET_BUFFERSW ib
;
5330 skip_receive_notification_tests
= TRUE
;
5332 memset(&ib
, 0, sizeof(ib
));
5333 ib
.dwStructSize
= sizeof(ib
);
5336 trace("Testing redirection...\n");
5338 open_socket_request(port
, &req
, NULL
);
5340 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5341 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
5342 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5343 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5345 server_send_string("HTTP/1.1 302 Found\r\n"
5346 "Server: winetest\r\n"
5347 "Location: test_redirection\r\n"
5348 "Connection: keep-alive\r\n"
5349 "Content-Length: 0\r\n"
5352 server_read_request("GET /test_redirection HTTP/1.1");
5354 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5356 sprintf(expect_url
, "http://localhost:%u/test_redirection", port
);
5357 test_request_url(req
.request
, expect_url
);
5359 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5361 server_send_string("HTTP/1.1 200 OK\r\n"
5362 "Server: winetest\r\n"
5363 "Content-Length: 3\r\n"
5367 WaitForSingleObject(complete_event
, INFINITE
);
5369 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5370 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5371 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
5372 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5373 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5375 test_status_code(req
.request
, 200);
5378 close_async_handle(req
.session
, 2);
5380 trace("Test redirect to non-http URL...\n");
5382 open_socket_request(port
, &req
, NULL
);
5384 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5386 server_send_string("HTTP/1.1 302 Found\r\n"
5387 "Server: winetest\r\n"
5388 "Location: test:non:http/url\r\n"
5389 "Connection: keep-alive\r\n"
5390 "Content-Length: 0\r\n"
5393 WaitForSingleObject(complete_event
, INFINITE
);
5395 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5396 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
5398 sprintf(expect_url
, "http://localhost:%u/socket", port
);
5399 test_request_url(req
.request
, expect_url
);
5400 test_status_code(req
.request
, 302);
5403 close_async_handle(req
.session
, 2);
5405 trace("Test redirect to http URL with no host name...\n");
5407 open_socket_request(port
, &req
, NULL
);
5409 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5411 server_send_string("HTTP/1.1 302 Found\r\n"
5412 "Server: winetest\r\n"
5413 "Location: http:///nohost\r\n"
5414 "Connection: keep-alive\r\n"
5415 "Content-Length: 0\r\n"
5418 WaitForSingleObject(complete_event
, INFINITE
);
5420 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5421 ok(req_error
== ERROR_INTERNET_INVALID_URL
, "expected ERROR_INTERNET_INVALID_URL, got %u\n", req_error
);
5423 sprintf(expect_url
, "http://localhost:%u/socket", port
);
5424 test_request_url(req
.request
, expect_url
);
5425 test_status_code(req
.request
, 302);
5428 close_async_handle(req
.session
, 2);
5430 skip_receive_notification_tests
= FALSE
;
5433 static void test_remove_dot_segments(int port
)
5438 open_simple_request(&req
, "localhost", port
, NULL
, "/A/../B/./C/../../test_remove_dot_segments");
5440 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
5441 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
5442 test_status_code(req
.request
, 200);
5444 close_request(&req
);
5447 static void test_http_connection(void)
5449 struct server_info si
;
5453 si
.hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
5456 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
5457 ok( hThread
!= NULL
, "create thread failed\n");
5459 r
= WaitForSingleObject(si
.hEvent
, 10000);
5460 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
5461 if (r
!= WAIT_OBJECT_0
)
5463 CloseHandle(hThread
);
5467 test_basic_request(si
.port
, "GET", "/test1");
5468 test_proxy_indirect(si
.port
);
5469 test_proxy_direct(si
.port
);
5470 test_header_handling_order(si
.port
);
5471 test_basic_request(si
.port
, "POST", "/test5");
5472 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
5473 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
5474 test_basic_request(si
.port
, "GET", "/test6");
5475 test_basic_request(si
.port
, "GET", "/testF");
5476 test_connection_header(si
.port
);
5477 test_header_override(si
.port
);
5478 test_cookie_header(si
.port
);
5479 test_basic_authentication(si
.port
);
5480 test_invalid_response_headers(si
.port
);
5481 test_response_without_headers(si
.port
);
5482 test_HttpQueryInfo(si
.port
);
5483 test_HttpSendRequestW(si
.port
);
5484 test_options(si
.port
);
5485 test_no_content(si
.port
);
5486 test_conn_close(si
.port
);
5487 test_no_cache(si
.port
);
5488 test_cache_read_gzipped(si
.port
);
5489 test_http_status(si
.port
);
5490 test_premature_disconnect(si
.port
);
5491 test_connection_closing(si
.port
);
5492 test_cache_control_verb(si
.port
);
5493 test_successive_HttpSendRequest(si
.port
);
5494 test_head_request(si
.port
);
5495 test_request_content_length(si
.port
);
5496 test_accept_encoding(si
.port
);
5497 test_basic_auth_credentials_reuse(si
.port
);
5498 test_async_read(si
.port
);
5499 test_http_read(si
.port
);
5500 test_connection_break(si
.port
);
5501 test_long_url(si
.port
);
5502 test_redirect(si
.port
);
5503 test_persistent_connection(si
.port
);
5504 test_remove_dot_segments(si
.port
);
5506 /* send the basic request again to shutdown the server thread */
5507 test_basic_request(si
.port
, "GET", "/quit");
5509 r
= WaitForSingleObject(hThread
, 3000);
5510 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
5511 CloseHandle(hThread
);
5514 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
5516 LocalFree(info
->lpszSubjectInfo
);
5517 LocalFree(info
->lpszIssuerInfo
);
5518 LocalFree(info
->lpszProtocolName
);
5519 LocalFree(info
->lpszSignatureAlgName
);
5520 LocalFree(info
->lpszEncryptionAlgName
);
5524 const char *ex_subject
;
5525 const char *ex_issuer
;
5526 } cert_struct_test_t
;
5528 static const cert_struct_test_t test_winehq_org_cert
= {
5533 "RapidSSL SHA256 CA"
5536 static const cert_struct_test_t test_winehq_com_cert
= {
5541 "test.winehq.com\r\n"
5542 "webmaster@winehq.org",
5547 "test.winehq.com\r\n"
5548 "webmaster@winehq.org"
5551 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
5553 INTERNET_CERTIFICATE_INFOA info
;
5557 memset(&info
, 0x5, sizeof(info
));
5559 size
= sizeof(info
);
5560 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
5561 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
5562 ok(size
== sizeof(info
), "size = %u\n", size
);
5564 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
5565 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
5566 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
5567 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
5568 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
5569 ok(info
.dwKeySize
>= 128 && info
.dwKeySize
<= 256, "dwKeySize = %u\n", info
.dwKeySize
);
5571 release_cert_info(&info
);
5574 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
5575 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
5577 char url
[INTERNET_MAX_URL_LENGTH
];
5578 const CERT_CHAIN_CONTEXT
*chain
;
5582 if(!pInternetGetSecurityInfoByURLA
) {
5583 win_skip("pInternetGetSecurityInfoByURLA not available\n");
5588 chain
= (void*)0xdeadbeef;
5590 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
5591 if(error
== ERROR_SUCCESS
) {
5592 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
5593 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
5594 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
5595 CertFreeCertificateChain(chain
);
5597 SetLastError(0xdeadbeef);
5598 res
= pInternetGetSecurityInfoByURLA(url
, NULL
, NULL
);
5599 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
,
5600 "InternetGetSecurityInfoByURLA returned: %x(%u)\n", res
, GetLastError());
5602 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, NULL
);
5603 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
5604 CertFreeCertificateChain(chain
);
5606 res
= pInternetGetSecurityInfoByURLA(url
, NULL
, &flags
);
5607 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
5609 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
5610 "InternetGetSecurityInfoByURLA returned: %x(%u), expected %u\n", res
, GetLastError(), error
);
5614 #define test_secflags_option(a,b,c) _test_secflags_option(__LINE__,a,b,c)
5615 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
, DWORD opt_flags
)
5621 size
= sizeof(flags
);
5622 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
5623 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
5624 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n",
5627 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
5629 size
= sizeof(flags
);
5630 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
5631 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
5632 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n",
5636 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
5637 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
5641 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
5642 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
5645 static void test_security_flags(void)
5647 INTERNET_CERTIFICATE_INFOA
*cert
;
5648 HINTERNET ses
, conn
, req
;
5653 trace("Testing security flags...\n");
5656 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5657 ok(ses
!= NULL
, "InternetOpen failed\n");
5659 pInternetSetStatusCallbackA(ses
, &callback
);
5661 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5662 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
5663 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
5664 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
5665 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5667 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5668 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5669 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5671 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5672 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5675 size
= sizeof(flags
);
5676 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
5677 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
5678 win_skip("Incomplete security flags support, skipping\n");
5680 close_async_handle(ses
, 2);
5684 test_secflags_option(req
, 0, 0);
5685 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5687 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
5688 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
, 0);
5690 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
5691 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
5693 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
5694 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
5696 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
5697 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
5698 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
5700 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
5701 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
5702 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5703 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5704 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5705 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5706 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5707 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5708 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5709 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5710 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5711 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5712 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5713 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5714 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5716 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5717 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5719 WaitForSingleObject(complete_event
, INFINITE
);
5720 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5722 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
5723 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
5724 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5725 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5726 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5727 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5728 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5729 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5730 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5731 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5732 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5733 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5734 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5736 test_request_flags(req
, 0);
5737 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
5738 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
, 0);
5740 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5741 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5742 ok(size
, "size = 0\n");
5744 /* Collect all existing persistent connections */
5745 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5746 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5748 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5749 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5750 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5752 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5753 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5755 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
5756 res
= InternetSetOptionA(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
5757 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
5759 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5760 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5761 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5762 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5763 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5764 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5765 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5766 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5767 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5768 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5769 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5771 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5772 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5774 WaitForSingleObject(complete_event
, INFINITE
);
5775 ok(req_error
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| broken(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
),
5776 "req_error = %d\n", req_error
);
5779 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
5780 ok(res
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5781 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %u\n", size
);
5782 cert
= HeapAlloc(GetProcessHeap(), 0, size
);
5783 cert
->lpszSubjectInfo
= NULL
;
5784 cert
->lpszIssuerInfo
= NULL
;
5785 cert
->lpszSignatureAlgName
= (char *)0xdeadbeef;
5786 cert
->lpszEncryptionAlgName
= (char *)0xdeadbeef;
5787 cert
->lpszProtocolName
= (char *)0xdeadbeef;
5788 cert
->dwKeySize
= 0xdeadbeef;
5789 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, cert
, &size
);
5790 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
5793 ok(cert
->lpszSubjectInfo
&& strlen(cert
->lpszSubjectInfo
) > 1, "expected a non-empty subject name\n");
5794 ok(cert
->lpszIssuerInfo
&& strlen(cert
->lpszIssuerInfo
) > 1, "expected a non-empty issuer name\n");
5795 ok(!cert
->lpszSignatureAlgName
, "unexpected signature algorithm name\n");
5796 ok(!cert
->lpszEncryptionAlgName
, "unexpected encryption algorithm name\n");
5797 ok(!cert
->lpszProtocolName
, "unexpected protocol name\n");
5798 ok(cert
->dwKeySize
!= 0xdeadbeef, "unexpected key size\n");
5800 HeapFree(GetProcessHeap(), 0, cert
);
5802 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5803 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5804 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
5805 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
5806 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5807 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5808 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5810 if(req_error
!= ERROR_INTERNET_SEC_CERT_REV_FAILED
) {
5811 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error
);
5813 close_async_handle(ses
, 3);
5818 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
5819 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
5821 test_request_flags(req
, 8);
5822 /* IE11 finds both rev failure and invalid CA. Previous versions required rev failure
5823 to be ignored before invalid CA was reported. */
5824 test_secflags_option(req
, _SECURITY_FLAG_CERT_REV_FAILED
, _SECURITY_FLAG_CERT_INVALID_CA
);
5826 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
5827 test_secflags_option(req
, _SECURITY_FLAG_CERT_REV_FAILED
|SECURITY_FLAG_IGNORE_REVOCATION
, _SECURITY_FLAG_CERT_INVALID_CA
);
5829 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5830 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5831 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5832 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5833 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5834 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5835 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5837 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5838 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5840 WaitForSingleObject(complete_event
, INFINITE
);
5841 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
5843 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5844 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5845 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5846 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5847 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5848 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5849 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5851 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
5852 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5853 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5855 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
5856 test_secflags_option(req
, _SECURITY_FLAG_CERT_INVALID_CA
|_SECURITY_FLAG_CERT_REV_FAILED
5857 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
, 0);
5858 test_http_version(req
);
5860 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5861 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5862 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5863 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5864 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5865 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5866 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5867 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5868 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5869 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5870 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5871 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5872 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5874 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5875 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5877 WaitForSingleObject(complete_event
, INFINITE
);
5878 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5880 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5881 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5882 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5883 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5884 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5885 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5886 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5887 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5888 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5889 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5890 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5892 test_request_flags(req
, 0);
5893 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
5894 |SECURITY_FLAG_STRENGTH_STRONG
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5896 test_cert_struct(req
, &test_winehq_com_cert
);
5897 test_security_info("https://test.winehq.com/data/some_file.html?q", 0,
5898 _SECURITY_FLAG_CERT_INVALID_CA
|_SECURITY_FLAG_CERT_REV_FAILED
);
5900 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5901 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5902 ok(size
, "size = 0\n");
5904 close_async_handle(ses
, 3);
5906 /* Collect all existing persistent connections */
5907 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5908 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5910 /* Make another request, without setting security flags */
5912 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5913 ok(ses
!= NULL
, "InternetOpen failed\n");
5915 pInternetSetStatusCallbackA(ses
, &callback
);
5917 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5918 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
5919 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
5920 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
5921 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5923 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5924 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5925 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5927 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5928 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5930 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
5931 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5932 test_http_version(req
);
5934 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5935 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5936 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5937 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5938 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5939 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5940 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5941 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5942 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5943 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5944 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5945 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5947 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5948 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5950 WaitForSingleObject(complete_event
, INFINITE
);
5951 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5953 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5954 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5955 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5956 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5957 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5958 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5959 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5960 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5961 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5962 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5964 test_request_flags(req
, 0);
5965 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
5966 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5968 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5969 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5970 ok(size
, "size = 0\n");
5972 close_async_handle(ses
, 2);
5974 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5975 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5976 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5979 static void test_secure_connection(void)
5981 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
5982 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
5983 static const WCHAR get
[] = {'G','E','T',0};
5984 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
5985 HINTERNET ses
, con
, req
;
5987 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
5988 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
5991 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5992 ok(ses
!= NULL
, "InternetOpen failed\n");
5994 con
= InternetConnectA(ses
, "test.winehq.org",
5995 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
5996 INTERNET_SERVICE_HTTP
, 0, 0);
5997 ok(con
!= NULL
, "InternetConnect failed\n");
5999 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
6000 INTERNET_FLAG_SECURE
, 0);
6001 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6003 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
6004 ok(ret
|| broken(GetLastError() == ERROR_INTERNET_CANNOT_CONNECT
),
6005 "HttpSendRequest failed: %d\n", GetLastError());
6008 win_skip("Cannot connect to https.\n");
6012 size
= sizeof(flags
);
6013 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
6014 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6015 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
6017 test_cert_struct(req
, &test_winehq_org_cert
);
6019 /* Querying the same option through InternetQueryOptionW still results in
6020 * ASCII strings being returned.
6023 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6025 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
6026 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
6027 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
6028 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6029 certificate_structW
, &size
);
6030 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
6031 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6034 ok(certificate_structA
->lpszSubjectInfo
&&
6035 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
6036 "expected a non-empty subject name\n");
6037 ok(certificate_structA
->lpszIssuerInfo
&&
6038 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
6039 "expected a non-empty issuer name\n");
6040 ok(!certificate_structA
->lpszSignatureAlgName
,
6041 "unexpected signature algorithm name\n");
6042 ok(!certificate_structA
->lpszEncryptionAlgName
,
6043 "unexpected encryption algorithm name\n");
6044 ok(!certificate_structA
->lpszProtocolName
,
6045 "unexpected protocol name\n");
6046 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
6047 release_cert_info(certificate_structA
);
6049 HeapFree(GetProcessHeap(), 0, certificate_structW
);
6051 InternetCloseHandle(req
);
6052 InternetCloseHandle(con
);
6053 InternetCloseHandle(ses
);
6055 /* Repeating the tests with the W functions has the same result: */
6056 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
6057 ok(ses
!= NULL
, "InternetOpen failed\n");
6059 con
= InternetConnectW(ses
, testsite
,
6060 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
6061 INTERNET_SERVICE_HTTP
, 0, 0);
6062 ok(con
!= NULL
, "InternetConnect failed\n");
6064 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
6065 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
6066 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6068 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
6069 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
6071 size
= sizeof(flags
);
6072 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
6073 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6074 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %x\n", flags
);
6076 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6078 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
6079 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
6080 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
6081 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6082 certificate_structA
, &size
);
6083 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6086 ok(certificate_structA
->lpszSubjectInfo
&&
6087 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
6088 "expected a non-empty subject name\n");
6089 ok(certificate_structA
->lpszIssuerInfo
&&
6090 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
6091 "expected a non-empty issuer name\n");
6092 ok(!certificate_structA
->lpszSignatureAlgName
,
6093 "unexpected signature algorithm name\n");
6094 ok(!certificate_structA
->lpszEncryptionAlgName
,
6095 "unexpected encryption algorithm name\n");
6096 ok(!certificate_structA
->lpszProtocolName
,
6097 "unexpected protocol name\n");
6098 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
6099 release_cert_info(certificate_structA
);
6101 HeapFree(GetProcessHeap(), 0, certificate_structA
);
6103 /* Again, querying the same option through InternetQueryOptionW still
6104 * results in ASCII strings being returned.
6107 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6109 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
6110 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
6111 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
6112 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
6113 certificate_structW
, &size
);
6114 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
6115 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
6118 ok(certificate_structA
->lpszSubjectInfo
&&
6119 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
6120 "expected a non-empty subject name\n");
6121 ok(certificate_structA
->lpszIssuerInfo
&&
6122 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
6123 "expected a non-empty issuer name\n");
6124 ok(!certificate_structA
->lpszSignatureAlgName
,
6125 "unexpected signature algorithm name\n");
6126 ok(!certificate_structA
->lpszEncryptionAlgName
,
6127 "unexpected encryption algorithm name\n");
6128 ok(!certificate_structA
->lpszProtocolName
,
6129 "unexpected protocol name\n");
6130 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
6131 release_cert_info(certificate_structA
);
6133 HeapFree(GetProcessHeap(), 0, certificate_structW
);
6136 InternetCloseHandle(req
);
6137 InternetCloseHandle(con
);
6138 InternetCloseHandle(ses
);
6141 static void test_user_agent_header(void)
6143 HINTERNET ses
, con
, req
;
6148 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
6149 ok(ses
!= NULL
, "InternetOpen failed\n");
6151 con
= InternetConnectA(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
6152 ok(con
!= NULL
, "InternetConnect failed\n");
6154 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
6155 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6157 size
= sizeof(buffer
);
6158 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6159 err
= GetLastError();
6160 ok(!ret
, "HttpQueryInfo succeeded\n");
6161 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
6163 ret
= HttpAddRequestHeadersA(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
6164 ok(ret
, "HttpAddRequestHeaders succeeded\n");
6166 size
= sizeof(buffer
);
6167 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6168 err
= GetLastError();
6169 ok(ret
, "HttpQueryInfo failed\n");
6171 InternetCloseHandle(req
);
6173 req
= HttpOpenRequestA(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
6174 ok(req
!= NULL
, "HttpOpenRequest failed\n");
6176 size
= sizeof(buffer
);
6177 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6178 err
= GetLastError();
6179 ok(!ret
, "HttpQueryInfo succeeded\n");
6180 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
6182 ret
= HttpAddRequestHeadersA(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
6183 ok(ret
, "HttpAddRequestHeaders failed\n");
6186 size
= sizeof(buffer
);
6187 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6188 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
6189 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
6191 InternetCloseHandle(req
);
6192 InternetCloseHandle(con
);
6193 InternetCloseHandle(ses
);
6196 static void test_bogus_accept_types_array(void)
6198 HINTERNET ses
, con
, req
;
6199 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
6204 ses
= InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
6205 con
= InternetConnectA(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
6206 req
= HttpOpenRequestA(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
6208 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
6211 size
= sizeof(buffer
);
6212 SetLastError(0xdeadbeef);
6213 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6214 error
= GetLastError();
6215 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
6216 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
6217 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
6218 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
6219 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
6221 InternetCloseHandle(req
);
6222 InternetCloseHandle(con
);
6223 InternetCloseHandle(ses
);
6232 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
6234 INTERNET_ASYNC_RESULT
*result
= info
;
6235 struct context
*ctx
= (struct context
*)context
;
6237 if(winetest_debug
> 1)
6238 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
6241 case INTERNET_STATUS_REQUEST_COMPLETE
:
6242 trace("request handle: 0x%08lx\n", result
->dwResult
);
6243 ctx
->req
= (HINTERNET
)result
->dwResult
;
6244 SetEvent(ctx
->event
);
6246 case INTERNET_STATUS_HANDLE_CLOSING
: {
6247 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
6249 if (InternetQueryOptionA(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
6250 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
6251 SetEvent(ctx
->event
);
6254 case INTERNET_STATUS_NAME_RESOLVED
:
6255 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
6256 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
6258 ok(str
[0] && str
[1], "Got string: %s\n", str
);
6259 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
6264 static void test_open_url_async(void)
6272 /* Collect all existing persistent connections */
6273 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
6274 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
6277 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
6278 * other versions never do. They also hang of following tests. We disable it for everything older
6285 ctx
.event
= CreateEventA(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
6287 ses
= InternetOpenA("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6288 ok(ses
!= NULL
, "InternetOpen failed\n");
6290 SetLastError(0xdeadbeef);
6291 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
6292 error
= GetLastError();
6293 ok(!ret
, "InternetSetOptionA succeeded\n");
6294 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
6296 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
6297 error
= GetLastError();
6298 ok(!ret
, "InternetSetOptionA failed\n");
6299 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
6301 pInternetSetStatusCallbackW(ses
, cb
);
6302 ResetEvent(ctx
.event
);
6304 req
= InternetOpenUrlA(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
6305 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
6307 WaitForSingleObject(ctx
.event
, INFINITE
);
6310 size
= sizeof(type
);
6311 ret
= InternetQueryOptionA(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
6312 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
6313 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
6314 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
6317 ret
= HttpQueryInfoA(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
6318 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
6319 ok(size
> 0, "expected size > 0\n");
6321 ResetEvent(ctx
.event
);
6322 InternetCloseHandle(ctx
.req
);
6323 WaitForSingleObject(ctx
.event
, INFINITE
);
6325 InternetCloseHandle(ses
);
6326 CloseHandle(ctx
.event
);
6331 internet_connect
= 1,
6333 http_send_request_ex
,
6336 internet_close_handle
6341 enum api function
; /* api responsible for notification */
6342 unsigned int status
; /* status received */
6343 BOOL async
; /* delivered from another thread? */
6351 const struct notification
*test
;
6357 DWORD expect_result
;
6361 static CRITICAL_SECTION notification_cs
;
6363 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
6365 BOOL status_ok
, function_ok
;
6366 struct info
*info
= (struct info
*)context
;
6369 EnterCriticalSection( ¬ification_cs
);
6371 if(info
->is_aborted
) {
6372 LeaveCriticalSection(¬ification_cs
);
6376 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
6378 DWORD size
= sizeof(struct info
*);
6379 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
6380 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
6381 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
6383 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
6384 if(info
->expect_result
== ERROR_SUCCESS
) {
6385 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
6387 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
6388 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
6393 if (i
>= info
->count
)
6395 LeaveCriticalSection( ¬ification_cs
);
6399 while (info
->test
[i
].status
!= status
&&
6400 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
6401 i
< info
->count
- 1 &&
6402 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
6407 status_ok
= (info
->test
[i
].status
== status
);
6408 function_ok
= (info
->test
[i
].function
== info
->function
);
6410 if (!info
->test
[i
].todo
)
6412 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
6413 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
6415 if (info
->test
[i
].async
)
6416 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
6417 info
->line
, info
->thread
, GetCurrentThreadId());
6421 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
6423 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
6425 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
6428 LeaveCriticalSection( ¬ification_cs
);
6431 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
6433 info
->function
= function
;
6435 info
->expect_result
= expect_result
;
6438 struct notification_data
6440 const struct notification
*test
;
6441 const unsigned int count
;
6446 BOOL expect_conn_failure
;
6449 static const struct notification async_send_request_ex_test
[] =
6451 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6452 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6453 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6454 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6455 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6456 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6457 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
6458 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
6459 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6460 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6461 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6462 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, FALSE
},
6463 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, FALSE
},
6464 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6465 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6466 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6467 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6468 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6469 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6470 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6473 static const struct notification async_send_request_ex_test2
[] =
6475 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6476 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6477 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6478 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6479 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6480 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6481 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
, TRUE
},
6482 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
, TRUE
},
6483 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6484 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6485 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6486 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6487 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6488 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6489 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6490 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6491 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6492 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6495 static const struct notification async_send_request_ex_resolve_failure_test
[] =
6497 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6498 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6499 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6500 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
},
6501 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6502 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6503 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6504 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6505 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6506 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6507 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6510 static const struct notification async_send_request_ex_chunked_test
[] =
6512 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
},
6513 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
},
6514 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6515 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6516 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6517 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6518 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
6519 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
6520 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6521 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6522 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6523 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6524 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6525 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6526 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
},
6527 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
},
6528 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
},
6529 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
}
6532 static const struct notification_data notification_data
[] = {
6534 async_send_request_ex_chunked_test
,
6535 sizeof(async_send_request_ex_chunked_test
)/sizeof(async_send_request_ex_chunked_test
[0]),
6541 async_send_request_ex_test
,
6542 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
6546 "Public ID=codeweavers"
6549 async_send_request_ex_test2
,
6550 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
6556 async_send_request_ex_resolve_failure_test
,
6557 sizeof(async_send_request_ex_resolve_failure_test
)/sizeof(async_send_request_ex_resolve_failure_test
[0]),
6566 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
6569 HINTERNET ses
, req
, con
;
6571 DWORD size
, written
, error
;
6572 INTERNET_BUFFERSA b
;
6573 static const char *accept
[2] = {"*/*", NULL
};
6576 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
6578 InitializeCriticalSection( ¬ification_cs
);
6580 info
.test
= nd
->test
;
6581 info
.count
= nd
->count
;
6583 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
6584 info
.thread
= GetCurrentThreadId();
6585 info
.is_aborted
= FALSE
;
6587 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6588 ok( ses
!= NULL
, "InternetOpen failed\n" );
6590 pInternetSetStatusCallbackA( ses
, check_notification
);
6592 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
6593 con
= InternetConnectA( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
6594 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
6596 WaitForSingleObject( info
.wait
, 10000 );
6598 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
6599 req
= HttpOpenRequestA( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
6600 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
6602 WaitForSingleObject( info
.wait
, 10000 );
6605 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
6606 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
6607 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
6608 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
6609 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
6612 setup_test( &info
, http_send_request_ex
, __LINE__
,
6613 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
6614 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
6615 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
6617 error
= WaitForSingleObject( info
.wait
, 10000 );
6618 if(error
!= WAIT_OBJECT_0
) {
6619 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
6620 info
.is_aborted
= TRUE
;
6624 size
= sizeof(buffer
);
6625 SetLastError( 0xdeadbeef );
6626 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
6627 error
= GetLastError();
6628 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
6629 if(nd
->expect_conn_failure
) {
6630 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
6633 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
6634 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
6640 size
= strlen( nd
->data
);
6641 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
6642 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
6643 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
6644 ok( written
== size
, "expected %u got %u\n", written
, size
);
6646 WaitForSingleObject( info
.wait
, 10000 );
6648 SetLastError( 0xdeadbeef );
6649 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
6650 error
= GetLastError();
6651 ok( !ret
, "HttpEndRequestA succeeded\n" );
6652 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
6655 SetLastError( 0xdeadbeef );
6656 setup_test( &info
, http_end_request
, __LINE__
,
6657 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
6658 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
6659 error
= GetLastError();
6660 ok( !ret
, "HttpEndRequestA succeeded\n" );
6661 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
6663 WaitForSingleObject( info
.wait
, 10000 );
6665 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
6667 InternetCloseHandle( req
);
6668 InternetCloseHandle( con
);
6669 InternetCloseHandle( ses
);
6671 WaitForSingleObject( info
.wait
, 10000 );
6673 CloseHandle( info
.wait
);
6674 DeleteCriticalSection( ¬ification_cs
);
6677 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
6678 static BOOL closetest_closed
;
6680 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
6681 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
6686 if(winetest_debug
> 1)
6687 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
6689 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
6690 "Unexpected hInternet %p\n", hInternet
);
6691 if(!closetest_closed
)
6695 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
6696 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
6697 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
6698 closetest_req
, res
, GetLastError());
6701 static void test_InternetCloseHandle(void)
6706 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6707 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
6709 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
6711 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
6712 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
6713 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
6715 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
6716 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
6718 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
6719 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
6720 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
6722 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
6724 res
= InternetCloseHandle(closetest_session
);
6725 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
6726 closetest_closed
= TRUE
;
6727 trace("Closed session handle\n");
6729 res
= InternetCloseHandle(closetest_conn
);
6730 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
6731 res
, GetLastError());
6733 res
= InternetCloseHandle(closetest_req
);
6734 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
6735 res
, GetLastError());
6737 len
= sizeof(flags
);
6738 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
6739 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
6740 "InternetQueryOptionA(%p INTERNET_OPTION_REQUEST_FLAGS) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
6741 closetest_req
, res
, GetLastError());
6744 static void test_connection_failure(void)
6750 open_simple_request(&req
, "localhost", 1, NULL
, "/");
6752 SetLastError(0xdeadbeef);
6753 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
6754 error
= GetLastError();
6755 ok(!ret
, "unexpected success\n");
6756 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
6758 close_request(&req
);
6761 static void test_default_service_port(void)
6763 HINTERNET session
, connect
, request
;
6771 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
6772 ok(session
!= NULL
, "InternetOpen failed\n");
6774 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6775 INTERNET_SERVICE_HTTP
, 0, 0);
6776 ok(connect
!= NULL
, "InternetConnect failed\n");
6778 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
6779 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6781 SetLastError(0xdeadbeef);
6782 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6783 error
= GetLastError();
6784 ok(!ret
, "HttpSendRequest succeeded\n");
6785 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
6788 size
= sizeof(buffer
);
6789 memset(buffer
, 0, sizeof(buffer
));
6790 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6791 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
6792 ok(!strcmp(buffer
, "test.winehq.org:80"), "Expected test.winehg.org:80, got '%s'\n", buffer
);
6794 InternetCloseHandle(request
);
6795 InternetCloseHandle(connect
);
6797 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6798 INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
6799 ok(connect
!= NULL
, "InternetConnect failed\n");
6801 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
6802 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6804 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6805 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
6807 size
= sizeof(buffer
);
6808 memset(buffer
, 0, sizeof(buffer
));
6809 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6810 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
6811 ok(!strcmp(buffer
, "test.winehq.org"), "Expected test.winehg.org, got '%s'\n", buffer
);
6813 InternetCloseHandle(request
);
6814 InternetCloseHandle(connect
);
6816 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6817 INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
6818 ok(connect
!= NULL
, "InternetConnect failed\n");
6820 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
6821 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6823 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6824 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
6826 size
= sizeof(buffer
);
6827 memset(buffer
, 0, sizeof(buffer
));
6828 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6829 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
6830 ok(!strcmp(buffer
, "test.winehq.org:443"), "Expected test.winehg.org:443, got '%s'\n", buffer
);
6832 InternetCloseHandle(request
);
6833 InternetCloseHandle(connect
);
6834 InternetCloseHandle(session
);
6837 static void init_status_tests(void)
6839 memset(expect
, 0, sizeof(expect
));
6840 memset(optional
, 0, sizeof(optional
));
6841 memset(wine_allow
, 0, sizeof(wine_allow
));
6842 memset(notified
, 0, sizeof(notified
));
6843 memset(status_string
, 0, sizeof(status_string
));
6845 #define STATUS_STRING(status) status_string[status] = #status
6846 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
6847 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
6848 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6849 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6850 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
6851 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
6852 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
6853 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
6854 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
6855 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
6856 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
6857 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
6858 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
6859 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
6860 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
6861 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
6862 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
6863 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
6864 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
6865 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
6866 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
6867 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
6868 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
6869 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
6870 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
6871 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
6872 #undef STATUS_STRING
6875 static void WINAPI
header_cb( HINTERNET handle
, DWORD_PTR ctx
, DWORD status
, LPVOID info
, DWORD len
)
6881 if (status
== INTERNET_STATUS_SENDING_REQUEST
)
6883 ret
= HttpAddRequestHeadersA( handle
, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD
);
6884 ok( ret
, "HttpAddRequestHeadersA failed %u\n", GetLastError() );
6885 SetEvent( (HANDLE
)ctx
);
6887 else if (status
== INTERNET_STATUS_REQUEST_SENT
)
6891 ret
= HttpQueryInfoA( handle
, HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
6892 buf
, &size
, &index
);
6893 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
6894 ok( strstr( buf
, "winetest: winetest" ) != NULL
, "header missing\n" );
6895 SetEvent( (HANDLE
)ctx
);
6899 static void test_concurrent_header_access(void)
6901 HINTERNET ses
, con
, req
;
6904 HANDLE wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
6906 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6907 ok( ses
!= NULL
, "InternetOpenA failed\n" );
6909 con
= InternetConnectA( ses
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
6910 INTERNET_SERVICE_HTTP
, 0, 0 );
6911 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
6913 req
= HttpOpenRequestA( con
, NULL
, "/", NULL
, NULL
, NULL
, 0, (DWORD_PTR
)wait
);
6914 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
6916 pInternetSetStatusCallbackA( req
, header_cb
);
6918 SetLastError( 0xdeadbeef );
6919 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
6920 err
= GetLastError();
6921 ok( !ret
, "HttpSendRequestA succeeded\n" );
6922 ok( err
== ERROR_IO_PENDING
, "got %u\n", ERROR_IO_PENDING
);
6924 WaitForSingleObject( wait
, 5000 );
6925 WaitForSingleObject( wait
, 5000 );
6927 InternetCloseHandle( req
);
6928 InternetCloseHandle( con
);
6929 InternetCloseHandle( ses
);
6930 CloseHandle( wait
);
6936 hdll
= GetModuleHandleA("wininet.dll");
6938 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
6939 win_skip("Too old IE (older than 6.0)\n");
6943 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
6944 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
6945 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
6947 if(!pInternetGetSecurityInfoByURLA
) {
6949 win_skip("IE6 found. It's too old for some tests.\n");
6953 init_status_tests();
6954 test_InternetCloseHandle();
6955 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
6956 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
6957 InternetReadFile_test(0, &test_data
[1]);
6958 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
6959 test_security_flags();
6960 InternetReadFile_test(0, &test_data
[2]);
6961 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
6962 test_open_url_async();
6963 test_async_HttpSendRequestEx(¬ification_data
[0]);
6964 test_async_HttpSendRequestEx(¬ification_data
[1]);
6965 test_async_HttpSendRequestEx(¬ification_data
[2]);
6966 test_async_HttpSendRequestEx(¬ification_data
[3]);
6967 InternetOpenRequest_test();
6969 InternetLockRequestFile_test();
6970 InternetOpenUrlA_test();
6972 test_http_connection();
6973 test_secure_connection();
6974 test_user_agent_header();
6975 test_bogus_accept_types_array();
6976 InternetReadFile_chunked_test();
6977 HttpSendRequestEx_test();
6978 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
6979 test_connection_failure();
6980 test_default_service_port();
6981 test_concurrent_header_access();