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
= CreateEventW(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
= InternetSetOptionA(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
);
822 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
824 res
= InternetReadFile(hor
,buffer
,length
,&got
);
827 trace("ReadFile -> %i %i\n",res
,got
);
828 ok( length
== got
, "only got %u of %u available\n", got
, length
);
829 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
831 HeapFree(GetProcessHeap(),0,buffer
);
837 res
= InternetReadFile( hor
, buffer
, 1, &got
);
838 ok( res
, "InternetReadFile failed: %u\n", GetLastError() );
839 ok( !got
, "got %u\n", got
);
846 res
= InternetCloseHandle(hor
);
847 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
850 res
= InternetCloseHandle(hi
);
851 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
855 static void InternetReadFileExA_test(int flags
)
859 const char *types
[2] = { "*", NULL
};
860 HINTERNET hi
, hic
= 0, hor
= 0;
861 INTERNET_BUFFERSA inetbuffers
;
863 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
865 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
867 trace("InternetOpenA <--\n");
868 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
869 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
870 trace("InternetOpenA -->\n");
872 if (hi
== 0x0) goto abort
;
874 pInternetSetStatusCallbackA(hi
,&callback
);
876 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
878 trace("InternetConnectA <--\n");
879 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
880 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
881 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
882 trace("InternetConnectA -->\n");
884 if (hic
== 0x0) goto abort
;
886 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
887 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
889 trace("HttpOpenRequestA <--\n");
890 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
891 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
893 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
895 * If the internet name can't be resolved we are probably behind
896 * a firewall or in some other way not directly connected to the
897 * Internet. Not enough reason to fail the test. Just ignore and
901 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
903 trace("HttpOpenRequestA -->\n");
905 if (hor
== 0x0) goto abort
;
907 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
908 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
909 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
910 if (first_connection_to_test_url
)
912 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
913 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
915 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
, 2);
916 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
917 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
918 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
919 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
920 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
921 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
922 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
923 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
924 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
925 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
926 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
927 if (flags
& INTERNET_FLAG_ASYNC
)
928 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
930 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
932 trace("HttpSendRequestA -->\n");
933 SetLastError(0xdeadbeef);
934 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
935 if (flags
& INTERNET_FLAG_ASYNC
)
936 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
937 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
939 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
940 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
941 trace("HttpSendRequestA <--\n");
943 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
944 WaitForSingleObject(hCompleteEvent
, INFINITE
);
945 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
948 if (first_connection_to_test_url
)
950 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
951 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
955 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
956 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
958 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
959 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
960 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
961 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
962 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
963 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
964 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
965 if (flags
& INTERNET_FLAG_ASYNC
)
966 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
968 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
969 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
970 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
971 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
972 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
974 /* tests invalid dwStructSize */
975 inetbuffers
.dwStructSize
= sizeof(inetbuffers
)+1;
976 inetbuffers
.lpcszHeader
= NULL
;
977 inetbuffers
.dwHeadersLength
= 0;
978 inetbuffers
.dwBufferLength
= 10;
979 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
980 inetbuffers
.dwOffsetHigh
= 1234;
981 inetbuffers
.dwOffsetLow
= 5678;
982 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
983 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
984 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
985 rc
? "TRUE" : "FALSE", GetLastError());
986 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
988 test_request_flags(hor
, 0);
990 /* tests to see whether lpcszHeader is used - it isn't */
991 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
992 inetbuffers
.lpcszHeader
= (LPCSTR
)0xdeadbeef;
993 inetbuffers
.dwHeadersLength
= 255;
994 inetbuffers
.dwBufferLength
= 0;
995 inetbuffers
.lpvBuffer
= NULL
;
996 inetbuffers
.dwOffsetHigh
= 1234;
997 inetbuffers
.dwOffsetLow
= 5678;
998 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
999 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
1000 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1001 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
1002 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1005 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1006 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1009 rc
= InternetReadFileExA(NULL
, &inetbuffers
, 0, 0xdeadcafe);
1010 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
1011 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1012 rc
? "TRUE" : "FALSE", GetLastError());
1015 trace("Entering Query loop\n");
1019 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1020 inetbuffers
.dwBufferLength
= 1024;
1021 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
1022 inetbuffers
.dwOffsetHigh
= 1234;
1023 inetbuffers
.dwOffsetLow
= 5678;
1025 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1026 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1027 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1028 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
1031 if (GetLastError() == ERROR_IO_PENDING
)
1033 trace("InternetReadFileEx -> PENDING\n");
1034 ok(flags
& INTERNET_FLAG_ASYNC
,
1035 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1036 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1037 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1038 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1039 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1040 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1044 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1050 trace("InternetReadFileEx -> SUCCEEDED\n");
1051 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1052 if (inetbuffers
.dwBufferLength
)
1055 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1056 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1061 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1062 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1063 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1067 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1068 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
1070 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
1071 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1072 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
1074 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1076 if (!inetbuffers
.dwBufferLength
)
1079 length
+= inetbuffers
.dwBufferLength
;
1081 ok(length
> 0, "failed to read any of the document\n");
1082 trace("Finished. Read %d bytes\n", length
);
1085 close_async_handle(hi
, hCompleteEvent
, 2);
1086 CloseHandle(hCompleteEvent
);
1087 first_connection_to_test_url
= FALSE
;
1090 static void InternetOpenUrlA_test(void)
1092 HINTERNET myhinternet
, myhttp
;
1094 DWORD size
, readbytes
, totalbytes
=0;
1097 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1098 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
1099 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret
, GetLastError());
1101 myhinternet
= InternetOpenA("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
1102 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
1104 ret
= InternetCanonicalizeUrlA(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1105 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1108 myhttp
= InternetOpenUrlA(myhinternet
, TEST_URL
, 0, 0,
1109 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
1110 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1111 return; /* WinXP returns this when not connected to the net */
1112 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1113 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
1114 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
1115 totalbytes
+= readbytes
;
1116 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
1117 totalbytes
+= readbytes
;
1118 trace("read 0x%08x bytes\n",totalbytes
);
1120 InternetCloseHandle(myhttp
);
1121 InternetCloseHandle(myhinternet
);
1123 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1124 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1127 static void HttpSendRequestEx_test(void)
1133 INTERNET_BUFFERSA BufferIn
;
1134 DWORD dwBytesWritten
, dwBytesRead
, error
;
1139 static char szPostData
[] = "mode=Test";
1140 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
1142 hSession
= InternetOpenA("Wine Regression Test",
1143 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1144 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1145 hConnect
= InternetConnectA(hSession
, "crossover.codeweavers.com",
1146 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1148 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
1149 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/posttest.php",
1150 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1151 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1153 skip( "Network unreachable, skipping test\n" );
1156 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1158 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1160 BufferIn
.dwStructSize
= sizeof(BufferIn
);
1161 BufferIn
.Next
= (INTERNET_BUFFERSA
*)0xdeadcab;
1162 BufferIn
.lpcszHeader
= szContentType
;
1163 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1164 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1165 BufferIn
.lpvBuffer
= szPostData
;
1166 BufferIn
.dwBufferLength
= 3;
1167 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1168 BufferIn
.dwOffsetLow
= 0;
1169 BufferIn
.dwOffsetHigh
= 0;
1171 SetLastError(0xdeadbeef);
1172 ret
= HttpSendRequestExA(hRequest
, &BufferIn
, NULL
, 0 ,0);
1173 error
= GetLastError();
1174 ok(ret
, "HttpSendRequestEx Failed with error %u\n", error
);
1175 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", error
);
1177 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1179 for (i
= 3; szPostData
[i
]; i
++)
1180 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1181 "InternetWriteFile failed\n");
1183 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1185 ok(HttpEndRequestA(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1187 test_request_flags(hRequest
, 0);
1189 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1190 "Unable to read response\n");
1191 szBuffer
[dwBytesRead
] = 0;
1193 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
1194 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1196 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1198 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1199 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1202 static void InternetOpenRequest_test(void)
1204 HINTERNET session
, connect
, request
;
1205 static const char *types
[] = { "*", "", NULL
};
1206 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1207 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1210 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1211 ok(session
!= NULL
,"Unable to open Internet session\n");
1213 connect
= InternetConnectA(session
, NULL
, 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 NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1218 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1219 INTERNET_SERVICE_HTTP
, 0, 0);
1220 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1221 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1223 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1224 INTERNET_SERVICE_HTTP
, 0, 0);
1225 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1227 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1228 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1230 skip( "Network unreachable, skipping test\n" );
1233 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1235 ret
= HttpSendRequestW(request
, NULL
, 0, NULL
, 0);
1236 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1237 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1239 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1240 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1242 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1243 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1244 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1247 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1248 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1251 static void test_cache_read(void)
1253 HINTERNET session
, connection
, req
;
1254 FILETIME now
, tomorrow
, yesterday
;
1255 BYTE content
[1000], buf
[2000];
1256 char file_path
[MAX_PATH
];
1263 static const char cache_only_url
[] = "http://test.winehq.org/tests/cache-only";
1264 BYTE cache_headers
[] = "HTTP/1.1 200 OK\r\n\r\n";
1266 trace("Testing cache read...\n");
1268 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1270 for(i
= 0; i
< sizeof(content
); i
++)
1271 content
[i
] = '0' + (i
%10);
1273 GetSystemTimeAsFileTime(&now
);
1274 li
.u
.HighPart
= now
.dwHighDateTime
;
1275 li
.u
.LowPart
= now
.dwLowDateTime
;
1276 li
.QuadPart
+= (LONGLONG
)10000000 * 3600 * 24;
1277 tomorrow
.dwHighDateTime
= li
.u
.HighPart
;
1278 tomorrow
.dwLowDateTime
= li
.u
.LowPart
;
1279 li
.QuadPart
-= (LONGLONG
)10000000 * 3600 * 24 * 2;
1280 yesterday
.dwHighDateTime
= li
.u
.HighPart
;
1281 yesterday
.dwLowDateTime
= li
.u
.LowPart
;
1283 res
= CreateUrlCacheEntryA(cache_only_url
, sizeof(content
), "", file_path
, 0);
1284 ok(res
, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1286 file
= CreateFileA(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1287 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
1289 WriteFile(file
, content
, sizeof(content
), &size
, NULL
);
1292 res
= CommitUrlCacheEntryA(cache_only_url
, file_path
, tomorrow
, yesterday
, NORMAL_CACHE_ENTRY
,
1293 cache_headers
, sizeof(cache_headers
)-1, "", 0);
1294 ok(res
, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1296 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
1297 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
1299 pInternetSetStatusCallbackA(session
, callback
);
1301 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1302 connection
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
,
1303 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1304 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
1305 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1307 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1308 req
= HttpOpenRequestA(connection
, "GET", "/tests/cache-only", NULL
, NULL
, NULL
, 0, 0xdeadbead);
1309 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
1310 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1312 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1313 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1314 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST
);
1315 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT
);
1316 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1317 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1318 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1320 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
1322 ok(res
, "HttpSendRequest failed: %u\n", GetLastError());
1326 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
1327 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1328 ok(size
== sizeof(content
), "size = %u\n", size
);
1331 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
1332 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
1333 ok(size
== sizeof(content
), "size = %u\n", size
);
1334 ok(!memcmp(content
, buf
, sizeof(content
)), "unexpected content\n");
1337 close_async_handle(session
, hCompleteEvent
, 2);
1339 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1340 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1341 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
1342 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
1343 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1344 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1345 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1347 res
= DeleteUrlCacheEntryA(cache_only_url
);
1348 ok(res
, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1350 CloseHandle(hCompleteEvent
);
1353 static void test_http_cache(void)
1355 HINTERNET session
, connect
, request
;
1356 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1357 DWORD size
, file_size
;
1362 static const char *types
[] = { "*", "", NULL
};
1364 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1365 ok(session
!= NULL
,"Unable to open Internet session\n");
1367 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1368 INTERNET_SERVICE_HTTP
, 0, 0);
1369 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1371 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1372 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1374 skip( "Network unreachable, skipping test\n" );
1376 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1377 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1381 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1384 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1385 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1386 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1388 size
= sizeof(file_name
);
1389 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1390 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1391 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1392 ok(!size
, "size = %d\n", size
);
1394 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1395 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1397 size
= sizeof(file_name
);
1398 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1399 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1401 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1402 FILE_ATTRIBUTE_NORMAL
, NULL
);
1403 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1404 file_size
= GetFileSize(file
, NULL
);
1405 ok(file_size
== 106, "file size = %u\n", file_size
);
1408 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1409 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1410 ok(size
== 100, "size = %u\n", size
);
1412 file_size
= GetFileSize(file
, NULL
);
1413 ok(file_size
== 106, "file size = %u\n", file_size
);
1416 ret
= DeleteFileA(file_name
);
1417 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1419 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1421 file
= CreateFileA(file_name
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
1422 FILE_ATTRIBUTE_NORMAL
, NULL
);
1423 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1426 /* Send the same request, requiring it to be retrieved from the cache */
1427 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1429 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1430 ok(ret
, "HttpSendRequest failed\n");
1433 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1434 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1435 ok(size
== 100, "size = %u\n", size
);
1437 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1439 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1440 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1442 size
= sizeof(file_name
);
1443 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1444 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1445 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1446 ok(!size
, "size = %d\n", size
);
1448 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1449 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1451 size
= sizeof(file_name
);
1453 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1456 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1457 FILE_ATTRIBUTE_NORMAL
, NULL
);
1458 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1464 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1467 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1468 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1469 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1474 static void InternetLockRequestFile_test(void)
1476 HINTERNET session
, connect
, request
;
1477 char file_name
[MAX_PATH
];
1482 static const char *types
[] = { "*", "", NULL
};
1484 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1485 ok(session
!= NULL
,"Unable to open Internet session\n");
1487 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1488 INTERNET_SERVICE_HTTP
, 0, 0);
1489 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1491 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
|INTERNET_FLAG_RELOAD
, 0);
1492 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1494 skip( "Network unreachable, skipping test\n" );
1496 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1497 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1501 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1503 size
= sizeof(file_name
);
1504 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1505 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1506 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1507 ok(!size
, "size = %d\n", size
);
1510 ret
= InternetLockRequestFile(request
, &lock
);
1511 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1513 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1514 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1516 size
= sizeof(file_name
);
1517 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1518 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1520 ret
= InternetLockRequestFile(request
, &lock
);
1521 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1522 ok(lock
!= NULL
, "lock == NULL\n");
1524 ret
= InternetLockRequestFile(request
, &lock2
);
1525 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1526 ok(lock
== lock2
, "lock != lock2\n");
1528 ret
= InternetUnlockRequestFile(lock2
);
1529 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1531 ret
= DeleteFileA(file_name
);
1532 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1534 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1536 ret
= DeleteFileA(file_name
);
1537 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1539 ret
= InternetUnlockRequestFile(lock
);
1540 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1542 ret
= DeleteFileA(file_name
);
1543 ok(ret
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1546 static void HttpHeaders_test(void)
1558 hSession
= InternetOpenA("Wine Regression Test",
1559 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1560 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1561 hConnect
= InternetConnectA(hSession
, "crossover.codeweavers.com",
1562 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1564 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
1565 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/posttest.php",
1566 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1567 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1569 skip( "Network unreachable, skipping test\n" );
1572 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1575 len
= sizeof(buffer
);
1576 strcpy(buffer
,"Warning");
1577 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1578 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1580 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1581 "Failed to add new header\n");
1584 len
= sizeof(buffer
);
1585 strcpy(buffer
,"Warning");
1586 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1587 buffer
,&len
,&index
),"Unable to query header\n");
1588 ok(index
== 1, "Index was not incremented\n");
1589 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1590 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1591 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1592 len
= sizeof(buffer
);
1593 strcpy(buffer
,"Warning");
1594 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1595 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1598 len
= 5; /* could store the string but not the NULL terminator */
1599 strcpy(buffer
,"Warning");
1600 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1601 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1602 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1603 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1605 /* a call with NULL will fail but will return the length */
1607 len
= sizeof(buffer
);
1608 SetLastError(0xdeadbeef);
1609 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1610 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1611 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1612 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1613 ok(index
== 0, "Index was incremented\n");
1615 /* even for a len that is too small */
1618 SetLastError(0xdeadbeef);
1619 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1620 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1621 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1622 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1623 ok(index
== 0, "Index was incremented\n");
1627 SetLastError(0xdeadbeef);
1628 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1629 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1630 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1631 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1632 ok(index
== 0, "Index was incremented\n");
1633 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1636 /* a working query */
1638 len
= sizeof(buffer
);
1639 memset(buffer
, 'x', sizeof(buffer
));
1640 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1641 buffer
,&len
,&index
),"Unable to query header\n");
1642 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1643 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1644 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1645 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1646 ok(strncmp(buffer
, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1647 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1648 ok(index
== 0, "Index was incremented\n");
1650 /* Like above two tests, but for W version */
1654 SetLastError(0xdeadbeef);
1655 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1656 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1657 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1658 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1659 ok(index
== 0, "Index was incremented\n");
1660 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1662 /* a working query */
1664 len
= sizeof(wbuffer
);
1665 memset(wbuffer
, 'x', sizeof(wbuffer
));
1666 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1667 wbuffer
,&len
,&index
),"Unable to query header\n");
1668 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1669 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1670 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1671 ok(index
== 0, "Index was incremented\n");
1673 /* end of W version tests */
1675 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1677 len
= sizeof(buffer
);
1678 memset(buffer
, 'x', sizeof(buffer
));
1679 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1680 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1681 ok(len
== 2, "Expected 2, got %d\n", len
);
1682 ok(strcmp(buffer
, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer
);
1683 ok(index
== 0, "Index was incremented\n");
1685 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1686 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1689 len
= sizeof(buffer
);
1690 strcpy(buffer
,"Warning");
1691 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1692 buffer
,&len
,&index
),"Unable to query header\n");
1693 ok(index
== 1, "Index was not incremented\n");
1694 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1695 len
= sizeof(buffer
);
1696 strcpy(buffer
,"Warning");
1697 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1698 buffer
,&len
,&index
),"Failed to get second header\n");
1699 ok(index
== 2, "Index was not incremented\n");
1700 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1701 len
= sizeof(buffer
);
1702 strcpy(buffer
,"Warning");
1703 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1704 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1706 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1709 len
= sizeof(buffer
);
1710 strcpy(buffer
,"Warning");
1711 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1712 buffer
,&len
,&index
),"Unable to query header\n");
1713 ok(index
== 1, "Index was not incremented\n");
1714 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1715 len
= sizeof(buffer
);
1716 strcpy(buffer
,"Warning");
1717 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1718 buffer
,&len
,&index
),"Failed to get second header\n");
1719 ok(index
== 2, "Index was not incremented\n");
1720 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1721 len
= sizeof(buffer
);
1722 strcpy(buffer
,"Warning");
1723 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1724 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1726 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1729 len
= sizeof(buffer
);
1730 strcpy(buffer
,"Warning");
1731 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1732 buffer
,&len
,&index
),"Unable to query header\n");
1733 ok(index
== 1, "Index was not incremented\n");
1734 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1735 len
= sizeof(buffer
);
1736 strcpy(buffer
,"Warning");
1737 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1738 buffer
,&len
,&index
),"Failed to get second header\n");
1739 ok(index
== 2, "Index was not incremented\n");
1740 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1741 len
= sizeof(buffer
);
1742 strcpy(buffer
,"Warning");
1743 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1744 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1746 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1749 len
= sizeof(buffer
);
1750 strcpy(buffer
,"Warning");
1751 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1752 buffer
,&len
,&index
),"Unable to query header\n");
1753 ok(index
== 1, "Index was not incremented\n");
1754 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1755 len
= sizeof(buffer
);
1756 strcpy(buffer
,"Warning");
1757 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1758 ok(index
== 2, "Index was not incremented\n");
1759 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1760 len
= sizeof(buffer
);
1761 strcpy(buffer
,"Warning");
1762 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1764 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1767 len
= sizeof(buffer
);
1768 strcpy(buffer
,"Warning");
1769 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1770 ok(index
== 1, "Index was not incremented\n");
1771 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1772 len
= sizeof(buffer
);
1773 strcpy(buffer
,"Warning");
1774 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1775 ok(index
== 2, "Index was not incremented\n");
1776 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1777 len
= sizeof(buffer
);
1778 strcpy(buffer
,"Warning");
1779 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1781 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1784 len
= sizeof(buffer
);
1785 strcpy(buffer
,"Warning");
1786 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1787 ok(index
== 1, "Index was not incremented\n");
1788 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1789 len
= sizeof(buffer
);
1790 strcpy(buffer
,"Warning");
1791 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1792 ok(index
== 2, "Index was not incremented\n");
1793 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1794 len
= sizeof(buffer
);
1795 strcpy(buffer
,"Warning");
1796 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1798 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test7",-1, HTTP_ADDREQ_FLAG_ADD
|HTTP_ADDREQ_FLAG_REPLACE
), "HTTP_ADDREQ_FLAG_ADD with HTTP_ADDREQ_FLAG_REPALCE Did not work\n");
1801 len
= sizeof(buffer
);
1802 strcpy(buffer
,"Warning");
1803 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1804 ok(index
== 1, "Index was not incremented\n");
1805 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1806 len
= sizeof(buffer
);
1807 strcpy(buffer
,"Warning");
1808 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1809 ok(index
== 2, "Index was not incremented\n");
1810 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1811 len
= sizeof(buffer
);
1812 strcpy(buffer
,"Warning");
1813 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1815 /* Ensure that blank headers are ignored and don't cause a failure */
1816 ok(HttpAddRequestHeadersA(hRequest
,"\r\nBlankTest:value\r\n\r\n",-1, HTTP_ADDREQ_FLAG_ADD_IF_NEW
), "Failed to add header with blank entries in list\n");
1819 len
= sizeof(buffer
);
1820 strcpy(buffer
,"BlankTest");
1821 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1822 ok(index
== 1, "Index was not incremented\n");
1823 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1825 /* Ensure that malformed header separators are ignored and don't cause a failure */
1826 ok(HttpAddRequestHeadersA(hRequest
,"\r\rMalformedTest:value\n\nMalformedTestTwo: value2\rMalformedTestThree: value3\n\n\r\r\n",-1, HTTP_ADDREQ_FLAG_ADD
|HTTP_ADDREQ_FLAG_REPLACE
),
1827 "Failed to add header with malformed entries in list\n");
1830 len
= sizeof(buffer
);
1831 strcpy(buffer
,"MalformedTest");
1832 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1833 ok(index
== 1, "Index was not incremented\n");
1834 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1836 len
= sizeof(buffer
);
1837 strcpy(buffer
,"MalformedTestTwo");
1838 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1839 ok(index
== 1, "Index was not incremented\n");
1840 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
1842 len
= sizeof(buffer
);
1843 strcpy(buffer
,"MalformedTestThree");
1844 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1845 ok(index
== 1, "Index was not incremented\n");
1846 ok(strcmp(buffer
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
1848 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD
);
1849 ok(ret
, "unable to add header %u\n", GetLastError());
1853 len
= sizeof(buffer
);
1854 ret
= HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
);
1855 ok(ret
, "unable to query header %u\n", GetLastError());
1856 ok(index
== 1, "index was not incremented\n");
1857 ok(!strcmp(buffer
, "Basic"), "incorrect string was returned (%s)\n", buffer
);
1859 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE
);
1860 ok(ret
, "unable to remove header %u\n", GetLastError());
1863 len
= sizeof(buffer
);
1864 SetLastError(0xdeadbeef);
1865 ok(!HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
),
1866 "header still present\n");
1867 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "got %u\n", GetLastError());
1869 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1871 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1872 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1875 static const char garbagemsg
[] =
1876 "Garbage: Header\r\n";
1878 static const char contmsg
[] =
1879 "HTTP/1.1 100 Continue\r\n";
1881 static const char expandcontmsg
[] =
1882 "HTTP/1.1 100 Continue\r\n"
1883 "Server: winecontinue\r\n"
1884 "Tag: something witty\r\n"
1887 static const char okmsg
[] =
1888 "HTTP/1.1 200 OK\r\n"
1889 "Server: winetest\r\n"
1892 static const char okmsg2
[] =
1893 "HTTP/1.1 200 OK\r\n"
1894 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1895 "Server: winetest\r\n"
1896 "Content-Length: 0\r\n"
1897 "Set-Cookie: one\r\n"
1898 "Set-Cookie: two\r\n"
1901 static const char notokmsg
[] =
1902 "HTTP/1.1 400 Bad Request\r\n"
1903 "Server: winetest\r\n"
1906 static const char noauthmsg
[] =
1907 "HTTP/1.1 401 Unauthorized\r\n"
1908 "Server: winetest\r\n"
1909 "Connection: close\r\n"
1910 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1913 static const char noauthmsg2
[] =
1914 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
1915 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
1917 "Server: winetest\r\n";
1919 static const char proxymsg
[] =
1920 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1921 "Server: winetest\r\n"
1922 "Proxy-Connection: close\r\n"
1923 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1926 static const char page1
[] =
1928 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1929 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1932 static const char ok_with_length
[] =
1933 "HTTP/1.1 200 OK\r\n"
1934 "Connection: Keep-Alive\r\n"
1935 "Content-Length: 18\r\n\r\n"
1936 "HTTP/1.1 211 OK\r\n\r\n";
1938 static const char ok_with_length2
[] =
1939 "HTTP/1.1 210 OK\r\n"
1940 "Connection: Keep-Alive\r\n"
1941 "Content-Length: 19\r\n\r\n"
1942 "HTTP/1.1 211 OK\r\n\r\n";
1944 struct server_info
{
1949 static int test_cache_gzip
;
1950 static const char *send_buffer
;
1952 static DWORD CALLBACK
server_thread(LPVOID param
)
1954 struct server_info
*si
= param
;
1955 int r
, c
, i
, on
, count
= 0;
1957 struct sockaddr_in sa
;
1960 int last_request
= 0;
1961 char host_header
[22];
1962 static BOOL test_b
= FALSE
;
1963 static int test_no_cache
= 0;
1965 WSAStartup(MAKEWORD(1,1), &wsaData
);
1967 s
= socket(AF_INET
, SOCK_STREAM
, 0);
1968 if (s
== INVALID_SOCKET
)
1972 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
1974 memset(&sa
, 0, sizeof sa
);
1975 sa
.sin_family
= AF_INET
;
1976 sa
.sin_port
= htons(si
->port
);
1977 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
1979 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
1985 SetEvent(si
->hEvent
);
1987 sprintf(host_header
, "Host: localhost:%d", si
->port
);
1991 c
= accept(s
, NULL
, NULL
);
1993 memset(buffer
, 0, sizeof buffer
);
1994 for(i
=0; i
<(sizeof buffer
-1); i
++)
1996 r
= recv(c
, &buffer
[i
], 1, 0);
2000 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
2001 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
2004 if (strstr(buffer
, "GET /test1"))
2006 if (!strstr(buffer
, "Content-Length: 0"))
2008 send(c
, okmsg
, sizeof okmsg
-1, 0);
2009 send(c
, page1
, sizeof page1
-1, 0);
2012 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2014 if (strstr(buffer
, "/test2"))
2016 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2018 send(c
, okmsg
, sizeof okmsg
-1, 0);
2019 send(c
, page1
, sizeof page1
-1, 0);
2022 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2024 if (strstr(buffer
, "/test3"))
2026 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2027 send(c
, okmsg
, sizeof okmsg
-1, 0);
2029 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2031 if (strstr(buffer
, "/test4"))
2033 if (strstr(buffer
, "Connection: Close"))
2034 send(c
, okmsg
, sizeof okmsg
-1, 0);
2036 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2038 if (strstr(buffer
, "POST /test5") ||
2039 strstr(buffer
, "RPC_IN_DATA /test5") ||
2040 strstr(buffer
, "RPC_OUT_DATA /test5"))
2042 if (strstr(buffer
, "Content-Length: 0"))
2044 send(c
, okmsg
, sizeof okmsg
-1, 0);
2045 send(c
, page1
, sizeof page1
-1, 0);
2048 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2050 if (strstr(buffer
, "GET /test6"))
2052 send(c
, contmsg
, sizeof contmsg
-1, 0);
2053 send(c
, contmsg
, sizeof contmsg
-1, 0);
2054 send(c
, okmsg
, sizeof okmsg
-1, 0);
2055 send(c
, page1
, sizeof page1
-1, 0);
2057 if (strstr(buffer
, "POST /test7"))
2059 if (strstr(buffer
, "Content-Length: 100"))
2061 send(c
, okmsg
, sizeof okmsg
-1, 0);
2062 send(c
, page1
, sizeof page1
-1, 0);
2065 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2067 if (strstr(buffer
, "/test8"))
2069 if (!strstr(buffer
, "Connection: Close") &&
2070 strstr(buffer
, "Connection: Keep-Alive") &&
2071 !strstr(buffer
, "Cache-Control: no-cache") &&
2072 !strstr(buffer
, "Pragma: no-cache") &&
2073 strstr(buffer
, host_header
))
2074 send(c
, okmsg
, sizeof okmsg
-1, 0);
2076 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2078 if (strstr(buffer
, "/test9"))
2080 if (!strstr(buffer
, "Connection: Close") &&
2081 !strstr(buffer
, "Connection: Keep-Alive") &&
2082 !strstr(buffer
, "Cache-Control: no-cache") &&
2083 !strstr(buffer
, "Pragma: no-cache") &&
2084 strstr(buffer
, host_header
))
2085 send(c
, okmsg
, sizeof okmsg
-1, 0);
2087 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2089 if (strstr(buffer
, "/testA"))
2091 if (!strstr(buffer
, "Connection: Close") &&
2092 !strstr(buffer
, "Connection: Keep-Alive") &&
2093 (strstr(buffer
, "Cache-Control: no-cache") ||
2094 strstr(buffer
, "Pragma: no-cache")) &&
2095 strstr(buffer
, host_header
))
2096 send(c
, okmsg
, sizeof okmsg
-1, 0);
2098 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2100 if (!test_b
&& strstr(buffer
, "/testB HTTP/1.1"))
2103 send(c
, okmsg
, sizeof okmsg
-1, 0);
2104 recvfrom(c
, buffer
, sizeof buffer
, 0, NULL
, NULL
);
2105 send(c
, okmsg
, sizeof okmsg
-1, 0);
2107 if (strstr(buffer
, "/testC"))
2109 if (strstr(buffer
, "Cookie: cookie=biscuit"))
2110 send(c
, okmsg
, sizeof okmsg
-1, 0);
2112 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2114 if (strstr(buffer
, "/testD"))
2116 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
2118 if (strstr(buffer
, "/testE"))
2120 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
2122 if (strstr(buffer
, "GET /quit"))
2124 send(c
, okmsg
, sizeof okmsg
-1, 0);
2125 send(c
, page1
, sizeof page1
-1, 0);
2128 if (strstr(buffer
, "GET /testF"))
2130 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
2131 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2132 send(c
, contmsg
, sizeof contmsg
-1, 0);
2133 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2134 send(c
, okmsg
, sizeof okmsg
-1, 0);
2135 send(c
, page1
, sizeof page1
-1, 0);
2137 if (strstr(buffer
, "GET /testG"))
2139 send(c
, page1
, sizeof page1
-1, 0);
2142 if (strstr(buffer
, "GET /testJ"))
2147 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2151 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2155 if (strstr(buffer
, "GET /testH"))
2157 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2158 recvfrom(c
, buffer
, sizeof(buffer
), 0, NULL
, NULL
);
2159 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2162 if (strstr(buffer
, "GET /test_no_content"))
2164 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2165 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2167 if (strstr(buffer
, "GET /test_conn_close"))
2169 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2170 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
2171 WaitForSingleObject(conn_close_event
, INFINITE
);
2172 trace("closing connection\n");
2174 if (strstr(buffer
, "GET /test_cache_control_no_cache"))
2176 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2177 if(!test_no_cache
++)
2178 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2180 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2182 if (strstr(buffer
, "GET /test_cache_control_no_store"))
2184 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2185 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2187 if (strstr(buffer
, "GET /test_cache_gzip"))
2189 static const char gzip_response
[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2190 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2191 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2192 if(!test_cache_gzip
++)
2193 send(c
, gzip_response
, sizeof(gzip_response
), 0);
2195 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2197 if (strstr(buffer
, "GET /send_from_buffer"))
2198 send(c
, send_buffer
, strlen(send_buffer
), 0);
2199 if (strstr(buffer
, "/test_cache_control_verb"))
2201 if (!memcmp(buffer
, "GET ", sizeof("GET ")-1) &&
2202 !strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2203 else if (strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2204 else send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2206 if (strstr(buffer
, "GET /test_premature_disconnect"))
2207 trace("closing connection\n");
2211 } while (!last_request
);
2218 static void test_basic_request(int port
, const char *verb
, const char *url
)
2220 HINTERNET hi
, hc
, hr
;
2221 DWORD r
, count
, error
;
2224 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2225 ok(hi
!= NULL
, "open failed\n");
2227 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2228 ok(hc
!= NULL
, "connect failed\n");
2230 hr
= HttpOpenRequestA(hc
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
2231 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2233 SetLastError(0xdeadbeef);
2234 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2235 error
= GetLastError();
2236 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
2237 ok(r
, "HttpSendRequest failed\n");
2240 memset(buffer
, 0, sizeof buffer
);
2241 SetLastError(0xdeadbeef);
2242 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
2243 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2244 ok(count
== sizeof page1
- 1, "count was wrong\n");
2245 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2247 InternetCloseHandle(hr
);
2248 InternetCloseHandle(hc
);
2249 InternetCloseHandle(hi
);
2252 static void test_proxy_indirect(int port
)
2254 HINTERNET hi
, hc
, hr
;
2258 hi
= InternetOpenA(NULL
, 0, NULL
, NULL
, 0);
2259 ok(hi
!= NULL
, "open failed\n");
2261 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2262 ok(hc
!= NULL
, "connect failed\n");
2264 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2265 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2267 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2268 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2271 r
= HttpQueryInfoA(hr
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2272 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
2275 skip("missing proxy header, not testing remaining proxy headers\n");
2278 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2280 test_status_code(hr
, 407);
2281 test_request_flags(hr
, 0);
2284 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2285 ok(r
, "HttpQueryInfo failed\n");
2286 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2289 r
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2290 ok(r
, "HttpQueryInfo failed\n");
2291 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2294 r
= HttpQueryInfoA(hr
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2295 ok(r
, "HttpQueryInfo failed\n");
2296 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2299 r
= HttpQueryInfoA(hr
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2300 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2301 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2304 InternetCloseHandle(hr
);
2305 InternetCloseHandle(hc
);
2306 InternetCloseHandle(hi
);
2309 static void test_proxy_direct(int port
)
2311 HINTERNET hi
, hc
, hr
;
2313 char buffer
[0x40], *url
;
2314 WCHAR bufferW
[0x40];
2315 static const char url_fmt
[] = "http://test.winehq.org:%u/test2";
2316 static CHAR username
[] = "mike",
2317 password
[] = "1101",
2318 useragent
[] = "winetest";
2319 static const WCHAR usernameW
[] = {'m','i','k','e',0},
2320 passwordW
[] = {'1','1','0','1',0},
2321 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2323 /* specify proxy type without the proxy and bypass */
2324 SetLastError(0xdeadbeef);
2325 hi
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2326 error
= GetLastError();
2327 ok(error
== ERROR_INVALID_PARAMETER
||
2328 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %u\n", error
);
2329 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2331 sprintf(buffer
, "localhost:%d\n", port
);
2332 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2333 ok(hi
!= NULL
, "open failed\n");
2335 /* try connect without authorization */
2336 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2337 ok(hc
!= NULL
, "connect failed\n");
2339 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2340 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2343 SetLastError(0xdeadbeef);
2344 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
2345 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2346 ok(!r
, "unexpected success\n");
2347 ok(sz
== 1, "got %u\n", sz
);
2350 SetLastError(0xdeadbeef);
2351 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
2352 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2353 ok(!r
, "unexpected success\n");
2354 ok(sz
== 1, "got %u\n", sz
);
2356 sz
= sizeof(buffer
);
2357 SetLastError(0xdeadbeef);
2358 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2359 ok(r
, "unexpected failure %u\n", GetLastError());
2360 ok(!sz
, "got %u\n", sz
);
2362 sz
= sizeof(buffer
);
2363 SetLastError(0xdeadbeef);
2364 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2365 ok(r
, "unexpected failure %u\n", GetLastError());
2366 ok(!sz
, "got %u\n", sz
);
2369 SetLastError(0xdeadbeef);
2370 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
2371 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2372 ok(!r
, "unexpected success\n");
2373 ok(sz
== 1, "got %u\n", sz
);
2376 SetLastError(0xdeadbeef);
2377 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
2378 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2379 ok(!r
, "unexpected success\n");
2380 ok(sz
== 1, "got %u\n", sz
);
2382 sz
= sizeof(buffer
);
2383 SetLastError(0xdeadbeef);
2384 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2385 ok(r
, "unexpected failure %u\n", GetLastError());
2386 ok(!sz
, "got %u\n", sz
);
2388 sz
= sizeof(buffer
);
2389 SetLastError(0xdeadbeef);
2390 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2391 ok(r
, "unexpected failure %u\n", GetLastError());
2392 ok(!sz
, "got %u\n", sz
);
2395 SetLastError(0xdeadbeef);
2396 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
2397 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2398 ok(!r
, "unexpected success\n");
2399 ok(sz
== 34, "got %u\n", sz
);
2401 sz
= sizeof(buffer
);
2402 SetLastError(0xdeadbeef);
2403 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2404 ok(r
, "unexpected failure %u\n", GetLastError());
2405 ok(sz
== 33, "got %u\n", sz
);
2407 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2408 ok(r
|| broken(!r
), "HttpSendRequest failed %u\n", GetLastError());
2411 win_skip("skipping proxy tests on broken wininet\n");
2415 test_status_code(hr
, 407);
2417 /* set the user + password then try again */
2418 r
= InternetSetOptionA(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2419 ok(!r
, "unexpected success\n");
2421 r
= InternetSetOptionA(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2422 ok(r
, "failed to set user\n");
2424 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2425 ok(r
, "failed to set user\n");
2429 SetLastError(0xdeadbeef);
2430 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2431 ok(!r
, "unexpected failure %u\n", GetLastError());
2432 ok(!buffer
[0], "got %s\n", buffer
);
2433 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2437 SetLastError(0xdeadbeef);
2438 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2439 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2440 ok(!r
, "unexpected success\n");
2441 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2445 SetLastError(0xdeadbeef);
2446 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2447 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2448 ok(!r
, "unexpected success\n");
2449 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2452 sz
= sizeof(buffer
);
2453 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2454 ok(r
, "failed to get username\n");
2455 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2456 ok(sz
== strlen(username
), "got %u\n", sz
);
2459 sz
= sizeof(bufferW
);
2460 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2461 ok(r
, "failed to get username\n");
2462 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
2463 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2465 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
2466 ok(r
, "failed to set user\n");
2469 sz
= sizeof(buffer
);
2470 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2471 ok(r
, "failed to get username\n");
2472 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2473 ok(sz
== strlen(username
), "got %u\n", sz
);
2475 r
= InternetSetOptionA(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
2476 ok(r
, "failed to set useragent\n");
2480 SetLastError(0xdeadbeef);
2481 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2482 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2483 ok(!r
, "unexpected success\n");
2484 ok(sz
== strlen(useragent
) + 1, "got %u\n", sz
);
2487 sz
= sizeof(buffer
);
2488 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2489 ok(r
, "failed to get user agent\n");
2490 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
2491 ok(sz
== strlen(useragent
), "got %u\n", sz
);
2495 SetLastError(0xdeadbeef);
2496 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2497 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2498 ok(!r
, "unexpected success\n");
2499 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2502 sz
= sizeof(bufferW
);
2503 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2504 ok(r
, "failed to get user agent\n");
2505 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
2506 ok(sz
== lstrlenW(useragentW
), "got %u\n", sz
);
2508 r
= InternetSetOptionA(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
2509 ok(r
, "failed to set user\n");
2513 SetLastError(0xdeadbeef);
2514 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2515 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2516 ok(!r
, "unexpected success\n");
2517 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2520 sz
= sizeof(buffer
);
2521 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2522 ok(r
, "failed to get user\n");
2523 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2524 ok(sz
== strlen(username
), "got %u\n", sz
);
2528 SetLastError(0xdeadbeef);
2529 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2530 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2531 ok(!r
, "unexpected success\n");
2532 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2535 sz
= sizeof(bufferW
);
2536 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2537 ok(r
, "failed to get user\n");
2538 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
2539 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2541 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
2542 ok(r
, "failed to set password\n");
2546 SetLastError(0xdeadbeef);
2547 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2548 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2549 ok(!r
, "unexpected success\n");
2550 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2553 sz
= sizeof(buffer
);
2554 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2555 ok(r
, "failed to get password\n");
2556 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2557 ok(sz
== strlen(password
), "got %u\n", sz
);
2561 SetLastError(0xdeadbeef);
2562 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2563 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2564 ok(!r
, "unexpected success\n");
2565 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2568 sz
= sizeof(bufferW
);
2569 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2570 ok(r
, "failed to get password\n");
2571 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2572 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2574 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
2575 sprintf(url
, url_fmt
, port
);
2578 SetLastError(0xdeadbeef);
2579 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2580 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2581 ok(!r
, "unexpected success\n");
2582 ok(sz
== strlen(url
) + 1, "got %u\n", sz
);
2585 sz
= sizeof(buffer
);
2586 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2587 ok(r
, "failed to get url\n");
2588 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
2589 ok(sz
== strlen(url
), "got %u\n", sz
);
2593 SetLastError(0xdeadbeef);
2594 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2595 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2596 ok(!r
, "unexpected success\n");
2597 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2600 sz
= sizeof(bufferW
);
2601 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2602 ok(r
, "failed to get url\n");
2603 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
2604 ok(sz
== strlen(url
), "got %u\n", sz
);
2605 HeapFree(GetProcessHeap(), 0, url
);
2607 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2608 ok(r
, "failed to set password\n");
2612 SetLastError(0xdeadbeef);
2613 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2614 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2615 ok(!r
, "unexpected success\n");
2616 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2619 sz
= sizeof(buffer
);
2620 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2621 ok(r
, "failed to get password\n");
2622 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2623 ok(sz
== strlen(password
), "got %u\n", sz
);
2627 SetLastError(0xdeadbeef);
2628 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2629 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2630 ok(!r
, "unexpected success\n");
2631 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2634 sz
= sizeof(bufferW
);
2635 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2636 ok(r
, "failed to get password\n");
2637 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2638 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2640 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2643 win_skip("skipping proxy tests on broken wininet\n");
2646 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2648 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2649 ok(r
, "HttpQueryInfo failed\n");
2650 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2653 InternetCloseHandle(hr
);
2654 InternetCloseHandle(hc
);
2655 InternetCloseHandle(hi
);
2658 static void test_header_handling_order(int port
)
2660 static const char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
2661 static const char connection
[] = "Connection: Close";
2663 static const char *types
[2] = { "*", NULL
};
2664 HINTERNET session
, connect
, request
;
2668 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2669 ok(session
!= NULL
, "InternetOpen failed\n");
2671 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2672 ok(connect
!= NULL
, "InternetConnect failed\n");
2674 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2675 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2677 ret
= HttpAddRequestHeadersA(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
2678 ok(ret
, "HttpAddRequestHeaders failed\n");
2680 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
2681 ok(ret
, "HttpSendRequest failed\n");
2683 test_status_code(request
, 200);
2684 test_request_flags(request
, 0);
2686 InternetCloseHandle(request
);
2688 request
= HttpOpenRequestA(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2689 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2691 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2692 ok(ret
, "HttpSendRequest failed\n");
2695 size
= sizeof(status
);
2696 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2697 ok(ret
, "HttpQueryInfo failed\n");
2698 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2700 InternetCloseHandle(request
);
2702 request
= HttpOpenRequestA(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2703 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2705 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2706 ok(ret
, "HttpAddRequestHeaders failed\n");
2708 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2709 ok(ret
, "HttpSendRequest failed\n");
2712 size
= sizeof(status
);
2713 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2714 ok(ret
, "HttpQueryInfo failed\n");
2715 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2717 InternetCloseHandle(request
);
2718 InternetCloseHandle(connect
);
2719 InternetCloseHandle(session
);
2722 static void test_connection_header(int port
)
2724 HINTERNET ses
, con
, req
;
2727 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2728 ok(ses
!= NULL
, "InternetOpen failed\n");
2730 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2731 ok(con
!= NULL
, "InternetConnect failed\n");
2733 req
= HttpOpenRequestA(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2734 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2736 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2737 ok(ret
, "HttpSendRequest failed\n");
2739 test_status_code(req
, 200);
2741 InternetCloseHandle(req
);
2743 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
2744 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2746 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2747 ok(ret
, "HttpSendRequest failed\n");
2749 test_status_code(req
, 200);
2751 InternetCloseHandle(req
);
2753 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2754 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2756 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2757 ok(ret
, "HttpSendRequest failed\n");
2759 test_status_code(req
, 200);
2761 InternetCloseHandle(req
);
2763 req
= HttpOpenRequestA(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2764 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2766 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2767 ok(ret
, "HttpSendRequest failed\n");
2769 test_status_code(req
, 200);
2771 InternetCloseHandle(req
);
2772 InternetCloseHandle(con
);
2773 InternetCloseHandle(ses
);
2776 static void test_http1_1(int port
)
2778 HINTERNET ses
, con
, req
;
2781 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2782 ok(ses
!= NULL
, "InternetOpen failed\n");
2784 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2785 ok(con
!= NULL
, "InternetConnect failed\n");
2787 req
= HttpOpenRequestA(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2788 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2790 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2793 InternetCloseHandle(req
);
2795 req
= HttpOpenRequestA(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2796 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2798 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2799 ok(ret
, "HttpSendRequest failed\n");
2802 InternetCloseHandle(req
);
2803 InternetCloseHandle(con
);
2804 InternetCloseHandle(ses
);
2807 static void test_connection_closing(int port
)
2809 HINTERNET session
, connection
, req
;
2812 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2814 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2815 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2817 pInternetSetStatusCallbackA(session
, callback
);
2819 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2820 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2821 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2822 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2824 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2825 req
= HttpOpenRequestA(connection
, "GET", "/testJ", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
2826 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2827 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2829 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2830 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2831 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2832 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2833 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2834 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2835 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2836 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2837 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
2838 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
2839 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2841 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2842 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2843 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2844 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2845 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2847 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2848 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2849 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2850 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2851 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2852 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2853 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2854 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2855 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2856 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2857 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2859 test_status_code(req
, 200);
2861 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2862 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2863 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2864 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2865 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2866 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2867 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2868 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2869 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2871 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2872 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2873 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2874 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2875 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2877 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2878 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2879 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2880 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2881 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2882 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2883 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2884 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2885 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2887 test_status_code(req
, 210);
2889 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2890 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2891 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2892 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2893 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2894 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2895 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2896 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2897 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
2898 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
2899 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2901 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2902 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2903 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2904 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2905 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2907 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2908 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2909 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2910 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2911 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2912 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2913 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2914 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2915 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2916 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2917 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2919 test_status_code(req
, 200);
2921 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
2922 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
2924 close_async_handle(session
, hCompleteEvent
, 2);
2925 CloseHandle(hCompleteEvent
);
2928 static void test_successive_HttpSendRequest(int port
)
2930 HINTERNET session
, connection
, req
;
2933 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2935 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, 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
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2942 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2943 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2945 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2946 req
= HttpOpenRequestA(connection
, "GET", "/testH", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
2947 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2948 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2950 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2951 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2952 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2953 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2954 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2955 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2956 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2957 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2958 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2960 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2961 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2962 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2963 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2964 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2966 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2967 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
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
);
2976 test_status_code(req
, 210);
2978 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2979 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2980 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2981 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2982 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2983 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2984 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
2985 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
2986 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2988 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2989 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2990 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2991 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2992 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2994 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2995 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2996 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2997 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2998 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2999 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3000 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3001 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3002 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3004 test_status_code(req
, 200);
3006 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3007 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3009 close_async_handle(session
, hCompleteEvent
, 2);
3010 CloseHandle(hCompleteEvent
);
3013 static void test_no_content(int port
)
3015 HINTERNET session
, connection
, req
;
3018 trace("Testing 204 no content response...\n");
3020 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3022 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3023 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3025 pInternetSetStatusCallbackA(session
, callback
);
3027 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3028 connection
= InternetConnectA(session
, "localhost", port
,
3029 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3030 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3031 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3033 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3034 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
3035 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3036 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3037 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3039 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3040 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3041 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3042 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3043 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3044 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3045 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3046 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3047 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3048 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3050 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3051 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3052 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3053 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3054 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3056 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3057 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3058 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3059 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3060 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3061 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3062 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3063 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3065 close_async_handle(session
, hCompleteEvent
, 2);
3066 CloseHandle(hCompleteEvent
);
3069 * The connection should be closed before closing handle. This is true for most
3070 * wininet versions (including Wine), but some old win2k versions fail to do that.
3072 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3073 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3076 static void test_conn_close(int port
)
3078 HINTERNET session
, connection
, req
;
3079 DWORD res
, avail
, size
;
3082 trace("Testing connection close connection...\n");
3084 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3085 conn_close_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3087 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3088 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3090 pInternetSetStatusCallbackA(session
, callback
);
3092 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3093 connection
= InternetConnectA(session
, "localhost", port
,
3094 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3095 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3096 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3098 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3099 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
3100 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3101 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3102 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3104 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3105 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3106 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3107 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3108 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3109 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3110 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3111 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3113 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3114 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3115 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3116 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3117 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3119 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3120 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3121 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3122 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3123 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3124 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3125 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3126 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3129 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3130 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3131 ok(avail
!= 0, "avail = 0\n");
3134 res
= InternetReadFile(req
, buf
, avail
, &size
);
3135 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3137 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3138 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3139 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3140 ok(!avail
, "avail = %u, expected 0\n", avail
);
3142 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3143 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3144 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3145 SetEvent(conn_close_event
);
3146 #ifdef ROSTESTS_73_FIXED
3147 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3148 #else /* ROSTESTS_73_FIXED */
3149 ok(WaitForSingleObject(hCompleteEvent
, 5000) == WAIT_OBJECT_0
, "Wait timed out\n");
3150 #endif /* ROSTESTS_73_FIXED */
3151 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3152 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3153 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3154 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3156 close_async_handle(session
, hCompleteEvent
, 2);
3157 CloseHandle(hCompleteEvent
);
3160 static void test_no_cache(int port
)
3162 static const char cache_control_no_cache
[] = "/test_cache_control_no_cache";
3163 static const char cache_control_no_store
[] = "/test_cache_control_no_store";
3164 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3166 char cache_url
[256], buf
[256];
3167 HINTERNET ses
, con
, req
;
3171 trace("Testing no-cache header\n");
3173 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3174 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3176 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3177 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3179 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3180 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3182 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_cache
);
3183 DeleteUrlCacheEntryA(cache_url
);
3185 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3186 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3188 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3190 ok(size
== 12, "read %d bytes of data\n", size
);
3191 InternetCloseHandle(req
);
3193 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3194 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3196 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3197 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3199 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3201 ok(size
== 0, "read %d bytes of data\n", size
);
3202 InternetCloseHandle(req
);
3203 DeleteUrlCacheEntryA(cache_url
);
3205 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_store
, NULL
, NULL
, NULL
, 0, 0);
3206 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3208 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_store
);
3209 DeleteUrlCacheEntryA(cache_url
);
3211 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3212 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3214 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3216 ok(size
== 12, "read %d bytes of data\n", size
);
3217 InternetCloseHandle(req
);
3219 ret
= DeleteUrlCacheEntryA(cache_url
);
3220 ok(!ret
&& GetLastError()==ERROR_FILE_NOT_FOUND
, "cache entry should not exist\n");
3222 InternetCloseHandle(con
);
3223 InternetCloseHandle(ses
);
3226 static void test_cache_read_gzipped(int port
)
3228 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3229 static const char get_gzip
[] = "/test_cache_gzip";
3230 static const char content
[] = "gzip test\n";
3231 static const char text_html
[] = "text/html";
3232 static const char raw_header
[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3234 HINTERNET ses
, con
, req
;
3236 char cache_url
[256], buf
[256];
3239 trace("Testing reading compressed content from cache\n");
3241 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3242 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3244 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3245 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3247 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3248 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3251 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3252 if(!ret
&& GetLastError()==ERROR_INTERNET_INVALID_OPTION
) {
3253 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3254 InternetCloseHandle(req
);
3255 InternetCloseHandle(con
);
3256 InternetCloseHandle(ses
);
3259 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3261 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3262 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3264 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-size
, &read
) && read
)
3266 ok(size
== 10, "read %d bytes of data\n", size
);
3268 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3270 size
= sizeof(buf
)-1;
3271 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3272 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3274 ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3276 size
= sizeof(buf
)-1;
3277 ret
= HttpQueryInfoA(req
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &size
, 0);
3278 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3280 ok(!strncmp(raw_header
, buf
, size
), "buf = %s\n", buf
);
3281 InternetCloseHandle(req
);
3283 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3284 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3287 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3288 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3290 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3291 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3293 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3295 todo_wine
ok(size
== 10, "read %d bytes of data\n", size
);
3297 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3300 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3301 ok(!ret
&& GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND
,
3302 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3303 ret
, GetLastError());
3305 size
= sizeof(buf
)-1;
3306 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3307 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3309 todo_wine
ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3310 InternetCloseHandle(req
);
3312 /* Decompression doesn't work while reading from cache */
3313 test_cache_gzip
= 0;
3314 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3315 DeleteUrlCacheEntryA(cache_url
);
3317 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3318 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3320 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3321 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3323 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3325 ok(size
== 31, "read %d bytes of data\n", size
);
3326 InternetCloseHandle(req
);
3328 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3329 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3332 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3333 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3335 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3336 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3338 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3340 todo_wine
ok(size
== 31, "read %d bytes of data\n", size
);
3343 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3344 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3345 InternetCloseHandle(req
);
3347 InternetCloseHandle(con
);
3348 InternetCloseHandle(ses
);
3350 DeleteUrlCacheEntryA(cache_url
);
3353 static void test_HttpSendRequestW(int port
)
3355 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3356 HINTERNET ses
, con
, req
;
3360 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3361 ok(ses
!= NULL
, "InternetOpen failed\n");
3363 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3364 ok(con
!= NULL
, "InternetConnect failed\n");
3366 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3367 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3369 SetLastError(0xdeadbeef);
3370 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
3371 error
= GetLastError();
3372 ok(!ret
, "HttpSendRequestW succeeded\n");
3373 ok(error
== ERROR_IO_PENDING
||
3374 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
3375 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
3376 "got %u expected ERROR_IO_PENDING\n", error
);
3378 InternetCloseHandle(req
);
3379 InternetCloseHandle(con
);
3380 InternetCloseHandle(ses
);
3383 static void test_cookie_header(int port
)
3385 HINTERNET ses
, con
, req
;
3390 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3391 ok(ses
!= NULL
, "InternetOpen failed\n");
3393 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3394 ok(con
!= NULL
, "InternetConnect failed\n");
3396 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3398 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3399 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3402 size
= sizeof(buffer
);
3403 SetLastError(0xdeadbeef);
3404 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3405 error
= GetLastError();
3406 ok(!ret
, "HttpQueryInfo succeeded\n");
3407 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3409 ret
= HttpAddRequestHeadersA(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
3410 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3413 size
= sizeof(buffer
);
3414 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3415 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3416 ok(!strcmp(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
3418 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3419 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3421 test_status_code(req
, 200);
3424 size
= sizeof(buffer
);
3425 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3426 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3427 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
3429 InternetCloseHandle(req
);
3430 InternetCloseHandle(con
);
3431 InternetCloseHandle(ses
);
3434 static void test_basic_authentication(int port
)
3436 HINTERNET session
, connect
, request
;
3439 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3440 ok(session
!= NULL
, "InternetOpen failed\n");
3442 connect
= InternetConnectA(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
3443 ok(connect
!= NULL
, "InternetConnect failed\n");
3445 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
3446 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3448 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3449 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3451 test_status_code(request
, 200);
3452 test_request_flags(request
, 0);
3454 InternetCloseHandle(request
);
3455 InternetCloseHandle(connect
);
3456 InternetCloseHandle(session
);
3459 static void test_premature_disconnect(int port
)
3461 HINTERNET session
, connect
, request
;
3465 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3466 ok(session
!= NULL
, "InternetOpen failed\n");
3468 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3469 ok(connect
!= NULL
, "InternetConnect failed\n");
3471 request
= HttpOpenRequestA(connect
, NULL
, "/premature_disconnect", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3472 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3474 SetLastError(0xdeadbeef);
3475 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3476 err
= GetLastError();
3477 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
3478 todo_wine
ok(err
== ERROR_HTTP_INVALID_SERVER_RESPONSE
, "got %u\n", err
);
3480 InternetCloseHandle(request
);
3481 InternetCloseHandle(connect
);
3482 InternetCloseHandle(session
);
3485 static void test_invalid_response_headers(int port
)
3487 HINTERNET session
, connect
, request
;
3492 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3493 ok(session
!= NULL
, "InternetOpen failed\n");
3495 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3496 ok(connect
!= NULL
, "InternetConnect failed\n");
3498 request
= HttpOpenRequestA(connect
, NULL
, "/testE", NULL
, NULL
, NULL
, 0, 0);
3499 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3501 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3502 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3504 test_status_code(request
, 401);
3505 test_request_flags(request
, 0);
3508 size
= sizeof(buffer
);
3509 ret
= HttpQueryInfoA( request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3510 ok(ret
, "HttpQueryInfo failed\n");
3511 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
3512 "headers wrong \"%s\"\n", buffer
);
3515 size
= sizeof(buffer
);
3516 ret
= HttpQueryInfoA( request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
3517 ok(ret
, "HttpQueryInfo failed\n");
3518 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
3520 InternetCloseHandle(request
);
3521 InternetCloseHandle(connect
);
3522 InternetCloseHandle(session
);
3525 static void test_response_without_headers(int port
)
3527 HINTERNET hi
, hc
, hr
;
3528 DWORD r
, count
, size
;
3531 SetLastError(0xdeadbeef);
3532 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3533 ok(hi
!= NULL
, "open failed %u\n", GetLastError());
3535 SetLastError(0xdeadbeef);
3536 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3537 ok(hc
!= NULL
, "connect failed %u\n", GetLastError());
3539 SetLastError(0xdeadbeef);
3540 hr
= HttpOpenRequestA(hc
, NULL
, "/testG", NULL
, NULL
, NULL
, 0, 0);
3541 ok(hr
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError());
3543 test_request_flags(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3545 SetLastError(0xdeadbeef);
3546 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
3547 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
3549 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3552 memset(buffer
, 0, sizeof buffer
);
3553 SetLastError(0xdeadbeef);
3554 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
3555 ok(r
, "InternetReadFile failed %u\n", GetLastError());
3556 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
3557 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
3559 test_status_code(hr
, 200);
3560 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3563 size
= sizeof(buffer
);
3564 SetLastError(0xdeadbeef);
3565 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
3566 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3567 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
3570 size
= sizeof(buffer
);
3571 SetLastError(0xdeadbeef);
3572 r
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
3573 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3574 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
3577 size
= sizeof(buffer
);
3578 SetLastError(0xdeadbeef);
3579 r
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3580 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3581 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
3583 InternetCloseHandle(hr
);
3584 InternetCloseHandle(hc
);
3585 InternetCloseHandle(hi
);
3588 static void test_HttpQueryInfo(int port
)
3590 HINTERNET hi
, hc
, hr
;
3591 DWORD size
, index
, error
;
3595 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3596 ok(hi
!= NULL
, "InternetOpen failed\n");
3598 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3599 ok(hc
!= NULL
, "InternetConnect failed\n");
3601 hr
= HttpOpenRequestA(hc
, NULL
, "/testD", NULL
, NULL
, NULL
, 0, 0);
3602 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
3604 size
= sizeof(buffer
);
3605 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3606 error
= GetLastError();
3607 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
3608 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3610 ret
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
3611 ok(ret
, "HttpSendRequest failed\n");
3614 size
= sizeof(buffer
);
3615 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
3616 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3617 ok(index
== 1, "expected 1 got %u\n", index
);
3620 size
= sizeof(buffer
);
3621 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
3622 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3623 ok(index
== 1, "expected 1 got %u\n", index
);
3626 size
= sizeof(buffer
);
3627 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3628 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3629 ok(index
== 0, "expected 0 got %u\n", index
);
3631 size
= sizeof(buffer
);
3632 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3633 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3634 ok(index
== 0, "expected 0 got %u\n", index
);
3636 index
= 0xdeadbeef; /* invalid start index */
3637 size
= sizeof(buffer
);
3638 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3639 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
3640 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
3641 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
3644 size
= sizeof(buffer
);
3645 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
3646 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3647 ok(index
== 0, "expected 0 got %u\n", index
);
3649 size
= sizeof(buffer
);
3650 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3651 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3652 ok(index
== 0, "expected 0 got %u\n", index
);
3654 size
= sizeof(buffer
);
3655 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
3656 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3657 ok(index
== 0, "expected 0 got %u\n", index
);
3659 test_status_code(hr
, 200);
3662 size
= sizeof(buffer
);
3663 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
3664 ok(!ret
, "HttpQueryInfo succeeded\n");
3665 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
3668 size
= sizeof(buffer
);
3669 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
3670 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3671 ok(index
== 1, "expected 1 got %u\n", index
);
3674 size
= sizeof(buffer
);
3675 strcpy(buffer
, "Server");
3676 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
3677 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3678 ok(index
== 1, "expected 1 got %u\n", index
);
3681 size
= sizeof(buffer
);
3682 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
3683 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3684 ok(index
== 1, "expected 1 got %u\n", index
);
3686 size
= sizeof(buffer
);
3687 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
3688 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3689 ok(index
== 2, "expected 2 got %u\n", index
);
3691 InternetCloseHandle(hr
);
3692 InternetCloseHandle(hc
);
3693 InternetCloseHandle(hi
);
3696 static void test_options(int port
)
3698 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi
;
3699 HINTERNET ses
, con
, req
;
3704 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3705 ok(ses
!= NULL
, "InternetOpen failed\n");
3707 SetLastError(0xdeadbeef);
3708 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
3709 error
= GetLastError();
3710 ok(!ret
, "InternetSetOption succeeded\n");
3711 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3713 SetLastError(0xdeadbeef);
3714 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
3715 ok(!ret
, "InternetSetOption succeeded\n");
3716 error
= GetLastError();
3717 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3719 SetLastError(0xdeadbeef);
3720 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
3721 ok(!ret
, "InternetSetOption succeeded\n");
3722 error
= GetLastError();
3723 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3726 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3727 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3729 SetLastError(0xdeadbeef);
3730 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
3731 error
= GetLastError();
3732 ok(!ret
, "InternetQueryOption succeeded\n");
3733 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3735 SetLastError(0xdeadbeef);
3736 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
3737 error
= GetLastError();
3738 ok(!ret
, "InternetQueryOption succeeded\n");
3739 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3742 SetLastError(0xdeadbeef);
3743 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
3744 error
= GetLastError();
3745 ok(!ret
, "InternetQueryOption succeeded\n");
3746 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
3749 SetLastError(0xdeadbeef);
3750 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3751 error
= GetLastError();
3752 ok(!ret
, "InternetQueryOption succeeded\n");
3753 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
3757 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3758 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3759 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
3761 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3762 ok(con
!= NULL
, "InternetConnect failed\n");
3766 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3767 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3768 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
3771 ret
= InternetSetOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3772 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3776 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3777 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3778 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
3780 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3781 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3785 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3786 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3787 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
3790 ret
= InternetSetOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3791 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3795 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3796 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3797 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
3799 size
= sizeof(idsi
);
3800 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO
, &idsi
, &size
);
3801 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3804 SetLastError(0xdeadbeef);
3805 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
3806 error
= GetLastError();
3807 ok(!ret
, "InternetQueryOption succeeded\n");
3808 ok(error
== ERROR_INTERNET_INVALID_OPERATION
, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error
);
3810 /* INTERNET_OPTION_PROXY */
3811 SetLastError(0xdeadbeef);
3812 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
3813 error
= GetLastError();
3814 ok(!ret
, "InternetQueryOption succeeded\n");
3815 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3817 SetLastError(0xdeadbeef);
3818 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
3819 error
= GetLastError();
3820 ok(!ret
, "InternetQueryOption succeeded\n");
3821 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3824 SetLastError(0xdeadbeef);
3825 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
3826 error
= GetLastError();
3827 ok(!ret
, "InternetQueryOption succeeded\n");
3828 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
3829 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
3831 InternetCloseHandle(req
);
3832 InternetCloseHandle(con
);
3833 InternetCloseHandle(ses
);
3837 const char *response_text
;
3839 const char *status_text
;
3840 const char *raw_headers
;
3841 } http_status_test_t
;
3843 static const http_status_test_t http_status_tests
[] = {
3845 "HTTP/1.1 200 OK\r\n"
3846 "Content-Length: 1\r\n"
3852 "HTTP/1.1 404 Fail\r\n"
3853 "Content-Length: 1\r\n"
3860 "Content-Length: 1\r\n"
3867 "Content-Length: 1\r\n"
3874 static void test_http_status(int port
)
3876 HINTERNET ses
, con
, req
;
3881 for(i
=0; i
< sizeof(http_status_tests
)/sizeof(*http_status_tests
); i
++) {
3882 send_buffer
= http_status_tests
[i
].response_text
;
3884 ses
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3885 ok(ses
!= NULL
, "InternetOpen failed\n");
3887 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3888 ok(con
!= NULL
, "InternetConnect failed\n");
3890 req
= HttpOpenRequestA(con
, NULL
, "/send_from_buffer", NULL
, NULL
, NULL
, 0, 0);
3891 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3893 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3894 ok(res
, "HttpSendRequest failed\n");
3896 test_status_code(req
, http_status_tests
[i
].status_code
);
3899 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_TEXT
, buf
, &size
, NULL
);
3900 ok(res
, "HttpQueryInfo failed: %u\n", GetLastError());
3901 ok(!strcmp(buf
, http_status_tests
[i
].status_text
), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
3902 i
, buf
, http_status_tests
[i
].status_text
);
3904 InternetCloseHandle(req
);
3905 InternetCloseHandle(con
);
3906 InternetCloseHandle(ses
);
3910 static void test_cache_control_verb(int port
)
3912 HINTERNET session
, connect
, request
;
3915 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3916 ok(session
!= NULL
, "InternetOpen failed\n");
3918 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3919 ok(connect
!= NULL
, "InternetConnect failed\n");
3921 request
= HttpOpenRequestA(connect
, "RPC_OUT_DATA", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3922 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3923 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3924 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3925 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3926 test_status_code(request
, 200);
3927 InternetCloseHandle(request
);
3929 request
= HttpOpenRequestA(connect
, "POST", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3930 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3931 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3932 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3933 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3934 test_status_code(request
, 200);
3935 InternetCloseHandle(request
);
3937 request
= HttpOpenRequestA(connect
, "HEAD", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3938 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3939 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3940 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3941 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3942 test_status_code(request
, 200);
3943 InternetCloseHandle(request
);
3945 request
= HttpOpenRequestA(connect
, "GET", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3946 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3947 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3948 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3949 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3950 test_status_code(request
, 200);
3951 InternetCloseHandle(request
);
3953 InternetCloseHandle(connect
);
3954 InternetCloseHandle(session
);
3957 static void test_http_connection(void)
3959 struct server_info si
;
3963 si
.hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
3966 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
3967 ok( hThread
!= NULL
, "create thread failed\n");
3969 r
= WaitForSingleObject(si
.hEvent
, 10000);
3970 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
3971 if (r
!= WAIT_OBJECT_0
)
3974 test_basic_request(si
.port
, "GET", "/test1");
3975 test_proxy_indirect(si
.port
);
3976 test_proxy_direct(si
.port
);
3977 test_header_handling_order(si
.port
);
3978 test_basic_request(si
.port
, "POST", "/test5");
3979 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
3980 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
3981 test_basic_request(si
.port
, "GET", "/test6");
3982 test_basic_request(si
.port
, "GET", "/testF");
3983 test_connection_header(si
.port
);
3984 test_http1_1(si
.port
);
3985 test_cookie_header(si
.port
);
3986 test_basic_authentication(si
.port
);
3987 test_invalid_response_headers(si
.port
);
3988 test_response_without_headers(si
.port
);
3989 test_HttpQueryInfo(si
.port
);
3990 test_HttpSendRequestW(si
.port
);
3991 test_options(si
.port
);
3992 test_no_content(si
.port
);
3993 test_conn_close(si
.port
);
3994 test_no_cache(si
.port
);
3995 test_cache_read_gzipped(si
.port
);
3996 test_http_status(si
.port
);
3997 test_premature_disconnect(si
.port
);
3998 test_connection_closing(si
.port
);
3999 test_cache_control_verb(si
.port
);
4000 test_successive_HttpSendRequest(si
.port
);
4002 /* send the basic request again to shutdown the server thread */
4003 test_basic_request(si
.port
, "GET", "/quit");
4005 r
= WaitForSingleObject(hThread
, 3000);
4006 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
4007 CloseHandle(hThread
);
4010 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
4012 LocalFree(info
->lpszSubjectInfo
);
4013 LocalFree(info
->lpszIssuerInfo
);
4014 LocalFree(info
->lpszProtocolName
);
4015 LocalFree(info
->lpszSignatureAlgName
);
4016 LocalFree(info
->lpszEncryptionAlgName
);
4020 const char *ex_subject
;
4021 const char *ex_issuer
;
4022 } cert_struct_test_t
;
4024 static const cert_struct_test_t test_winehq_org_cert
= {
4025 "6JcR7G3G8tgjkeoMcitK-bTbzcpumDSy\r\n"
4027 "See www.rapidssl.com/resources/cps (c)14\r\n"
4028 "Domain Control Validated - RapidSSL(R)\r\n"
4032 "\"GeoTrust, Inc.\"\r\n"
4036 static const cert_struct_test_t test_winehq_com_cert
= {
4041 "test.winehq.com\r\n"
4042 "webmaster@winehq.org",
4047 "test.winehq.com\r\n"
4048 "webmaster@winehq.org"
4051 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
4053 INTERNET_CERTIFICATE_INFOA info
;
4057 memset(&info
, 0x5, sizeof(info
));
4059 size
= sizeof(info
);
4060 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
4061 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
4062 ok(size
== sizeof(info
), "size = %u\n", size
);
4064 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
4065 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
4066 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
4067 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
4068 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
4069 ok(info
.dwKeySize
== 128, "dwKeySize = %u\n", info
.dwKeySize
);
4071 release_cert_info(&info
);
4074 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
4075 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
4077 char url
[INTERNET_MAX_URL_LENGTH
];
4078 const CERT_CHAIN_CONTEXT
*chain
;
4082 if(!pInternetGetSecurityInfoByURLA
) {
4083 win_skip("pInternetGetSecurityInfoByURLA not available\n");
4088 chain
= (void*)0xdeadbeef;
4090 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
4091 if(error
== ERROR_SUCCESS
) {
4092 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
4093 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
4094 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
4095 CertFreeCertificateChain(chain
);
4097 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
4098 "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res
, GetLastError(), error
);
4102 #define test_secflags_option(a,b) _test_secflags_option(__LINE__,a,b)
4103 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
)
4109 size
= sizeof(flags
);
4110 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4111 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4112 ok_(__FILE__
,line
)(flags
== ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n", flags
, ex_flags
);
4114 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
4116 size
= sizeof(flags
);
4117 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4118 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
4119 ok_(__FILE__
,line
)(flags
== ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n", flags
, ex_flags
);
4122 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
4123 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
4127 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
4128 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4131 static void test_security_flags(void)
4133 INTERNET_CERTIFICATE_INFOA
*cert
;
4134 HINTERNET ses
, conn
, req
;
4139 trace("Testing security flags...\n");
4141 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4143 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4144 ok(ses
!= NULL
, "InternetOpen failed\n");
4146 pInternetSetStatusCallbackA(ses
, &callback
);
4148 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4149 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
4150 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
4151 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
4152 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4154 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4155 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4156 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4158 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4159 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4162 size
= sizeof(flags
);
4163 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4164 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
4165 win_skip("Incomplete security flags support, skipping\n");
4167 close_async_handle(ses
, hCompleteEvent
, 2);
4168 CloseHandle(hCompleteEvent
);
4172 test_secflags_option(req
, 0);
4173 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4175 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4176 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
);
4178 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4179 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4181 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4182 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4184 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
4185 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
4186 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
4188 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
4189 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
4190 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4191 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4192 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4193 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4194 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4195 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4196 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4197 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4198 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4200 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4201 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4203 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4204 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4206 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
4207 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
4208 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4209 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4210 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4211 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4212 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4213 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4214 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4215 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4216 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4218 test_request_flags(req
, 0);
4219 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4220 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
);
4222 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4223 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4224 ok(size
, "size = 0\n");
4226 /* Collect all existing persistent connections */
4227 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4228 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4230 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4231 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4232 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4234 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4235 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4237 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
4238 res
= InternetSetOptionA(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
4239 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
4241 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4242 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4243 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4244 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4245 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4246 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4247 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4249 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4250 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4252 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4253 ok(req_error
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| broken(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
),
4254 "req_error = %d\n", req_error
);
4257 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
4258 ok(res
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4259 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %u\n", size
);
4260 cert
= HeapAlloc(GetProcessHeap(), 0, size
);
4261 cert
->lpszSubjectInfo
= NULL
;
4262 cert
->lpszIssuerInfo
= NULL
;
4263 cert
->lpszSignatureAlgName
= (char *)0xdeadbeef;
4264 cert
->lpszEncryptionAlgName
= (char *)0xdeadbeef;
4265 cert
->lpszProtocolName
= (char *)0xdeadbeef;
4266 cert
->dwKeySize
= 0xdeadbeef;
4267 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, cert
, &size
);
4268 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
4271 ok(cert
->lpszSubjectInfo
&& strlen(cert
->lpszSubjectInfo
) > 1, "expected a non-empty subject name\n");
4272 ok(cert
->lpszIssuerInfo
&& strlen(cert
->lpszIssuerInfo
) > 1, "expected a non-empty issuer name\n");
4273 ok(!cert
->lpszSignatureAlgName
, "unexpected signature algorithm name\n");
4274 ok(!cert
->lpszEncryptionAlgName
, "unexpected encryption algorithm name\n");
4275 ok(!cert
->lpszProtocolName
, "unexpected protocol name\n");
4276 ok(cert
->dwKeySize
!= 0xdeadbeef, "unexpected key size\n");
4278 HeapFree(GetProcessHeap(), 0, cert
);
4280 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4281 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4282 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4283 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4284 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4285 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4286 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4288 if(req_error
!= ERROR_INTERNET_SEC_CERT_REV_FAILED
) {
4289 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error
);
4291 close_async_handle(ses
, hCompleteEvent
, 3);
4292 CloseHandle(hCompleteEvent
);
4297 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
4298 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
4300 test_request_flags(req
, 8);
4301 test_secflags_option(req
, 0x800000);
4303 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4304 test_secflags_option(req
, 0x800000|SECURITY_FLAG_IGNORE_REVOCATION
);
4306 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4307 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4308 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4309 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4310 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4311 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4312 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4314 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4315 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4317 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4318 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
4320 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4321 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4322 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4323 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4324 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4325 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4326 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4328 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
4329 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4330 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4332 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4333 test_secflags_option(req
, 0x1800000|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4334 |SECURITY_FLAG_IGNORE_REVOCATION
);
4335 test_http_version(req
);
4337 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4338 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4339 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4340 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4341 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4342 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4343 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4344 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4345 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4347 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4348 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4350 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4351 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4353 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4354 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4355 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4356 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4357 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4358 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4359 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4360 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4361 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4363 test_request_flags(req
, 0);
4364 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
4365 |SECURITY_FLAG_STRENGTH_STRONG
|0x1800000);
4367 test_cert_struct(req
, &test_winehq_com_cert
);
4368 test_security_info("https://test.winehq.com/data/some_file.html?q", 0, 0x1800000);
4370 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4371 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4372 ok(size
, "size = 0\n");
4374 close_async_handle(ses
, hCompleteEvent
, 3);
4376 /* Collect all existing persistent connections */
4377 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4378 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4380 /* Make another request, without setting security flags */
4382 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4383 ok(ses
!= NULL
, "InternetOpen failed\n");
4385 pInternetSetStatusCallbackA(ses
, &callback
);
4387 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4388 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
4389 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
4390 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
4391 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4393 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4394 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4395 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4397 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4398 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4400 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
4401 |SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4402 test_http_version(req
);
4404 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4405 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4406 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4407 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4408 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4409 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4410 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4411 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4413 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4414 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4416 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4417 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4419 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4420 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4421 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4422 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4423 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4424 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4425 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4426 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4428 test_request_flags(req
, 0);
4429 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
4430 |SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4432 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4433 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4434 ok(size
, "size = 0\n");
4436 close_async_handle(ses
, hCompleteEvent
, 2);
4438 CloseHandle(hCompleteEvent
);
4440 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4441 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4442 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4445 static void test_secure_connection(void)
4447 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
4448 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
4449 static const WCHAR get
[] = {'G','E','T',0};
4450 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
4451 HINTERNET ses
, con
, req
;
4453 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
4454 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
4457 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4458 ok(ses
!= NULL
, "InternetOpen failed\n");
4460 con
= InternetConnectA(ses
, "test.winehq.org",
4461 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
4462 INTERNET_SERVICE_HTTP
, 0, 0);
4463 ok(con
!= NULL
, "InternetConnect failed\n");
4465 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4466 INTERNET_FLAG_SECURE
, 0);
4467 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4469 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4470 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
4472 size
= sizeof(flags
);
4473 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4474 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4475 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
4477 if (!winetest_interactive
)
4479 skip("test_cert_struct(req, &test_winehq_org_cert), ROSTESTS-121\n");
4483 test_cert_struct(req
, &test_winehq_org_cert
);
4486 /* Querying the same option through InternetQueryOptionW still results in
4487 * ASCII strings being returned.
4490 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4492 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4493 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
4494 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
4495 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4496 certificate_structW
, &size
);
4497 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
4498 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4501 ok(certificate_structA
->lpszSubjectInfo
&&
4502 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4503 "expected a non-empty subject name\n");
4504 ok(certificate_structA
->lpszIssuerInfo
&&
4505 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4506 "expected a non-empty issuer name\n");
4507 ok(!certificate_structA
->lpszSignatureAlgName
,
4508 "unexpected signature algorithm name\n");
4509 ok(!certificate_structA
->lpszEncryptionAlgName
,
4510 "unexpected encryption algorithm name\n");
4511 ok(!certificate_structA
->lpszProtocolName
,
4512 "unexpected protocol name\n");
4513 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4514 release_cert_info(certificate_structA
);
4516 HeapFree(GetProcessHeap(), 0, certificate_structW
);
4518 InternetCloseHandle(req
);
4519 InternetCloseHandle(con
);
4520 InternetCloseHandle(ses
);
4522 /* Repeating the tests with the W functions has the same result: */
4523 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4524 ok(ses
!= NULL
, "InternetOpen failed\n");
4526 con
= InternetConnectW(ses
, testsite
,
4527 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
4528 INTERNET_SERVICE_HTTP
, 0, 0);
4529 ok(con
!= NULL
, "InternetConnect failed\n");
4531 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
4532 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
4533 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4535 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4536 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
4538 size
= sizeof(flags
);
4539 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4540 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4541 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %x\n", flags
);
4543 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4545 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4546 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
4547 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
4548 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4549 certificate_structA
, &size
);
4550 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4553 ok(certificate_structA
->lpszSubjectInfo
&&
4554 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4555 "expected a non-empty subject name\n");
4556 ok(certificate_structA
->lpszIssuerInfo
&&
4557 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4558 "expected a non-empty issuer name\n");
4559 ok(!certificate_structA
->lpszSignatureAlgName
,
4560 "unexpected signature algorithm name\n");
4561 ok(!certificate_structA
->lpszEncryptionAlgName
,
4562 "unexpected encryption algorithm name\n");
4563 ok(!certificate_structA
->lpszProtocolName
,
4564 "unexpected protocol name\n");
4565 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4566 release_cert_info(certificate_structA
);
4568 HeapFree(GetProcessHeap(), 0, certificate_structA
);
4570 /* Again, querying the same option through InternetQueryOptionW still
4571 * results in ASCII strings being returned.
4574 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4576 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4577 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
4578 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
4579 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4580 certificate_structW
, &size
);
4581 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
4582 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4585 ok(certificate_structA
->lpszSubjectInfo
&&
4586 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4587 "expected a non-empty subject name\n");
4588 ok(certificate_structA
->lpszIssuerInfo
&&
4589 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4590 "expected a non-empty issuer name\n");
4591 ok(!certificate_structA
->lpszSignatureAlgName
,
4592 "unexpected signature algorithm name\n");
4593 ok(!certificate_structA
->lpszEncryptionAlgName
,
4594 "unexpected encryption algorithm name\n");
4595 ok(!certificate_structA
->lpszProtocolName
,
4596 "unexpected protocol name\n");
4597 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4598 release_cert_info(certificate_structA
);
4600 HeapFree(GetProcessHeap(), 0, certificate_structW
);
4602 InternetCloseHandle(req
);
4603 InternetCloseHandle(con
);
4604 InternetCloseHandle(ses
);
4607 static void test_user_agent_header(void)
4609 HINTERNET ses
, con
, req
;
4614 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4615 ok(ses
!= NULL
, "InternetOpen failed\n");
4617 con
= InternetConnectA(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4618 ok(con
!= NULL
, "InternetConnect failed\n");
4620 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
4621 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4623 size
= sizeof(buffer
);
4624 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4625 err
= GetLastError();
4626 ok(!ret
, "HttpQueryInfo succeeded\n");
4627 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4629 ret
= HttpAddRequestHeadersA(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
4630 ok(ret
, "HttpAddRequestHeaders succeeded\n");
4632 size
= sizeof(buffer
);
4633 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4634 err
= GetLastError();
4635 ok(ret
, "HttpQueryInfo failed\n");
4636 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4638 InternetCloseHandle(req
);
4640 req
= HttpOpenRequestA(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
4641 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4643 size
= sizeof(buffer
);
4644 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4645 err
= GetLastError();
4646 ok(!ret
, "HttpQueryInfo succeeded\n");
4647 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4649 ret
= HttpAddRequestHeadersA(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
4650 ok(ret
, "HttpAddRequestHeaders failed\n");
4653 size
= sizeof(buffer
);
4654 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4655 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
4656 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
4658 InternetCloseHandle(req
);
4659 InternetCloseHandle(con
);
4660 InternetCloseHandle(ses
);
4663 static void test_bogus_accept_types_array(void)
4665 HINTERNET ses
, con
, req
;
4666 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
4671 ses
= InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
4672 con
= InternetConnectA(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4673 req
= HttpOpenRequestA(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
4675 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
4678 size
= sizeof(buffer
);
4679 SetLastError(0xdeadbeef);
4680 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4681 error
= GetLastError();
4682 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
4683 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
4684 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
4685 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
4686 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
4688 InternetCloseHandle(req
);
4689 InternetCloseHandle(con
);
4690 InternetCloseHandle(ses
);
4699 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
4701 INTERNET_ASYNC_RESULT
*result
= info
;
4702 struct context
*ctx
= (struct context
*)context
;
4704 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
4707 case INTERNET_STATUS_REQUEST_COMPLETE
:
4708 trace("request handle: 0x%08lx\n", result
->dwResult
);
4709 ctx
->req
= (HINTERNET
)result
->dwResult
;
4710 SetEvent(ctx
->event
);
4712 case INTERNET_STATUS_HANDLE_CLOSING
: {
4713 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
4715 if (InternetQueryOptionA(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
4716 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
4717 SetEvent(ctx
->event
);
4720 case INTERNET_STATUS_NAME_RESOLVED
:
4721 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
4722 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
4724 ok(str
[0] && str
[1], "Got string: %s\n", str
);
4725 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
4730 static void test_open_url_async(void)
4738 /* Collect all existing persistent connections */
4739 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4740 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4743 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
4744 * other versions never do. They also hang of following tests. We disable it for everything older
4747 if(!pInternetGetSecurityInfoByURLA
) {
4748 win_skip("Skipping async open on too old wininet version.\n");
4753 ctx
.event
= CreateEventA(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
4755 ses
= InternetOpenA("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4756 ok(ses
!= NULL
, "InternetOpen failed\n");
4758 SetLastError(0xdeadbeef);
4759 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
4760 error
= GetLastError();
4761 ok(!ret
, "InternetSetOptionA succeeded\n");
4762 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
4764 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
4765 error
= GetLastError();
4766 ok(!ret
, "InternetSetOptionA failed\n");
4767 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
4769 pInternetSetStatusCallbackW(ses
, cb
);
4770 ResetEvent(ctx
.event
);
4772 req
= InternetOpenUrlA(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
4773 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
4775 WaitForSingleObject(ctx
.event
, INFINITE
);
4778 size
= sizeof(type
);
4779 ret
= InternetQueryOptionA(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
4780 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
4781 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
4782 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
4785 ret
= HttpQueryInfoA(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
4786 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
4787 ok(size
> 0, "expected size > 0\n");
4789 ResetEvent(ctx
.event
);
4790 InternetCloseHandle(ctx
.req
);
4791 WaitForSingleObject(ctx
.event
, INFINITE
);
4793 InternetCloseHandle(ses
);
4794 CloseHandle(ctx
.event
);
4799 internet_connect
= 1,
4801 http_send_request_ex
,
4804 internet_close_handle
4809 enum api function
; /* api responsible for notification */
4810 unsigned int status
; /* status received */
4811 BOOL async
; /* delivered from another thread? */
4819 const struct notification
*test
;
4825 DWORD expect_result
;
4829 static CRITICAL_SECTION notification_cs
;
4831 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
4833 BOOL status_ok
, function_ok
;
4834 struct info
*info
= (struct info
*)context
;
4837 EnterCriticalSection( ¬ification_cs
);
4839 if(info
->is_aborted
) {
4840 LeaveCriticalSection(¬ification_cs
);
4844 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
4846 DWORD size
= sizeof(struct info
*);
4847 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
4848 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
4849 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
4851 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
4852 if(info
->expect_result
== ERROR_SUCCESS
) {
4853 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
4855 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
4856 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
4861 if (i
>= info
->count
)
4863 LeaveCriticalSection( ¬ification_cs
);
4867 while (info
->test
[i
].status
!= status
&&
4868 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
4869 i
< info
->count
- 1 &&
4870 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
4875 status_ok
= (info
->test
[i
].status
== status
);
4876 function_ok
= (info
->test
[i
].function
== info
->function
);
4878 if (!info
->test
[i
].todo
)
4880 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
4881 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
4883 if (info
->test
[i
].async
)
4884 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
4885 info
->line
, info
->thread
, GetCurrentThreadId());
4889 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
4891 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
4893 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
4896 LeaveCriticalSection( ¬ification_cs
);
4899 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
4901 info
->function
= function
;
4903 info
->expect_result
= expect_result
;
4906 struct notification_data
4908 const struct notification
*test
;
4909 const unsigned int count
;
4914 BOOL expect_conn_failure
;
4917 static const struct notification async_send_request_ex_test
[] =
4919 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
4920 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
4921 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
4922 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
4923 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
4924 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
4925 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
4926 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
4927 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
4928 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
4929 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
4930 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, FALSE
},
4931 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, FALSE
},
4932 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
4933 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
4934 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
4935 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
4936 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
4937 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
4938 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
4941 static const struct notification async_send_request_ex_test2
[] =
4943 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
4944 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
4945 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
4946 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
4947 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
4948 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
4949 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
, TRUE
},
4950 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
, TRUE
},
4951 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
4952 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
4953 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
4954 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
4955 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
4956 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
4957 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
4958 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
4959 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
4960 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
4963 static const struct notification async_send_request_ex_resolve_failure_test
[] =
4965 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
4966 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
4967 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
4968 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
},
4969 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
4970 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
4971 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
4972 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
4973 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
4974 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
4975 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
4978 static const struct notification async_send_request_ex_chunked_test
[] =
4980 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
},
4981 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
},
4982 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
4983 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
4984 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
4985 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
4986 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
4987 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
4988 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
4989 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
4990 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
4991 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
4992 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
4993 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
4994 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
},
4995 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
},
4996 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
},
4997 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
}
5000 static const struct notification_data notification_data
[] = {
5002 async_send_request_ex_chunked_test
,
5003 sizeof(async_send_request_ex_chunked_test
)/sizeof(async_send_request_ex_chunked_test
[0]),
5009 async_send_request_ex_test
,
5010 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
5013 "tests/posttest.php",
5014 "Public ID=codeweavers"
5017 async_send_request_ex_test2
,
5018 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
5021 "tests/posttest.php"
5024 async_send_request_ex_resolve_failure_test
,
5025 sizeof(async_send_request_ex_resolve_failure_test
)/sizeof(async_send_request_ex_resolve_failure_test
[0]),
5034 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
5037 HINTERNET ses
, req
, con
;
5039 DWORD size
, written
, error
;
5040 INTERNET_BUFFERSA b
;
5041 static const char *accept
[2] = {"*/*", NULL
};
5044 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
5046 InitializeCriticalSection( ¬ification_cs
);
5048 info
.test
= nd
->test
;
5049 info
.count
= nd
->count
;
5051 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
5052 info
.thread
= GetCurrentThreadId();
5053 info
.is_aborted
= FALSE
;
5055 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5056 ok( ses
!= NULL
, "InternetOpen failed\n" );
5058 pInternetSetStatusCallbackA( ses
, check_notification
);
5060 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
5061 con
= InternetConnectA( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
5062 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
5064 WaitForSingleObject( info
.wait
, 10000 );
5066 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
5067 req
= HttpOpenRequestA( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
5068 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
5070 WaitForSingleObject( info
.wait
, 10000 );
5073 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
5074 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
5075 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
5076 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
5077 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
5080 setup_test( &info
, http_send_request_ex
, __LINE__
,
5081 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
5082 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
5083 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
5085 error
= WaitForSingleObject( info
.wait
, 10000 );
5086 if(error
!= WAIT_OBJECT_0
) {
5087 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
5088 info
.is_aborted
= TRUE
;
5092 size
= sizeof(buffer
);
5093 SetLastError( 0xdeadbeef );
5094 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
5095 error
= GetLastError();
5096 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
5097 if(nd
->expect_conn_failure
) {
5098 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
5101 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
5102 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
5108 size
= strlen( nd
->data
);
5109 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
5110 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
5111 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
5112 ok( written
== size
, "expected %u got %u\n", written
, size
);
5114 WaitForSingleObject( info
.wait
, 10000 );
5116 SetLastError( 0xdeadbeef );
5117 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
5118 error
= GetLastError();
5119 ok( !ret
, "HttpEndRequestA succeeded\n" );
5120 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
5123 SetLastError( 0xdeadbeef );
5124 setup_test( &info
, http_end_request
, __LINE__
,
5125 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
5126 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
5127 error
= GetLastError();
5128 ok( !ret
, "HttpEndRequestA succeeded\n" );
5129 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
5131 WaitForSingleObject( info
.wait
, 10000 );
5133 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
5135 InternetCloseHandle( req
);
5136 InternetCloseHandle( con
);
5137 InternetCloseHandle( ses
);
5139 WaitForSingleObject( info
.wait
, 10000 );
5141 CloseHandle( info
.wait
);
5144 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
5145 static BOOL closetest_closed
;
5147 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
5148 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
5153 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
5155 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
5156 "Unexpected hInternet %p\n", hInternet
);
5157 if(!closetest_closed
)
5161 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
5162 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
5163 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5164 closetest_req
, res
, GetLastError());
5167 static void test_InternetCloseHandle(void)
5172 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5173 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
5175 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
5177 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
5178 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
5179 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
5181 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
5182 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
5184 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
5185 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
5186 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
5188 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
5190 res
= InternetCloseHandle(closetest_session
);
5191 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
5192 closetest_closed
= TRUE
;
5193 trace("Closed session handle\n");
5195 res
= InternetCloseHandle(closetest_conn
);
5196 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
5197 res
, GetLastError());
5199 res
= InternetCloseHandle(closetest_req
);
5200 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
5201 res
, GetLastError());
5203 len
= sizeof(flags
);
5204 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
5205 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
5206 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5207 closetest_req
, res
, GetLastError());
5210 static void test_connection_failure(void)
5212 HINTERNET session
, connect
, request
;
5216 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5217 ok(session
!= NULL
, "failed to get session handle\n");
5219 connect
= InternetConnectA(session
, "localhost", 1, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5220 ok(connect
!= NULL
, "failed to get connection handle\n");
5222 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
5223 ok(request
!= NULL
, "failed to get request handle\n");
5225 SetLastError(0xdeadbeef);
5226 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
5227 error
= GetLastError();
5228 ok(!ret
, "unexpected success\n");
5229 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
5231 InternetCloseHandle(request
);
5232 InternetCloseHandle(connect
);
5233 InternetCloseHandle(session
);
5236 static void test_default_service_port(void)
5238 HINTERNET session
, connect
, request
;
5242 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
5243 ok(session
!= NULL
, "InternetOpen failed\n");
5245 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
5246 INTERNET_SERVICE_HTTP
, 0, 0);
5247 ok(connect
!= NULL
, "InternetConnect failed\n");
5249 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
5250 ok(request
!= NULL
, "HttpOpenRequest failed\n");
5252 SetLastError(0xdeadbeef);
5253 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
5254 error
= GetLastError();
5255 ok(!ret
, "HttpSendRequest succeeded\n");
5256 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
5259 InternetCloseHandle(request
);
5260 InternetCloseHandle(connect
);
5261 InternetCloseHandle(session
);
5264 static void init_status_tests(void)
5266 memset(expect
, 0, sizeof(expect
));
5267 memset(optional
, 0, sizeof(optional
));
5268 memset(wine_allow
, 0, sizeof(wine_allow
));
5269 memset(notified
, 0, sizeof(notified
));
5270 memset(status_string
, 0, sizeof(status_string
));
5272 #define STATUS_STRING(status) status_string[status] = #status
5273 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
5274 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
5275 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5276 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5277 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
5278 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
5279 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
5280 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
5281 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
5282 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
5283 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
5284 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
5285 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
5286 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
5287 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
5288 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
5289 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
5290 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
5291 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
5292 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
5293 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
5294 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
5295 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
5296 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
5297 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
5298 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
5299 #undef STATUS_STRING
5305 hdll
= GetModuleHandleA("wininet.dll");
5307 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
5308 win_skip("Too old IE (older than 6.0)\n");
5312 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
5313 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
5314 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
5316 init_status_tests();
5317 test_InternetCloseHandle();
5318 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
5319 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
5320 InternetReadFile_test(0, &test_data
[1]);
5321 first_connection_to_test_url
= TRUE
;
5322 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
5323 test_security_flags();
5324 InternetReadFile_test(0, &test_data
[2]);
5325 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
5326 test_open_url_async();
5327 test_async_HttpSendRequestEx(¬ification_data
[0]);
5328 test_async_HttpSendRequestEx(¬ification_data
[1]);
5329 test_async_HttpSendRequestEx(¬ification_data
[2]);
5330 test_async_HttpSendRequestEx(¬ification_data
[3]);
5331 InternetOpenRequest_test();
5333 InternetLockRequestFile_test();
5334 InternetOpenUrlA_test();
5336 test_http_connection();
5337 test_secure_connection();
5338 test_user_agent_header();
5339 test_bogus_accept_types_array();
5340 InternetReadFile_chunked_test();
5341 HttpSendRequestEx_test();
5342 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
5343 test_connection_failure();
5344 test_default_service_port();