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
27 #define WIN32_NO_STATUS
38 #include <wine/test.h>
40 #define TEST_URL "http://test.winehq.org/tests/hello.html"
42 static BOOL first_connection_to_test_url
= TRUE
;
44 /* Adapted from dlls/urlmon/tests/protocol.c */
46 #define SET_EXPECT2(status, num) \
49 #define SET_EXPECT(status) \
50 SET_EXPECT2(status, 1)
52 #define SET_OPTIONAL2(status, num) \
53 optional[status] = num
55 #define SET_OPTIONAL(status) \
56 SET_OPTIONAL2(status, 1)
58 /* SET_WINE_ALLOW's should be used with an appropriate
59 * todo_wine CHECK_NOTIFIED at a later point in the code */
60 #define SET_WINE_ALLOW2(status, num) \
61 wine_allow[status] = num
63 #define SET_WINE_ALLOW(status) \
64 SET_WINE_ALLOW2(status, 1)
66 #define CHECK_EXPECT(status) \
68 if (!expect[status] && !optional[status] && wine_allow[status]) \
70 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
71 status < MAX_INTERNET_STATUS && status_string[status] ? \
72 status_string[status] : "unknown"); \
73 wine_allow[status]--; \
77 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
78 status < MAX_INTERNET_STATUS && status_string[status] ? \
79 status_string[status] : "unknown"); \
80 if (expect[status]) expect[status]--; \
81 else optional[status]--; \
86 /* CLEAR_NOTIFIED used in cases when notification behavior
87 * differs between Windows versions */
88 #define CLEAR_NOTIFIED(status) \
89 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
91 #define CHECK_NOTIFIED2(status, num) \
93 ok(notified[status] + optional[status] == (num), \
94 "expected status %d (%s) %d times, received %d times\n", \
95 status, status < MAX_INTERNET_STATUS && status_string[status] ? \
96 status_string[status] : "unknown", (num), notified[status]); \
97 CLEAR_NOTIFIED(status); \
100 #define CHECK_NOTIFIED(status) \
101 CHECK_NOTIFIED2(status, 1)
103 #define CHECK_NOT_NOTIFIED(status) \
104 CHECK_NOTIFIED2(status, 0)
106 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
107 static int expect
[MAX_INTERNET_STATUS
], optional
[MAX_INTERNET_STATUS
],
108 wine_allow
[MAX_INTERNET_STATUS
], notified
[MAX_INTERNET_STATUS
];
109 static const char *status_string
[MAX_INTERNET_STATUS
];
111 static HANDLE hCompleteEvent
, conn_close_event
;
112 static DWORD req_error
;
114 #define TESTF_REDIRECT 0x01
115 #define TESTF_COMPRESSED 0x02
116 #define TESTF_CHUNKED 0x04
120 const char *redirected_url
;
125 const char *post_data
;
129 static const test_data_t test_data
[] = {
131 "http://test.winehq.org/tests/data.php",
132 "http://test.winehq.org/tests/data.php",
139 "http://test.winehq.org/tests/redirect",
140 "http://test.winehq.org/tests/hello.html",
147 "http://www.codeweavers.com/",
148 "http://www.codeweavers.com/",
149 "www.codeweavers.com",
151 "Accept-Encoding: gzip, deflate",
155 "http://test.winehq.org/tests/post.php",
156 "http://test.winehq.org/tests/post.php",
159 "Content-Type: application/x-www-form-urlencoded",
166 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackA
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
167 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackW
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
168 static BOOL (WINAPI
*pInternetGetSecurityInfoByURLA
)(LPSTR
,PCCERT_CHAIN_CONTEXT
*,DWORD
*);
170 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
173 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
174 return lstrcmpW(strw
, buf
);
177 static BOOL
proxy_active(void)
179 HKEY internet_settings
;
183 if (RegOpenKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
184 0, KEY_QUERY_VALUE
, &internet_settings
) != ERROR_SUCCESS
)
187 size
= sizeof(DWORD
);
188 if (RegQueryValueExA(internet_settings
, "ProxyEnable", NULL
, NULL
, (LPBYTE
) &proxy_enable
, &size
) != ERROR_SUCCESS
)
191 RegCloseKey(internet_settings
);
193 return proxy_enable
!= 0;
196 #define test_status_code(a,b) _test_status_code(__LINE__,a,b, FALSE)
197 #define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)
198 static void _test_status_code(unsigned line
, HINTERNET req
, DWORD excode
, BOOL is_todo
)
200 DWORD code
, size
, index
;
201 char exbuf
[10], bufa
[10];
207 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, NULL
);
208 ok_(__FILE__
,line
)(res
, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
210 todo_wine
ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
212 ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
213 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
218 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
219 ok_(__FILE__
,line
)(res
, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
221 todo_wine
ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
223 ok_(__FILE__
,line
)(!index
, "index = %d, expected 0\n", code
);
224 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
226 sprintf(exbuf
, "%u", excode
);
229 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, bufa
, &size
, NULL
);
230 ok_(__FILE__
,line
)(res
, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
232 todo_wine
ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
234 ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
235 ok_(__FILE__
,line
)(size
== strlen(exbuf
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
238 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
239 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
240 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
241 ok_(__FILE__
,line
)(size
== strlen(exbuf
)+1, "unexpected size %d for \"%s\"\n", size
, exbuf
);
244 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
245 ok_(__FILE__
,line
)(res
, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
247 todo_wine
ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
249 ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
250 ok_(__FILE__
,line
)(size
== strlen(exbuf
)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
253 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
254 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
255 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
256 ok_(__FILE__
,line
)(size
== (strlen(exbuf
)+1)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
260 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
261 ok(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
262 ok(size
== sizeof(bufw
), "unexpected size %d\n", size
);
268 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
269 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
270 "[7] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
274 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, &code
, &size
, NULL
);
275 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST
,
276 "[8] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
279 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
280 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
281 static void _test_request_flags(unsigned line
, HINTERNET req
, DWORD exflags
, BOOL is_todo
)
287 size
= sizeof(flags
);
288 res
= InternetQueryOptionW(req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &size
);
289 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
291 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
292 flags
&= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED
;
294 ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
296 todo_wine
ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
299 #define test_http_version(a) _test_http_version(__LINE__,a)
300 static void _test_http_version(unsigned line
, HINTERNET req
)
302 HTTP_VERSION_INFO v
= {0xdeadbeef, 0xdeadbeef};
307 res
= InternetQueryOptionW(req
, INTERNET_OPTION_HTTP_VERSION
, &v
, &size
);
308 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
309 ok_(__FILE__
,line
)(v
.dwMajorVersion
== 1, "dwMajorVersion = %d\n", v
.dwMajorVersion
);
310 ok_(__FILE__
,line
)(v
.dwMinorVersion
== 1, "dwMinorVersion = %d\n", v
.dwMinorVersion
);
313 static int close_handle_cnt
;
315 static VOID WINAPI
callback(
318 DWORD dwInternetStatus
,
319 LPVOID lpvStatusInformation
,
320 DWORD dwStatusInformationLength
323 CHECK_EXPECT(dwInternetStatus
);
324 switch (dwInternetStatus
)
326 case INTERNET_STATUS_RESOLVING_NAME
:
327 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
328 GetCurrentThreadId(), hInternet
, dwContext
,
329 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
330 *(LPSTR
)lpvStatusInformation
= '\0';
332 case INTERNET_STATUS_NAME_RESOLVED
:
333 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
334 GetCurrentThreadId(), hInternet
, dwContext
,
335 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
336 *(LPSTR
)lpvStatusInformation
= '\0';
338 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
339 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
340 GetCurrentThreadId(), hInternet
, dwContext
,
341 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
342 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
343 dwStatusInformationLength
);
344 *(LPSTR
)lpvStatusInformation
= '\0';
346 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
347 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
348 GetCurrentThreadId(), hInternet
, dwContext
,
349 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
350 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
351 dwStatusInformationLength
);
352 *(LPSTR
)lpvStatusInformation
= '\0';
354 case INTERNET_STATUS_SENDING_REQUEST
:
355 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
356 GetCurrentThreadId(), hInternet
, dwContext
,
357 lpvStatusInformation
,dwStatusInformationLength
);
359 case INTERNET_STATUS_REQUEST_SENT
:
360 ok(dwStatusInformationLength
== sizeof(DWORD
),
361 "info length should be sizeof(DWORD) instead of %d\n",
362 dwStatusInformationLength
);
363 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
364 GetCurrentThreadId(), hInternet
, dwContext
,
365 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
367 case INTERNET_STATUS_RECEIVING_RESPONSE
:
368 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
369 GetCurrentThreadId(), hInternet
, dwContext
,
370 lpvStatusInformation
,dwStatusInformationLength
);
372 case INTERNET_STATUS_RESPONSE_RECEIVED
:
373 ok(dwStatusInformationLength
== sizeof(DWORD
),
374 "info length should be sizeof(DWORD) instead of %d\n",
375 dwStatusInformationLength
);
376 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
377 GetCurrentThreadId(), hInternet
, dwContext
,
378 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
380 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
381 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
382 GetCurrentThreadId(), hInternet
,dwContext
,
383 lpvStatusInformation
,dwStatusInformationLength
);
385 case INTERNET_STATUS_PREFETCH
:
386 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
387 GetCurrentThreadId(), hInternet
, dwContext
,
388 lpvStatusInformation
,dwStatusInformationLength
);
390 case INTERNET_STATUS_CLOSING_CONNECTION
:
391 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
392 GetCurrentThreadId(), hInternet
, dwContext
,
393 lpvStatusInformation
,dwStatusInformationLength
);
395 case INTERNET_STATUS_CONNECTION_CLOSED
:
396 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
397 GetCurrentThreadId(), hInternet
, dwContext
,
398 lpvStatusInformation
,dwStatusInformationLength
);
400 case INTERNET_STATUS_HANDLE_CREATED
:
401 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
402 "info length should be sizeof(HINTERNET) instead of %d\n",
403 dwStatusInformationLength
);
404 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
405 GetCurrentThreadId(), hInternet
, dwContext
,
406 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
407 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
408 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
410 case INTERNET_STATUS_HANDLE_CLOSING
:
411 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
412 "info length should be sizeof(HINTERNET) instead of %d\n",
413 dwStatusInformationLength
);
414 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
415 GetCurrentThreadId(), hInternet
, dwContext
,
416 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
417 if(!InterlockedDecrement(&close_handle_cnt
))
418 SetEvent(hCompleteEvent
);
420 case INTERNET_STATUS_REQUEST_COMPLETE
:
422 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
423 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
424 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
425 dwStatusInformationLength
);
426 ok(iar
->dwResult
== 1 || iar
->dwResult
== 0, "iar->dwResult = %ld\n", iar
->dwResult
);
427 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
428 GetCurrentThreadId(), hInternet
, dwContext
,
429 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
430 req_error
= iar
->dwError
;
431 if(!close_handle_cnt
)
432 SetEvent(hCompleteEvent
);
435 case INTERNET_STATUS_REDIRECT
:
436 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
437 GetCurrentThreadId(), hInternet
, dwContext
,
438 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
439 *(LPSTR
)lpvStatusInformation
= '\0';
440 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
441 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
443 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
444 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
445 GetCurrentThreadId(), hInternet
, dwContext
,
446 lpvStatusInformation
, dwStatusInformationLength
);
449 trace("%04x:Callback %p 0x%lx %d %p %d\n",
450 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
451 lpvStatusInformation
, dwStatusInformationLength
);
455 static void close_async_handle(HINTERNET handle
, HANDLE complete_event
, int handle_cnt
)
459 close_handle_cnt
= handle_cnt
;
461 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
462 res
= InternetCloseHandle(handle
);
463 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
464 WaitForSingleObject(hCompleteEvent
, INFINITE
);
465 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
468 static void InternetReadFile_test(int flags
, const test_data_t
*test
)
470 char *post_data
= NULL
;
471 BOOL res
, on_async
= TRUE
;
473 DWORD length
, exlen
= 0, post_len
= 0;
474 const char *types
[2] = { "*", NULL
};
475 HINTERNET hi
, hic
= 0, hor
= 0;
477 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
479 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags
,test
->url
);
481 trace("InternetOpenA <--\n");
482 hi
= InternetOpenA((test
->flags
& TESTF_COMPRESSED
) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
483 INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
484 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
485 trace("InternetOpenA -->\n");
487 if (hi
== 0x0) goto abort
;
489 pInternetSetStatusCallbackA(hi
,&callback
);
491 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
493 trace("InternetConnectA <--\n");
494 hic
=InternetConnectA(hi
, test
->host
, INTERNET_INVALID_PORT_NUMBER
,
495 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
496 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
497 trace("InternetConnectA -->\n");
499 if (hic
== 0x0) goto abort
;
501 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
502 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
504 trace("HttpOpenRequestA <--\n");
505 hor
= HttpOpenRequestA(hic
, test
->post_data
? "POST" : "GET", test
->path
, NULL
, NULL
, types
,
506 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
508 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
510 * If the internet name can't be resolved we are probably behind
511 * a firewall or in some other way not directly connected to the
512 * Internet. Not enough reason to fail the test. Just ignore and
516 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
518 trace("HttpOpenRequestA -->\n");
520 if (hor
== 0x0) goto abort
;
522 test_request_flags(hor
, INTERNET_REQFLAG_NO_HEADERS
);
524 length
= sizeof(buffer
);
525 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
526 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
527 ok(!strcmp(buffer
, test
->url
), "Wrong URL %s, expected %s\n", buffer
, test
->url
);
529 length
= sizeof(buffer
);
530 res
= HttpQueryInfoA(hor
, HTTP_QUERY_RAW_HEADERS
, buffer
, &length
, 0x0);
531 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
532 ok(length
== 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length
);
533 ok(!strcmp(buffer
, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer
);
535 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
536 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
537 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
538 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
,2);
539 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED
,2);
540 if (first_connection_to_test_url
)
542 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
543 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
545 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
546 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
547 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
548 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
549 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
550 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
551 if(test
->flags
& TESTF_REDIRECT
) {
552 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
553 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
555 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
556 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
557 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
558 if (flags
& INTERNET_FLAG_ASYNC
)
559 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
561 if(test
->flags
& TESTF_COMPRESSED
) {
564 res
= InternetSetOption(hor
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
565 ok(res
|| broken(!res
&& GetLastError() == ERROR_INTERNET_INVALID_OPTION
),
566 "InternetSetOption failed: %u\n", GetLastError());
571 test_status_code(hor
, 0);
573 trace("HttpSendRequestA -->\n");
574 if(test
->post_data
) {
575 post_len
= strlen(test
->post_data
);
576 post_data
= HeapAlloc(GetProcessHeap(), 0, post_len
);
577 memcpy(post_data
, test
->post_data
, post_len
);
579 SetLastError(0xdeadbeef);
580 res
= HttpSendRequestA(hor
, test
->headers
, -1, post_data
, post_len
);
581 if (flags
& INTERNET_FLAG_ASYNC
)
582 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
583 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
585 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
586 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
587 trace("HttpSendRequestA <--\n");
589 if (flags
& INTERNET_FLAG_ASYNC
) {
590 WaitForSingleObject(hCompleteEvent
, INFINITE
);
591 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
593 HeapFree(GetProcessHeap(), 0, post_data
);
595 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
596 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED
);
597 if (first_connection_to_test_url
)
599 if (! proxy_active())
601 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
602 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
606 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
607 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
612 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
613 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
615 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
616 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
617 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
618 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
619 if(test
->flags
& TESTF_REDIRECT
)
620 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
621 if (flags
& INTERNET_FLAG_ASYNC
)
622 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
623 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
624 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
625 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
627 test_request_flags(hor
, 0);
630 res
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
631 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
633 length
= sizeof(buffer
)-1;
634 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
635 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
638 length
= sizeof(buffer
);
639 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
640 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
641 ok(!strcmp(buffer
, test
->redirected_url
), "Wrong URL %s\n", buffer
);
644 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
645 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res
,buffer
,GetLastError());
646 if(test
->flags
& TESTF_COMPRESSED
)
647 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
648 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res
, GetLastError());
651 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
653 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res
,buffer
);
656 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_ENCODING
,buffer
,&length
,0x0);
658 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res
,buffer
);
660 SetLastError(0xdeadbeef);
661 res
= InternetReadFile(NULL
, buffer
, 100, &length
);
662 ok(!res
, "InternetReadFile should have failed\n");
663 ok(GetLastError() == ERROR_INVALID_HANDLE
,
664 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
668 trace("Entering Query loop\n");
672 if (flags
& INTERNET_FLAG_ASYNC
)
673 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
675 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
676 if (flags
& INTERNET_FLAG_ASYNC
)
680 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
682 ok(length
>= exlen
, "length %u < exlen %u\n", length
, exlen
);
686 else if (GetLastError() == ERROR_IO_PENDING
)
689 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
690 if(!(test
->flags
& TESTF_CHUNKED
))
691 ok(!length
, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length
);
692 WaitForSingleObject(hCompleteEvent
, INFINITE
);
694 ok(exlen
, "length = 0\n");
695 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
696 ok(req_error
, "req_error = 0\n");
699 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
702 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
704 trace("LENGTH %d\n", length
);
705 if(test
->flags
& TESTF_CHUNKED
)
706 ok(length
<= 8192, "length = %d, expected <= 8192\n", length
);
710 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
712 res
= InternetReadFile(hor
,buffer
,length
,&length
);
716 trace("ReadFile -> %s %i\n",res
?"TRUE":"FALSE",length
);
719 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
720 HeapFree(GetProcessHeap(),0,buffer
);
722 ok(!on_async
, "Returned zero size in response to request complete\n");
727 if(test
->flags
& TESTF_REDIRECT
) {
728 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
729 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
733 close_async_handle(hi
, hCompleteEvent
, 2);
734 CloseHandle(hCompleteEvent
);
735 first_connection_to_test_url
= FALSE
;
738 static void InternetReadFile_chunked_test(void)
743 const char *types
[2] = { "*", NULL
};
744 HINTERNET hi
, hic
= 0, hor
= 0;
746 trace("Starting InternetReadFile chunked test\n");
748 trace("InternetOpenA <--\n");
749 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
750 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
751 trace("InternetOpenA -->\n");
753 if (hi
== 0x0) goto abort
;
755 trace("InternetConnectA <--\n");
756 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
757 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
758 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
759 trace("InternetConnectA -->\n");
761 if (hic
== 0x0) goto abort
;
763 trace("HttpOpenRequestA <--\n");
764 hor
= HttpOpenRequestA(hic
, "GET", "/tests/chunked", NULL
, NULL
, types
,
765 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
767 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
769 * If the internet name can't be resolved we are probably behind
770 * a firewall or in some other way not directly connected to the
771 * Internet. Not enough reason to fail the test. Just ignore and
775 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
777 trace("HttpOpenRequestA -->\n");
779 if (hor
== 0x0) goto abort
;
781 trace("HttpSendRequestA -->\n");
782 SetLastError(0xdeadbeef);
783 res
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
784 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
785 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
786 trace("HttpSendRequestA <--\n");
788 test_request_flags(hor
, 0);
791 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
793 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
795 SetLastError( 0xdeadbeef );
797 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
799 trace("Option TRANSFER_ENCODING -> %i %s\n",res
,buffer
);
800 ok( res
|| ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
801 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
802 ok( !strcmp( buffer
, "chunked" ) || ( ! res
&& proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
803 "Wrong transfer encoding '%s'\n", buffer
);
805 SetLastError( 0xdeadbeef );
807 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
808 ok( !res
, "Found CONTENT_LENGTH option '%s'\n", buffer
);
809 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Wrong error %u\n", GetLastError() );
812 trace("Entering Query loop\n");
816 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
817 ok(!(!res
&& length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
818 ok(res
, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
819 trace("got %u available\n",length
);
823 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
825 res
= InternetReadFile(hor
,buffer
,length
,&got
);
828 trace("ReadFile -> %i %i\n",res
,got
);
829 ok( length
== got
, "only got %u of %u available\n", got
, length
);
830 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
832 HeapFree(GetProcessHeap(),0,buffer
);
841 res
= InternetCloseHandle(hor
);
842 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
845 res
= InternetCloseHandle(hi
);
846 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
850 static void InternetReadFileExA_test(int flags
)
854 const char *types
[2] = { "*", NULL
};
855 HINTERNET hi
, hic
= 0, hor
= 0;
856 INTERNET_BUFFERS inetbuffers
;
858 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
860 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
862 trace("InternetOpenA <--\n");
863 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
864 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
865 trace("InternetOpenA -->\n");
867 if (hi
== 0x0) goto abort
;
869 pInternetSetStatusCallbackA(hi
,&callback
);
871 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
873 trace("InternetConnectA <--\n");
874 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
875 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
876 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
877 trace("InternetConnectA -->\n");
879 if (hic
== 0x0) goto abort
;
881 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
882 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
884 trace("HttpOpenRequestA <--\n");
885 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
886 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
888 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
890 * If the internet name can't be resolved we are probably behind
891 * a firewall or in some other way not directly connected to the
892 * Internet. Not enough reason to fail the test. Just ignore and
896 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
898 trace("HttpOpenRequestA -->\n");
900 if (hor
== 0x0) goto abort
;
902 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
903 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
904 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
905 if (first_connection_to_test_url
)
907 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
908 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
910 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
, 2);
911 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
912 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
913 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
914 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
915 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
916 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
917 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
918 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
919 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
920 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
921 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
922 if (flags
& INTERNET_FLAG_ASYNC
)
923 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
925 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
927 trace("HttpSendRequestA -->\n");
928 SetLastError(0xdeadbeef);
929 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
930 if (flags
& INTERNET_FLAG_ASYNC
)
931 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
932 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
934 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
935 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
936 trace("HttpSendRequestA <--\n");
938 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
939 WaitForSingleObject(hCompleteEvent
, INFINITE
);
940 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
943 if (first_connection_to_test_url
)
945 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
946 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
950 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
951 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
953 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
954 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
955 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
956 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
957 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
958 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
959 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
960 if (flags
& INTERNET_FLAG_ASYNC
)
961 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
963 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
964 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
965 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
966 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
967 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
969 /* tests invalid dwStructSize */
970 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
)+1;
971 inetbuffers
.lpcszHeader
= NULL
;
972 inetbuffers
.dwHeadersLength
= 0;
973 inetbuffers
.dwBufferLength
= 10;
974 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
975 inetbuffers
.dwOffsetHigh
= 1234;
976 inetbuffers
.dwOffsetLow
= 5678;
977 rc
= InternetReadFileEx(hor
, &inetbuffers
, 0, 0xdeadcafe);
978 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
979 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
980 rc
? "TRUE" : "FALSE", GetLastError());
981 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
983 test_request_flags(hor
, 0);
985 /* tests to see whether lpcszHeader is used - it isn't */
986 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
);
987 inetbuffers
.lpcszHeader
= (LPCTSTR
)0xdeadbeef;
988 inetbuffers
.dwHeadersLength
= 255;
989 inetbuffers
.dwBufferLength
= 0;
990 inetbuffers
.lpvBuffer
= NULL
;
991 inetbuffers
.dwOffsetHigh
= 1234;
992 inetbuffers
.dwOffsetLow
= 5678;
993 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
994 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
995 rc
= InternetReadFileEx(hor
, &inetbuffers
, 0, 0xdeadcafe);
996 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
997 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1000 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1001 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1004 rc
= InternetReadFileEx(NULL
, &inetbuffers
, 0, 0xdeadcafe);
1005 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
1006 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1007 rc
? "TRUE" : "FALSE", GetLastError());
1010 trace("Entering Query loop\n");
1014 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
);
1015 inetbuffers
.dwBufferLength
= 1024;
1016 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
1017 inetbuffers
.dwOffsetHigh
= 1234;
1018 inetbuffers
.dwOffsetLow
= 5678;
1020 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1021 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1022 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1023 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
1026 if (GetLastError() == ERROR_IO_PENDING
)
1028 trace("InternetReadFileEx -> PENDING\n");
1029 ok(flags
& INTERNET_FLAG_ASYNC
,
1030 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1031 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1032 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1033 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1034 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1035 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1039 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1045 trace("InternetReadFileEx -> SUCCEEDED\n");
1046 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1047 if (inetbuffers
.dwBufferLength
)
1050 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1051 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1056 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1057 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1058 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1062 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1063 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
1065 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
1066 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1067 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
1069 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1071 if (!inetbuffers
.dwBufferLength
)
1074 length
+= inetbuffers
.dwBufferLength
;
1076 ok(length
> 0, "failed to read any of the document\n");
1077 trace("Finished. Read %d bytes\n", length
);
1080 close_async_handle(hi
, hCompleteEvent
, 2);
1081 CloseHandle(hCompleteEvent
);
1082 first_connection_to_test_url
= FALSE
;
1085 static void InternetOpenUrlA_test(void)
1087 HINTERNET myhinternet
, myhttp
;
1089 DWORD size
, readbytes
, totalbytes
=0;
1092 ret
= DeleteUrlCacheEntry(TEST_URL
);
1093 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
1094 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret
, GetLastError());
1096 myhinternet
= InternetOpen("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
1097 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
1099 ret
= InternetCanonicalizeUrl(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1100 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1103 myhttp
= InternetOpenUrl(myhinternet
, TEST_URL
, 0, 0,
1104 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
1105 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1106 return; /* WinXP returns this when not connected to the net */
1107 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1108 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
1109 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
1110 totalbytes
+= readbytes
;
1111 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
1112 totalbytes
+= readbytes
;
1113 trace("read 0x%08x bytes\n",totalbytes
);
1115 InternetCloseHandle(myhttp
);
1116 InternetCloseHandle(myhinternet
);
1118 ret
= DeleteUrlCacheEntry(TEST_URL
);
1119 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1122 static void HttpSendRequestEx_test(void)
1128 INTERNET_BUFFERS BufferIn
;
1129 DWORD dwBytesWritten
, dwBytesRead
, error
;
1134 static char szPostData
[] = "mode=Test";
1135 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
1137 hSession
= InternetOpen("Wine Regression Test",
1138 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1139 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1140 hConnect
= InternetConnect(hSession
, "crossover.codeweavers.com",
1141 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1143 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
1144 hRequest
= HttpOpenRequest(hConnect
, "POST", "/posttest.php",
1145 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1146 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1148 skip( "Network unreachable, skipping test\n" );
1151 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1153 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1155 BufferIn
.dwStructSize
= sizeof( INTERNET_BUFFERS
);
1156 BufferIn
.Next
= (LPINTERNET_BUFFERS
)0xdeadcab;
1157 BufferIn
.lpcszHeader
= szContentType
;
1158 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1159 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1160 BufferIn
.lpvBuffer
= szPostData
;
1161 BufferIn
.dwBufferLength
= 3;
1162 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1163 BufferIn
.dwOffsetLow
= 0;
1164 BufferIn
.dwOffsetHigh
= 0;
1166 SetLastError(0xdeadbeef);
1167 ret
= HttpSendRequestEx(hRequest
, &BufferIn
, NULL
, 0 ,0);
1168 error
= GetLastError();
1169 ok(ret
, "HttpSendRequestEx Failed with error %u\n", error
);
1170 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", error
);
1172 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1174 for (i
= 3; szPostData
[i
]; i
++)
1175 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1176 "InternetWriteFile failed\n");
1178 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1180 ok(HttpEndRequest(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1182 test_request_flags(hRequest
, 0);
1184 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1185 "Unable to read response\n");
1186 szBuffer
[dwBytesRead
] = 0;
1188 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
1189 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1191 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1193 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1194 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1197 static void InternetOpenRequest_test(void)
1199 HINTERNET session
, connect
, request
;
1200 static const char *types
[] = { "*", "", NULL
};
1201 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1202 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1205 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1206 ok(session
!= NULL
,"Unable to open Internet session\n");
1208 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1209 INTERNET_SERVICE_HTTP
, 0, 0);
1210 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1211 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1213 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1214 INTERNET_SERVICE_HTTP
, 0, 0);
1215 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1216 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1218 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1219 INTERNET_SERVICE_HTTP
, 0, 0);
1220 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1222 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1223 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1225 skip( "Network unreachable, skipping test\n" );
1228 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1230 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1231 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1232 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1234 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1235 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1237 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1238 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1239 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1242 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1243 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1246 static void test_cache_read(void)
1248 HINTERNET session
, connection
, req
;
1249 FILETIME now
, tomorrow
, yesterday
;
1250 BYTE content
[1000], buf
[2000];
1251 char file_path
[MAX_PATH
];
1258 static const char cache_only_url
[] = "http://test.winehq.org/tests/cache-only";
1259 BYTE cache_headers
[] = "HTTP/1.1 200 OK\r\n\r\n";
1261 trace("Testing cache read...\n");
1263 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
1265 for(i
= 0; i
< sizeof(content
); i
++)
1266 content
[i
] = '0' + (i
%10);
1268 GetSystemTimeAsFileTime(&now
);
1269 li
.u
.HighPart
= now
.dwHighDateTime
;
1270 li
.u
.LowPart
= now
.dwLowDateTime
;
1271 li
.QuadPart
+= (LONGLONG
)10000000 * 3600 * 24;
1272 tomorrow
.dwHighDateTime
= li
.u
.HighPart
;
1273 tomorrow
.dwLowDateTime
= li
.u
.LowPart
;
1274 li
.QuadPart
-= (LONGLONG
)10000000 * 3600 * 24 * 2;
1275 yesterday
.dwHighDateTime
= li
.u
.HighPart
;
1276 yesterday
.dwLowDateTime
= li
.u
.LowPart
;
1278 res
= CreateUrlCacheEntryA(cache_only_url
, sizeof(content
), "", file_path
, 0);
1279 ok(res
, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1281 file
= CreateFileA(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1282 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
1284 WriteFile(file
, content
, sizeof(content
), &size
, NULL
);
1287 res
= CommitUrlCacheEntryA(cache_only_url
, file_path
, tomorrow
, yesterday
, NORMAL_CACHE_ENTRY
,
1288 cache_headers
, sizeof(cache_headers
)-1, "", 0);
1289 ok(res
, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1291 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
1292 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
1294 pInternetSetStatusCallbackA(session
, callback
);
1296 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1297 connection
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
,
1298 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1299 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
1300 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1302 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1303 req
= HttpOpenRequestA(connection
, "GET", "/tests/cache-only", NULL
, NULL
, NULL
, 0, 0xdeadbead);
1304 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
1305 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1307 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1308 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1309 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST
);
1310 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT
);
1311 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1312 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1313 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1315 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
1317 ok(res
, "HttpSendRequest failed: %u\n", GetLastError());
1321 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
1322 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1323 ok(size
== sizeof(content
), "size = %u\n", size
);
1326 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
1327 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
1328 ok(size
== sizeof(content
), "size = %u\n", size
);
1329 ok(!memcmp(content
, buf
, sizeof(content
)), "unexpected content\n");
1332 close_async_handle(session
, hCompleteEvent
, 2);
1334 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1335 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1336 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
1337 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
1338 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1339 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1340 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1342 res
= DeleteUrlCacheEntryA(cache_only_url
);
1343 ok(res
, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1345 CloseHandle(hCompleteEvent
);
1348 static void test_http_cache(void)
1350 HINTERNET session
, connect
, request
;
1351 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1352 DWORD size
, file_size
;
1357 static const char *types
[] = { "*", "", NULL
};
1359 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1360 ok(session
!= NULL
,"Unable to open Internet session\n");
1362 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1363 INTERNET_SERVICE_HTTP
, 0, 0);
1364 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1366 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1367 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1369 skip( "Network unreachable, skipping test\n" );
1371 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1372 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1376 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1379 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1380 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1381 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1383 size
= sizeof(file_name
);
1384 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1385 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1386 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1387 ok(!size
, "size = %d\n", size
);
1389 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1390 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1392 size
= sizeof(file_name
);
1393 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1394 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1396 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1397 FILE_ATTRIBUTE_NORMAL
, NULL
);
1398 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1399 file_size
= GetFileSize(file
, NULL
);
1400 ok(file_size
== 106, "file size = %u\n", file_size
);
1403 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1404 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1405 ok(size
== 100, "size = %u\n", size
);
1407 file_size
= GetFileSize(file
, NULL
);
1408 ok(file_size
== 106, "file size = %u\n", file_size
);
1411 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1413 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1414 FILE_ATTRIBUTE_NORMAL
, NULL
);
1415 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1418 /* Send the same request, requiring it to be retrieved from the cache */
1419 request
= HttpOpenRequest(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1421 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1422 ok(ret
, "HttpSendRequest failed\n");
1425 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1426 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1427 ok(size
== 100, "size = %u\n", size
);
1429 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1431 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1432 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1434 size
= sizeof(file_name
);
1435 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1436 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1437 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1438 ok(!size
, "size = %d\n", size
);
1440 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1441 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1443 size
= sizeof(file_name
);
1445 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1448 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1449 FILE_ATTRIBUTE_NORMAL
, NULL
);
1450 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1456 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1459 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1460 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1461 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1466 static void HttpHeaders_test(void)
1477 hSession
= InternetOpen("Wine Regression Test",
1478 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1479 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1480 hConnect
= InternetConnect(hSession
, "crossover.codeweavers.com",
1481 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1483 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
1484 hRequest
= HttpOpenRequest(hConnect
, "POST", "/posttest.php",
1485 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1486 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1488 skip( "Network unreachable, skipping test\n" );
1491 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1494 len
= sizeof(buffer
);
1495 strcpy(buffer
,"Warning");
1496 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1497 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1499 ok(HttpAddRequestHeaders(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1500 "Failed to add new header\n");
1503 len
= sizeof(buffer
);
1504 strcpy(buffer
,"Warning");
1505 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1506 buffer
,&len
,&index
),"Unable to query header\n");
1507 ok(index
== 1, "Index was not incremented\n");
1508 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1509 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1510 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1511 len
= sizeof(buffer
);
1512 strcpy(buffer
,"Warning");
1513 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1514 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1517 len
= 5; /* could store the string but not the NULL terminator */
1518 strcpy(buffer
,"Warning");
1519 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1520 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1521 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1522 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1524 /* a call with NULL will fail but will return the length */
1526 len
= sizeof(buffer
);
1527 SetLastError(0xdeadbeef);
1528 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1529 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1530 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1531 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1532 ok(index
== 0, "Index was incremented\n");
1534 /* even for a len that is too small */
1537 SetLastError(0xdeadbeef);
1538 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1539 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1540 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1541 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1542 ok(index
== 0, "Index was incremented\n");
1546 SetLastError(0xdeadbeef);
1547 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1548 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1549 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1550 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1551 ok(index
== 0, "Index was incremented\n");
1552 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1555 /* a working query */
1557 len
= sizeof(buffer
);
1558 memset(buffer
, 'x', sizeof(buffer
));
1559 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1560 buffer
,&len
,&index
),"Unable to query header\n");
1561 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1562 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1563 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1564 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1565 ok(strncmp(buffer
, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1566 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1567 ok(index
== 0, "Index was incremented\n");
1569 /* Like above two tests, but for W version */
1573 SetLastError(0xdeadbeef);
1574 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1575 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1576 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1577 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1578 ok(index
== 0, "Index was incremented\n");
1579 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1581 /* a working query */
1583 len
= sizeof(wbuffer
);
1584 memset(wbuffer
, 'x', sizeof(wbuffer
));
1585 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1586 wbuffer
,&len
,&index
),"Unable to query header\n");
1587 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1588 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1589 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1590 ok(index
== 0, "Index was incremented\n");
1592 /* end of W version tests */
1594 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1596 len
= sizeof(buffer
);
1597 memset(buffer
, 'x', sizeof(buffer
));
1598 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1599 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1600 ok(len
== 2, "Expected 2, got %d\n", len
);
1601 ok(strcmp(buffer
, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer
);
1602 ok(index
== 0, "Index was incremented\n");
1604 ok(HttpAddRequestHeaders(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1605 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1608 len
= sizeof(buffer
);
1609 strcpy(buffer
,"Warning");
1610 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1611 buffer
,&len
,&index
),"Unable to query header\n");
1612 ok(index
== 1, "Index was not incremented\n");
1613 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1614 len
= sizeof(buffer
);
1615 strcpy(buffer
,"Warning");
1616 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1617 buffer
,&len
,&index
),"Failed to get second header\n");
1618 ok(index
== 2, "Index was not incremented\n");
1619 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1620 len
= sizeof(buffer
);
1621 strcpy(buffer
,"Warning");
1622 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1623 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1625 ok(HttpAddRequestHeaders(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1628 len
= sizeof(buffer
);
1629 strcpy(buffer
,"Warning");
1630 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1631 buffer
,&len
,&index
),"Unable to query header\n");
1632 ok(index
== 1, "Index was not incremented\n");
1633 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1634 len
= sizeof(buffer
);
1635 strcpy(buffer
,"Warning");
1636 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1637 buffer
,&len
,&index
),"Failed to get second header\n");
1638 ok(index
== 2, "Index was not incremented\n");
1639 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1640 len
= sizeof(buffer
);
1641 strcpy(buffer
,"Warning");
1642 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1643 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1645 ok(HttpAddRequestHeaders(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1648 len
= sizeof(buffer
);
1649 strcpy(buffer
,"Warning");
1650 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1651 buffer
,&len
,&index
),"Unable to query header\n");
1652 ok(index
== 1, "Index was not incremented\n");
1653 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1654 len
= sizeof(buffer
);
1655 strcpy(buffer
,"Warning");
1656 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1657 buffer
,&len
,&index
),"Failed to get second header\n");
1658 ok(index
== 2, "Index was not incremented\n");
1659 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1660 len
= sizeof(buffer
);
1661 strcpy(buffer
,"Warning");
1662 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1663 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1665 ok(HttpAddRequestHeaders(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1668 len
= sizeof(buffer
);
1669 strcpy(buffer
,"Warning");
1670 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1671 buffer
,&len
,&index
),"Unable to query header\n");
1672 ok(index
== 1, "Index was not incremented\n");
1673 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1674 len
= sizeof(buffer
);
1675 strcpy(buffer
,"Warning");
1676 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1677 ok(index
== 2, "Index was not incremented\n");
1678 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1679 len
= sizeof(buffer
);
1680 strcpy(buffer
,"Warning");
1681 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1683 ok(HttpAddRequestHeaders(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1686 len
= sizeof(buffer
);
1687 strcpy(buffer
,"Warning");
1688 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1689 ok(index
== 1, "Index was not incremented\n");
1690 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1691 len
= sizeof(buffer
);
1692 strcpy(buffer
,"Warning");
1693 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1694 ok(index
== 2, "Index was not incremented\n");
1695 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1696 len
= sizeof(buffer
);
1697 strcpy(buffer
,"Warning");
1698 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1700 ok(HttpAddRequestHeaders(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1703 len
= sizeof(buffer
);
1704 strcpy(buffer
,"Warning");
1705 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1706 ok(index
== 1, "Index was not incremented\n");
1707 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1708 len
= sizeof(buffer
);
1709 strcpy(buffer
,"Warning");
1710 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1711 ok(index
== 2, "Index was not incremented\n");
1712 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1713 len
= sizeof(buffer
);
1714 strcpy(buffer
,"Warning");
1715 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1717 ok(HttpAddRequestHeaders(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");
1720 len
= sizeof(buffer
);
1721 strcpy(buffer
,"Warning");
1722 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1723 ok(index
== 1, "Index was not incremented\n");
1724 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1725 len
= sizeof(buffer
);
1726 strcpy(buffer
,"Warning");
1727 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1728 ok(index
== 2, "Index was not incremented\n");
1729 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1730 len
= sizeof(buffer
);
1731 strcpy(buffer
,"Warning");
1732 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1734 /* Ensure that blank headers are ignored and don't cause a failure */
1735 ok(HttpAddRequestHeaders(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");
1738 len
= sizeof(buffer
);
1739 strcpy(buffer
,"BlankTest");
1740 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1741 ok(index
== 1, "Index was not incremented\n");
1742 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1744 /* Ensure that malformed header separators are ignored and don't cause a failure */
1745 ok(HttpAddRequestHeaders(hRequest
,"\r\rMalformedTest:value\n\nMalformedTestTwo: value2\rMalformedTestThree: value3\n\n\r\r\n",-1, HTTP_ADDREQ_FLAG_ADD
|HTTP_ADDREQ_FLAG_REPLACE
),
1746 "Failed to add header with malformed entries in list\n");
1749 len
= sizeof(buffer
);
1750 strcpy(buffer
,"MalformedTest");
1751 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1752 ok(index
== 1, "Index was not incremented\n");
1753 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1755 len
= sizeof(buffer
);
1756 strcpy(buffer
,"MalformedTestTwo");
1757 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1758 ok(index
== 1, "Index was not incremented\n");
1759 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
1761 len
= sizeof(buffer
);
1762 strcpy(buffer
,"MalformedTestThree");
1763 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1764 ok(index
== 1, "Index was not incremented\n");
1765 ok(strcmp(buffer
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
1767 ok(HttpAddRequestHeaders(hRequest
, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD
),
1768 "unable to add header %u\n", GetLastError());
1772 len
= sizeof(buffer
);
1773 ok(HttpQueryInfo(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
),
1774 "unable to query header %u\n", GetLastError());
1775 ok(index
== 1, "index was not incremented\n");
1776 ok(!strcmp(buffer
, "Basic"), "incorrect string was returned (%s)\n", buffer
);
1778 ok(HttpAddRequestHeaders(hRequest
, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE
),
1779 "unable to remove header %u\n", GetLastError());
1782 len
= sizeof(buffer
);
1783 SetLastError(0xdeadbeef);
1784 ok(!HttpQueryInfo(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
),
1785 "header still present\n");
1786 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "got %u\n", GetLastError());
1788 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1790 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1791 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1794 static const char garbagemsg
[] =
1795 "Garbage: Header\r\n";
1797 static const char contmsg
[] =
1798 "HTTP/1.1 100 Continue\r\n";
1800 static const char expandcontmsg
[] =
1801 "HTTP/1.1 100 Continue\r\n"
1802 "Server: winecontinue\r\n"
1803 "Tag: something witty\r\n"
1806 static const char okmsg
[] =
1807 "HTTP/1.1 200 OK\r\n"
1808 "Server: winetest\r\n"
1811 static const char okmsg2
[] =
1812 "HTTP/1.1 200 OK\r\n"
1813 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1814 "Server: winetest\r\n"
1815 "Content-Length: 0\r\n"
1816 "Set-Cookie: one\r\n"
1817 "Set-Cookie: two\r\n"
1820 static const char notokmsg
[] =
1821 "HTTP/1.1 400 Bad Request\r\n"
1822 "Server: winetest\r\n"
1825 static const char noauthmsg
[] =
1826 "HTTP/1.1 401 Unauthorized\r\n"
1827 "Server: winetest\r\n"
1828 "Connection: close\r\n"
1829 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1832 static const char noauthmsg2
[] =
1833 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
1834 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
1836 "Server: winetest\r\n";
1838 static const char proxymsg
[] =
1839 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1840 "Server: winetest\r\n"
1841 "Proxy-Connection: close\r\n"
1842 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1845 static const char page1
[] =
1847 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1848 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1851 static const char ok_with_length
[] =
1852 "HTTP/1.1 200 OK\r\n"
1853 "Connection: Keep-Alive\r\n"
1854 "Content-Length: 23\r\n\r\n"
1855 "abc\r\nHTTP/1.1 211 OK\r\n\r\n";
1857 static const char ok_with_length2
[] =
1858 "HTTP/1.1 210 OK\r\n"
1859 "Connection: Keep-Alive\r\n"
1860 "Content-Length: 24\r\n\r\n"
1861 "abc\r\nHTTP/1.1 211 OK\r\n\r\n";
1863 struct server_info
{
1868 static int test_cache_gzip
;
1869 static const char *send_buffer
;
1871 static DWORD CALLBACK
server_thread(LPVOID param
)
1873 struct server_info
*si
= param
;
1874 int r
, c
, i
, on
, count
= 0;
1876 struct sockaddr_in sa
;
1879 int last_request
= 0;
1880 char host_header
[22];
1881 static int test_b
= 0;
1882 static int test_no_cache
= 0;
1884 WSAStartup(MAKEWORD(1,1), &wsaData
);
1886 s
= socket(AF_INET
, SOCK_STREAM
, 0);
1887 if (s
== INVALID_SOCKET
)
1891 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
1893 memset(&sa
, 0, sizeof sa
);
1894 sa
.sin_family
= AF_INET
;
1895 sa
.sin_port
= htons(si
->port
);
1896 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
1898 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
1904 SetEvent(si
->hEvent
);
1906 sprintf(host_header
, "Host: localhost:%d", si
->port
);
1910 c
= accept(s
, NULL
, NULL
);
1912 memset(buffer
, 0, sizeof buffer
);
1913 for(i
=0; i
<(sizeof buffer
-1); i
++)
1915 r
= recv(c
, &buffer
[i
], 1, 0);
1919 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
1920 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
1923 if (strstr(buffer
, "GET /test1"))
1925 if (!strstr(buffer
, "Content-Length: 0"))
1927 send(c
, okmsg
, sizeof okmsg
-1, 0);
1928 send(c
, page1
, sizeof page1
-1, 0);
1931 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1933 if (strstr(buffer
, "/test2"))
1935 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
1937 send(c
, okmsg
, sizeof okmsg
-1, 0);
1938 send(c
, page1
, sizeof page1
-1, 0);
1941 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
1943 if (strstr(buffer
, "/test3"))
1945 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
1946 send(c
, okmsg
, sizeof okmsg
-1, 0);
1948 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
1950 if (strstr(buffer
, "/test4"))
1952 if (strstr(buffer
, "Connection: Close"))
1953 send(c
, okmsg
, sizeof okmsg
-1, 0);
1955 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1957 if (strstr(buffer
, "POST /test5") ||
1958 strstr(buffer
, "RPC_IN_DATA /test5") ||
1959 strstr(buffer
, "RPC_OUT_DATA /test5"))
1961 if (strstr(buffer
, "Content-Length: 0"))
1963 send(c
, okmsg
, sizeof okmsg
-1, 0);
1964 send(c
, page1
, sizeof page1
-1, 0);
1967 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1969 if (strstr(buffer
, "GET /test6"))
1971 send(c
, contmsg
, sizeof contmsg
-1, 0);
1972 send(c
, contmsg
, sizeof contmsg
-1, 0);
1973 send(c
, okmsg
, sizeof okmsg
-1, 0);
1974 send(c
, page1
, sizeof page1
-1, 0);
1976 if (strstr(buffer
, "POST /test7"))
1978 if (strstr(buffer
, "Content-Length: 100"))
1980 send(c
, okmsg
, sizeof okmsg
-1, 0);
1981 send(c
, page1
, sizeof page1
-1, 0);
1984 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1986 if (strstr(buffer
, "/test8"))
1988 if (!strstr(buffer
, "Connection: Close") &&
1989 strstr(buffer
, "Connection: Keep-Alive") &&
1990 !strstr(buffer
, "Cache-Control: no-cache") &&
1991 !strstr(buffer
, "Pragma: no-cache") &&
1992 strstr(buffer
, host_header
))
1993 send(c
, okmsg
, sizeof okmsg
-1, 0);
1995 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1997 if (strstr(buffer
, "/test9"))
1999 if (!strstr(buffer
, "Connection: Close") &&
2000 !strstr(buffer
, "Connection: Keep-Alive") &&
2001 !strstr(buffer
, "Cache-Control: no-cache") &&
2002 !strstr(buffer
, "Pragma: no-cache") &&
2003 strstr(buffer
, host_header
))
2004 send(c
, okmsg
, sizeof okmsg
-1, 0);
2006 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2008 if (strstr(buffer
, "/testA"))
2010 if (!strstr(buffer
, "Connection: Close") &&
2011 !strstr(buffer
, "Connection: Keep-Alive") &&
2012 (strstr(buffer
, "Cache-Control: no-cache") ||
2013 strstr(buffer
, "Pragma: no-cache")) &&
2014 strstr(buffer
, host_header
))
2015 send(c
, okmsg
, sizeof okmsg
-1, 0);
2017 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2019 if (!test_b
&& strstr(buffer
, "/testB HTTP/1.1"))
2022 send(c
, okmsg
, sizeof okmsg
-1, 0);
2023 recvfrom(c
, buffer
, sizeof buffer
, 0, NULL
, NULL
);
2024 send(c
, okmsg
, sizeof okmsg
-1, 0);
2026 if (strstr(buffer
, "/testC"))
2028 if (strstr(buffer
, "Cookie: cookie=biscuit"))
2029 send(c
, okmsg
, sizeof okmsg
-1, 0);
2031 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2033 if (strstr(buffer
, "/testD"))
2035 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
2037 if (strstr(buffer
, "/testE"))
2039 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
2041 if (strstr(buffer
, "GET /quit"))
2043 send(c
, okmsg
, sizeof okmsg
-1, 0);
2044 send(c
, page1
, sizeof page1
-1, 0);
2047 if (strstr(buffer
, "GET /testF"))
2049 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
2050 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2051 send(c
, contmsg
, sizeof contmsg
-1, 0);
2052 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2053 send(c
, okmsg
, sizeof okmsg
-1, 0);
2054 send(c
, page1
, sizeof page1
-1, 0);
2056 if (strstr(buffer
, "GET /testG"))
2058 send(c
, page1
, sizeof page1
-1, 0);
2061 if (strstr(buffer
, "GET /testJ"))
2066 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2070 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2075 if (strstr(buffer
, "GET /test_no_content"))
2077 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2078 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2080 if (strstr(buffer
, "GET /test_conn_close"))
2082 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2083 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
2084 WaitForSingleObject(conn_close_event
, INFINITE
);
2085 trace("closing connection\n");
2087 if (strstr(buffer
, "GET /test_cache_control_no_cache"))
2089 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2090 if(!test_no_cache
++)
2091 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2093 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2095 if (strstr(buffer
, "GET /test_cache_control_no_store"))
2097 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2098 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2100 if (strstr(buffer
, "GET /test_cache_gzip"))
2102 static const char gzip_response
[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2103 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2104 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2105 if(!test_cache_gzip
++)
2106 send(c
, gzip_response
, sizeof(gzip_response
), 0);
2108 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2110 if (strstr(buffer
, "GET /send_from_buffer"))
2111 send(c
, send_buffer
, strlen(send_buffer
), 0);
2112 if (strstr(buffer
, "/test_cache_control_verb"))
2114 if (!memcmp(buffer
, "GET ", sizeof("GET ")-1) &&
2115 !strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2116 else if (strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2117 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2119 if (strstr(buffer
, "GET /test_premature_disconnect"))
2120 trace("closing connection\n");
2124 } while (!last_request
);
2131 static void test_basic_request(int port
, const char *verb
, const char *url
)
2133 HINTERNET hi
, hc
, hr
;
2137 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2138 ok(hi
!= NULL
, "open failed\n");
2140 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2141 ok(hc
!= NULL
, "connect failed\n");
2143 hr
= HttpOpenRequest(hc
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
2144 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2146 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
2147 ok(r
, "HttpSendRequest failed\n");
2150 memset(buffer
, 0, sizeof buffer
);
2151 SetLastError(0xdeadbeef);
2152 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
2153 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2154 ok(count
== sizeof page1
- 1, "count was wrong\n");
2155 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2157 InternetCloseHandle(hr
);
2158 InternetCloseHandle(hc
);
2159 InternetCloseHandle(hi
);
2162 static void test_last_error(int port
)
2164 HINTERNET hi
, hc
, hr
;
2168 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2169 ok(hi
!= NULL
, "open failed\n");
2171 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2172 ok(hc
!= NULL
, "connect failed\n");
2174 hr
= HttpOpenRequest(hc
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
2175 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2177 SetLastError(0xdeadbeef);
2178 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
2179 error
= GetLastError();
2180 ok(r
, "HttpSendRequest failed\n");
2181 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
2183 InternetCloseHandle(hr
);
2184 InternetCloseHandle(hc
);
2185 InternetCloseHandle(hi
);
2188 static void test_proxy_indirect(int port
)
2190 HINTERNET hi
, hc
, hr
;
2194 hi
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
2195 ok(hi
!= NULL
, "open failed\n");
2197 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2198 ok(hc
!= NULL
, "connect failed\n");
2200 hr
= HttpOpenRequest(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2201 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2203 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
2204 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2207 r
= HttpQueryInfo(hr
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2208 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
2211 skip("missing proxy header, not testing remaining proxy headers\n");
2214 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2216 test_status_code(hr
, 407);
2217 test_request_flags(hr
, 0);
2220 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2221 ok(r
, "HttpQueryInfo failed\n");
2222 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2225 r
= HttpQueryInfo(hr
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2226 ok(r
, "HttpQueryInfo failed\n");
2227 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2230 r
= HttpQueryInfo(hr
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2231 ok(r
, "HttpQueryInfo failed\n");
2232 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2235 r
= HttpQueryInfo(hr
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2236 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2237 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2240 InternetCloseHandle(hr
);
2241 InternetCloseHandle(hc
);
2242 InternetCloseHandle(hi
);
2245 static void test_proxy_direct(int port
)
2247 HINTERNET hi
, hc
, hr
;
2249 char buffer
[0x40], *url
;
2250 WCHAR bufferW
[0x40];
2251 static CHAR username
[] = "mike",
2252 password
[] = "1101",
2253 useragent
[] = "winetest",
2254 url_fmt
[] = "http://test.winehq.org:%u/test2";
2255 static WCHAR usernameW
[] = {'m','i','k','e',0},
2256 passwordW
[] = {'1','1','0','1',0},
2257 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2259 /* specify proxy type without the proxy and bypass */
2260 SetLastError(0xdeadbeef);
2261 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2262 error
= GetLastError();
2263 ok(error
== ERROR_INVALID_PARAMETER
||
2264 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %u\n", error
);
2265 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2267 sprintf(buffer
, "localhost:%d\n", port
);
2268 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2269 ok(hi
!= NULL
, "open failed\n");
2271 /* try connect without authorization */
2272 hc
= InternetConnect(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2273 ok(hc
!= NULL
, "connect failed\n");
2275 hr
= HttpOpenRequest(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2276 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2279 SetLastError(0xdeadbeef);
2280 r
= InternetQueryOption(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
2281 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2282 ok(!r
, "unexpected success\n");
2283 ok(sz
== 1, "got %u\n", sz
);
2286 SetLastError(0xdeadbeef);
2287 r
= InternetQueryOption(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
2288 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2289 ok(!r
, "unexpected success\n");
2290 ok(sz
== 1, "got %u\n", sz
);
2292 sz
= sizeof(buffer
);
2293 SetLastError(0xdeadbeef);
2294 r
= InternetQueryOption(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2295 ok(r
, "unexpected failure %u\n", GetLastError());
2296 ok(!sz
, "got %u\n", sz
);
2298 sz
= sizeof(buffer
);
2299 SetLastError(0xdeadbeef);
2300 r
= InternetQueryOption(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2301 ok(r
, "unexpected failure %u\n", GetLastError());
2302 ok(!sz
, "got %u\n", sz
);
2305 SetLastError(0xdeadbeef);
2306 r
= InternetQueryOption(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
2307 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2308 ok(!r
, "unexpected success\n");
2309 ok(sz
== 1, "got %u\n", sz
);
2312 SetLastError(0xdeadbeef);
2313 r
= InternetQueryOption(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
2314 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2315 ok(!r
, "unexpected success\n");
2316 ok(sz
== 1, "got %u\n", sz
);
2318 sz
= sizeof(buffer
);
2319 SetLastError(0xdeadbeef);
2320 r
= InternetQueryOption(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2321 ok(r
, "unexpected failure %u\n", GetLastError());
2322 ok(!sz
, "got %u\n", sz
);
2324 sz
= sizeof(buffer
);
2325 SetLastError(0xdeadbeef);
2326 r
= InternetQueryOption(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2327 ok(r
, "unexpected failure %u\n", GetLastError());
2328 ok(!sz
, "got %u\n", sz
);
2331 SetLastError(0xdeadbeef);
2332 r
= InternetQueryOption(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
2333 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2334 ok(!r
, "unexpected success\n");
2335 ok(sz
== 34, "got %u\n", sz
);
2337 sz
= sizeof(buffer
);
2338 SetLastError(0xdeadbeef);
2339 r
= InternetQueryOption(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2340 ok(r
, "unexpected failure %u\n", GetLastError());
2341 ok(sz
== 33, "got %u\n", sz
);
2343 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
2344 ok(r
|| broken(!r
), "HttpSendRequest failed %u\n", GetLastError());
2347 win_skip("skipping proxy tests on broken wininet\n");
2351 test_status_code(hr
, 407);
2353 /* set the user + password then try again */
2354 r
= InternetSetOption(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2355 ok(!r
, "unexpected success\n");
2357 r
= InternetSetOption(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2358 ok(r
, "failed to set user\n");
2360 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2361 ok(r
, "failed to set user\n");
2365 SetLastError(0xdeadbeef);
2366 r
= InternetQueryOption(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2367 ok(!r
, "unexpected failure %u\n", GetLastError());
2368 ok(!buffer
[0], "got %s\n", buffer
);
2369 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2373 SetLastError(0xdeadbeef);
2374 r
= InternetQueryOption(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2375 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2376 ok(!r
, "unexpected success\n");
2377 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2381 SetLastError(0xdeadbeef);
2382 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2383 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2384 ok(!r
, "unexpected success\n");
2385 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2388 sz
= sizeof(buffer
);
2389 r
= InternetQueryOption(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2390 ok(r
, "failed to get username\n");
2391 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2392 ok(sz
== strlen(username
), "got %u\n", sz
);
2395 sz
= sizeof(bufferW
);
2396 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2397 ok(r
, "failed to get username\n");
2398 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
2399 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2401 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
2402 ok(r
, "failed to set user\n");
2405 sz
= sizeof(buffer
);
2406 r
= InternetQueryOption(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2407 ok(r
, "failed to get username\n");
2408 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2409 ok(sz
== strlen(username
), "got %u\n", sz
);
2411 r
= InternetSetOption(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
2412 ok(r
, "failed to set useragent\n");
2416 SetLastError(0xdeadbeef);
2417 r
= InternetQueryOption(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2418 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2419 ok(!r
, "unexpected success\n");
2420 ok(sz
== strlen(useragent
) + 1, "got %u\n", sz
);
2423 sz
= sizeof(buffer
);
2424 r
= InternetQueryOption(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2425 ok(r
, "failed to get user agent\n");
2426 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
2427 ok(sz
== strlen(useragent
), "got %u\n", sz
);
2431 SetLastError(0xdeadbeef);
2432 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2433 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2434 ok(!r
, "unexpected success\n");
2435 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2438 sz
= sizeof(bufferW
);
2439 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2440 ok(r
, "failed to get user agent\n");
2441 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
2442 ok(sz
== lstrlenW(useragentW
), "got %u\n", sz
);
2444 r
= InternetSetOption(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
2445 ok(r
, "failed to set user\n");
2449 SetLastError(0xdeadbeef);
2450 r
= InternetQueryOption(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2451 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2452 ok(!r
, "unexpected success\n");
2453 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2456 sz
= sizeof(buffer
);
2457 r
= InternetQueryOption(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2458 ok(r
, "failed to get user\n");
2459 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2460 ok(sz
== strlen(username
), "got %u\n", sz
);
2464 SetLastError(0xdeadbeef);
2465 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2466 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2467 ok(!r
, "unexpected success\n");
2468 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2471 sz
= sizeof(bufferW
);
2472 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2473 ok(r
, "failed to get user\n");
2474 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
2475 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2477 r
= InternetSetOption(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
2478 ok(r
, "failed to set password\n");
2482 SetLastError(0xdeadbeef);
2483 r
= InternetQueryOption(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2484 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2485 ok(!r
, "unexpected success\n");
2486 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2489 sz
= sizeof(buffer
);
2490 r
= InternetQueryOption(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2491 ok(r
, "failed to get password\n");
2492 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2493 ok(sz
== strlen(password
), "got %u\n", sz
);
2497 SetLastError(0xdeadbeef);
2498 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2499 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2500 ok(!r
, "unexpected success\n");
2501 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2504 sz
= sizeof(bufferW
);
2505 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2506 ok(r
, "failed to get password\n");
2507 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2508 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2510 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
2511 sprintf(url
, url_fmt
, port
);
2514 SetLastError(0xdeadbeef);
2515 r
= InternetQueryOption(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2516 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2517 ok(!r
, "unexpected success\n");
2518 ok(sz
== strlen(url
) + 1, "got %u\n", sz
);
2521 sz
= sizeof(buffer
);
2522 r
= InternetQueryOption(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2523 ok(r
, "failed to get url\n");
2524 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
2525 ok(sz
== strlen(url
), "got %u\n", sz
);
2529 SetLastError(0xdeadbeef);
2530 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2531 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2532 ok(!r
, "unexpected success\n");
2533 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2536 sz
= sizeof(bufferW
);
2537 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2538 ok(r
, "failed to get url\n");
2539 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
2540 ok(sz
== strlen(url
), "got %u\n", sz
);
2541 HeapFree(GetProcessHeap(), 0, url
);
2543 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2544 ok(r
, "failed to set password\n");
2548 SetLastError(0xdeadbeef);
2549 r
= InternetQueryOption(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2550 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2551 ok(!r
, "unexpected success\n");
2552 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2555 sz
= sizeof(buffer
);
2556 r
= InternetQueryOption(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2557 ok(r
, "failed to get password\n");
2558 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2559 ok(sz
== strlen(password
), "got %u\n", sz
);
2563 SetLastError(0xdeadbeef);
2564 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2565 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2566 ok(!r
, "unexpected success\n");
2567 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2570 sz
= sizeof(bufferW
);
2571 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2572 ok(r
, "failed to get password\n");
2573 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2574 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2576 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
2579 win_skip("skipping proxy tests on broken wininet\n");
2582 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2584 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2585 ok(r
, "HttpQueryInfo failed\n");
2586 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2589 InternetCloseHandle(hr
);
2590 InternetCloseHandle(hc
);
2591 InternetCloseHandle(hi
);
2594 static void test_header_handling_order(int port
)
2596 static char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
2597 static char connection
[] = "Connection: Close";
2599 static const char *types
[2] = { "*", NULL
};
2600 HINTERNET session
, connect
, request
;
2604 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2605 ok(session
!= NULL
, "InternetOpen failed\n");
2607 connect
= InternetConnect(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2608 ok(connect
!= NULL
, "InternetConnect failed\n");
2610 request
= HttpOpenRequest(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2611 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2613 ret
= HttpAddRequestHeaders(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
2614 ok(ret
, "HttpAddRequestHeaders failed\n");
2616 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
2617 ok(ret
, "HttpSendRequest failed\n");
2619 test_status_code(request
, 200);
2620 test_request_flags(request
, 0);
2622 InternetCloseHandle(request
);
2624 request
= HttpOpenRequest(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2625 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2627 ret
= HttpSendRequest(request
, connection
, ~0u, NULL
, 0);
2628 ok(ret
, "HttpSendRequest failed\n");
2631 size
= sizeof(status
);
2632 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2633 ok(ret
, "HttpQueryInfo failed\n");
2634 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2636 InternetCloseHandle(request
);
2638 request
= HttpOpenRequest(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2639 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2641 ret
= HttpAddRequestHeaders(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2642 ok(ret
, "HttpAddRequestHeaders failed\n");
2644 ret
= HttpSendRequest(request
, connection
, ~0u, NULL
, 0);
2645 ok(ret
, "HttpSendRequest failed\n");
2648 size
= sizeof(status
);
2649 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2650 ok(ret
, "HttpQueryInfo failed\n");
2651 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2653 InternetCloseHandle(request
);
2654 InternetCloseHandle(connect
);
2655 InternetCloseHandle(session
);
2658 static void test_connection_header(int port
)
2660 HINTERNET ses
, con
, req
;
2663 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2664 ok(ses
!= NULL
, "InternetOpen failed\n");
2666 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2667 ok(con
!= NULL
, "InternetConnect failed\n");
2669 req
= HttpOpenRequest(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2670 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2672 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2673 ok(ret
, "HttpSendRequest failed\n");
2675 test_status_code(req
, 200);
2677 InternetCloseHandle(req
);
2679 req
= HttpOpenRequest(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
2680 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2682 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2683 ok(ret
, "HttpSendRequest failed\n");
2685 test_status_code(req
, 200);
2687 InternetCloseHandle(req
);
2689 req
= HttpOpenRequest(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2690 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2692 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2693 ok(ret
, "HttpSendRequest failed\n");
2695 test_status_code(req
, 200);
2697 InternetCloseHandle(req
);
2699 req
= HttpOpenRequest(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2700 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2702 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2703 ok(ret
, "HttpSendRequest failed\n");
2705 test_status_code(req
, 200);
2707 InternetCloseHandle(req
);
2708 InternetCloseHandle(con
);
2709 InternetCloseHandle(ses
);
2712 static void test_http1_1(int port
)
2714 HINTERNET ses
, con
, req
;
2717 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2718 ok(ses
!= NULL
, "InternetOpen failed\n");
2720 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2721 ok(con
!= NULL
, "InternetConnect failed\n");
2723 req
= HttpOpenRequest(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2724 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2726 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2729 InternetCloseHandle(req
);
2731 req
= HttpOpenRequest(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2732 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2734 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2735 ok(ret
, "HttpSendRequest failed\n");
2738 InternetCloseHandle(req
);
2739 InternetCloseHandle(con
);
2740 InternetCloseHandle(ses
);
2743 static void test_connection_closing(int port
)
2745 HINTERNET session
, connection
, req
;
2748 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2750 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2751 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2753 pInternetSetStatusCallbackA(session
, callback
);
2755 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2756 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2757 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2758 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2760 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2761 req
= HttpOpenRequestA(connection
, "GET", "/testJ", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
2762 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2763 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2765 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2766 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2767 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2768 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2769 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2770 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2771 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2772 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2773 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
2774 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
2775 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2777 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2778 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2779 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2780 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2781 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2783 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2784 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2785 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2786 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2787 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2788 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2789 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2790 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2791 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2792 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2793 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2795 test_status_code(req
, 200);
2797 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2798 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2799 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2800 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2801 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2802 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2803 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2804 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2805 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2807 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2808 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2809 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2810 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2811 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2813 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2814 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2815 todo_wine
CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2816 todo_wine
CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2817 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2818 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2819 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2820 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2821 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2823 test_status_code_todo(req
, 210);
2825 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2826 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2827 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2828 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2829 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2830 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST
);
2831 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2832 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2833 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2834 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
2835 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
2836 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2838 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2839 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2840 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2841 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2842 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2844 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2845 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2846 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2847 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2848 todo_wine
CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2849 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2850 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2851 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2852 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2853 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2854 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2856 test_status_code_todo(req
, 200);
2858 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
2859 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
2861 close_async_handle(session
, hCompleteEvent
, 2);
2862 CloseHandle(hCompleteEvent
);
2866 static void test_no_content(int port
)
2868 HINTERNET session
, connection
, req
;
2871 trace("Testing 204 no content response...\n");
2873 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2875 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2876 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2878 pInternetSetStatusCallbackA(session
, callback
);
2880 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2881 connection
= InternetConnectA(session
, "localhost", port
,
2882 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2883 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2884 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2886 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2887 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
2888 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
2889 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2890 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2892 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2893 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2894 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2895 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2896 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2897 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2898 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2899 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
2900 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
2901 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2903 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
2904 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2905 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2906 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2907 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2909 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2910 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2911 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2912 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2913 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2914 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2915 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2916 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2917 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2918 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2920 close_async_handle(session
, hCompleteEvent
, 2);
2921 CloseHandle(hCompleteEvent
);
2924 static void test_conn_close(int port
)
2926 HINTERNET session
, connection
, req
;
2927 DWORD res
, avail
, size
;
2930 trace("Testing connection close connection...\n");
2932 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2933 conn_close_event
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2935 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2936 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2938 pInternetSetStatusCallbackA(session
, callback
);
2940 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2941 connection
= InternetConnectA(session
, "localhost", port
,
2942 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2943 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2944 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2946 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2947 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
2948 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
2949 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2950 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2952 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2953 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2954 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2955 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2956 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2957 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2958 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2959 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2961 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
2962 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2963 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2964 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2965 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2967 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2968 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2969 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2970 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2971 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2972 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2973 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2974 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2977 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
2978 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
2979 ok(avail
!= 0, "avail = 0\n");
2982 res
= InternetReadFile(req
, buf
, avail
, &size
);
2983 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
2985 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
2986 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2987 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2988 ok(!avail
, "avail = %u, expected 0\n", avail
);
2990 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
2991 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
2992 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2993 SetEvent(conn_close_event
);
2994 #ifdef ROSTESTS_73_FIXED
2995 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2996 #else /* ROSTESTS_73_FIXED */
2997 ok(WaitForSingleObject(hCompleteEvent
, 5000) == WAIT_OBJECT_0
, "Wait timed out\n");
2998 #endif /* ROSTESTS_73_FIXED */
2999 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3000 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3001 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3002 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3004 close_async_handle(session
, hCompleteEvent
, 2);
3005 CloseHandle(hCompleteEvent
);
3008 static void test_no_cache(int port
)
3010 static const char cache_control_no_cache
[] = "/test_cache_control_no_cache";
3011 static const char cache_control_no_store
[] = "/test_cache_control_no_store";
3012 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3014 char cache_url
[256], buf
[256];
3015 HINTERNET ses
, con
, req
;
3019 trace("Testing no-cache header\n");
3021 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3022 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3024 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3025 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3027 req
= HttpOpenRequest(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3028 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3030 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_cache
);
3031 DeleteUrlCacheEntry(cache_url
);
3033 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
3034 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3036 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3038 ok(size
== 12, "read %d bytes of data\n", size
);
3039 InternetCloseHandle(req
);
3041 req
= HttpOpenRequest(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3042 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3044 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
3045 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3047 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3049 ok(size
== 0, "read %d bytes of data\n", size
);
3050 InternetCloseHandle(req
);
3051 DeleteUrlCacheEntry(cache_url
);
3053 req
= HttpOpenRequest(con
, NULL
, cache_control_no_store
, NULL
, NULL
, NULL
, 0, 0);
3054 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3056 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_store
);
3057 DeleteUrlCacheEntry(cache_url
);
3059 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
3060 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3062 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3064 ok(size
== 12, "read %d bytes of data\n", size
);
3065 InternetCloseHandle(req
);
3067 ret
= DeleteUrlCacheEntry(cache_url
);
3068 ok(!ret
&& GetLastError()==ERROR_FILE_NOT_FOUND
, "cache entry should not exist\n");
3070 InternetCloseHandle(con
);
3071 InternetCloseHandle(ses
);
3074 static void test_cache_read_gzipped(int port
)
3076 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3077 static const char get_gzip
[] = "/test_cache_gzip";
3078 static const char content
[] = "gzip test\n";
3079 static const char text_html
[] = "text/html";
3080 static const char raw_header
[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3082 HINTERNET ses
, con
, req
;
3084 char cache_url
[256], buf
[256];
3087 trace("Testing reading compressed content from cache\n");
3089 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3090 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3092 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3093 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3095 req
= HttpOpenRequest(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3096 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3099 ret
= InternetSetOption(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3100 if(!ret
&& GetLastError()==ERROR_INTERNET_INVALID_OPTION
) {
3101 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3102 InternetCloseHandle(req
);
3103 InternetCloseHandle(con
);
3104 InternetCloseHandle(ses
);
3107 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3109 ret
= HttpSendRequest(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3110 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3112 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-size
, &read
) && read
)
3114 ok(size
== 10, "read %d bytes of data\n", size
);
3116 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3118 size
= sizeof(buf
)-1;
3119 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3120 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3122 ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3124 size
= sizeof(buf
)-1;
3125 ret
= HttpQueryInfoA(req
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &size
, 0);
3126 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3128 ok(!strncmp(raw_header
, buf
, size
), "buf = %s\n", buf
);
3129 InternetCloseHandle(req
);
3131 req
= HttpOpenRequest(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3132 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3135 ret
= InternetSetOption(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3136 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3138 ret
= HttpSendRequest(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3139 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3141 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3143 todo_wine
ok(size
== 10, "read %d bytes of data\n", size
);
3145 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3148 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3149 ok(!ret
&& GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND
,
3150 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3151 ret
, GetLastError());
3153 size
= sizeof(buf
)-1;
3154 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3155 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3157 todo_wine
ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3158 InternetCloseHandle(req
);
3160 /* Decompression doesn't work while reading from cache */
3161 test_cache_gzip
= 0;
3162 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3163 DeleteUrlCacheEntry(cache_url
);
3165 req
= HttpOpenRequest(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3166 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3168 ret
= HttpSendRequest(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3169 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3171 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3173 ok(size
== 31, "read %d bytes of data\n", size
);
3174 InternetCloseHandle(req
);
3176 req
= HttpOpenRequest(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3177 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3180 ret
= InternetSetOption(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3181 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3183 ret
= HttpSendRequest(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3184 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3186 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3188 todo_wine
ok(size
== 31, "read %d bytes of data\n", size
);
3191 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3192 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3193 InternetCloseHandle(req
);
3195 InternetCloseHandle(con
);
3196 InternetCloseHandle(ses
);
3198 DeleteUrlCacheEntry(cache_url
);
3201 static void test_HttpSendRequestW(int port
)
3203 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3204 HINTERNET ses
, con
, req
;
3208 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3209 ok(ses
!= NULL
, "InternetOpen failed\n");
3211 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3212 ok(con
!= NULL
, "InternetConnect failed\n");
3214 req
= HttpOpenRequest(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3215 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3217 SetLastError(0xdeadbeef);
3218 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
3219 error
= GetLastError();
3220 ok(!ret
, "HttpSendRequestW succeeded\n");
3221 ok(error
== ERROR_IO_PENDING
||
3222 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
3223 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
3224 "got %u expected ERROR_IO_PENDING\n", error
);
3226 InternetCloseHandle(req
);
3227 InternetCloseHandle(con
);
3228 InternetCloseHandle(ses
);
3231 static void test_cookie_header(int port
)
3233 HINTERNET ses
, con
, req
;
3238 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3239 ok(ses
!= NULL
, "InternetOpen failed\n");
3241 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3242 ok(con
!= NULL
, "InternetConnect failed\n");
3244 InternetSetCookie("http://localhost", "cookie", "biscuit");
3246 req
= HttpOpenRequest(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3247 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3250 size
= sizeof(buffer
);
3251 SetLastError(0xdeadbeef);
3252 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3253 error
= GetLastError();
3254 ok(!ret
, "HttpQueryInfo succeeded\n");
3255 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3257 ret
= HttpAddRequestHeaders(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
3258 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3261 size
= sizeof(buffer
);
3262 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3263 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3264 ok(!strcmp(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
3266 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
3267 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3269 test_status_code(req
, 200);
3272 size
= sizeof(buffer
);
3273 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3274 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3275 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
3277 InternetCloseHandle(req
);
3278 InternetCloseHandle(con
);
3279 InternetCloseHandle(ses
);
3282 static void test_basic_authentication(int port
)
3284 HINTERNET session
, connect
, request
;
3287 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3288 ok(session
!= NULL
, "InternetOpen failed\n");
3290 connect
= InternetConnect(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
3291 ok(connect
!= NULL
, "InternetConnect failed\n");
3293 request
= HttpOpenRequest(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
3294 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3296 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
3297 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3299 test_status_code(request
, 200);
3300 test_request_flags(request
, 0);
3302 InternetCloseHandle(request
);
3303 InternetCloseHandle(connect
);
3304 InternetCloseHandle(session
);
3307 static void test_premature_disconnect(int port
)
3309 HINTERNET session
, connect
, request
;
3313 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3314 ok(session
!= NULL
, "InternetOpen failed\n");
3316 connect
= InternetConnect(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3317 ok(connect
!= NULL
, "InternetConnect failed\n");
3319 request
= HttpOpenRequest(connect
, NULL
, "/premature_disconnect", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3320 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3322 SetLastError(0xdeadbeef);
3323 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
3324 err
= GetLastError();
3325 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
3326 todo_wine
ok(err
== ERROR_HTTP_INVALID_SERVER_RESPONSE
, "got %u\n", err
);
3328 InternetCloseHandle(request
);
3329 InternetCloseHandle(connect
);
3330 InternetCloseHandle(session
);
3333 static void test_invalid_response_headers(int port
)
3335 HINTERNET session
, connect
, request
;
3340 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3341 ok(session
!= NULL
, "InternetOpen failed\n");
3343 connect
= InternetConnect(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3344 ok(connect
!= NULL
, "InternetConnect failed\n");
3346 request
= HttpOpenRequest(connect
, NULL
, "/testE", NULL
, NULL
, NULL
, 0, 0);
3347 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3349 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
3350 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3352 test_status_code(request
, 401);
3353 test_request_flags(request
, 0);
3356 size
= sizeof(buffer
);
3357 ret
= HttpQueryInfo( request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3358 ok(ret
, "HttpQueryInfo failed\n");
3359 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
3360 "headers wrong \"%s\"\n", buffer
);
3363 size
= sizeof(buffer
);
3364 ret
= HttpQueryInfo( request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
3365 ok(ret
, "HttpQueryInfo failed\n");
3366 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
3368 InternetCloseHandle(request
);
3369 InternetCloseHandle(connect
);
3370 InternetCloseHandle(session
);
3373 static void test_response_without_headers(int port
)
3375 HINTERNET hi
, hc
, hr
;
3376 DWORD r
, count
, size
;
3379 SetLastError(0xdeadbeef);
3380 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3381 ok(hi
!= NULL
, "open failed %u\n", GetLastError());
3383 SetLastError(0xdeadbeef);
3384 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3385 ok(hc
!= NULL
, "connect failed %u\n", GetLastError());
3387 SetLastError(0xdeadbeef);
3388 hr
= HttpOpenRequest(hc
, NULL
, "/testG", NULL
, NULL
, NULL
, 0, 0);
3389 ok(hr
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError());
3391 test_request_flags(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3393 SetLastError(0xdeadbeef);
3394 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
3395 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
3397 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3400 memset(buffer
, 0, sizeof buffer
);
3401 SetLastError(0xdeadbeef);
3402 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
3403 ok(r
, "InternetReadFile failed %u\n", GetLastError());
3404 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
3405 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
3407 test_status_code(hr
, 200);
3408 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3411 size
= sizeof(buffer
);
3412 SetLastError(0xdeadbeef);
3413 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
3414 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3415 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
3418 size
= sizeof(buffer
);
3419 SetLastError(0xdeadbeef);
3420 r
= HttpQueryInfo(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
3421 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3422 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
3425 size
= sizeof(buffer
);
3426 SetLastError(0xdeadbeef);
3427 r
= HttpQueryInfo(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3428 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3429 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
3431 InternetCloseHandle(hr
);
3432 InternetCloseHandle(hc
);
3433 InternetCloseHandle(hi
);
3436 static void test_HttpQueryInfo(int port
)
3438 HINTERNET hi
, hc
, hr
;
3443 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3444 ok(hi
!= NULL
, "InternetOpen failed\n");
3446 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3447 ok(hc
!= NULL
, "InternetConnect failed\n");
3449 hr
= HttpOpenRequest(hc
, NULL
, "/testD", NULL
, NULL
, NULL
, 0, 0);
3450 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
3452 size
= sizeof(buffer
);
3453 ret
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3454 ok(!ret
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed %u\n", GetLastError());
3456 ret
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
3457 ok(ret
, "HttpSendRequest failed\n");
3460 size
= sizeof(buffer
);
3461 ret
= HttpQueryInfo(hr
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
3462 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3463 ok(index
== 1, "expected 1 got %u\n", index
);
3466 size
= sizeof(buffer
);
3467 ret
= HttpQueryInfo(hr
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
3468 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3469 ok(index
== 1, "expected 1 got %u\n", index
);
3472 size
= sizeof(buffer
);
3473 ret
= HttpQueryInfo(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3474 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3475 ok(index
== 0, "expected 0 got %u\n", index
);
3477 size
= sizeof(buffer
);
3478 ret
= HttpQueryInfo(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3479 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3480 ok(index
== 0, "expected 0 got %u\n", index
);
3482 index
= 0xdeadbeef; /* invalid start index */
3483 size
= sizeof(buffer
);
3484 ret
= HttpQueryInfo(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3485 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
3486 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
3487 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
3490 size
= sizeof(buffer
);
3491 ret
= HttpQueryInfo(hr
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
3492 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3493 ok(index
== 0, "expected 0 got %u\n", index
);
3495 size
= sizeof(buffer
);
3496 ret
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3497 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3498 ok(index
== 0, "expected 0 got %u\n", index
);
3500 size
= sizeof(buffer
);
3501 ret
= HttpQueryInfo(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
3502 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3503 ok(index
== 0, "expected 0 got %u\n", index
);
3505 test_status_code(hr
, 200);
3508 size
= sizeof(buffer
);
3509 ret
= HttpQueryInfo(hr
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
3510 ok(!ret
, "HttpQueryInfo succeeded\n");
3511 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
3514 size
= sizeof(buffer
);
3515 ret
= HttpQueryInfo(hr
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
3516 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3517 ok(index
== 1, "expected 1 got %u\n", index
);
3520 size
= sizeof(buffer
);
3521 strcpy(buffer
, "Server");
3522 ret
= HttpQueryInfo(hr
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
3523 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3524 ok(index
== 1, "expected 1 got %u\n", index
);
3527 size
= sizeof(buffer
);
3528 ret
= HttpQueryInfo(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
3529 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3530 ok(index
== 1, "expected 1 got %u\n", index
);
3532 size
= sizeof(buffer
);
3533 ret
= HttpQueryInfo(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
3534 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3535 ok(index
== 2, "expected 2 got %u\n", index
);
3537 InternetCloseHandle(hr
);
3538 InternetCloseHandle(hc
);
3539 InternetCloseHandle(hi
);
3542 static void test_options(int port
)
3544 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi
;
3545 HINTERNET ses
, con
, req
;
3550 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3551 ok(ses
!= NULL
, "InternetOpen failed\n");
3553 SetLastError(0xdeadbeef);
3554 ret
= InternetSetOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
3555 error
= GetLastError();
3556 ok(!ret
, "InternetSetOption succeeded\n");
3557 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3559 SetLastError(0xdeadbeef);
3560 ret
= InternetSetOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
3561 ok(!ret
, "InternetSetOption succeeded\n");
3562 error
= GetLastError();
3563 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3565 SetLastError(0xdeadbeef);
3566 ret
= InternetSetOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
3567 ok(!ret
, "InternetSetOption succeeded\n");
3568 error
= GetLastError();
3569 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3572 ret
= InternetSetOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3573 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3575 SetLastError(0xdeadbeef);
3576 ret
= InternetQueryOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
3577 error
= GetLastError();
3578 ok(!ret
, "InternetQueryOption succeeded\n");
3579 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3581 SetLastError(0xdeadbeef);
3582 ret
= InternetQueryOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
3583 error
= GetLastError();
3584 ok(!ret
, "InternetQueryOption succeeded\n");
3585 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3588 SetLastError(0xdeadbeef);
3589 ret
= InternetQueryOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
3590 error
= GetLastError();
3591 ok(!ret
, "InternetQueryOption succeeded\n");
3592 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
3595 SetLastError(0xdeadbeef);
3596 ret
= InternetQueryOption(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3597 error
= GetLastError();
3598 ok(!ret
, "InternetQueryOption succeeded\n");
3599 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
3603 ret
= InternetQueryOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3604 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3605 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
3607 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3608 ok(con
!= NULL
, "InternetConnect failed\n");
3612 ret
= InternetQueryOption(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3613 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3614 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
3617 ret
= InternetSetOption(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3618 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3622 ret
= InternetQueryOption(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3623 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3624 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
3626 req
= HttpOpenRequest(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3627 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3631 ret
= InternetQueryOption(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3632 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3633 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
3636 ret
= InternetSetOption(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3637 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3641 ret
= InternetQueryOption(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3642 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3643 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
3645 size
= sizeof(idsi
);
3646 ret
= InternetQueryOption(req
, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO
, &idsi
, &size
);
3647 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3650 SetLastError(0xdeadbeef);
3651 ret
= InternetQueryOption(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
3652 error
= GetLastError();
3653 ok(!ret
, "InternetQueryOption succeeded\n");
3654 ok(error
== ERROR_INTERNET_INVALID_OPERATION
, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error
);
3656 /* INTERNET_OPTION_PROXY */
3657 SetLastError(0xdeadbeef);
3658 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
3659 error
= GetLastError();
3660 ok(!ret
, "InternetQueryOption succeeded\n");
3661 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3663 SetLastError(0xdeadbeef);
3664 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
3665 error
= GetLastError();
3666 ok(!ret
, "InternetQueryOption succeeded\n");
3667 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3670 SetLastError(0xdeadbeef);
3671 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
3672 error
= GetLastError();
3673 ok(!ret
, "InternetQueryOption succeeded\n");
3674 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
3675 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
3677 InternetCloseHandle(req
);
3678 InternetCloseHandle(con
);
3679 InternetCloseHandle(ses
);
3683 const char *response_text
;
3685 const char *status_text
;
3686 const char *raw_headers
;
3687 } http_status_test_t
;
3689 static const http_status_test_t http_status_tests
[] = {
3691 "HTTP/1.1 200 OK\r\n"
3692 "Content-Length: 1\r\n"
3698 "HTTP/1.1 404 Fail\r\n"
3699 "Content-Length: 1\r\n"
3706 "Content-Length: 1\r\n"
3713 "Content-Length: 1\r\n"
3720 static void test_http_status(int port
)
3722 HINTERNET ses
, con
, req
;
3727 for(i
=0; i
< sizeof(http_status_tests
)/sizeof(*http_status_tests
); i
++) {
3728 send_buffer
= http_status_tests
[i
].response_text
;
3730 ses
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3731 ok(ses
!= NULL
, "InternetOpen failed\n");
3733 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3734 ok(con
!= NULL
, "InternetConnect failed\n");
3736 req
= HttpOpenRequest(con
, NULL
, "/send_from_buffer", NULL
, NULL
, NULL
, 0, 0);
3737 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3739 res
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
3740 ok(res
, "HttpSendRequest failed\n");
3742 test_status_code(req
, http_status_tests
[i
].status_code
);
3745 res
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_TEXT
, buf
, &size
, NULL
);
3746 ok(res
, "HttpQueryInfo failed: %u\n", GetLastError());
3747 ok(!strcmp(buf
, http_status_tests
[i
].status_text
), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
3748 i
, buf
, http_status_tests
[i
].status_text
);
3750 InternetCloseHandle(req
);
3751 InternetCloseHandle(con
);
3752 InternetCloseHandle(ses
);
3756 static void test_cache_control_verb(int port
)
3758 HINTERNET session
, connect
, request
;
3761 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3762 ok(session
!= NULL
, "InternetOpen failed\n");
3764 connect
= InternetConnect(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3765 ok(connect
!= NULL
, "InternetConnect failed\n");
3767 request
= HttpOpenRequest(connect
, "RPC_OUT_DATA", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3768 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3769 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3770 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
3771 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3772 test_status_code(request
, 200);
3774 request
= HttpOpenRequest(connect
, "POST", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3775 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3776 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3777 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
3778 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3779 test_status_code(request
, 200);
3781 request
= HttpOpenRequest(connect
, "HEAD", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3782 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3783 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3784 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
3785 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3786 test_status_code(request
, 200);
3788 request
= HttpOpenRequest(connect
, "GET", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3789 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3790 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3791 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
3792 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3793 test_status_code(request
, 200);
3795 InternetCloseHandle(request
);
3796 InternetCloseHandle(connect
);
3797 InternetCloseHandle(session
);
3800 static void test_http_connection(void)
3802 struct server_info si
;
3806 si
.hEvent
= CreateEvent(NULL
, 0, 0, NULL
);
3809 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
3810 ok( hThread
!= NULL
, "create thread failed\n");
3812 r
= WaitForSingleObject(si
.hEvent
, 10000);
3813 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
3814 if (r
!= WAIT_OBJECT_0
)
3817 test_basic_request(si
.port
, "GET", "/test1");
3818 test_proxy_indirect(si
.port
);
3819 test_proxy_direct(si
.port
);
3820 test_header_handling_order(si
.port
);
3821 test_basic_request(si
.port
, "POST", "/test5");
3822 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
3823 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
3824 test_basic_request(si
.port
, "GET", "/test6");
3825 test_basic_request(si
.port
, "GET", "/testF");
3826 test_connection_header(si
.port
);
3827 test_http1_1(si
.port
);
3828 test_cookie_header(si
.port
);
3829 test_basic_authentication(si
.port
);
3830 test_invalid_response_headers(si
.port
);
3831 test_response_without_headers(si
.port
);
3832 test_HttpQueryInfo(si
.port
);
3833 test_HttpSendRequestW(si
.port
);
3834 test_last_error(si
.port
);
3835 test_options(si
.port
);
3836 test_no_content(si
.port
);
3837 test_conn_close(si
.port
);
3838 test_no_cache(si
.port
);
3839 test_cache_read_gzipped(si
.port
);
3840 test_http_status(si
.port
);
3841 test_premature_disconnect(si
.port
);
3842 test_connection_closing(si
.port
);
3843 test_cache_control_verb(si
.port
);
3845 /* send the basic request again to shutdown the server thread */
3846 test_basic_request(si
.port
, "GET", "/quit");
3848 r
= WaitForSingleObject(hThread
, 3000);
3849 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
3850 CloseHandle(hThread
);
3853 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
3855 LocalFree(info
->lpszSubjectInfo
);
3856 LocalFree(info
->lpszIssuerInfo
);
3857 LocalFree(info
->lpszProtocolName
);
3858 LocalFree(info
->lpszSignatureAlgName
);
3859 LocalFree(info
->lpszEncryptionAlgName
);
3863 const char *ex_subject
;
3864 const char *ex_issuer
;
3865 } cert_struct_test_t
;
3867 static const cert_struct_test_t test_winehq_org_cert
= {
3868 "0mJuv1t-1CFypQkyTZwfvjHHBAbnUndG\r\n"
3870 "See www.rapidssl.com/resources/cps (c)13\r\n"
3871 "Domain Control Validated - RapidSSL(R)\r\n"
3875 "\"GeoTrust, Inc.\"\r\n"
3879 static const cert_struct_test_t test_winehq_com_cert
= {
3884 "test.winehq.com\r\n"
3885 "webmaster@winehq.org",
3890 "test.winehq.com\r\n"
3891 "webmaster@winehq.org"
3894 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
3896 INTERNET_CERTIFICATE_INFOA info
;
3900 memset(&info
, 0x5, sizeof(info
));
3902 size
= sizeof(info
);
3903 res
= InternetQueryOption(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
3904 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
3905 ok(size
== sizeof(info
), "size = %u\n", size
);
3907 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
3908 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
3909 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
3910 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
3911 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
3912 ok(info
.dwKeySize
== 128, "dwKeySize = %u\n", info
.dwKeySize
);
3914 release_cert_info(&info
);
3917 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
3918 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
3920 char url
[INTERNET_MAX_URL_LENGTH
];
3921 const CERT_CHAIN_CONTEXT
*chain
;
3925 if(!pInternetGetSecurityInfoByURLA
) {
3926 win_skip("pInternetGetSecurityInfoByURLA not available\n");
3931 chain
= (void*)0xdeadbeef;
3933 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
3934 if(error
== ERROR_SUCCESS
) {
3935 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
3936 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
3937 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
3938 CertFreeCertificateChain(chain
);
3940 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
3941 "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res
, GetLastError(), error
);
3945 #define test_secflags_option(a,b) _test_secflags_option(__LINE__,a,b)
3946 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
)
3952 size
= sizeof(flags
);
3953 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
3954 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
3955 ok_(__FILE__
,line
)(flags
== ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n", flags
, ex_flags
);
3957 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
3959 size
= sizeof(flags
);
3960 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
3961 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
3962 ok_(__FILE__
,line
)(flags
== ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n", flags
, ex_flags
);
3965 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
3966 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
3970 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
3971 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
3974 static void test_security_flags(void)
3976 HINTERNET ses
, conn
, req
;
3981 trace("Testing security flags...\n");
3983 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
3985 ses
= InternetOpen("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3986 ok(ses
!= NULL
, "InternetOpen failed\n");
3988 pInternetSetStatusCallbackA(ses
, &callback
);
3990 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3991 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
3992 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
3993 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3994 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3996 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3997 req
= HttpOpenRequest(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
3998 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4000 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4001 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4004 size
= sizeof(flags
);
4005 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4006 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
4007 win_skip("Incomplete security flags support, skipping\n");
4009 close_async_handle(ses
, hCompleteEvent
, 2);
4010 CloseHandle(hCompleteEvent
);
4014 test_secflags_option(req
, 0);
4015 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4017 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4018 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
);
4020 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4021 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4023 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4024 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4026 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
4027 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
4028 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
4030 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
4031 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
4032 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4033 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4034 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4035 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4036 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4037 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4038 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4039 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4040 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4042 res
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
4043 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4045 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4046 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4048 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
4049 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
4050 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4051 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4052 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4053 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4054 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4055 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4056 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4057 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4058 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4060 test_request_flags(req
, 0);
4061 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4062 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
);
4064 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4065 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4066 ok(size
, "size = 0\n");
4068 /* Collect all existing persistent connections */
4069 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4070 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4072 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4073 req
= HttpOpenRequest(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4074 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4076 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4077 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4079 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
4080 res
= InternetSetOption(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
4081 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
4083 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4084 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4085 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4086 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4087 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4088 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4089 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4091 res
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
4092 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4094 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4095 ok(req_error
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| broken(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
),
4096 "req_error = %d\n", req_error
);
4098 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4099 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4100 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4101 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4102 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4103 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4104 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4106 if(req_error
!= ERROR_INTERNET_SEC_CERT_REV_FAILED
) {
4107 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error
);
4109 close_async_handle(ses
, hCompleteEvent
, 3);
4110 CloseHandle(hCompleteEvent
);
4115 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
4116 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
4118 test_request_flags(req
, 8);
4119 test_secflags_option(req
, 0x800000);
4121 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4122 test_secflags_option(req
, 0x800000|SECURITY_FLAG_IGNORE_REVOCATION
);
4124 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4125 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4126 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4127 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4128 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4129 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4130 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4132 res
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
4133 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4135 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4136 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
4138 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4139 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4140 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4141 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4142 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4143 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4144 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4146 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
4147 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4148 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4150 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4151 test_secflags_option(req
, 0x1800000|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4152 |SECURITY_FLAG_IGNORE_REVOCATION
);
4153 test_http_version(req
);
4155 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4156 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4157 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4158 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4159 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4160 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4161 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4162 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4163 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4165 res
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
4166 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4168 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4169 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4171 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4172 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4173 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4174 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4175 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4176 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4177 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4178 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4179 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4181 test_request_flags(req
, 0);
4182 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
4183 |SECURITY_FLAG_STRENGTH_STRONG
|0x1800000);
4185 test_cert_struct(req
, &test_winehq_com_cert
);
4186 test_security_info("https://test.winehq.com/data/some_file.html?q", 0, 0x1800000);
4188 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4189 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4190 ok(size
, "size = 0\n");
4192 close_async_handle(ses
, hCompleteEvent
, 3);
4194 /* Collect all existing persistent connections */
4195 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4196 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4198 /* Make another request, without setting security flags */
4200 ses
= InternetOpen("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4201 ok(ses
!= NULL
, "InternetOpen failed\n");
4203 pInternetSetStatusCallbackA(ses
, &callback
);
4205 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4206 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
4207 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
4208 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
4209 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4211 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4212 req
= HttpOpenRequest(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4213 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4215 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4216 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4218 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
4219 |SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4220 test_http_version(req
);
4222 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4223 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4224 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4225 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4226 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4227 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4228 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4229 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4231 res
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
4232 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4234 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4235 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4237 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4238 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4239 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4240 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4241 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4242 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4243 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4244 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4246 test_request_flags(req
, 0);
4247 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
4248 |SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4250 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4251 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4252 ok(size
, "size = 0\n");
4254 close_async_handle(ses
, hCompleteEvent
, 2);
4256 CloseHandle(hCompleteEvent
);
4258 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4259 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4260 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4263 static void test_secure_connection(void)
4265 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
4266 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
4267 static const WCHAR get
[] = {'G','E','T',0};
4268 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
4269 HINTERNET ses
, con
, req
;
4271 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
4272 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
4275 ses
= InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4276 ok(ses
!= NULL
, "InternetOpen failed\n");
4278 con
= InternetConnect(ses
, "test.winehq.org",
4279 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
4280 INTERNET_SERVICE_HTTP
, 0, 0);
4281 ok(con
!= NULL
, "InternetConnect failed\n");
4283 req
= HttpOpenRequest(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4284 INTERNET_FLAG_SECURE
, 0);
4285 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4287 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
4288 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
4290 size
= sizeof(flags
);
4291 ret
= InternetQueryOption(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4292 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4293 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
4295 if (!winetest_interactive
)
4297 skip("test_cert_struct(req, &test_winehq_org_cert), ROSTESTS-121\n");
4301 test_cert_struct(req
, &test_winehq_org_cert
);
4304 /* Querying the same option through InternetQueryOptionW still results in
4305 * ASCII strings being returned.
4308 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4310 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4311 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
4312 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
4313 ret
= InternetQueryOption(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4314 certificate_structW
, &size
);
4315 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
4316 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4319 ok(certificate_structA
->lpszSubjectInfo
&&
4320 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4321 "expected a non-empty subject name\n");
4322 ok(certificate_structA
->lpszIssuerInfo
&&
4323 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4324 "expected a non-empty issuer name\n");
4325 ok(!certificate_structA
->lpszSignatureAlgName
,
4326 "unexpected signature algorithm name\n");
4327 ok(!certificate_structA
->lpszEncryptionAlgName
,
4328 "unexpected encryption algorithm name\n");
4329 ok(!certificate_structA
->lpszProtocolName
,
4330 "unexpected protocol name\n");
4331 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4332 release_cert_info(certificate_structA
);
4334 HeapFree(GetProcessHeap(), 0, certificate_structW
);
4336 InternetCloseHandle(req
);
4337 InternetCloseHandle(con
);
4338 InternetCloseHandle(ses
);
4340 /* Repeating the tests with the W functions has the same result: */
4341 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4342 ok(ses
!= NULL
, "InternetOpen failed\n");
4344 con
= InternetConnectW(ses
, testsite
,
4345 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
4346 INTERNET_SERVICE_HTTP
, 0, 0);
4347 ok(con
!= NULL
, "InternetConnect failed\n");
4349 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
4350 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
4351 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4353 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
4354 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
4356 size
= sizeof(flags
);
4357 ret
= InternetQueryOption(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4358 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4359 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %x\n", flags
);
4361 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4363 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4364 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
4365 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
4366 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4367 certificate_structA
, &size
);
4368 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4371 ok(certificate_structA
->lpszSubjectInfo
&&
4372 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4373 "expected a non-empty subject name\n");
4374 ok(certificate_structA
->lpszIssuerInfo
&&
4375 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4376 "expected a non-empty issuer name\n");
4377 ok(!certificate_structA
->lpszSignatureAlgName
,
4378 "unexpected signature algorithm name\n");
4379 ok(!certificate_structA
->lpszEncryptionAlgName
,
4380 "unexpected encryption algorithm name\n");
4381 ok(!certificate_structA
->lpszProtocolName
,
4382 "unexpected protocol name\n");
4383 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4384 release_cert_info(certificate_structA
);
4386 HeapFree(GetProcessHeap(), 0, certificate_structA
);
4388 /* Again, querying the same option through InternetQueryOptionW still
4389 * results in ASCII strings being returned.
4392 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4394 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4395 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
4396 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
4397 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4398 certificate_structW
, &size
);
4399 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
4400 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4403 ok(certificate_structA
->lpszSubjectInfo
&&
4404 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4405 "expected a non-empty subject name\n");
4406 ok(certificate_structA
->lpszIssuerInfo
&&
4407 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4408 "expected a non-empty issuer name\n");
4409 ok(!certificate_structA
->lpszSignatureAlgName
,
4410 "unexpected signature algorithm name\n");
4411 ok(!certificate_structA
->lpszEncryptionAlgName
,
4412 "unexpected encryption algorithm name\n");
4413 ok(!certificate_structA
->lpszProtocolName
,
4414 "unexpected protocol name\n");
4415 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4416 release_cert_info(certificate_structA
);
4418 HeapFree(GetProcessHeap(), 0, certificate_structW
);
4420 InternetCloseHandle(req
);
4421 InternetCloseHandle(con
);
4422 InternetCloseHandle(ses
);
4425 static void test_user_agent_header(void)
4427 HINTERNET ses
, con
, req
;
4432 ses
= InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4433 ok(ses
!= NULL
, "InternetOpen failed\n");
4435 con
= InternetConnect(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4436 ok(con
!= NULL
, "InternetConnect failed\n");
4438 req
= HttpOpenRequest(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
4439 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4441 size
= sizeof(buffer
);
4442 ret
= HttpQueryInfo(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4443 err
= GetLastError();
4444 ok(!ret
, "HttpQueryInfo succeeded\n");
4445 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4447 ret
= HttpAddRequestHeaders(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
4448 ok(ret
, "HttpAddRequestHeaders succeeded\n");
4450 size
= sizeof(buffer
);
4451 ret
= HttpQueryInfo(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4452 err
= GetLastError();
4453 ok(ret
, "HttpQueryInfo failed\n");
4454 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4456 InternetCloseHandle(req
);
4458 req
= HttpOpenRequest(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
4459 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4461 size
= sizeof(buffer
);
4462 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4463 err
= GetLastError();
4464 ok(!ret
, "HttpQueryInfo succeeded\n");
4465 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4467 ret
= HttpAddRequestHeaders(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
4468 ok(ret
, "HttpAddRequestHeaders failed\n");
4471 size
= sizeof(buffer
);
4472 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4473 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
4474 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
4476 InternetCloseHandle(req
);
4477 InternetCloseHandle(con
);
4478 InternetCloseHandle(ses
);
4481 static void test_bogus_accept_types_array(void)
4483 HINTERNET ses
, con
, req
;
4484 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
4489 ses
= InternetOpen("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
4490 con
= InternetConnect(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4491 req
= HttpOpenRequest(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
4493 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
4496 size
= sizeof(buffer
);
4497 SetLastError(0xdeadbeef);
4498 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4499 error
= GetLastError();
4500 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
4501 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
4502 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
4503 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
4504 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
4506 InternetCloseHandle(req
);
4507 InternetCloseHandle(con
);
4508 InternetCloseHandle(ses
);
4517 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
4519 INTERNET_ASYNC_RESULT
*result
= info
;
4520 struct context
*ctx
= (struct context
*)context
;
4522 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
4525 case INTERNET_STATUS_REQUEST_COMPLETE
:
4526 trace("request handle: 0x%08lx\n", result
->dwResult
);
4527 ctx
->req
= (HINTERNET
)result
->dwResult
;
4528 SetEvent(ctx
->event
);
4530 case INTERNET_STATUS_HANDLE_CLOSING
: {
4531 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
4533 if (InternetQueryOption(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
4534 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
4535 SetEvent(ctx
->event
);
4538 case INTERNET_STATUS_NAME_RESOLVED
:
4539 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
4540 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
4542 ok(str
[0] && str
[1], "Got string: %s\n", str
);
4543 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
4548 static void test_open_url_async(void)
4556 /* Collect all existing persistent connections */
4557 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4558 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4561 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
4562 * other versions never do. They also hang of following tests. We disable it for everything older
4565 if(!pInternetGetSecurityInfoByURLA
) {
4566 win_skip("Skipping async open on too old wininet version.\n");
4571 ctx
.event
= CreateEvent(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
4573 ses
= InternetOpen("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4574 ok(ses
!= NULL
, "InternetOpen failed\n");
4576 SetLastError(0xdeadbeef);
4577 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
4578 error
= GetLastError();
4579 ok(!ret
, "InternetSetOptionA succeeded\n");
4580 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
4582 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
4583 error
= GetLastError();
4584 ok(!ret
, "InternetSetOptionA failed\n");
4585 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
4587 pInternetSetStatusCallbackW(ses
, cb
);
4588 ResetEvent(ctx
.event
);
4590 req
= InternetOpenUrl(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
4591 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
4593 WaitForSingleObject(ctx
.event
, INFINITE
);
4596 size
= sizeof(type
);
4597 ret
= InternetQueryOption(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
4598 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
4599 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
4600 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
4603 ret
= HttpQueryInfo(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
4604 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
4605 ok(size
> 0, "expected size > 0\n");
4607 ResetEvent(ctx
.event
);
4608 InternetCloseHandle(ctx
.req
);
4609 WaitForSingleObject(ctx
.event
, INFINITE
);
4611 InternetCloseHandle(ses
);
4612 CloseHandle(ctx
.event
);
4617 internet_connect
= 1,
4619 http_send_request_ex
,
4622 internet_close_handle
4627 enum api function
; /* api responsible for notification */
4628 unsigned int status
; /* status received */
4629 int async
; /* delivered from another thread? */
4637 const struct notification
*test
;
4643 DWORD expect_result
;
4647 static CRITICAL_SECTION notification_cs
;
4649 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
4651 BOOL status_ok
, function_ok
;
4652 struct info
*info
= (struct info
*)context
;
4655 EnterCriticalSection( ¬ification_cs
);
4657 if(info
->is_aborted
) {
4658 LeaveCriticalSection(¬ification_cs
);
4662 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
4664 DWORD size
= sizeof(struct info
*);
4665 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
4666 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
4667 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
4669 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
4670 if(info
->expect_result
== ERROR_SUCCESS
) {
4671 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
4673 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
4674 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
4679 if (i
>= info
->count
)
4681 LeaveCriticalSection( ¬ification_cs
);
4685 while (info
->test
[i
].status
!= status
&&
4686 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
4687 i
< info
->count
- 1 &&
4688 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
4693 status_ok
= (info
->test
[i
].status
== status
);
4694 function_ok
= (info
->test
[i
].function
== info
->function
);
4696 if (!info
->test
[i
].todo
)
4698 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
4699 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
4701 if (info
->test
[i
].async
)
4702 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
4703 info
->line
, info
->thread
, GetCurrentThreadId());
4707 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
4709 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
4711 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
4714 LeaveCriticalSection( ¬ification_cs
);
4717 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
4719 info
->function
= function
;
4721 info
->expect_result
= expect_result
;
4724 struct notification_data
4726 const struct notification
*test
;
4727 const unsigned int count
;
4732 BOOL expect_conn_failure
;
4735 static const struct notification async_send_request_ex_test
[] =
4737 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
4738 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
4739 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
4740 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, 1, 0, 1 },
4741 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, 1, 0, 1 },
4742 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, 1, 0, 1 },
4743 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, 1 },
4744 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, 1 },
4745 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, 1 },
4746 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, 1 },
4747 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
4748 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, 0 },
4749 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, 0 },
4750 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, 1 },
4751 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, 1 },
4752 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
4753 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0, 1 },
4754 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0, 1 },
4755 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, },
4756 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, }
4759 static const struct notification async_send_request_ex_test2
[] =
4761 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
4762 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
4763 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
4764 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, 1, 0, 1 },
4765 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, 1, 0, 1 },
4766 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, 1, 0, 1 },
4767 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, 1, 1 },
4768 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, 1, 1 },
4769 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, 1 },
4770 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, 1 },
4771 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
4772 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, 1 },
4773 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, 1 },
4774 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
4775 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0, 1 },
4776 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0, 1 },
4777 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, },
4778 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, }
4781 static const struct notification async_send_request_ex_resolve_failure_test
[] =
4783 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
4784 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
4785 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
4786 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, 1 },
4787 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
4788 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
4789 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
4790 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0, 1 },
4791 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0, 1 },
4792 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, },
4793 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, }
4796 static const struct notification_data notification_data
[] = {
4798 async_send_request_ex_test
,
4799 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
4802 "tests/posttest.php",
4803 "Public ID=codeweavers"
4806 async_send_request_ex_test2
,
4807 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
4810 "tests/posttest.php"
4813 async_send_request_ex_resolve_failure_test
,
4814 sizeof(async_send_request_ex_resolve_failure_test
)/sizeof(async_send_request_ex_resolve_failure_test
[0]),
4823 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
4826 HINTERNET ses
, req
, con
;
4828 DWORD size
, written
, error
;
4829 INTERNET_BUFFERSA b
;
4830 static const char *accept
[2] = {"*/*", NULL
};
4833 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
4835 InitializeCriticalSection( ¬ification_cs
);
4837 info
.test
= nd
->test
;
4838 info
.count
= nd
->count
;
4840 info
.wait
= CreateEvent( NULL
, FALSE
, FALSE
, NULL
);
4841 info
.thread
= GetCurrentThreadId();
4842 info
.is_aborted
= FALSE
;
4844 ses
= InternetOpen( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4845 ok( ses
!= NULL
, "InternetOpen failed\n" );
4847 pInternetSetStatusCallbackA( ses
, check_notification
);
4849 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
4850 con
= InternetConnect( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
4851 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
4853 WaitForSingleObject( info
.wait
, 10000 );
4855 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
4856 req
= HttpOpenRequest( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
4857 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
4859 WaitForSingleObject( info
.wait
, 10000 );
4862 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
4863 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
4864 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
4865 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
4866 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
4869 setup_test( &info
, http_send_request_ex
, __LINE__
,
4870 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
4871 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
4872 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
4874 error
= WaitForSingleObject( info
.wait
, 10000 );
4875 if(error
!= WAIT_OBJECT_0
) {
4876 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
4877 info
.is_aborted
= TRUE
;
4881 size
= sizeof(buffer
);
4882 SetLastError( 0xdeadbeef );
4883 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
4884 error
= GetLastError();
4885 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4886 if(nd
->expect_conn_failure
) {
4887 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
4890 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
4891 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
4897 size
= strlen( nd
->data
);
4898 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
4899 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
4900 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
4901 ok( written
== size
, "expected %u got %u\n", written
, size
);
4903 WaitForSingleObject( info
.wait
, 10000 );
4905 SetLastError( 0xdeadbeef );
4906 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
4907 error
= GetLastError();
4908 ok( !ret
, "HttpEndRequestA succeeded\n" );
4909 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
4912 SetLastError( 0xdeadbeef );
4913 setup_test( &info
, http_end_request
, __LINE__
,
4914 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
4915 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
4916 error
= GetLastError();
4917 ok( !ret
, "HttpEndRequestA succeeded\n" );
4918 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
4920 WaitForSingleObject( info
.wait
, 10000 );
4922 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
4924 InternetCloseHandle( req
);
4925 InternetCloseHandle( con
);
4926 InternetCloseHandle( ses
);
4928 WaitForSingleObject( info
.wait
, 10000 );
4930 CloseHandle( info
.wait
);
4933 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
4934 static BOOL closetest_closed
;
4936 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
4937 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
4942 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
4944 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
4945 "Unexpected hInternet %p\n", hInternet
);
4946 if(!closetest_closed
)
4950 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
4951 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
4952 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
4953 closetest_req
, res
, GetLastError());
4956 static void test_InternetCloseHandle(void)
4961 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4962 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
4964 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
4966 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
4967 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
4968 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
4970 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
4971 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
4973 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
4974 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
4975 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
4977 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
4979 res
= InternetCloseHandle(closetest_session
);
4980 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
4981 closetest_closed
= TRUE
;
4982 trace("Closed session handle\n");
4984 res
= InternetCloseHandle(closetest_conn
);
4985 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
4986 res
, GetLastError());
4988 res
= InternetCloseHandle(closetest_req
);
4989 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
4990 res
, GetLastError());
4992 len
= sizeof(flags
);
4993 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
4994 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
4995 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
4996 closetest_req
, res
, GetLastError());
4999 static void test_connection_failure(void)
5001 HINTERNET session
, connect
, request
;
5005 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5006 ok(session
!= NULL
, "failed to get session handle\n");
5008 connect
= InternetConnectA(session
, "localhost", 1, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5009 ok(connect
!= NULL
, "failed to get connection handle\n");
5011 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
5012 ok(request
!= NULL
, "failed to get request handle\n");
5014 SetLastError(0xdeadbeef);
5015 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
5016 error
= GetLastError();
5017 ok(!ret
, "unexpected success\n");
5018 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
5020 InternetCloseHandle(request
);
5021 InternetCloseHandle(connect
);
5022 InternetCloseHandle(session
);
5025 static void test_default_service_port(void)
5027 HINTERNET session
, connect
, request
;
5031 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
5032 ok(session
!= NULL
, "InternetOpen failed\n");
5034 connect
= InternetConnect(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
5035 INTERNET_SERVICE_HTTP
, 0, 0);
5036 ok(connect
!= NULL
, "InternetConnect failed\n");
5038 request
= HttpOpenRequest(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
5039 ok(request
!= NULL
, "HttpOpenRequest failed\n");
5041 SetLastError(0xdeadbeef);
5042 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
5043 error
= GetLastError();
5044 ok(!ret
, "HttpSendRequest succeeded\n");
5045 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
5048 InternetCloseHandle(request
);
5049 InternetCloseHandle(connect
);
5050 InternetCloseHandle(session
);
5053 static void init_status_tests(void)
5055 memset(expect
, 0, sizeof(expect
));
5056 memset(optional
, 0, sizeof(optional
));
5057 memset(wine_allow
, 0, sizeof(wine_allow
));
5058 memset(notified
, 0, sizeof(notified
));
5059 memset(status_string
, 0, sizeof(status_string
));
5061 #define STATUS_STRING(status) status_string[status] = #status
5062 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
5063 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
5064 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5065 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5066 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
5067 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
5068 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
5069 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
5070 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
5071 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
5072 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
5073 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
5074 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
5075 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
5076 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
5077 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
5078 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
5079 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
5080 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
5081 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
5082 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
5083 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
5084 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
5085 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
5086 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
5087 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
5088 #undef STATUS_STRING
5094 hdll
= GetModuleHandleA("wininet.dll");
5096 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
5097 win_skip("Too old IE (older than 6.0)\n");
5101 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
5102 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
5103 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
5105 init_status_tests();
5106 test_InternetCloseHandle();
5107 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
5108 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
5109 InternetReadFile_test(0, &test_data
[1]);
5110 first_connection_to_test_url
= TRUE
;
5111 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
5112 test_security_flags();
5113 InternetReadFile_test(0, &test_data
[2]);
5114 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
5115 test_open_url_async();
5116 test_async_HttpSendRequestEx(¬ification_data
[0]);
5117 test_async_HttpSendRequestEx(¬ification_data
[1]);
5118 test_async_HttpSendRequestEx(¬ification_data
[2]);
5119 InternetOpenRequest_test();
5121 InternetOpenUrlA_test();
5123 test_http_connection();
5124 test_secure_connection();
5125 test_user_agent_header();
5126 test_bogus_accept_types_array();
5127 InternetReadFile_chunked_test();
5128 HttpSendRequestEx_test();
5129 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
5130 test_connection_failure();
5131 test_default_service_port();