4 * Copyright 2002 Aric Stewart
5 * Copyright 2004 Mike McCormack
6 * Copyright 2005 Hans Leidekker
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/test.h"
35 #define TEST_URL "http://test.winehq.org/tests/hello.html"
37 static BOOL first_connection_to_test_url
= TRUE
;
39 /* Adapted from dlls/urlmon/tests/protocol.c */
41 #define SET_EXPECT2(status, num) \
44 #define SET_EXPECT(status) \
45 SET_EXPECT2(status, 1)
47 #define SET_OPTIONAL2(status, num) \
48 optional[status] = num
50 #define SET_OPTIONAL(status) \
51 SET_OPTIONAL2(status, 1)
53 /* SET_WINE_ALLOW's should be used with an appropriate
54 * todo_wine CHECK_NOTIFIED at a later point in the code */
55 #define SET_WINE_ALLOW2(status, num) \
56 wine_allow[status] = num
58 #define SET_WINE_ALLOW(status) \
59 SET_WINE_ALLOW2(status, 1)
61 #define CHECK_EXPECT(status) \
63 if (!expect[status] && !optional[status] && wine_allow[status]) \
65 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
66 status < MAX_INTERNET_STATUS && status_string[status] ? \
67 status_string[status] : "unknown"); \
68 wine_allow[status]--; \
72 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
73 status < MAX_INTERNET_STATUS && status_string[status] ? \
74 status_string[status] : "unknown"); \
75 if (expect[status]) expect[status]--; \
76 else optional[status]--; \
81 /* CLEAR_NOTIFIED used in cases when notification behavior
82 * differs between Windows versions */
83 #define CLEAR_NOTIFIED(status) \
84 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
86 #define CHECK_NOTIFIED2(status, num) \
88 ok(notified[status] + optional[status] == (num), \
89 "expected status %d (%s) %d times, received %d times\n", \
90 status, status < MAX_INTERNET_STATUS && status_string[status] ? \
91 status_string[status] : "unknown", (num), notified[status]); \
92 CLEAR_NOTIFIED(status); \
95 #define CHECK_NOTIFIED(status) \
96 CHECK_NOTIFIED2(status, 1)
98 #define CHECK_NOT_NOTIFIED(status) \
99 CHECK_NOTIFIED2(status, 0)
101 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
102 static int expect
[MAX_INTERNET_STATUS
], optional
[MAX_INTERNET_STATUS
],
103 wine_allow
[MAX_INTERNET_STATUS
], notified
[MAX_INTERNET_STATUS
];
104 static const char *status_string
[MAX_INTERNET_STATUS
];
106 static HANDLE hCompleteEvent
, conn_close_event
;
107 static DWORD req_error
;
109 #define TESTF_REDIRECT 0x01
110 #define TESTF_COMPRESSED 0x02
111 #define TESTF_CHUNKED 0x04
115 const char *redirected_url
;
120 const char *post_data
;
124 static const test_data_t test_data
[] = {
126 "http://test.winehq.org/tests/data.php",
127 "http://test.winehq.org/tests/data.php",
134 "http://test.winehq.org/tests/redirect",
135 "http://test.winehq.org/tests/hello.html",
142 "http://www.codeweavers.com/",
143 "http://www.codeweavers.com/",
144 "www.codeweavers.com",
146 "Accept-Encoding: gzip, deflate",
150 "http://test.winehq.org/tests/post.php",
151 "http://test.winehq.org/tests/post.php",
154 "Content-Type: application/x-www-form-urlencoded",
161 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackA
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
162 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackW
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
163 static BOOL (WINAPI
*pInternetGetSecurityInfoByURLA
)(LPSTR
,PCCERT_CHAIN_CONTEXT
*,DWORD
*);
165 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
168 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
169 return lstrcmpW(strw
, buf
);
172 static BOOL
proxy_active(void)
174 HKEY internet_settings
;
178 if (RegOpenKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
179 0, KEY_QUERY_VALUE
, &internet_settings
) != ERROR_SUCCESS
)
182 size
= sizeof(DWORD
);
183 if (RegQueryValueExA(internet_settings
, "ProxyEnable", NULL
, NULL
, (LPBYTE
) &proxy_enable
, &size
) != ERROR_SUCCESS
)
186 RegCloseKey(internet_settings
);
188 return proxy_enable
!= 0;
191 #define test_status_code(a,b) _test_status_code(__LINE__,a,b, FALSE)
192 #define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)
193 static void _test_status_code(unsigned line
, HINTERNET req
, DWORD excode
, BOOL is_todo
)
195 DWORD code
, size
, index
;
196 char exbuf
[10], bufa
[10];
202 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, NULL
);
203 ok_(__FILE__
,line
)(res
, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
205 todo_wine
ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
207 ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
208 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
213 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
214 ok_(__FILE__
,line
)(res
, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
216 todo_wine
ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
218 ok_(__FILE__
,line
)(!index
, "index = %d, expected 0\n", code
);
219 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
221 sprintf(exbuf
, "%u", excode
);
224 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, bufa
, &size
, NULL
);
225 ok_(__FILE__
,line
)(res
, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
227 todo_wine
ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
229 ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
230 ok_(__FILE__
,line
)(size
== strlen(exbuf
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
233 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
234 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
235 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
236 ok_(__FILE__
,line
)(size
== strlen(exbuf
)+1, "unexpected size %d for \"%s\"\n", size
, exbuf
);
239 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
240 ok_(__FILE__
,line
)(res
, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
242 todo_wine
ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
244 ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
245 ok_(__FILE__
,line
)(size
== strlen(exbuf
)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
248 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
249 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
250 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
251 ok_(__FILE__
,line
)(size
== (strlen(exbuf
)+1)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
255 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
256 ok(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
257 ok(size
== sizeof(bufw
), "unexpected size %d\n", size
);
263 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
264 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
265 "[7] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
269 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, &code
, &size
, NULL
);
270 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST
,
271 "[8] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
274 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
275 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
276 static void _test_request_flags(unsigned line
, HINTERNET req
, DWORD exflags
, BOOL is_todo
)
282 size
= sizeof(flags
);
283 res
= InternetQueryOptionW(req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &size
);
284 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
286 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
287 flags
&= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED
;
289 ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
291 todo_wine
ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
294 #define test_http_version(a) _test_http_version(__LINE__,a)
295 static void _test_http_version(unsigned line
, HINTERNET req
)
297 HTTP_VERSION_INFO v
= {0xdeadbeef, 0xdeadbeef};
302 res
= InternetQueryOptionW(req
, INTERNET_OPTION_HTTP_VERSION
, &v
, &size
);
303 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
304 ok_(__FILE__
,line
)(v
.dwMajorVersion
== 1, "dwMajorVersion = %d\n", v
.dwMajorVersion
);
305 ok_(__FILE__
,line
)(v
.dwMinorVersion
== 1, "dwMinorVersion = %d\n", v
.dwMinorVersion
);
308 static int close_handle_cnt
;
310 static VOID WINAPI
callback(
313 DWORD dwInternetStatus
,
314 LPVOID lpvStatusInformation
,
315 DWORD dwStatusInformationLength
318 CHECK_EXPECT(dwInternetStatus
);
319 switch (dwInternetStatus
)
321 case INTERNET_STATUS_RESOLVING_NAME
:
322 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
323 GetCurrentThreadId(), hInternet
, dwContext
,
324 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
325 *(LPSTR
)lpvStatusInformation
= '\0';
327 case INTERNET_STATUS_NAME_RESOLVED
:
328 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
329 GetCurrentThreadId(), hInternet
, dwContext
,
330 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
331 *(LPSTR
)lpvStatusInformation
= '\0';
333 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
334 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
335 GetCurrentThreadId(), hInternet
, dwContext
,
336 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
337 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
338 dwStatusInformationLength
);
339 *(LPSTR
)lpvStatusInformation
= '\0';
341 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
342 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
343 GetCurrentThreadId(), hInternet
, dwContext
,
344 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
345 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
346 dwStatusInformationLength
);
347 *(LPSTR
)lpvStatusInformation
= '\0';
349 case INTERNET_STATUS_SENDING_REQUEST
:
350 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
351 GetCurrentThreadId(), hInternet
, dwContext
,
352 lpvStatusInformation
,dwStatusInformationLength
);
354 case INTERNET_STATUS_REQUEST_SENT
:
355 ok(dwStatusInformationLength
== sizeof(DWORD
),
356 "info length should be sizeof(DWORD) instead of %d\n",
357 dwStatusInformationLength
);
358 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
359 GetCurrentThreadId(), hInternet
, dwContext
,
360 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
362 case INTERNET_STATUS_RECEIVING_RESPONSE
:
363 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
364 GetCurrentThreadId(), hInternet
, dwContext
,
365 lpvStatusInformation
,dwStatusInformationLength
);
367 case INTERNET_STATUS_RESPONSE_RECEIVED
:
368 ok(dwStatusInformationLength
== sizeof(DWORD
),
369 "info length should be sizeof(DWORD) instead of %d\n",
370 dwStatusInformationLength
);
371 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
372 GetCurrentThreadId(), hInternet
, dwContext
,
373 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
375 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
376 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
377 GetCurrentThreadId(), hInternet
,dwContext
,
378 lpvStatusInformation
,dwStatusInformationLength
);
380 case INTERNET_STATUS_PREFETCH
:
381 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
382 GetCurrentThreadId(), hInternet
, dwContext
,
383 lpvStatusInformation
,dwStatusInformationLength
);
385 case INTERNET_STATUS_CLOSING_CONNECTION
:
386 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
387 GetCurrentThreadId(), hInternet
, dwContext
,
388 lpvStatusInformation
,dwStatusInformationLength
);
390 case INTERNET_STATUS_CONNECTION_CLOSED
:
391 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
392 GetCurrentThreadId(), hInternet
, dwContext
,
393 lpvStatusInformation
,dwStatusInformationLength
);
395 case INTERNET_STATUS_HANDLE_CREATED
:
396 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
397 "info length should be sizeof(HINTERNET) instead of %d\n",
398 dwStatusInformationLength
);
399 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
400 GetCurrentThreadId(), hInternet
, dwContext
,
401 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
402 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
403 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
405 case INTERNET_STATUS_HANDLE_CLOSING
:
406 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
407 "info length should be sizeof(HINTERNET) instead of %d\n",
408 dwStatusInformationLength
);
409 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
410 GetCurrentThreadId(), hInternet
, dwContext
,
411 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
412 if(!InterlockedDecrement(&close_handle_cnt
))
413 SetEvent(hCompleteEvent
);
415 case INTERNET_STATUS_REQUEST_COMPLETE
:
417 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
418 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
419 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
420 dwStatusInformationLength
);
421 ok(iar
->dwResult
== 1 || iar
->dwResult
== 0, "iar->dwResult = %ld\n", iar
->dwResult
);
422 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
423 GetCurrentThreadId(), hInternet
, dwContext
,
424 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
425 req_error
= iar
->dwError
;
426 if(!close_handle_cnt
)
427 SetEvent(hCompleteEvent
);
430 case INTERNET_STATUS_REDIRECT
:
431 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
432 GetCurrentThreadId(), hInternet
, dwContext
,
433 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
434 *(LPSTR
)lpvStatusInformation
= '\0';
435 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
436 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
438 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
439 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
440 GetCurrentThreadId(), hInternet
, dwContext
,
441 lpvStatusInformation
, dwStatusInformationLength
);
444 trace("%04x:Callback %p 0x%lx %d %p %d\n",
445 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
446 lpvStatusInformation
, dwStatusInformationLength
);
450 static void close_async_handle(HINTERNET handle
, HANDLE complete_event
, int handle_cnt
)
454 close_handle_cnt
= handle_cnt
;
456 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
457 res
= InternetCloseHandle(handle
);
458 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
459 WaitForSingleObject(hCompleteEvent
, INFINITE
);
460 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
463 static void InternetReadFile_test(int flags
, const test_data_t
*test
)
465 char *post_data
= NULL
;
466 BOOL res
, on_async
= TRUE
;
469 DWORD length
, length2
, index
, exlen
= 0, post_len
= 0;
470 const char *types
[2] = { "*", NULL
};
471 HINTERNET hi
, hic
= 0, hor
= 0;
473 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
475 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags
,test
->url
);
477 trace("InternetOpenA <--\n");
478 hi
= InternetOpenA((test
->flags
& TESTF_COMPRESSED
) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
479 INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
480 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
481 trace("InternetOpenA -->\n");
483 if (hi
== 0x0) goto abort
;
485 pInternetSetStatusCallbackA(hi
,&callback
);
487 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
489 trace("InternetConnectA <--\n");
490 hic
=InternetConnectA(hi
, test
->host
, INTERNET_INVALID_PORT_NUMBER
,
491 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
492 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
493 trace("InternetConnectA -->\n");
495 if (hic
== 0x0) goto abort
;
497 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
498 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
500 trace("HttpOpenRequestA <--\n");
501 hor
= HttpOpenRequestA(hic
, test
->post_data
? "POST" : "GET", test
->path
, NULL
, NULL
, types
,
502 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
504 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
506 * If the internet name can't be resolved we are probably behind
507 * a firewall or in some other way not directly connected to the
508 * Internet. Not enough reason to fail the test. Just ignore and
512 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
514 trace("HttpOpenRequestA -->\n");
516 if (hor
== 0x0) goto abort
;
518 test_request_flags(hor
, INTERNET_REQFLAG_NO_HEADERS
);
520 length
= sizeof(buffer
);
521 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
522 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
523 ok(!strcmp(buffer
, test
->url
), "Wrong URL %s, expected %s\n", buffer
, test
->url
);
525 length
= sizeof(buffer
);
526 res
= HttpQueryInfoA(hor
, HTTP_QUERY_RAW_HEADERS
, buffer
, &length
, 0x0);
527 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
528 ok(length
== 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length
);
529 ok(!strcmp(buffer
, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer
);
531 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
532 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
533 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
534 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
,2);
535 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED
,2);
536 if (first_connection_to_test_url
)
538 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
539 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
541 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
542 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
543 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
544 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
545 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
546 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
547 if(test
->flags
& TESTF_REDIRECT
) {
548 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
549 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
551 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
552 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
553 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
554 if (flags
& INTERNET_FLAG_ASYNC
)
555 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
557 if(test
->flags
& TESTF_COMPRESSED
) {
560 res
= InternetSetOptionA(hor
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
561 ok(res
|| broken(!res
&& GetLastError() == ERROR_INTERNET_INVALID_OPTION
),
562 "InternetSetOption failed: %u\n", GetLastError());
567 test_status_code(hor
, 0);
569 trace("HttpSendRequestA -->\n");
570 if(test
->post_data
) {
571 post_len
= strlen(test
->post_data
);
572 post_data
= HeapAlloc(GetProcessHeap(), 0, post_len
);
573 memcpy(post_data
, test
->post_data
, post_len
);
575 SetLastError(0xdeadbeef);
576 res
= HttpSendRequestA(hor
, test
->headers
, -1, post_data
, post_len
);
577 if (flags
& INTERNET_FLAG_ASYNC
)
578 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
579 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
581 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
582 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
583 trace("HttpSendRequestA <--\n");
585 if (flags
& INTERNET_FLAG_ASYNC
) {
586 WaitForSingleObject(hCompleteEvent
, INFINITE
);
587 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
589 HeapFree(GetProcessHeap(), 0, post_data
);
591 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
592 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED
);
593 if (first_connection_to_test_url
)
595 if (! proxy_active())
597 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
598 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
602 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
603 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
608 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
609 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
611 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
612 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
613 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
614 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
615 if(test
->flags
& TESTF_REDIRECT
)
616 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
617 if (flags
& INTERNET_FLAG_ASYNC
)
618 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
619 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
620 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
621 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
623 test_request_flags(hor
, 0);
626 res
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
627 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
629 length
= sizeof(buffer
)-1;
630 memset(buffer
, 0x77, sizeof(buffer
));
631 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
632 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
633 /* show that the function writes data past the length returned */
634 ok(buffer
[length
-2], "Expected any header character, got 0x00\n");
635 ok(!buffer
[length
-1], "Expected 0x00, got %02X\n", buffer
[length
-1]);
636 ok(!buffer
[length
], "Expected 0x00, got %02X\n", buffer
[length
]);
637 ok(buffer
[length
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length
+1]);
640 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
641 ok(!res
, "Expected 0x00, got %d\n", res
);
642 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
643 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
644 /* the in length of the buffer must be +1 but the length returned does not count this */
646 memset(buffer
, 0x77, sizeof(buffer
));
647 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
648 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
649 ok(buffer
[length2
] == 0x00, "Expected 0x00, got %02X\n", buffer
[length2
]);
650 ok(buffer
[length2
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length2
+1]);
651 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
653 length
= sizeof(wbuffer
)-sizeof(WCHAR
);
654 memset(wbuffer
, 0x77, sizeof(wbuffer
));
655 res
= HttpQueryInfoW(hor
, HTTP_QUERY_RAW_HEADERS
, wbuffer
, &length
, 0x0);
656 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
657 ok(length
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length
);
658 length
/= sizeof(WCHAR
);
659 /* show that the function writes data past the length returned */
660 ok(wbuffer
[length
-2], "Expected any header character, got 0x0000\n");
661 ok(!wbuffer
[length
-1], "Expected 0x0000, got %04X\n", wbuffer
[length
-1]);
662 ok(!wbuffer
[length
], "Expected 0x0000, got %04X\n", wbuffer
[length
]);
663 ok(wbuffer
[length
+1] == 0x7777 || broken(wbuffer
[length
+1] != 0x7777),
664 "Expected 0x7777, got %04X\n", wbuffer
[length
+1]);
666 length2
= length
*sizeof(WCHAR
);
667 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
668 ok(!res
, "Expected 0x00, got %d\n", res
);
669 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
670 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
671 length2
/= sizeof(WCHAR
);
672 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
673 /* the in length of the buffer must be +1 but the length returned does not count this */
674 length2
= (length
+1)*sizeof(WCHAR
);
675 memset(wbuffer
, 0x77, sizeof(wbuffer
));
676 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
677 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
678 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
679 length2
/= sizeof(WCHAR
);
680 ok(!wbuffer
[length2
], "Expected 0x0000, got %04X\n", wbuffer
[length2
]);
681 ok(wbuffer
[length2
+1] == 0x7777, "Expected 0x7777, got %04X\n", wbuffer
[length2
+1]);
682 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
684 length
= sizeof(buffer
);
685 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
686 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
687 ok(!strcmp(buffer
, test
->redirected_url
), "Wrong URL %s\n", buffer
);
691 SetLastError(0xdeadbeef);
692 ok(HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,NULL
,&length
,&index
) == FALSE
,"Query worked\n");
693 if(test
->flags
& TESTF_COMPRESSED
)
694 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
695 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
696 ok(index
== 0, "Index was incremented\n");
700 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,&index
);
701 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res
,buffer
,GetLastError());
702 if(test
->flags
& TESTF_COMPRESSED
)
703 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
704 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res
, GetLastError());
705 ok(!res
|| index
== 1, "Index was not incremented although result is %x (index = %u)\n", res
, index
);
708 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
710 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res
,buffer
);
713 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_ENCODING
,buffer
,&length
,0x0);
715 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res
,buffer
);
717 SetLastError(0xdeadbeef);
718 res
= InternetReadFile(NULL
, buffer
, 100, &length
);
719 ok(!res
, "InternetReadFile should have failed\n");
720 ok(GetLastError() == ERROR_INVALID_HANDLE
,
721 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
725 trace("Entering Query loop\n");
729 if (flags
& INTERNET_FLAG_ASYNC
)
730 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
732 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
733 if (flags
& INTERNET_FLAG_ASYNC
)
737 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
739 ok(length
>= exlen
, "length %u < exlen %u\n", length
, exlen
);
743 else if (GetLastError() == ERROR_IO_PENDING
)
746 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
747 if(!(test
->flags
& TESTF_CHUNKED
))
748 ok(!length
, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length
);
749 WaitForSingleObject(hCompleteEvent
, INFINITE
);
751 ok(exlen
, "length = 0\n");
752 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
753 ok(req_error
, "req_error = 0\n");
756 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
759 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
761 trace("LENGTH %d\n", length
);
762 if(test
->flags
& TESTF_CHUNKED
)
763 ok(length
<= 8192, "length = %d, expected <= 8192\n", length
);
767 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
769 res
= InternetReadFile(hor
,buffer
,length
,&length
);
773 trace("ReadFile -> %s %i\n",res
?"TRUE":"FALSE",length
);
776 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
777 HeapFree(GetProcessHeap(),0,buffer
);
779 ok(!on_async
, "Returned zero size in response to request complete\n");
784 if(test
->flags
& TESTF_REDIRECT
) {
785 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
786 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
790 close_async_handle(hi
, hCompleteEvent
, 2);
791 CloseHandle(hCompleteEvent
);
792 first_connection_to_test_url
= FALSE
;
795 static void InternetReadFile_chunked_test(void)
800 const char *types
[2] = { "*", NULL
};
801 HINTERNET hi
, hic
= 0, hor
= 0;
803 trace("Starting InternetReadFile chunked test\n");
805 trace("InternetOpenA <--\n");
806 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
807 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
808 trace("InternetOpenA -->\n");
810 if (hi
== 0x0) goto abort
;
812 trace("InternetConnectA <--\n");
813 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
814 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
815 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
816 trace("InternetConnectA -->\n");
818 if (hic
== 0x0) goto abort
;
820 trace("HttpOpenRequestA <--\n");
821 hor
= HttpOpenRequestA(hic
, "GET", "/tests/chunked", NULL
, NULL
, types
,
822 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
824 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
826 * If the internet name can't be resolved we are probably behind
827 * a firewall or in some other way not directly connected to the
828 * Internet. Not enough reason to fail the test. Just ignore and
832 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
834 trace("HttpOpenRequestA -->\n");
836 if (hor
== 0x0) goto abort
;
838 trace("HttpSendRequestA -->\n");
839 SetLastError(0xdeadbeef);
840 res
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
841 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
842 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
843 trace("HttpSendRequestA <--\n");
845 test_request_flags(hor
, 0);
848 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
850 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
852 SetLastError( 0xdeadbeef );
854 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
856 trace("Option TRANSFER_ENCODING -> %i %s\n",res
,buffer
);
857 ok( res
|| ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
858 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
859 ok( !strcmp( buffer
, "chunked" ) || ( ! res
&& proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
860 "Wrong transfer encoding '%s'\n", buffer
);
862 SetLastError( 0xdeadbeef );
864 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
865 ok( !res
, "Found CONTENT_LENGTH option '%s'\n", buffer
);
866 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Wrong error %u\n", GetLastError() );
869 trace("Entering Query loop\n");
873 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
874 ok(!(!res
&& length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
875 ok(res
, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
876 trace("got %u available\n",length
);
879 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
881 res
= InternetReadFile(hor
,buffer
,length
,&got
);
884 trace("ReadFile -> %i %i\n",res
,got
);
885 ok( length
== got
, "only got %u of %u available\n", got
, length
);
886 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
888 HeapFree(GetProcessHeap(),0,buffer
);
894 res
= InternetReadFile( hor
, buffer
, 1, &got
);
895 ok( res
, "InternetReadFile failed: %u\n", GetLastError() );
896 ok( !got
, "got %u\n", got
);
903 res
= InternetCloseHandle(hor
);
904 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
907 res
= InternetCloseHandle(hi
);
908 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
912 static void InternetReadFileExA_test(int flags
)
916 const char *types
[2] = { "*", NULL
};
917 HINTERNET hi
, hic
= 0, hor
= 0;
918 INTERNET_BUFFERSA inetbuffers
;
920 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
922 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
924 trace("InternetOpenA <--\n");
925 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
926 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
927 trace("InternetOpenA -->\n");
929 if (hi
== 0x0) goto abort
;
931 pInternetSetStatusCallbackA(hi
,&callback
);
933 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
935 trace("InternetConnectA <--\n");
936 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
937 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
938 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
939 trace("InternetConnectA -->\n");
941 if (hic
== 0x0) goto abort
;
943 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
944 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
946 trace("HttpOpenRequestA <--\n");
947 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
948 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
950 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
952 * If the internet name can't be resolved we are probably behind
953 * a firewall or in some other way not directly connected to the
954 * Internet. Not enough reason to fail the test. Just ignore and
958 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
960 trace("HttpOpenRequestA -->\n");
962 if (hor
== 0x0) goto abort
;
964 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
965 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
966 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
967 if (first_connection_to_test_url
)
969 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
970 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
972 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
, 2);
973 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
974 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
975 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
976 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
977 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
978 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
979 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
980 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
981 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
982 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
983 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
984 if (flags
& INTERNET_FLAG_ASYNC
)
985 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
987 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
989 trace("HttpSendRequestA -->\n");
990 SetLastError(0xdeadbeef);
991 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
992 if (flags
& INTERNET_FLAG_ASYNC
)
993 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
994 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
996 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
997 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
998 trace("HttpSendRequestA <--\n");
1000 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
1001 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1002 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1005 if (first_connection_to_test_url
)
1007 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1008 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1012 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1013 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1015 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1016 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
1017 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1018 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1019 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1020 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1021 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
1022 if (flags
& INTERNET_FLAG_ASYNC
)
1023 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1025 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1026 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
1027 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
1028 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1029 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1031 /* tests invalid dwStructSize */
1032 inetbuffers
.dwStructSize
= sizeof(inetbuffers
)+1;
1033 inetbuffers
.lpcszHeader
= NULL
;
1034 inetbuffers
.dwHeadersLength
= 0;
1035 inetbuffers
.dwBufferLength
= 10;
1036 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
1037 inetbuffers
.dwOffsetHigh
= 1234;
1038 inetbuffers
.dwOffsetLow
= 5678;
1039 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1040 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1041 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1042 rc
? "TRUE" : "FALSE", GetLastError());
1043 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1045 test_request_flags(hor
, 0);
1047 /* tests to see whether lpcszHeader is used - it isn't */
1048 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1049 inetbuffers
.lpcszHeader
= (LPCSTR
)0xdeadbeef;
1050 inetbuffers
.dwHeadersLength
= 255;
1051 inetbuffers
.dwBufferLength
= 0;
1052 inetbuffers
.lpvBuffer
= NULL
;
1053 inetbuffers
.dwOffsetHigh
= 1234;
1054 inetbuffers
.dwOffsetLow
= 5678;
1055 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
1056 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
1057 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1058 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
1059 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1062 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1063 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1066 rc
= InternetReadFileExA(NULL
, &inetbuffers
, 0, 0xdeadcafe);
1067 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
1068 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1069 rc
? "TRUE" : "FALSE", GetLastError());
1072 trace("Entering Query loop\n");
1076 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1077 inetbuffers
.dwBufferLength
= 1024;
1078 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
1079 inetbuffers
.dwOffsetHigh
= 1234;
1080 inetbuffers
.dwOffsetLow
= 5678;
1082 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1083 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1084 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1085 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
1088 if (GetLastError() == ERROR_IO_PENDING
)
1090 trace("InternetReadFileEx -> PENDING\n");
1091 ok(flags
& INTERNET_FLAG_ASYNC
,
1092 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1093 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1094 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1095 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1096 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1097 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1101 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1107 trace("InternetReadFileEx -> SUCCEEDED\n");
1108 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1109 if (inetbuffers
.dwBufferLength
)
1112 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1113 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1118 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1119 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1120 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1124 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1125 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
1127 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
1128 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1129 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
1131 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1133 if (!inetbuffers
.dwBufferLength
)
1136 length
+= inetbuffers
.dwBufferLength
;
1138 ok(length
> 0, "failed to read any of the document\n");
1139 trace("Finished. Read %d bytes\n", length
);
1142 close_async_handle(hi
, hCompleteEvent
, 2);
1143 CloseHandle(hCompleteEvent
);
1144 first_connection_to_test_url
= FALSE
;
1147 static void InternetOpenUrlA_test(void)
1149 HINTERNET myhinternet
, myhttp
;
1151 DWORD size
, readbytes
, totalbytes
=0;
1154 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1155 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
1156 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret
, GetLastError());
1158 myhinternet
= InternetOpenA("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
1159 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
1161 ret
= InternetCanonicalizeUrlA(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1162 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1165 myhttp
= InternetOpenUrlA(myhinternet
, TEST_URL
, 0, 0,
1166 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
1167 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1168 return; /* WinXP returns this when not connected to the net */
1169 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1170 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
1171 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
1172 totalbytes
+= readbytes
;
1173 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
1174 totalbytes
+= readbytes
;
1175 trace("read 0x%08x bytes\n",totalbytes
);
1177 InternetCloseHandle(myhttp
);
1178 InternetCloseHandle(myhinternet
);
1180 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1181 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1184 static void HttpSendRequestEx_test(void)
1190 INTERNET_BUFFERSA BufferIn
;
1191 DWORD dwBytesWritten
, dwBytesRead
, error
;
1196 static char szPostData
[] = "mode=Test";
1197 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
1199 hSession
= InternetOpenA("Wine Regression Test",
1200 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1201 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1202 hConnect
= InternetConnectA(hSession
, "crossover.codeweavers.com",
1203 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1205 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
1206 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/posttest.php",
1207 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1208 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1210 skip( "Network unreachable, skipping test\n" );
1213 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1215 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1217 BufferIn
.dwStructSize
= sizeof(BufferIn
);
1218 BufferIn
.Next
= (INTERNET_BUFFERSA
*)0xdeadcab;
1219 BufferIn
.lpcszHeader
= szContentType
;
1220 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1221 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1222 BufferIn
.lpvBuffer
= szPostData
;
1223 BufferIn
.dwBufferLength
= 3;
1224 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1225 BufferIn
.dwOffsetLow
= 0;
1226 BufferIn
.dwOffsetHigh
= 0;
1228 SetLastError(0xdeadbeef);
1229 ret
= HttpSendRequestExA(hRequest
, &BufferIn
, NULL
, 0 ,0);
1230 error
= GetLastError();
1231 ok(ret
, "HttpSendRequestEx Failed with error %u\n", error
);
1232 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", error
);
1234 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1236 for (i
= 3; szPostData
[i
]; i
++)
1237 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1238 "InternetWriteFile failed\n");
1240 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1242 ok(HttpEndRequestA(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1244 test_request_flags(hRequest
, 0);
1246 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1247 "Unable to read response\n");
1248 szBuffer
[dwBytesRead
] = 0;
1250 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
1251 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1253 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1255 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1256 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1259 static void InternetOpenRequest_test(void)
1261 HINTERNET session
, connect
, request
;
1262 static const char *types
[] = { "*", "", NULL
};
1263 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1264 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1267 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1268 ok(session
!= NULL
,"Unable to open Internet session\n");
1270 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1271 INTERNET_SERVICE_HTTP
, 0, 0);
1272 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1273 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1275 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1276 INTERNET_SERVICE_HTTP
, 0, 0);
1277 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1278 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1280 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1281 INTERNET_SERVICE_HTTP
, 0, 0);
1282 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1284 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1285 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1287 skip( "Network unreachable, skipping test\n" );
1290 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1292 ret
= HttpSendRequestW(request
, NULL
, 0, NULL
, 0);
1293 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1294 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1296 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1297 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1299 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1300 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1301 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1304 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1305 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1308 static void test_cache_read(void)
1310 HINTERNET session
, connection
, req
;
1311 FILETIME now
, tomorrow
, yesterday
;
1312 BYTE content
[1000], buf
[2000];
1313 char file_path
[MAX_PATH
];
1320 static const char cache_only_url
[] = "http://test.winehq.org/tests/cache-only";
1321 BYTE cache_headers
[] = "HTTP/1.1 200 OK\r\n\r\n";
1323 trace("Testing cache read...\n");
1325 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1327 for(i
= 0; i
< sizeof(content
); i
++)
1328 content
[i
] = '0' + (i
%10);
1330 GetSystemTimeAsFileTime(&now
);
1331 li
.u
.HighPart
= now
.dwHighDateTime
;
1332 li
.u
.LowPart
= now
.dwLowDateTime
;
1333 li
.QuadPart
+= (LONGLONG
)10000000 * 3600 * 24;
1334 tomorrow
.dwHighDateTime
= li
.u
.HighPart
;
1335 tomorrow
.dwLowDateTime
= li
.u
.LowPart
;
1336 li
.QuadPart
-= (LONGLONG
)10000000 * 3600 * 24 * 2;
1337 yesterday
.dwHighDateTime
= li
.u
.HighPart
;
1338 yesterday
.dwLowDateTime
= li
.u
.LowPart
;
1340 res
= CreateUrlCacheEntryA(cache_only_url
, sizeof(content
), "", file_path
, 0);
1341 ok(res
, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1343 file
= CreateFileA(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1344 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
1346 WriteFile(file
, content
, sizeof(content
), &size
, NULL
);
1349 res
= CommitUrlCacheEntryA(cache_only_url
, file_path
, tomorrow
, yesterday
, NORMAL_CACHE_ENTRY
,
1350 cache_headers
, sizeof(cache_headers
)-1, "", 0);
1351 ok(res
, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1353 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
1354 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
1356 pInternetSetStatusCallbackA(session
, callback
);
1358 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1359 connection
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
,
1360 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1361 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
1362 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1364 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1365 req
= HttpOpenRequestA(connection
, "GET", "/tests/cache-only", NULL
, NULL
, NULL
, 0, 0xdeadbead);
1366 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
1367 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1369 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1370 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1371 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST
);
1372 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT
);
1373 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1374 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1375 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1377 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
1379 ok(res
, "HttpSendRequest failed: %u\n", GetLastError());
1383 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
1384 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1385 ok(size
== sizeof(content
), "size = %u\n", size
);
1388 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
1389 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
1390 ok(size
== sizeof(content
), "size = %u\n", size
);
1391 ok(!memcmp(content
, buf
, sizeof(content
)), "unexpected content\n");
1394 close_async_handle(session
, hCompleteEvent
, 2);
1396 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1397 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1398 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
1399 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
1400 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1401 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1402 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1404 res
= DeleteUrlCacheEntryA(cache_only_url
);
1405 ok(res
, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1407 CloseHandle(hCompleteEvent
);
1410 static void test_http_cache(void)
1412 HINTERNET session
, connect
, request
;
1413 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1414 DWORD size
, file_size
;
1419 static const char *types
[] = { "*", "", NULL
};
1421 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1422 ok(session
!= NULL
,"Unable to open Internet session\n");
1424 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1425 INTERNET_SERVICE_HTTP
, 0, 0);
1426 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1428 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1429 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1431 skip( "Network unreachable, skipping test\n" );
1433 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1434 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1438 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1441 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1442 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1443 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1445 size
= sizeof(file_name
);
1446 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1447 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1448 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1449 ok(!size
, "size = %d\n", size
);
1451 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1452 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1454 size
= sizeof(file_name
);
1455 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1456 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1458 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1459 FILE_ATTRIBUTE_NORMAL
, NULL
);
1460 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1461 file_size
= GetFileSize(file
, NULL
);
1462 ok(file_size
== 106, "file size = %u\n", file_size
);
1465 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1466 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1467 ok(size
== 100, "size = %u\n", size
);
1469 file_size
= GetFileSize(file
, NULL
);
1470 ok(file_size
== 106, "file size = %u\n", file_size
);
1473 ret
= DeleteFileA(file_name
);
1474 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1476 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1478 file
= CreateFileA(file_name
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
1479 FILE_ATTRIBUTE_NORMAL
, NULL
);
1480 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1483 /* Send the same request, requiring it to be retrieved from the cache */
1484 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1486 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1487 ok(ret
, "HttpSendRequest failed\n");
1490 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1491 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1492 ok(size
== 100, "size = %u\n", size
);
1494 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1496 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1497 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1499 size
= sizeof(file_name
);
1500 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1501 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1502 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1503 ok(!size
, "size = %d\n", size
);
1505 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1506 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1508 size
= sizeof(file_name
);
1510 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1513 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1514 FILE_ATTRIBUTE_NORMAL
, NULL
);
1515 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1521 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1524 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1525 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1526 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1531 static void InternetLockRequestFile_test(void)
1533 HINTERNET session
, connect
, request
;
1534 char file_name
[MAX_PATH
];
1539 static const char *types
[] = { "*", "", NULL
};
1541 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1542 ok(session
!= NULL
,"Unable to open Internet session\n");
1544 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1545 INTERNET_SERVICE_HTTP
, 0, 0);
1546 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1548 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
|INTERNET_FLAG_RELOAD
, 0);
1549 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1551 skip( "Network unreachable, skipping test\n" );
1553 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1554 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1558 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1560 size
= sizeof(file_name
);
1561 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1562 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1563 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1564 ok(!size
, "size = %d\n", size
);
1567 ret
= InternetLockRequestFile(request
, &lock
);
1568 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1570 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1571 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1573 size
= sizeof(file_name
);
1574 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1575 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1577 ret
= InternetLockRequestFile(request
, &lock
);
1578 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1579 ok(lock
!= NULL
, "lock == NULL\n");
1581 ret
= InternetLockRequestFile(request
, &lock2
);
1582 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1583 ok(lock
== lock2
, "lock != lock2\n");
1585 ret
= InternetUnlockRequestFile(lock2
);
1586 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1588 ret
= DeleteFileA(file_name
);
1589 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1591 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1593 ret
= DeleteFileA(file_name
);
1594 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1596 ret
= InternetUnlockRequestFile(lock
);
1597 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1599 ret
= DeleteFileA(file_name
);
1600 ok(ret
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1603 static void HttpHeaders_test(void)
1615 hSession
= InternetOpenA("Wine Regression Test",
1616 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1617 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1618 hConnect
= InternetConnectA(hSession
, "crossover.codeweavers.com",
1619 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1621 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
1622 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/posttest.php",
1623 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1624 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1626 skip( "Network unreachable, skipping test\n" );
1629 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1632 len
= sizeof(buffer
);
1633 strcpy(buffer
,"Warning");
1634 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1635 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1637 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1638 "Failed to add new header\n");
1641 len
= sizeof(buffer
);
1642 strcpy(buffer
,"Warning");
1643 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1644 buffer
,&len
,&index
),"Unable to query header\n");
1645 ok(index
== 1, "Index was not incremented\n");
1646 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1647 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1648 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1649 len
= sizeof(buffer
);
1650 strcpy(buffer
,"Warning");
1651 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1652 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1655 len
= 5; /* could store the string but not the NULL terminator */
1656 strcpy(buffer
,"Warning");
1657 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1658 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1659 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1660 ok(index
== 0, "Index was incremented\n");
1661 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1662 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1664 /* a call with NULL will fail but will return the length */
1666 len
= sizeof(buffer
);
1667 SetLastError(0xdeadbeef);
1668 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1669 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1670 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1671 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1672 ok(index
== 0, "Index was incremented\n");
1674 /* even for a len that is too small */
1677 SetLastError(0xdeadbeef);
1678 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1679 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1680 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1681 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1682 ok(index
== 0, "Index was incremented\n");
1686 SetLastError(0xdeadbeef);
1687 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1688 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1689 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1690 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1691 ok(index
== 0, "Index was incremented\n");
1692 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1695 /* a working query */
1697 len
= sizeof(buffer
);
1698 memset(buffer
, 'x', sizeof(buffer
));
1699 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1700 buffer
,&len
,&index
),"Unable to query header\n");
1701 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1702 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1703 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1704 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1705 ok(strncmp(buffer
, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1706 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1707 ok(index
== 0, "Index was incremented\n");
1709 /* Like above two tests, but for W version */
1713 SetLastError(0xdeadbeef);
1714 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1715 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1716 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1717 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1718 ok(index
== 0, "Index was incremented\n");
1719 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1721 /* a working query */
1723 len
= sizeof(wbuffer
);
1724 memset(wbuffer
, 'x', sizeof(wbuffer
));
1725 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1726 wbuffer
,&len
,&index
),"Unable to query header\n");
1727 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1728 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1729 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1730 ok(index
== 0, "Index was incremented\n");
1732 /* end of W version tests */
1734 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1736 len
= sizeof(buffer
);
1737 memset(buffer
, 'x', sizeof(buffer
));
1738 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1739 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1740 ok(len
== 2, "Expected 2, got %d\n", len
);
1741 ok(strcmp(buffer
, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer
);
1742 ok(index
== 0, "Index was incremented\n");
1744 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1745 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1748 len
= sizeof(buffer
);
1749 strcpy(buffer
,"Warning");
1750 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1751 buffer
,&len
,&index
),"Unable to query header\n");
1752 ok(index
== 1, "Index was not incremented\n");
1753 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1754 len
= sizeof(buffer
);
1755 strcpy(buffer
,"Warning");
1756 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1757 buffer
,&len
,&index
),"Failed to get second header\n");
1758 ok(index
== 2, "Index was not incremented\n");
1759 ok(strcmp(buffer
,"test2")==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
,
1763 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1765 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1768 len
= sizeof(buffer
);
1769 strcpy(buffer
,"Warning");
1770 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1771 buffer
,&len
,&index
),"Unable to query header\n");
1772 ok(index
== 1, "Index was not incremented\n");
1773 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1774 len
= sizeof(buffer
);
1775 strcpy(buffer
,"Warning");
1776 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1777 buffer
,&len
,&index
),"Failed to get second header\n");
1778 ok(index
== 2, "Index was not incremented\n");
1779 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1780 len
= sizeof(buffer
);
1781 strcpy(buffer
,"Warning");
1782 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1783 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1785 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1788 len
= sizeof(buffer
);
1789 strcpy(buffer
,"Warning");
1790 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1791 buffer
,&len
,&index
),"Unable to query header\n");
1792 ok(index
== 1, "Index was not incremented\n");
1793 ok(strcmp(buffer
,"test2")==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
,
1797 buffer
,&len
,&index
),"Failed to get second header\n");
1798 ok(index
== 2, "Index was not incremented\n");
1799 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1800 len
= sizeof(buffer
);
1801 strcpy(buffer
,"Warning");
1802 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1803 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1805 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1808 len
= sizeof(buffer
);
1809 strcpy(buffer
,"Warning");
1810 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1811 buffer
,&len
,&index
),"Unable to query header\n");
1812 ok(index
== 1, "Index was not incremented\n");
1813 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1814 len
= sizeof(buffer
);
1815 strcpy(buffer
,"Warning");
1816 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1817 ok(index
== 2, "Index was not incremented\n");
1818 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1819 len
= sizeof(buffer
);
1820 strcpy(buffer
,"Warning");
1821 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1823 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1826 len
= sizeof(buffer
);
1827 strcpy(buffer
,"Warning");
1828 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1829 ok(index
== 1, "Index was not incremented\n");
1830 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1831 len
= sizeof(buffer
);
1832 strcpy(buffer
,"Warning");
1833 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1834 ok(index
== 2, "Index was not incremented\n");
1835 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1836 len
= sizeof(buffer
);
1837 strcpy(buffer
,"Warning");
1838 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1840 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1843 len
= sizeof(buffer
);
1844 strcpy(buffer
,"Warning");
1845 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1846 ok(index
== 1, "Index was not incremented\n");
1847 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1848 len
= sizeof(buffer
);
1849 strcpy(buffer
,"Warning");
1850 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1851 ok(index
== 2, "Index was not incremented\n");
1852 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1853 len
= sizeof(buffer
);
1854 strcpy(buffer
,"Warning");
1855 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1857 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");
1860 len
= sizeof(buffer
);
1861 strcpy(buffer
,"Warning");
1862 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1863 ok(index
== 1, "Index was not incremented\n");
1864 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1865 len
= sizeof(buffer
);
1866 strcpy(buffer
,"Warning");
1867 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1868 ok(index
== 2, "Index was not incremented\n");
1869 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1870 len
= sizeof(buffer
);
1871 strcpy(buffer
,"Warning");
1872 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1874 /* Ensure that blank headers are ignored and don't cause a failure */
1875 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");
1878 len
= sizeof(buffer
);
1879 strcpy(buffer
,"BlankTest");
1880 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1881 ok(index
== 1, "Index was not incremented\n");
1882 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1884 /* Ensure that malformed header separators are ignored and don't cause a failure */
1885 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
),
1886 "Failed to add header with malformed entries in list\n");
1889 len
= sizeof(buffer
);
1890 strcpy(buffer
,"MalformedTest");
1891 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1892 ok(index
== 1, "Index was not incremented\n");
1893 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1895 len
= sizeof(buffer
);
1896 strcpy(buffer
,"MalformedTestTwo");
1897 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1898 ok(index
== 1, "Index was not incremented\n");
1899 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
1901 len
= sizeof(buffer
);
1902 strcpy(buffer
,"MalformedTestThree");
1903 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1904 ok(index
== 1, "Index was not incremented\n");
1905 ok(strcmp(buffer
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
1907 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD
);
1908 ok(ret
, "unable to add header %u\n", GetLastError());
1912 len
= sizeof(buffer
);
1913 ret
= HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
);
1914 ok(ret
, "unable to query header %u\n", GetLastError());
1915 ok(index
== 1, "index was not incremented\n");
1916 ok(!strcmp(buffer
, "Basic"), "incorrect string was returned (%s)\n", buffer
);
1918 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE
);
1919 ok(ret
, "unable to remove header %u\n", GetLastError());
1922 len
= sizeof(buffer
);
1923 SetLastError(0xdeadbeef);
1924 ok(!HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
),
1925 "header still present\n");
1926 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "got %u\n", GetLastError());
1928 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1930 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1931 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1934 static const char garbagemsg
[] =
1935 "Garbage: Header\r\n";
1937 static const char contmsg
[] =
1938 "HTTP/1.1 100 Continue\r\n";
1940 static const char expandcontmsg
[] =
1941 "HTTP/1.1 100 Continue\r\n"
1942 "Server: winecontinue\r\n"
1943 "Tag: something witty\r\n"
1946 static const char okmsg
[] =
1947 "HTTP/1.1 200 OK\r\n"
1948 "Server: winetest\r\n"
1951 static const char okmsg2
[] =
1952 "HTTP/1.1 200 OK\r\n"
1953 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1954 "Server: winetest\r\n"
1955 "Content-Length: 0\r\n"
1956 "Set-Cookie: one\r\n"
1957 "Set-Cookie: two\r\n"
1960 static const char notokmsg
[] =
1961 "HTTP/1.1 400 Bad Request\r\n"
1962 "Server: winetest\r\n"
1965 static const char noauthmsg
[] =
1966 "HTTP/1.1 401 Unauthorized\r\n"
1967 "Server: winetest\r\n"
1968 "Connection: close\r\n"
1969 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1972 static const char noauthmsg2
[] =
1973 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
1974 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
1976 "Server: winetest\r\n";
1978 static const char proxymsg
[] =
1979 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1980 "Server: winetest\r\n"
1981 "Proxy-Connection: close\r\n"
1982 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1985 static const char page1
[] =
1987 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1988 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1991 static const char ok_with_length
[] =
1992 "HTTP/1.1 200 OK\r\n"
1993 "Connection: Keep-Alive\r\n"
1994 "Content-Length: 18\r\n\r\n"
1995 "HTTP/1.1 211 OK\r\n\r\n";
1997 static const char ok_with_length2
[] =
1998 "HTTP/1.1 210 OK\r\n"
1999 "Connection: Keep-Alive\r\n"
2000 "Content-Length: 19\r\n\r\n"
2001 "HTTP/1.1 211 OK\r\n\r\n";
2003 struct server_info
{
2008 static int test_cache_gzip
;
2009 static const char *send_buffer
;
2011 static DWORD CALLBACK
server_thread(LPVOID param
)
2013 struct server_info
*si
= param
;
2014 int r
, c
= -1, i
, on
, count
= 0;
2016 struct sockaddr_in sa
;
2019 int last_request
= 0;
2020 char host_header
[22];
2021 static BOOL test_b
= FALSE
;
2022 static int test_no_cache
= 0;
2024 WSAStartup(MAKEWORD(1,1), &wsaData
);
2026 s
= socket(AF_INET
, SOCK_STREAM
, 0);
2027 if (s
== INVALID_SOCKET
)
2031 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
2033 memset(&sa
, 0, sizeof sa
);
2034 sa
.sin_family
= AF_INET
;
2035 sa
.sin_port
= htons(si
->port
);
2036 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
2038 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
2044 SetEvent(si
->hEvent
);
2046 sprintf(host_header
, "Host: localhost:%d", si
->port
);
2051 c
= accept(s
, NULL
, NULL
);
2053 memset(buffer
, 0, sizeof buffer
);
2054 for(i
=0; i
<(sizeof buffer
-1); i
++)
2056 r
= recv(c
, &buffer
[i
], 1, 0);
2060 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
2061 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
2064 if (strstr(buffer
, "GET /test1"))
2066 if (!strstr(buffer
, "Content-Length: 0"))
2068 send(c
, okmsg
, sizeof okmsg
-1, 0);
2069 send(c
, page1
, sizeof page1
-1, 0);
2072 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2074 if (strstr(buffer
, "/test2"))
2076 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2078 send(c
, okmsg
, sizeof okmsg
-1, 0);
2079 send(c
, page1
, sizeof page1
-1, 0);
2082 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2084 if (strstr(buffer
, "/test3"))
2086 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2087 send(c
, okmsg
, sizeof okmsg
-1, 0);
2089 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2091 if (strstr(buffer
, "/test4"))
2093 if (strstr(buffer
, "Connection: Close"))
2094 send(c
, okmsg
, sizeof okmsg
-1, 0);
2096 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2098 if (strstr(buffer
, "POST /test5") ||
2099 strstr(buffer
, "RPC_IN_DATA /test5") ||
2100 strstr(buffer
, "RPC_OUT_DATA /test5"))
2102 if (strstr(buffer
, "Content-Length: 0"))
2104 send(c
, okmsg
, sizeof okmsg
-1, 0);
2105 send(c
, page1
, sizeof page1
-1, 0);
2108 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2110 if (strstr(buffer
, "GET /test6"))
2112 send(c
, contmsg
, sizeof contmsg
-1, 0);
2113 send(c
, contmsg
, sizeof contmsg
-1, 0);
2114 send(c
, okmsg
, sizeof okmsg
-1, 0);
2115 send(c
, page1
, sizeof page1
-1, 0);
2117 if (strstr(buffer
, "POST /test7"))
2119 if (strstr(buffer
, "Content-Length: 100"))
2121 send(c
, okmsg
, sizeof okmsg
-1, 0);
2122 send(c
, page1
, sizeof page1
-1, 0);
2125 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2127 if (strstr(buffer
, "/test8"))
2129 if (!strstr(buffer
, "Connection: Close") &&
2130 strstr(buffer
, "Connection: Keep-Alive") &&
2131 !strstr(buffer
, "Cache-Control: no-cache") &&
2132 !strstr(buffer
, "Pragma: no-cache") &&
2133 strstr(buffer
, host_header
))
2134 send(c
, okmsg
, sizeof okmsg
-1, 0);
2136 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2138 if (strstr(buffer
, "/test9"))
2140 if (!strstr(buffer
, "Connection: Close") &&
2141 !strstr(buffer
, "Connection: Keep-Alive") &&
2142 !strstr(buffer
, "Cache-Control: no-cache") &&
2143 !strstr(buffer
, "Pragma: no-cache") &&
2144 strstr(buffer
, host_header
))
2145 send(c
, okmsg
, sizeof okmsg
-1, 0);
2147 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2149 if (strstr(buffer
, "/testA"))
2151 if (!strstr(buffer
, "Connection: Close") &&
2152 !strstr(buffer
, "Connection: Keep-Alive") &&
2153 (strstr(buffer
, "Cache-Control: no-cache") ||
2154 strstr(buffer
, "Pragma: no-cache")) &&
2155 strstr(buffer
, host_header
))
2156 send(c
, okmsg
, sizeof okmsg
-1, 0);
2158 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2160 if (!test_b
&& strstr(buffer
, "/testB HTTP/1.1"))
2163 send(c
, okmsg
, sizeof okmsg
-1, 0);
2164 recvfrom(c
, buffer
, sizeof buffer
, 0, NULL
, NULL
);
2165 send(c
, okmsg
, sizeof okmsg
-1, 0);
2167 if (strstr(buffer
, "/testC"))
2169 if (strstr(buffer
, "Cookie: cookie=biscuit"))
2170 send(c
, okmsg
, sizeof okmsg
-1, 0);
2172 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2174 if (strstr(buffer
, "/testD"))
2176 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
2178 if (strstr(buffer
, "/testE"))
2180 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
2182 if (strstr(buffer
, "GET /quit"))
2184 send(c
, okmsg
, sizeof okmsg
-1, 0);
2185 send(c
, page1
, sizeof page1
-1, 0);
2188 if (strstr(buffer
, "GET /testF"))
2190 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
2191 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2192 send(c
, contmsg
, sizeof contmsg
-1, 0);
2193 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2194 send(c
, okmsg
, sizeof okmsg
-1, 0);
2195 send(c
, page1
, sizeof page1
-1, 0);
2197 if (strstr(buffer
, "GET /testG"))
2199 send(c
, page1
, sizeof page1
-1, 0);
2202 if (strstr(buffer
, "GET /testJ"))
2207 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2211 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2215 if (strstr(buffer
, "GET /testH"))
2217 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2218 recvfrom(c
, buffer
, sizeof(buffer
), 0, NULL
, NULL
);
2219 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2222 if (strstr(buffer
, "GET /test_no_content"))
2224 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2225 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2227 if (strstr(buffer
, "GET /test_conn_close"))
2229 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2230 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
2231 WaitForSingleObject(conn_close_event
, INFINITE
);
2232 trace("closing connection\n");
2234 if (strstr(buffer
, "GET /test_cache_control_no_cache"))
2236 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2237 if(!test_no_cache
++)
2238 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2240 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2242 if (strstr(buffer
, "GET /test_cache_control_no_store"))
2244 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2245 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2247 if (strstr(buffer
, "GET /test_cache_gzip"))
2249 static const char gzip_response
[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2250 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2251 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2252 if(!test_cache_gzip
++)
2253 send(c
, gzip_response
, sizeof(gzip_response
), 0);
2255 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2257 if (strstr(buffer
, "HEAD /test_head")) {
2258 static const char head_response
[] =
2259 "HTTP/1.1 200 OK\r\n"
2260 "Connection: Keep-Alive\r\n"
2261 "Content-Length: 100\r\n"
2264 send(c
, head_response
, sizeof(head_response
), 0);
2267 if (strstr(buffer
, "GET /send_from_buffer"))
2268 send(c
, send_buffer
, strlen(send_buffer
), 0);
2269 if (strstr(buffer
, "/test_cache_control_verb"))
2271 if (!memcmp(buffer
, "GET ", sizeof("GET ")-1) &&
2272 !strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2273 else if (strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2274 else send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2276 if (strstr(buffer
, "GET /test_premature_disconnect"))
2277 trace("closing connection\n");
2282 } while (!last_request
);
2289 static void test_basic_request(int port
, const char *verb
, const char *url
)
2291 HINTERNET hi
, hc
, hr
;
2292 DWORD r
, count
, error
;
2295 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2296 ok(hi
!= NULL
, "open failed\n");
2298 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2299 ok(hc
!= NULL
, "connect failed\n");
2301 hr
= HttpOpenRequestA(hc
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
2302 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2304 SetLastError(0xdeadbeef);
2305 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2306 error
= GetLastError();
2307 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
2308 ok(r
, "HttpSendRequest failed\n");
2311 memset(buffer
, 0, sizeof buffer
);
2312 SetLastError(0xdeadbeef);
2313 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
2314 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2315 ok(count
== sizeof page1
- 1, "count was wrong\n");
2316 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2318 InternetCloseHandle(hr
);
2319 InternetCloseHandle(hc
);
2320 InternetCloseHandle(hi
);
2323 static void test_proxy_indirect(int port
)
2325 HINTERNET hi
, hc
, hr
;
2329 hi
= InternetOpenA(NULL
, 0, NULL
, NULL
, 0);
2330 ok(hi
!= NULL
, "open failed\n");
2332 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2333 ok(hc
!= NULL
, "connect failed\n");
2335 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2336 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2338 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2339 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2342 r
= HttpQueryInfoA(hr
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2343 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
2346 skip("missing proxy header, not testing remaining proxy headers\n");
2349 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2351 test_status_code(hr
, 407);
2352 test_request_flags(hr
, 0);
2355 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2356 ok(r
, "HttpQueryInfo failed\n");
2357 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2360 r
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2361 ok(r
, "HttpQueryInfo failed\n");
2362 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2365 r
= HttpQueryInfoA(hr
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2366 ok(r
, "HttpQueryInfo failed\n");
2367 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2370 r
= HttpQueryInfoA(hr
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2371 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2372 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2375 InternetCloseHandle(hr
);
2376 InternetCloseHandle(hc
);
2377 InternetCloseHandle(hi
);
2380 static void test_proxy_direct(int port
)
2382 HINTERNET hi
, hc
, hr
;
2384 char buffer
[0x40], *url
;
2385 WCHAR bufferW
[0x40];
2386 static const char url_fmt
[] = "http://test.winehq.org:%u/test2";
2387 static CHAR username
[] = "mike",
2388 password
[] = "1101",
2389 useragent
[] = "winetest";
2390 static const WCHAR usernameW
[] = {'m','i','k','e',0},
2391 passwordW
[] = {'1','1','0','1',0},
2392 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2394 /* specify proxy type without the proxy and bypass */
2395 SetLastError(0xdeadbeef);
2396 hi
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2397 error
= GetLastError();
2398 ok(error
== ERROR_INVALID_PARAMETER
||
2399 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %u\n", error
);
2400 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2402 sprintf(buffer
, "localhost:%d\n", port
);
2403 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2404 ok(hi
!= NULL
, "open failed\n");
2406 /* try connect without authorization */
2407 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2408 ok(hc
!= NULL
, "connect failed\n");
2410 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2411 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2414 SetLastError(0xdeadbeef);
2415 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
2416 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2417 ok(!r
, "unexpected success\n");
2418 ok(sz
== 1, "got %u\n", sz
);
2421 SetLastError(0xdeadbeef);
2422 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
2423 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2424 ok(!r
, "unexpected success\n");
2425 ok(sz
== 1, "got %u\n", sz
);
2427 sz
= sizeof(buffer
);
2428 SetLastError(0xdeadbeef);
2429 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2430 ok(r
, "unexpected failure %u\n", GetLastError());
2431 ok(!sz
, "got %u\n", sz
);
2433 sz
= sizeof(buffer
);
2434 SetLastError(0xdeadbeef);
2435 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2436 ok(r
, "unexpected failure %u\n", GetLastError());
2437 ok(!sz
, "got %u\n", sz
);
2440 SetLastError(0xdeadbeef);
2441 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
2442 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2443 ok(!r
, "unexpected success\n");
2444 ok(sz
== 1, "got %u\n", sz
);
2447 SetLastError(0xdeadbeef);
2448 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
2449 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2450 ok(!r
, "unexpected success\n");
2451 ok(sz
== 1, "got %u\n", sz
);
2453 sz
= sizeof(buffer
);
2454 SetLastError(0xdeadbeef);
2455 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2456 ok(r
, "unexpected failure %u\n", GetLastError());
2457 ok(!sz
, "got %u\n", sz
);
2459 sz
= sizeof(buffer
);
2460 SetLastError(0xdeadbeef);
2461 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2462 ok(r
, "unexpected failure %u\n", GetLastError());
2463 ok(!sz
, "got %u\n", sz
);
2466 SetLastError(0xdeadbeef);
2467 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
2468 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2469 ok(!r
, "unexpected success\n");
2470 ok(sz
== 34, "got %u\n", sz
);
2472 sz
= sizeof(buffer
);
2473 SetLastError(0xdeadbeef);
2474 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2475 ok(r
, "unexpected failure %u\n", GetLastError());
2476 ok(sz
== 33, "got %u\n", sz
);
2478 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2479 ok(r
|| broken(!r
), "HttpSendRequest failed %u\n", GetLastError());
2482 win_skip("skipping proxy tests on broken wininet\n");
2486 test_status_code(hr
, 407);
2488 /* set the user + password then try again */
2489 r
= InternetSetOptionA(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2490 ok(!r
, "unexpected success\n");
2492 r
= InternetSetOptionA(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2493 ok(r
, "failed to set user\n");
2495 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2496 ok(r
, "failed to set user\n");
2500 SetLastError(0xdeadbeef);
2501 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2502 ok(!r
, "unexpected failure %u\n", GetLastError());
2503 ok(!buffer
[0], "got %s\n", buffer
);
2504 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2508 SetLastError(0xdeadbeef);
2509 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2510 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2511 ok(!r
, "unexpected success\n");
2512 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2516 SetLastError(0xdeadbeef);
2517 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2518 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2519 ok(!r
, "unexpected success\n");
2520 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2523 sz
= sizeof(buffer
);
2524 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2525 ok(r
, "failed to get username\n");
2526 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2527 ok(sz
== strlen(username
), "got %u\n", sz
);
2530 sz
= sizeof(bufferW
);
2531 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2532 ok(r
, "failed to get username\n");
2533 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
2534 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2536 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
2537 ok(r
, "failed to set user\n");
2540 sz
= sizeof(buffer
);
2541 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2542 ok(r
, "failed to get username\n");
2543 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2544 ok(sz
== strlen(username
), "got %u\n", sz
);
2546 r
= InternetSetOptionA(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
2547 ok(r
, "failed to set useragent\n");
2551 SetLastError(0xdeadbeef);
2552 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2553 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2554 ok(!r
, "unexpected success\n");
2555 ok(sz
== strlen(useragent
) + 1, "got %u\n", sz
);
2558 sz
= sizeof(buffer
);
2559 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2560 ok(r
, "failed to get user agent\n");
2561 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
2562 ok(sz
== strlen(useragent
), "got %u\n", sz
);
2566 SetLastError(0xdeadbeef);
2567 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2568 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2569 ok(!r
, "unexpected success\n");
2570 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2573 sz
= sizeof(bufferW
);
2574 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2575 ok(r
, "failed to get user agent\n");
2576 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
2577 ok(sz
== lstrlenW(useragentW
), "got %u\n", sz
);
2579 r
= InternetSetOptionA(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
2580 ok(r
, "failed to set user\n");
2584 SetLastError(0xdeadbeef);
2585 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2586 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2587 ok(!r
, "unexpected success\n");
2588 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2591 sz
= sizeof(buffer
);
2592 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2593 ok(r
, "failed to get user\n");
2594 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2595 ok(sz
== strlen(username
), "got %u\n", sz
);
2599 SetLastError(0xdeadbeef);
2600 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2601 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2602 ok(!r
, "unexpected success\n");
2603 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2606 sz
= sizeof(bufferW
);
2607 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2608 ok(r
, "failed to get user\n");
2609 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
2610 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2612 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
2613 ok(r
, "failed to set password\n");
2617 SetLastError(0xdeadbeef);
2618 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2619 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2620 ok(!r
, "unexpected success\n");
2621 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2624 sz
= sizeof(buffer
);
2625 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2626 ok(r
, "failed to get password\n");
2627 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2628 ok(sz
== strlen(password
), "got %u\n", sz
);
2632 SetLastError(0xdeadbeef);
2633 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2634 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2635 ok(!r
, "unexpected success\n");
2636 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2639 sz
= sizeof(bufferW
);
2640 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2641 ok(r
, "failed to get password\n");
2642 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2643 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2645 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
2646 sprintf(url
, url_fmt
, port
);
2649 SetLastError(0xdeadbeef);
2650 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2651 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2652 ok(!r
, "unexpected success\n");
2653 ok(sz
== strlen(url
) + 1, "got %u\n", sz
);
2656 sz
= sizeof(buffer
);
2657 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2658 ok(r
, "failed to get url\n");
2659 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
2660 ok(sz
== strlen(url
), "got %u\n", sz
);
2664 SetLastError(0xdeadbeef);
2665 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2666 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2667 ok(!r
, "unexpected success\n");
2668 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2671 sz
= sizeof(bufferW
);
2672 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2673 ok(r
, "failed to get url\n");
2674 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
2675 ok(sz
== strlen(url
), "got %u\n", sz
);
2676 HeapFree(GetProcessHeap(), 0, url
);
2678 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2679 ok(r
, "failed to set password\n");
2683 SetLastError(0xdeadbeef);
2684 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2685 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2686 ok(!r
, "unexpected success\n");
2687 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2690 sz
= sizeof(buffer
);
2691 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2692 ok(r
, "failed to get password\n");
2693 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2694 ok(sz
== strlen(password
), "got %u\n", sz
);
2698 SetLastError(0xdeadbeef);
2699 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2700 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2701 ok(!r
, "unexpected success\n");
2702 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2705 sz
= sizeof(bufferW
);
2706 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2707 ok(r
, "failed to get password\n");
2708 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2709 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2711 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2714 win_skip("skipping proxy tests on broken wininet\n");
2717 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2719 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2720 ok(r
, "HttpQueryInfo failed\n");
2721 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2724 InternetCloseHandle(hr
);
2725 InternetCloseHandle(hc
);
2726 InternetCloseHandle(hi
);
2729 static void test_header_handling_order(int port
)
2731 static const char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
2732 static const char connection
[] = "Connection: Close";
2733 static const char *types
[2] = { "*", NULL
};
2735 HINTERNET session
, connect
, request
;
2736 DWORD size
, status
, data_len
;
2739 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2740 ok(session
!= NULL
, "InternetOpen failed\n");
2742 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2743 ok(connect
!= NULL
, "InternetConnect failed\n");
2745 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2746 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2748 ret
= HttpAddRequestHeadersA(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
2749 ok(ret
, "HttpAddRequestHeaders failed\n");
2751 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
2752 ok(ret
, "HttpSendRequest failed\n");
2754 test_status_code(request
, 200);
2755 test_request_flags(request
, 0);
2757 InternetCloseHandle(request
);
2759 request
= HttpOpenRequestA(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2760 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2762 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2763 ok(ret
, "HttpSendRequest failed\n");
2766 size
= sizeof(status
);
2767 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2768 ok(ret
, "HttpQueryInfo failed\n");
2769 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2771 InternetCloseHandle(request
);
2772 InternetCloseHandle(connect
);
2774 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2775 ok(connect
!= NULL
, "InternetConnect failed\n");
2777 request
= HttpOpenRequestA(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2778 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2780 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2781 ok(ret
, "HttpAddRequestHeaders failed\n");
2783 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2784 ok(ret
, "HttpSendRequest failed\n");
2787 size
= sizeof(status
);
2788 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2789 ok(ret
, "HttpQueryInfo failed\n");
2790 ok(status
== 200, "got status %u, expected 200\n", status
);
2792 InternetCloseHandle(request
);
2793 InternetCloseHandle(connect
);
2795 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2796 ok(connect
!= NULL
, "InternetConnect failed\n");
2798 request
= HttpOpenRequestA(connect
, "POST", "/test7b", NULL
, NULL
, types
, 0, 0);
2799 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2801 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2802 ok(ret
, "HttpAddRequestHeaders failed\n");
2804 data_len
= sizeof(data
);
2805 memset(data
, 'a', sizeof(data
));
2806 ret
= HttpSendRequestA(request
, connection
, ~0u, data
, data_len
);
2807 ok(ret
, "HttpSendRequest failed\n");
2810 size
= sizeof(status
);
2811 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2812 ok(ret
, "HttpQueryInfo failed\n");
2813 ok(status
== 200, "got status %u, expected 200\n", status
);
2815 InternetCloseHandle(request
);
2816 InternetCloseHandle(connect
);
2817 InternetCloseHandle(session
);
2820 static void test_connection_header(int port
)
2822 HINTERNET ses
, con
, req
;
2825 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2826 ok(ses
!= NULL
, "InternetOpen failed\n");
2828 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2829 ok(con
!= NULL
, "InternetConnect failed\n");
2831 req
= HttpOpenRequestA(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2832 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2834 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2835 ok(ret
, "HttpSendRequest failed\n");
2837 test_status_code(req
, 200);
2839 InternetCloseHandle(req
);
2841 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
2842 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2844 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2845 ok(ret
, "HttpSendRequest failed\n");
2847 test_status_code(req
, 200);
2849 InternetCloseHandle(req
);
2851 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2852 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2854 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2855 ok(ret
, "HttpSendRequest failed\n");
2857 test_status_code(req
, 200);
2859 InternetCloseHandle(req
);
2861 req
= HttpOpenRequestA(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2862 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2864 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2865 ok(ret
, "HttpSendRequest failed\n");
2867 test_status_code(req
, 200);
2869 InternetCloseHandle(req
);
2870 InternetCloseHandle(con
);
2871 InternetCloseHandle(ses
);
2874 static void test_http1_1(int port
)
2876 HINTERNET ses
, con
, req
;
2879 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2880 ok(ses
!= NULL
, "InternetOpen failed\n");
2882 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2883 ok(con
!= NULL
, "InternetConnect failed\n");
2885 req
= HttpOpenRequestA(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2886 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2888 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2891 InternetCloseHandle(req
);
2893 req
= HttpOpenRequestA(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2894 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2896 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2897 ok(ret
, "HttpSendRequest failed\n");
2900 InternetCloseHandle(req
);
2901 InternetCloseHandle(con
);
2902 InternetCloseHandle(ses
);
2905 static void test_connection_closing(int port
)
2907 HINTERNET session
, connection
, req
;
2910 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2912 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2913 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2915 pInternetSetStatusCallbackA(session
, callback
);
2917 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2918 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2919 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2920 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2922 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2923 req
= HttpOpenRequestA(connection
, "GET", "/testJ", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
2924 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2925 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2927 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2928 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2929 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2930 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2931 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2932 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2933 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2934 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2935 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
2936 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
2937 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2939 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2940 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2941 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2942 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2943 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2945 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2946 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2947 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2948 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2949 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2950 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2951 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2952 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2953 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2954 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2955 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2957 test_status_code(req
, 200);
2959 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2960 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2961 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2962 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2963 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2964 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2965 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2966 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2967 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2969 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2970 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2971 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2972 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2973 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2975 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2976 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2977 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2978 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2979 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2980 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2981 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2982 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2983 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2985 test_status_code(req
, 210);
2987 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2988 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2989 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2990 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2991 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2992 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2993 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2994 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2995 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
2996 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
2997 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2999 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3000 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3001 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3002 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3003 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3005 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3006 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3007 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3008 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3009 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3010 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3011 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3012 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3013 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3014 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3015 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3017 test_status_code(req
, 200);
3019 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3020 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3022 close_async_handle(session
, hCompleteEvent
, 2);
3023 CloseHandle(hCompleteEvent
);
3026 static void test_successive_HttpSendRequest(int port
)
3028 HINTERNET session
, connection
, req
;
3031 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3033 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3034 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3036 pInternetSetStatusCallbackA(session
, callback
);
3038 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3039 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3040 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3041 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3043 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3044 req
= HttpOpenRequestA(connection
, "GET", "/testH", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3045 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3046 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3048 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3049 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3050 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3051 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3052 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3053 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3054 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3055 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3056 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3058 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3059 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3060 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3061 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3062 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3064 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3065 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3066 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3067 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3068 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3069 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3070 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3071 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3072 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3074 test_status_code(req
, 210);
3076 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3077 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3078 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3079 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3080 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3081 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3082 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3083 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3084 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3086 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3087 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3088 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3089 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3090 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3092 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3093 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3094 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3095 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3096 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3097 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3098 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3099 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3100 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3102 test_status_code(req
, 200);
3104 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3105 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3107 close_async_handle(session
, hCompleteEvent
, 2);
3108 CloseHandle(hCompleteEvent
);
3111 static void test_no_content(int port
)
3113 HINTERNET session
, connection
, req
;
3116 trace("Testing 204 no content response...\n");
3118 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3120 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3121 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3123 pInternetSetStatusCallbackA(session
, callback
);
3125 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3126 connection
= InternetConnectA(session
, "localhost", port
,
3127 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3128 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3129 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3131 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3132 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
3133 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3134 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3135 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3137 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3138 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3139 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3140 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3141 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3142 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3143 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3144 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3145 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3146 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3148 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3149 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3150 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3151 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3152 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3154 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3155 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3156 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3157 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3158 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3159 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3160 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3161 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3163 close_async_handle(session
, hCompleteEvent
, 2);
3164 CloseHandle(hCompleteEvent
);
3167 * The connection should be closed before closing handle. This is true for most
3168 * wininet versions (including Wine), but some old win2k versions fail to do that.
3170 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3171 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3174 static void test_conn_close(int port
)
3176 HINTERNET session
, connection
, req
;
3177 DWORD res
, avail
, size
;
3180 trace("Testing connection close connection...\n");
3182 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3183 conn_close_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3185 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3186 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3188 pInternetSetStatusCallbackA(session
, callback
);
3190 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3191 connection
= InternetConnectA(session
, "localhost", port
,
3192 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3193 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3194 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3196 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3197 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
3198 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3199 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3200 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3202 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3203 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3204 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3205 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3206 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3207 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3208 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3209 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3211 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3212 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3213 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3214 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3215 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3217 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3218 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3219 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3220 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3221 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3222 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3223 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3224 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3227 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3228 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3229 ok(avail
!= 0, "avail = 0\n");
3232 res
= InternetReadFile(req
, buf
, avail
, &size
);
3233 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3235 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3236 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3237 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3238 ok(!avail
, "avail = %u, expected 0\n", avail
);
3240 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3241 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3242 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3243 SetEvent(conn_close_event
);
3244 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3245 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3246 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3247 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3248 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3250 close_async_handle(session
, hCompleteEvent
, 2);
3251 CloseHandle(hCompleteEvent
);
3254 static void test_no_cache(int port
)
3256 static const char cache_control_no_cache
[] = "/test_cache_control_no_cache";
3257 static const char cache_control_no_store
[] = "/test_cache_control_no_store";
3258 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3260 char cache_url
[256], buf
[256];
3261 HINTERNET ses
, con
, req
;
3265 trace("Testing no-cache header\n");
3267 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3268 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3270 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3271 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3273 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3274 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3276 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_cache
);
3277 DeleteUrlCacheEntryA(cache_url
);
3279 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3280 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3282 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3284 ok(size
== 12, "read %d bytes of data\n", size
);
3285 InternetCloseHandle(req
);
3287 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3288 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3290 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3291 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3293 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3295 ok(size
== 0, "read %d bytes of data\n", size
);
3296 InternetCloseHandle(req
);
3297 DeleteUrlCacheEntryA(cache_url
);
3299 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_store
, NULL
, NULL
, NULL
, 0, 0);
3300 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3302 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_store
);
3303 DeleteUrlCacheEntryA(cache_url
);
3305 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3306 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3308 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3310 ok(size
== 12, "read %d bytes of data\n", size
);
3311 InternetCloseHandle(req
);
3313 ret
= DeleteUrlCacheEntryA(cache_url
);
3314 ok(!ret
&& GetLastError()==ERROR_FILE_NOT_FOUND
, "cache entry should not exist\n");
3316 InternetCloseHandle(con
);
3317 InternetCloseHandle(ses
);
3320 static void test_cache_read_gzipped(int port
)
3322 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3323 static const char get_gzip
[] = "/test_cache_gzip";
3324 static const char content
[] = "gzip test\n";
3325 static const char text_html
[] = "text/html";
3326 static const char raw_header
[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3328 HINTERNET ses
, con
, req
;
3330 char cache_url
[256], buf
[256];
3333 trace("Testing reading compressed content from cache\n");
3335 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3336 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3338 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3339 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3341 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3342 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3345 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3346 if(!ret
&& GetLastError()==ERROR_INTERNET_INVALID_OPTION
) {
3347 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3348 InternetCloseHandle(req
);
3349 InternetCloseHandle(con
);
3350 InternetCloseHandle(ses
);
3353 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3355 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3356 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3358 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-size
, &read
) && read
)
3360 ok(size
== 10, "read %d bytes of data\n", size
);
3362 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3364 size
= sizeof(buf
)-1;
3365 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3366 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3368 ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3370 size
= sizeof(buf
)-1;
3371 ret
= HttpQueryInfoA(req
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &size
, 0);
3372 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3374 ok(!strncmp(raw_header
, buf
, size
), "buf = %s\n", buf
);
3375 InternetCloseHandle(req
);
3377 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3378 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3381 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3382 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3384 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3385 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3387 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3389 todo_wine
ok(size
== 10, "read %d bytes of data\n", size
);
3391 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3394 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3395 ok(!ret
&& GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND
,
3396 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3397 ret
, GetLastError());
3399 size
= sizeof(buf
)-1;
3400 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3401 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3403 todo_wine
ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3404 InternetCloseHandle(req
);
3406 /* Decompression doesn't work while reading from cache */
3407 test_cache_gzip
= 0;
3408 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3409 DeleteUrlCacheEntryA(cache_url
);
3411 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3412 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3414 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3415 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3417 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3419 ok(size
== 31, "read %d bytes of data\n", size
);
3420 InternetCloseHandle(req
);
3422 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3423 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3426 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3427 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3429 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3430 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3432 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3434 todo_wine
ok(size
== 31, "read %d bytes of data\n", size
);
3437 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3438 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3439 InternetCloseHandle(req
);
3441 InternetCloseHandle(con
);
3442 InternetCloseHandle(ses
);
3444 DeleteUrlCacheEntryA(cache_url
);
3447 static void test_HttpSendRequestW(int port
)
3449 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3450 HINTERNET ses
, con
, req
;
3454 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3455 ok(ses
!= NULL
, "InternetOpen failed\n");
3457 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3458 ok(con
!= NULL
, "InternetConnect failed\n");
3460 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3461 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3463 SetLastError(0xdeadbeef);
3464 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
3465 error
= GetLastError();
3466 ok(!ret
, "HttpSendRequestW succeeded\n");
3467 ok(error
== ERROR_IO_PENDING
||
3468 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
3469 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
3470 "got %u expected ERROR_IO_PENDING\n", error
);
3472 InternetCloseHandle(req
);
3473 InternetCloseHandle(con
);
3474 InternetCloseHandle(ses
);
3477 static void test_cookie_header(int port
)
3479 HINTERNET ses
, con
, req
;
3484 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3485 ok(ses
!= NULL
, "InternetOpen failed\n");
3487 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3488 ok(con
!= NULL
, "InternetConnect failed\n");
3490 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3492 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3493 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3496 size
= sizeof(buffer
);
3497 SetLastError(0xdeadbeef);
3498 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3499 error
= GetLastError();
3500 ok(!ret
, "HttpQueryInfo succeeded\n");
3501 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3503 ret
= HttpAddRequestHeadersA(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
3504 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3507 size
= sizeof(buffer
);
3508 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3509 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3510 ok(!strcmp(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
3512 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3513 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3515 test_status_code(req
, 200);
3518 size
= sizeof(buffer
);
3519 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3520 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3521 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
3523 InternetCloseHandle(req
);
3524 InternetCloseHandle(con
);
3525 InternetCloseHandle(ses
);
3528 static void test_basic_authentication(int port
)
3530 HINTERNET session
, connect
, request
;
3533 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3534 ok(session
!= NULL
, "InternetOpen failed\n");
3536 connect
= InternetConnectA(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
3537 ok(connect
!= NULL
, "InternetConnect failed\n");
3539 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
3540 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3542 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3543 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3545 test_status_code(request
, 200);
3546 test_request_flags(request
, 0);
3548 InternetCloseHandle(request
);
3549 InternetCloseHandle(connect
);
3550 InternetCloseHandle(session
);
3553 static void test_premature_disconnect(int port
)
3555 HINTERNET session
, connect
, request
;
3559 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3560 ok(session
!= NULL
, "InternetOpen failed\n");
3562 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3563 ok(connect
!= NULL
, "InternetConnect failed\n");
3565 request
= HttpOpenRequestA(connect
, NULL
, "/premature_disconnect", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3566 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3568 SetLastError(0xdeadbeef);
3569 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3570 err
= GetLastError();
3571 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
3572 todo_wine
ok(err
== ERROR_HTTP_INVALID_SERVER_RESPONSE
, "got %u\n", err
);
3574 InternetCloseHandle(request
);
3575 InternetCloseHandle(connect
);
3576 InternetCloseHandle(session
);
3579 static void test_invalid_response_headers(int port
)
3581 HINTERNET session
, connect
, request
;
3586 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3587 ok(session
!= NULL
, "InternetOpen failed\n");
3589 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3590 ok(connect
!= NULL
, "InternetConnect failed\n");
3592 request
= HttpOpenRequestA(connect
, NULL
, "/testE", NULL
, NULL
, NULL
, 0, 0);
3593 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3595 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3596 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3598 test_status_code(request
, 401);
3599 test_request_flags(request
, 0);
3602 size
= sizeof(buffer
);
3603 ret
= HttpQueryInfoA( request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3604 ok(ret
, "HttpQueryInfo failed\n");
3605 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
3606 "headers wrong \"%s\"\n", buffer
);
3609 size
= sizeof(buffer
);
3610 ret
= HttpQueryInfoA( request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
3611 ok(ret
, "HttpQueryInfo failed\n");
3612 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
3614 InternetCloseHandle(request
);
3615 InternetCloseHandle(connect
);
3616 InternetCloseHandle(session
);
3619 static void test_response_without_headers(int port
)
3621 HINTERNET hi
, hc
, hr
;
3622 DWORD r
, count
, size
;
3625 SetLastError(0xdeadbeef);
3626 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3627 ok(hi
!= NULL
, "open failed %u\n", GetLastError());
3629 SetLastError(0xdeadbeef);
3630 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3631 ok(hc
!= NULL
, "connect failed %u\n", GetLastError());
3633 SetLastError(0xdeadbeef);
3634 hr
= HttpOpenRequestA(hc
, NULL
, "/testG", NULL
, NULL
, NULL
, 0, 0);
3635 ok(hr
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError());
3637 test_request_flags(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3639 SetLastError(0xdeadbeef);
3640 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
3641 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
3643 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3646 memset(buffer
, 0, sizeof buffer
);
3647 SetLastError(0xdeadbeef);
3648 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
3649 ok(r
, "InternetReadFile failed %u\n", GetLastError());
3650 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
3651 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
3653 test_status_code(hr
, 200);
3654 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3657 size
= sizeof(buffer
);
3658 SetLastError(0xdeadbeef);
3659 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
3660 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3661 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
3664 size
= sizeof(buffer
);
3665 SetLastError(0xdeadbeef);
3666 r
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
3667 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3668 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
3671 size
= sizeof(buffer
);
3672 SetLastError(0xdeadbeef);
3673 r
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3674 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3675 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
3677 InternetCloseHandle(hr
);
3678 InternetCloseHandle(hc
);
3679 InternetCloseHandle(hi
);
3682 static void test_head_request(int port
)
3684 DWORD len
, content_length
;
3685 HINTERNET ses
, con
, req
;
3689 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3690 ok(ses
!= NULL
, "InternetOpen failed\n");
3692 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3693 ok(con
!= NULL
, "InternetConnect failed\n");
3695 req
= HttpOpenRequestA(con
, "HEAD", "/test_head", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3696 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3698 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3699 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3701 len
= sizeof(content_length
);
3702 content_length
= -1;
3703 ret
= HttpQueryInfoA(req
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
, &content_length
, &len
, 0);
3704 ok(ret
, "HttpQueryInfo dailed: %u\n", GetLastError());
3705 ok(len
== sizeof(DWORD
), "len = %u\n", len
);
3706 ok(content_length
== 100, "content_length = %u\n", content_length
);
3709 ret
= InternetReadFile(req
, buf
, sizeof(buf
), &len
);
3710 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
3713 ret
= InternetReadFile(req
, buf
, sizeof(buf
), &len
);
3714 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
3716 InternetCloseHandle(req
);
3717 InternetCloseHandle(con
);
3718 InternetCloseHandle(ses
);
3721 static void test_HttpQueryInfo(int port
)
3723 HINTERNET hi
, hc
, hr
;
3724 DWORD size
, index
, error
;
3728 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3729 ok(hi
!= NULL
, "InternetOpen failed\n");
3731 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3732 ok(hc
!= NULL
, "InternetConnect failed\n");
3734 hr
= HttpOpenRequestA(hc
, NULL
, "/testD", NULL
, NULL
, NULL
, 0, 0);
3735 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
3737 size
= sizeof(buffer
);
3738 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3739 error
= GetLastError();
3740 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
3741 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3743 ret
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
3744 ok(ret
, "HttpSendRequest failed\n");
3747 size
= sizeof(buffer
);
3748 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
3749 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3750 ok(index
== 1, "expected 1 got %u\n", index
);
3753 size
= sizeof(buffer
);
3754 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
3755 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3756 ok(index
== 1, "expected 1 got %u\n", index
);
3759 size
= sizeof(buffer
);
3760 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3761 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3762 ok(index
== 0, "expected 0 got %u\n", index
);
3764 size
= sizeof(buffer
);
3765 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3766 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3767 ok(index
== 0, "expected 0 got %u\n", index
);
3769 index
= 0xdeadbeef; /* invalid start index */
3770 size
= sizeof(buffer
);
3771 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3772 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
3773 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
3774 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
3777 size
= sizeof(buffer
);
3778 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
3779 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3780 ok(index
== 0, "expected 0 got %u\n", index
);
3782 size
= sizeof(buffer
);
3783 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3784 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3785 ok(index
== 0, "expected 0 got %u\n", index
);
3787 size
= sizeof(buffer
);
3788 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
3789 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3790 ok(index
== 0, "expected 0 got %u\n", index
);
3792 test_status_code(hr
, 200);
3795 size
= sizeof(buffer
);
3796 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
3797 ok(!ret
, "HttpQueryInfo succeeded\n");
3798 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
3801 size
= sizeof(buffer
);
3802 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
3803 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3804 ok(index
== 1, "expected 1 got %u\n", index
);
3807 size
= sizeof(buffer
);
3808 strcpy(buffer
, "Server");
3809 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
3810 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3811 ok(index
== 1, "expected 1 got %u\n", index
);
3814 size
= sizeof(buffer
);
3815 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
3816 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3817 ok(index
== 1, "expected 1 got %u\n", index
);
3819 size
= sizeof(buffer
);
3820 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
3821 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3822 ok(index
== 2, "expected 2 got %u\n", index
);
3824 InternetCloseHandle(hr
);
3825 InternetCloseHandle(hc
);
3826 InternetCloseHandle(hi
);
3829 static void test_options(int port
)
3831 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi
;
3832 HINTERNET ses
, con
, req
;
3837 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3838 ok(ses
!= NULL
, "InternetOpen failed\n");
3840 SetLastError(0xdeadbeef);
3841 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
3842 error
= GetLastError();
3843 ok(!ret
, "InternetSetOption succeeded\n");
3844 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3846 SetLastError(0xdeadbeef);
3847 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
3848 ok(!ret
, "InternetSetOption succeeded\n");
3849 error
= GetLastError();
3850 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3852 SetLastError(0xdeadbeef);
3853 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
3854 ok(!ret
, "InternetSetOption succeeded\n");
3855 error
= GetLastError();
3856 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3859 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3860 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3862 SetLastError(0xdeadbeef);
3863 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
3864 error
= GetLastError();
3865 ok(!ret
, "InternetQueryOption succeeded\n");
3866 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3868 SetLastError(0xdeadbeef);
3869 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
3870 error
= GetLastError();
3871 ok(!ret
, "InternetQueryOption succeeded\n");
3872 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3875 SetLastError(0xdeadbeef);
3876 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
3877 error
= GetLastError();
3878 ok(!ret
, "InternetQueryOption succeeded\n");
3879 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
3882 SetLastError(0xdeadbeef);
3883 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3884 error
= GetLastError();
3885 ok(!ret
, "InternetQueryOption succeeded\n");
3886 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
3890 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3891 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3892 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
3894 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3895 ok(con
!= NULL
, "InternetConnect failed\n");
3899 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3900 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3901 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
3904 ret
= InternetSetOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3905 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3909 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3910 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3911 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
3913 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3914 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3918 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3919 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3920 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
3923 ret
= InternetSetOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3924 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3928 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3929 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3930 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
3932 size
= sizeof(idsi
);
3933 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO
, &idsi
, &size
);
3934 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3937 SetLastError(0xdeadbeef);
3938 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
3939 error
= GetLastError();
3940 ok(!ret
, "InternetQueryOption succeeded\n");
3941 ok(error
== ERROR_INTERNET_INVALID_OPERATION
, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error
);
3943 /* INTERNET_OPTION_PROXY */
3944 SetLastError(0xdeadbeef);
3945 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
3946 error
= GetLastError();
3947 ok(!ret
, "InternetQueryOption succeeded\n");
3948 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3950 SetLastError(0xdeadbeef);
3951 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
3952 error
= GetLastError();
3953 ok(!ret
, "InternetQueryOption succeeded\n");
3954 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3957 SetLastError(0xdeadbeef);
3958 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
3959 error
= GetLastError();
3960 ok(!ret
, "InternetQueryOption succeeded\n");
3961 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
3962 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
3964 InternetCloseHandle(req
);
3965 InternetCloseHandle(con
);
3966 InternetCloseHandle(ses
);
3970 const char *response_text
;
3972 const char *status_text
;
3973 const char *raw_headers
;
3974 } http_status_test_t
;
3976 static const http_status_test_t http_status_tests
[] = {
3978 "HTTP/1.1 200 OK\r\n"
3979 "Content-Length: 1\r\n"
3985 "HTTP/1.1 404 Fail\r\n"
3986 "Content-Length: 1\r\n"
3993 "Content-Length: 1\r\n"
4000 "Content-Length: 1\r\n"
4007 static void test_http_status(int port
)
4009 HINTERNET ses
, con
, req
;
4014 for(i
=0; i
< sizeof(http_status_tests
)/sizeof(*http_status_tests
); i
++) {
4015 send_buffer
= http_status_tests
[i
].response_text
;
4017 ses
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4018 ok(ses
!= NULL
, "InternetOpen failed\n");
4020 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4021 ok(con
!= NULL
, "InternetConnect failed\n");
4023 req
= HttpOpenRequestA(con
, NULL
, "/send_from_buffer", NULL
, NULL
, NULL
, 0, 0);
4024 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4026 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4027 ok(res
, "HttpSendRequest failed\n");
4029 test_status_code(req
, http_status_tests
[i
].status_code
);
4032 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_TEXT
, buf
, &size
, NULL
);
4033 ok(res
, "HttpQueryInfo failed: %u\n", GetLastError());
4034 ok(!strcmp(buf
, http_status_tests
[i
].status_text
), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
4035 i
, buf
, http_status_tests
[i
].status_text
);
4037 InternetCloseHandle(req
);
4038 InternetCloseHandle(con
);
4039 InternetCloseHandle(ses
);
4043 static void test_cache_control_verb(int port
)
4045 HINTERNET session
, connect
, request
;
4048 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4049 ok(session
!= NULL
, "InternetOpen failed\n");
4051 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4052 ok(connect
!= NULL
, "InternetConnect failed\n");
4054 request
= HttpOpenRequestA(connect
, "RPC_OUT_DATA", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4055 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4056 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4057 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4058 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4059 test_status_code(request
, 200);
4060 InternetCloseHandle(request
);
4062 request
= HttpOpenRequestA(connect
, "POST", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4063 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4064 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4065 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4066 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4067 test_status_code(request
, 200);
4068 InternetCloseHandle(request
);
4070 request
= HttpOpenRequestA(connect
, "HEAD", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4071 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4072 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4073 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4074 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4075 test_status_code(request
, 200);
4076 InternetCloseHandle(request
);
4078 request
= HttpOpenRequestA(connect
, "GET", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4079 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4080 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4081 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4082 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4083 test_status_code(request
, 200);
4084 InternetCloseHandle(request
);
4086 InternetCloseHandle(connect
);
4087 InternetCloseHandle(session
);
4090 static void test_http_connection(void)
4092 struct server_info si
;
4096 si
.hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
4099 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
4100 ok( hThread
!= NULL
, "create thread failed\n");
4102 r
= WaitForSingleObject(si
.hEvent
, 10000);
4103 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
4104 if (r
!= WAIT_OBJECT_0
)
4107 test_basic_request(si
.port
, "GET", "/test1");
4108 test_proxy_indirect(si
.port
);
4109 test_proxy_direct(si
.port
);
4110 test_header_handling_order(si
.port
);
4111 test_basic_request(si
.port
, "POST", "/test5");
4112 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
4113 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
4114 test_basic_request(si
.port
, "GET", "/test6");
4115 test_basic_request(si
.port
, "GET", "/testF");
4116 test_connection_header(si
.port
);
4117 test_http1_1(si
.port
);
4118 test_cookie_header(si
.port
);
4119 test_basic_authentication(si
.port
);
4120 test_invalid_response_headers(si
.port
);
4121 test_response_without_headers(si
.port
);
4122 test_HttpQueryInfo(si
.port
);
4123 test_HttpSendRequestW(si
.port
);
4124 test_options(si
.port
);
4125 test_no_content(si
.port
);
4126 test_conn_close(si
.port
);
4127 test_no_cache(si
.port
);
4128 test_cache_read_gzipped(si
.port
);
4129 test_http_status(si
.port
);
4130 test_premature_disconnect(si
.port
);
4131 test_connection_closing(si
.port
);
4132 test_cache_control_verb(si
.port
);
4133 test_successive_HttpSendRequest(si
.port
);
4134 test_head_request(si
.port
);
4136 /* send the basic request again to shutdown the server thread */
4137 test_basic_request(si
.port
, "GET", "/quit");
4139 r
= WaitForSingleObject(hThread
, 3000);
4140 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
4141 CloseHandle(hThread
);
4144 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
4146 LocalFree(info
->lpszSubjectInfo
);
4147 LocalFree(info
->lpszIssuerInfo
);
4148 LocalFree(info
->lpszProtocolName
);
4149 LocalFree(info
->lpszSignatureAlgName
);
4150 LocalFree(info
->lpszEncryptionAlgName
);
4154 const char *ex_subject
;
4155 const char *ex_issuer
;
4156 } cert_struct_test_t
;
4158 static const cert_struct_test_t test_winehq_org_cert
= {
4159 "6JcR7G3G8tgjkeoMcitK-bTbzcpumDSy\r\n"
4161 "See www.rapidssl.com/resources/cps (c)14\r\n"
4162 "Domain Control Validated - RapidSSL(R)\r\n"
4166 "\"GeoTrust, Inc.\"\r\n"
4170 static const cert_struct_test_t test_winehq_com_cert
= {
4175 "test.winehq.com\r\n"
4176 "webmaster@winehq.org",
4181 "test.winehq.com\r\n"
4182 "webmaster@winehq.org"
4185 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
4187 INTERNET_CERTIFICATE_INFOA info
;
4191 memset(&info
, 0x5, sizeof(info
));
4193 size
= sizeof(info
);
4194 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
4195 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
4196 ok(size
== sizeof(info
), "size = %u\n", size
);
4198 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
4199 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
4200 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
4201 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
4202 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
4203 ok(info
.dwKeySize
== 128, "dwKeySize = %u\n", info
.dwKeySize
);
4205 release_cert_info(&info
);
4208 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
4209 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
4211 char url
[INTERNET_MAX_URL_LENGTH
];
4212 const CERT_CHAIN_CONTEXT
*chain
;
4216 if(!pInternetGetSecurityInfoByURLA
) {
4217 win_skip("pInternetGetSecurityInfoByURLA not available\n");
4222 chain
= (void*)0xdeadbeef;
4224 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
4225 if(error
== ERROR_SUCCESS
) {
4226 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
4227 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
4228 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
4229 CertFreeCertificateChain(chain
);
4231 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
4232 "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res
, GetLastError(), error
);
4236 #define test_secflags_option(a,b) _test_secflags_option(__LINE__,a,b)
4237 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
)
4243 size
= sizeof(flags
);
4244 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4245 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4246 ok_(__FILE__
,line
)(flags
== ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n", flags
, ex_flags
);
4248 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
4250 size
= sizeof(flags
);
4251 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4252 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
4253 ok_(__FILE__
,line
)(flags
== ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n", flags
, ex_flags
);
4256 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
4257 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
4261 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
4262 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4265 static void test_security_flags(void)
4267 INTERNET_CERTIFICATE_INFOA
*cert
;
4268 HINTERNET ses
, conn
, req
;
4273 trace("Testing security flags...\n");
4275 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4277 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4278 ok(ses
!= NULL
, "InternetOpen failed\n");
4280 pInternetSetStatusCallbackA(ses
, &callback
);
4282 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4283 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
4284 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
4285 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
4286 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4288 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4289 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4290 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4292 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4293 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4296 size
= sizeof(flags
);
4297 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4298 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
4299 win_skip("Incomplete security flags support, skipping\n");
4301 close_async_handle(ses
, hCompleteEvent
, 2);
4302 CloseHandle(hCompleteEvent
);
4306 test_secflags_option(req
, 0);
4307 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4309 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4310 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
);
4312 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4313 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4315 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4316 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4318 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
4319 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
4320 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
4322 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
4323 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
4324 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4325 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4326 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4327 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4328 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4329 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4330 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4331 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4332 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4334 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4335 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4337 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4338 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4340 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
4341 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
4342 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4343 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4344 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4345 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4346 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4347 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4348 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4349 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4350 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4352 test_request_flags(req
, 0);
4353 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4354 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
);
4356 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4357 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4358 ok(size
, "size = 0\n");
4360 /* Collect all existing persistent connections */
4361 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4362 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4364 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4365 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4366 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4368 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4369 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4371 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
4372 res
= InternetSetOptionA(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
4373 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
4375 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4376 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4377 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4378 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4379 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4380 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4381 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4383 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4384 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4386 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4387 ok(req_error
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| broken(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
),
4388 "req_error = %d\n", req_error
);
4391 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
4392 ok(res
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4393 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %u\n", size
);
4394 cert
= HeapAlloc(GetProcessHeap(), 0, size
);
4395 cert
->lpszSubjectInfo
= NULL
;
4396 cert
->lpszIssuerInfo
= NULL
;
4397 cert
->lpszSignatureAlgName
= (char *)0xdeadbeef;
4398 cert
->lpszEncryptionAlgName
= (char *)0xdeadbeef;
4399 cert
->lpszProtocolName
= (char *)0xdeadbeef;
4400 cert
->dwKeySize
= 0xdeadbeef;
4401 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, cert
, &size
);
4402 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
4405 ok(cert
->lpszSubjectInfo
&& strlen(cert
->lpszSubjectInfo
) > 1, "expected a non-empty subject name\n");
4406 ok(cert
->lpszIssuerInfo
&& strlen(cert
->lpszIssuerInfo
) > 1, "expected a non-empty issuer name\n");
4407 ok(!cert
->lpszSignatureAlgName
, "unexpected signature algorithm name\n");
4408 ok(!cert
->lpszEncryptionAlgName
, "unexpected encryption algorithm name\n");
4409 ok(!cert
->lpszProtocolName
, "unexpected protocol name\n");
4410 ok(cert
->dwKeySize
!= 0xdeadbeef, "unexpected key size\n");
4412 HeapFree(GetProcessHeap(), 0, cert
);
4414 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4415 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4416 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4417 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4418 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4419 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4420 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4422 if(req_error
!= ERROR_INTERNET_SEC_CERT_REV_FAILED
) {
4423 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error
);
4425 close_async_handle(ses
, hCompleteEvent
, 3);
4426 CloseHandle(hCompleteEvent
);
4431 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
4432 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
4434 test_request_flags(req
, 8);
4435 test_secflags_option(req
, 0x800000);
4437 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4438 test_secflags_option(req
, 0x800000|SECURITY_FLAG_IGNORE_REVOCATION
);
4440 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4441 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4442 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4443 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4444 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4445 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4446 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4448 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4449 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4451 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4452 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
4454 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4455 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4456 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4457 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4458 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4459 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4460 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4462 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
4463 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4464 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4466 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4467 test_secflags_option(req
, 0x1800000|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4468 |SECURITY_FLAG_IGNORE_REVOCATION
);
4469 test_http_version(req
);
4471 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4472 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4473 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4474 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4475 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4476 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4477 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4478 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4479 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4481 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4482 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4484 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4485 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4487 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4488 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4489 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4490 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4491 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4492 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4493 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4494 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4495 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4497 test_request_flags(req
, 0);
4498 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
4499 |SECURITY_FLAG_STRENGTH_STRONG
|0x1800000);
4501 test_cert_struct(req
, &test_winehq_com_cert
);
4502 test_security_info("https://test.winehq.com/data/some_file.html?q", 0, 0x1800000);
4504 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4505 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4506 ok(size
, "size = 0\n");
4508 close_async_handle(ses
, hCompleteEvent
, 3);
4510 /* Collect all existing persistent connections */
4511 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4512 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4514 /* Make another request, without setting security flags */
4516 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4517 ok(ses
!= NULL
, "InternetOpen failed\n");
4519 pInternetSetStatusCallbackA(ses
, &callback
);
4521 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4522 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
4523 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
4524 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
4525 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4527 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4528 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4529 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4531 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4532 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4534 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
4535 |SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4536 test_http_version(req
);
4538 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4539 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4540 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4541 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4542 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4543 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4544 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4545 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4547 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4548 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4550 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4551 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4553 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4554 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4555 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4556 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4557 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4558 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4559 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4560 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4562 test_request_flags(req
, 0);
4563 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
4564 |SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4566 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4567 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4568 ok(size
, "size = 0\n");
4570 close_async_handle(ses
, hCompleteEvent
, 2);
4572 CloseHandle(hCompleteEvent
);
4574 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4575 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4576 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4579 static void test_secure_connection(void)
4581 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
4582 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
4583 static const WCHAR get
[] = {'G','E','T',0};
4584 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
4585 HINTERNET ses
, con
, req
;
4587 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
4588 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
4591 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4592 ok(ses
!= NULL
, "InternetOpen failed\n");
4594 con
= InternetConnectA(ses
, "test.winehq.org",
4595 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
4596 INTERNET_SERVICE_HTTP
, 0, 0);
4597 ok(con
!= NULL
, "InternetConnect failed\n");
4599 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4600 INTERNET_FLAG_SECURE
, 0);
4601 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4603 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4604 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
4606 size
= sizeof(flags
);
4607 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4608 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4609 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
4611 test_cert_struct(req
, &test_winehq_org_cert
);
4613 /* Querying the same option through InternetQueryOptionW still results in
4614 * ASCII strings being returned.
4617 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4619 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4620 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
4621 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
4622 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4623 certificate_structW
, &size
);
4624 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
4625 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4628 ok(certificate_structA
->lpszSubjectInfo
&&
4629 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4630 "expected a non-empty subject name\n");
4631 ok(certificate_structA
->lpszIssuerInfo
&&
4632 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4633 "expected a non-empty issuer name\n");
4634 ok(!certificate_structA
->lpszSignatureAlgName
,
4635 "unexpected signature algorithm name\n");
4636 ok(!certificate_structA
->lpszEncryptionAlgName
,
4637 "unexpected encryption algorithm name\n");
4638 ok(!certificate_structA
->lpszProtocolName
,
4639 "unexpected protocol name\n");
4640 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4641 release_cert_info(certificate_structA
);
4643 HeapFree(GetProcessHeap(), 0, certificate_structW
);
4645 InternetCloseHandle(req
);
4646 InternetCloseHandle(con
);
4647 InternetCloseHandle(ses
);
4649 /* Repeating the tests with the W functions has the same result: */
4650 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4651 ok(ses
!= NULL
, "InternetOpen failed\n");
4653 con
= InternetConnectW(ses
, testsite
,
4654 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
4655 INTERNET_SERVICE_HTTP
, 0, 0);
4656 ok(con
!= NULL
, "InternetConnect failed\n");
4658 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
4659 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
4660 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4662 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4663 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
4665 size
= sizeof(flags
);
4666 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4667 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4668 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %x\n", flags
);
4670 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4672 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4673 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
4674 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
4675 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4676 certificate_structA
, &size
);
4677 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4680 ok(certificate_structA
->lpszSubjectInfo
&&
4681 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4682 "expected a non-empty subject name\n");
4683 ok(certificate_structA
->lpszIssuerInfo
&&
4684 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4685 "expected a non-empty issuer name\n");
4686 ok(!certificate_structA
->lpszSignatureAlgName
,
4687 "unexpected signature algorithm name\n");
4688 ok(!certificate_structA
->lpszEncryptionAlgName
,
4689 "unexpected encryption algorithm name\n");
4690 ok(!certificate_structA
->lpszProtocolName
,
4691 "unexpected protocol name\n");
4692 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4693 release_cert_info(certificate_structA
);
4695 HeapFree(GetProcessHeap(), 0, certificate_structA
);
4697 /* Again, querying the same option through InternetQueryOptionW still
4698 * results in ASCII strings being returned.
4701 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4703 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4704 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
4705 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
4706 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4707 certificate_structW
, &size
);
4708 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
4709 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4712 ok(certificate_structA
->lpszSubjectInfo
&&
4713 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4714 "expected a non-empty subject name\n");
4715 ok(certificate_structA
->lpszIssuerInfo
&&
4716 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4717 "expected a non-empty issuer name\n");
4718 ok(!certificate_structA
->lpszSignatureAlgName
,
4719 "unexpected signature algorithm name\n");
4720 ok(!certificate_structA
->lpszEncryptionAlgName
,
4721 "unexpected encryption algorithm name\n");
4722 ok(!certificate_structA
->lpszProtocolName
,
4723 "unexpected protocol name\n");
4724 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4725 release_cert_info(certificate_structA
);
4727 HeapFree(GetProcessHeap(), 0, certificate_structW
);
4729 InternetCloseHandle(req
);
4730 InternetCloseHandle(con
);
4731 InternetCloseHandle(ses
);
4734 static void test_user_agent_header(void)
4736 HINTERNET ses
, con
, req
;
4741 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4742 ok(ses
!= NULL
, "InternetOpen failed\n");
4744 con
= InternetConnectA(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4745 ok(con
!= NULL
, "InternetConnect failed\n");
4747 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
4748 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4750 size
= sizeof(buffer
);
4751 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4752 err
= GetLastError();
4753 ok(!ret
, "HttpQueryInfo succeeded\n");
4754 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4756 ret
= HttpAddRequestHeadersA(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
4757 ok(ret
, "HttpAddRequestHeaders succeeded\n");
4759 size
= sizeof(buffer
);
4760 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4761 err
= GetLastError();
4762 ok(ret
, "HttpQueryInfo failed\n");
4763 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4765 InternetCloseHandle(req
);
4767 req
= HttpOpenRequestA(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
4768 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4770 size
= sizeof(buffer
);
4771 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4772 err
= GetLastError();
4773 ok(!ret
, "HttpQueryInfo succeeded\n");
4774 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4776 ret
= HttpAddRequestHeadersA(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
4777 ok(ret
, "HttpAddRequestHeaders failed\n");
4780 size
= sizeof(buffer
);
4781 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4782 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
4783 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
4785 InternetCloseHandle(req
);
4786 InternetCloseHandle(con
);
4787 InternetCloseHandle(ses
);
4790 static void test_bogus_accept_types_array(void)
4792 HINTERNET ses
, con
, req
;
4793 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
4798 ses
= InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
4799 con
= InternetConnectA(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4800 req
= HttpOpenRequestA(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
4802 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
4805 size
= sizeof(buffer
);
4806 SetLastError(0xdeadbeef);
4807 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4808 error
= GetLastError();
4809 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
4810 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
4811 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
4812 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
4813 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
4815 InternetCloseHandle(req
);
4816 InternetCloseHandle(con
);
4817 InternetCloseHandle(ses
);
4826 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
4828 INTERNET_ASYNC_RESULT
*result
= info
;
4829 struct context
*ctx
= (struct context
*)context
;
4831 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
4834 case INTERNET_STATUS_REQUEST_COMPLETE
:
4835 trace("request handle: 0x%08lx\n", result
->dwResult
);
4836 ctx
->req
= (HINTERNET
)result
->dwResult
;
4837 SetEvent(ctx
->event
);
4839 case INTERNET_STATUS_HANDLE_CLOSING
: {
4840 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
4842 if (InternetQueryOptionA(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
4843 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
4844 SetEvent(ctx
->event
);
4847 case INTERNET_STATUS_NAME_RESOLVED
:
4848 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
4849 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
4851 ok(str
[0] && str
[1], "Got string: %s\n", str
);
4852 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
4857 static void test_open_url_async(void)
4865 /* Collect all existing persistent connections */
4866 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4867 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4870 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
4871 * other versions never do. They also hang of following tests. We disable it for everything older
4874 if(!pInternetGetSecurityInfoByURLA
) {
4875 win_skip("Skipping async open on too old wininet version.\n");
4880 ctx
.event
= CreateEventA(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
4882 ses
= InternetOpenA("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4883 ok(ses
!= NULL
, "InternetOpen failed\n");
4885 SetLastError(0xdeadbeef);
4886 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
4887 error
= GetLastError();
4888 ok(!ret
, "InternetSetOptionA succeeded\n");
4889 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
4891 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
4892 error
= GetLastError();
4893 ok(!ret
, "InternetSetOptionA failed\n");
4894 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
4896 pInternetSetStatusCallbackW(ses
, cb
);
4897 ResetEvent(ctx
.event
);
4899 req
= InternetOpenUrlA(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
4900 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
4902 WaitForSingleObject(ctx
.event
, INFINITE
);
4905 size
= sizeof(type
);
4906 ret
= InternetQueryOptionA(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
4907 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
4908 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
4909 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
4912 ret
= HttpQueryInfoA(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
4913 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
4914 ok(size
> 0, "expected size > 0\n");
4916 ResetEvent(ctx
.event
);
4917 InternetCloseHandle(ctx
.req
);
4918 WaitForSingleObject(ctx
.event
, INFINITE
);
4920 InternetCloseHandle(ses
);
4921 CloseHandle(ctx
.event
);
4926 internet_connect
= 1,
4928 http_send_request_ex
,
4931 internet_close_handle
4936 enum api function
; /* api responsible for notification */
4937 unsigned int status
; /* status received */
4938 BOOL async
; /* delivered from another thread? */
4946 const struct notification
*test
;
4952 DWORD expect_result
;
4956 static CRITICAL_SECTION notification_cs
;
4958 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
4960 BOOL status_ok
, function_ok
;
4961 struct info
*info
= (struct info
*)context
;
4964 EnterCriticalSection( ¬ification_cs
);
4966 if(info
->is_aborted
) {
4967 LeaveCriticalSection(¬ification_cs
);
4971 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
4973 DWORD size
= sizeof(struct info
*);
4974 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
4975 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
4976 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
4978 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
4979 if(info
->expect_result
== ERROR_SUCCESS
) {
4980 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
4982 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
4983 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
4988 if (i
>= info
->count
)
4990 LeaveCriticalSection( ¬ification_cs
);
4994 while (info
->test
[i
].status
!= status
&&
4995 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
4996 i
< info
->count
- 1 &&
4997 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
5002 status_ok
= (info
->test
[i
].status
== status
);
5003 function_ok
= (info
->test
[i
].function
== info
->function
);
5005 if (!info
->test
[i
].todo
)
5007 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
5008 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
5010 if (info
->test
[i
].async
)
5011 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
5012 info
->line
, info
->thread
, GetCurrentThreadId());
5016 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
5018 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
5020 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
5023 LeaveCriticalSection( ¬ification_cs
);
5026 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
5028 info
->function
= function
;
5030 info
->expect_result
= expect_result
;
5033 struct notification_data
5035 const struct notification
*test
;
5036 const unsigned int count
;
5041 BOOL expect_conn_failure
;
5044 static const struct notification async_send_request_ex_test
[] =
5046 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5047 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5048 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5049 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
5050 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
5051 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
5052 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
5053 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
5054 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
5055 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
5056 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5057 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, FALSE
},
5058 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, FALSE
},
5059 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
5060 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
5061 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5062 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
5063 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
5064 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
5065 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
5068 static const struct notification async_send_request_ex_test2
[] =
5070 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5071 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5072 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5073 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
5074 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
5075 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
5076 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
, TRUE
},
5077 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
, TRUE
},
5078 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
5079 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
5080 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5081 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
5082 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
5083 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5084 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
5085 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
5086 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
5087 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
5090 static const struct notification async_send_request_ex_resolve_failure_test
[] =
5092 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5093 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5094 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5095 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
},
5096 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5097 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5098 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5099 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
5100 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
5101 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
5102 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
5105 static const struct notification async_send_request_ex_chunked_test
[] =
5107 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
},
5108 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
},
5109 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5110 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
5111 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
5112 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
5113 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
5114 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
5115 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
5116 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
5117 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5118 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
5119 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
5120 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5121 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
},
5122 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
},
5123 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
},
5124 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
}
5127 static const struct notification_data notification_data
[] = {
5129 async_send_request_ex_chunked_test
,
5130 sizeof(async_send_request_ex_chunked_test
)/sizeof(async_send_request_ex_chunked_test
[0]),
5136 async_send_request_ex_test
,
5137 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
5140 "tests/posttest.php",
5141 "Public ID=codeweavers"
5144 async_send_request_ex_test2
,
5145 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
5148 "tests/posttest.php"
5151 async_send_request_ex_resolve_failure_test
,
5152 sizeof(async_send_request_ex_resolve_failure_test
)/sizeof(async_send_request_ex_resolve_failure_test
[0]),
5161 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
5164 HINTERNET ses
, req
, con
;
5166 DWORD size
, written
, error
;
5167 INTERNET_BUFFERSA b
;
5168 static const char *accept
[2] = {"*/*", NULL
};
5171 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
5173 InitializeCriticalSection( ¬ification_cs
);
5175 info
.test
= nd
->test
;
5176 info
.count
= nd
->count
;
5178 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
5179 info
.thread
= GetCurrentThreadId();
5180 info
.is_aborted
= FALSE
;
5182 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5183 ok( ses
!= NULL
, "InternetOpen failed\n" );
5185 pInternetSetStatusCallbackA( ses
, check_notification
);
5187 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
5188 con
= InternetConnectA( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
5189 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
5191 WaitForSingleObject( info
.wait
, 10000 );
5193 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
5194 req
= HttpOpenRequestA( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
5195 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
5197 WaitForSingleObject( info
.wait
, 10000 );
5200 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
5201 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
5202 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
5203 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
5204 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
5207 setup_test( &info
, http_send_request_ex
, __LINE__
,
5208 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
5209 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
5210 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
5212 error
= WaitForSingleObject( info
.wait
, 10000 );
5213 if(error
!= WAIT_OBJECT_0
) {
5214 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
5215 info
.is_aborted
= TRUE
;
5219 size
= sizeof(buffer
);
5220 SetLastError( 0xdeadbeef );
5221 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
5222 error
= GetLastError();
5223 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
5224 if(nd
->expect_conn_failure
) {
5225 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
5228 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
5229 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
5235 size
= strlen( nd
->data
);
5236 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
5237 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
5238 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
5239 ok( written
== size
, "expected %u got %u\n", written
, size
);
5241 WaitForSingleObject( info
.wait
, 10000 );
5243 SetLastError( 0xdeadbeef );
5244 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
5245 error
= GetLastError();
5246 ok( !ret
, "HttpEndRequestA succeeded\n" );
5247 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
5250 SetLastError( 0xdeadbeef );
5251 setup_test( &info
, http_end_request
, __LINE__
,
5252 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
5253 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
5254 error
= GetLastError();
5255 ok( !ret
, "HttpEndRequestA succeeded\n" );
5256 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
5258 WaitForSingleObject( info
.wait
, 10000 );
5260 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
5262 InternetCloseHandle( req
);
5263 InternetCloseHandle( con
);
5264 InternetCloseHandle( ses
);
5266 WaitForSingleObject( info
.wait
, 10000 );
5268 CloseHandle( info
.wait
);
5271 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
5272 static BOOL closetest_closed
;
5274 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
5275 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
5280 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
5282 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
5283 "Unexpected hInternet %p\n", hInternet
);
5284 if(!closetest_closed
)
5288 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
5289 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
5290 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5291 closetest_req
, res
, GetLastError());
5294 static void test_InternetCloseHandle(void)
5299 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5300 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
5302 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
5304 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
5305 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
5306 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
5308 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
5309 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
5311 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
5312 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
5313 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
5315 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
5317 res
= InternetCloseHandle(closetest_session
);
5318 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
5319 closetest_closed
= TRUE
;
5320 trace("Closed session handle\n");
5322 res
= InternetCloseHandle(closetest_conn
);
5323 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
5324 res
, GetLastError());
5326 res
= InternetCloseHandle(closetest_req
);
5327 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
5328 res
, GetLastError());
5330 len
= sizeof(flags
);
5331 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
5332 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
5333 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5334 closetest_req
, res
, GetLastError());
5337 static void test_connection_failure(void)
5339 HINTERNET session
, connect
, request
;
5343 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5344 ok(session
!= NULL
, "failed to get session handle\n");
5346 connect
= InternetConnectA(session
, "localhost", 1, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5347 ok(connect
!= NULL
, "failed to get connection handle\n");
5349 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
5350 ok(request
!= NULL
, "failed to get request handle\n");
5352 SetLastError(0xdeadbeef);
5353 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
5354 error
= GetLastError();
5355 ok(!ret
, "unexpected success\n");
5356 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
5358 InternetCloseHandle(request
);
5359 InternetCloseHandle(connect
);
5360 InternetCloseHandle(session
);
5363 static void test_default_service_port(void)
5365 HINTERNET session
, connect
, request
;
5369 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
5370 ok(session
!= NULL
, "InternetOpen failed\n");
5372 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
5373 INTERNET_SERVICE_HTTP
, 0, 0);
5374 ok(connect
!= NULL
, "InternetConnect failed\n");
5376 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
5377 ok(request
!= NULL
, "HttpOpenRequest failed\n");
5379 SetLastError(0xdeadbeef);
5380 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
5381 error
= GetLastError();
5382 ok(!ret
, "HttpSendRequest succeeded\n");
5383 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
5386 InternetCloseHandle(request
);
5387 InternetCloseHandle(connect
);
5388 InternetCloseHandle(session
);
5391 static void init_status_tests(void)
5393 memset(expect
, 0, sizeof(expect
));
5394 memset(optional
, 0, sizeof(optional
));
5395 memset(wine_allow
, 0, sizeof(wine_allow
));
5396 memset(notified
, 0, sizeof(notified
));
5397 memset(status_string
, 0, sizeof(status_string
));
5399 #define STATUS_STRING(status) status_string[status] = #status
5400 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
5401 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
5402 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5403 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5404 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
5405 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
5406 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
5407 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
5408 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
5409 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
5410 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
5411 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
5412 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
5413 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
5414 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
5415 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
5416 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
5417 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
5418 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
5419 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
5420 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
5421 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
5422 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
5423 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
5424 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
5425 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
5426 #undef STATUS_STRING
5432 hdll
= GetModuleHandleA("wininet.dll");
5434 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
5435 win_skip("Too old IE (older than 6.0)\n");
5439 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
5440 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
5441 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
5443 init_status_tests();
5444 test_InternetCloseHandle();
5445 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
5446 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
5447 InternetReadFile_test(0, &test_data
[1]);
5448 first_connection_to_test_url
= TRUE
;
5449 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
5450 test_security_flags();
5451 InternetReadFile_test(0, &test_data
[2]);
5452 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
5453 test_open_url_async();
5454 test_async_HttpSendRequestEx(¬ification_data
[0]);
5455 test_async_HttpSendRequestEx(¬ification_data
[1]);
5456 test_async_HttpSendRequestEx(¬ification_data
[2]);
5457 test_async_HttpSendRequestEx(¬ification_data
[3]);
5458 InternetOpenRequest_test();
5460 InternetLockRequestFile_test();
5461 InternetOpenUrlA_test();
5463 test_http_connection();
5464 test_secure_connection();
5465 test_user_agent_header();
5466 test_bogus_accept_types_array();
5467 InternetReadFile_chunked_test();
5468 HttpSendRequestEx_test();
5469 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
5470 test_connection_failure();
5471 test_default_service_port();