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 if(optional[status]) 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://test.winehq.org/tests/gzip.php",
143 "http://test.winehq.org/tests/gzip.php",
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 /* IE11 calls those in InternetQueryDataAvailable call. */
733 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
734 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
737 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
739 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
741 if (flags
& INTERNET_FLAG_ASYNC
)
745 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
747 ok(length
>= exlen
, "length %u < exlen %u\n", length
, exlen
);
751 else if (GetLastError() == ERROR_IO_PENDING
)
754 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
755 if(!(test
->flags
& TESTF_CHUNKED
))
756 ok(!length
, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length
);
757 WaitForSingleObject(hCompleteEvent
, INFINITE
);
759 ok(exlen
, "length = 0\n");
760 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
761 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
762 ok(req_error
, "req_error = 0\n");
765 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
768 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
770 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
772 trace("LENGTH %d\n", length
);
773 if(test
->flags
& TESTF_CHUNKED
)
774 ok(length
<= 8192, "length = %d, expected <= 8192\n", length
);
778 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
780 res
= InternetReadFile(hor
,buffer
,length
,&length
);
784 trace("ReadFile -> %s %i\n",res
?"TRUE":"FALSE",length
);
787 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
788 HeapFree(GetProcessHeap(),0,buffer
);
790 ok(!on_async
, "Returned zero size in response to request complete\n");
795 if(test
->flags
& TESTF_REDIRECT
) {
796 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
797 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
801 close_async_handle(hi
, hCompleteEvent
, 2);
802 CloseHandle(hCompleteEvent
);
803 first_connection_to_test_url
= FALSE
;
806 static void InternetReadFile_chunked_test(void)
811 const char *types
[2] = { "*", NULL
};
812 HINTERNET hi
, hic
= 0, hor
= 0;
814 trace("Starting InternetReadFile chunked test\n");
816 trace("InternetOpenA <--\n");
817 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
818 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
819 trace("InternetOpenA -->\n");
821 if (hi
== 0x0) goto abort
;
823 trace("InternetConnectA <--\n");
824 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
825 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
826 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
827 trace("InternetConnectA -->\n");
829 if (hic
== 0x0) goto abort
;
831 trace("HttpOpenRequestA <--\n");
832 hor
= HttpOpenRequestA(hic
, "GET", "/tests/chunked", NULL
, NULL
, types
,
833 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
835 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
837 * If the internet name can't be resolved we are probably behind
838 * a firewall or in some other way not directly connected to the
839 * Internet. Not enough reason to fail the test. Just ignore and
843 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
845 trace("HttpOpenRequestA -->\n");
847 if (hor
== 0x0) goto abort
;
849 trace("HttpSendRequestA -->\n");
850 SetLastError(0xdeadbeef);
851 res
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
852 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
853 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
854 trace("HttpSendRequestA <--\n");
856 test_request_flags(hor
, 0);
859 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
861 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
863 SetLastError( 0xdeadbeef );
865 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
867 trace("Option TRANSFER_ENCODING -> %i %s\n",res
,buffer
);
868 ok( res
|| ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
869 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
870 ok( !strcmp( buffer
, "chunked" ) || ( ! res
&& proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
871 "Wrong transfer encoding '%s'\n", buffer
);
873 SetLastError( 0xdeadbeef );
875 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
876 ok( !res
, "Found CONTENT_LENGTH option '%s'\n", buffer
);
877 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Wrong error %u\n", GetLastError() );
880 trace("Entering Query loop\n");
884 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
885 ok(!(!res
&& length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
886 ok(res
, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
887 trace("got %u available\n",length
);
890 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
892 res
= InternetReadFile(hor
,buffer
,length
,&got
);
895 trace("ReadFile -> %i %i\n",res
,got
);
896 ok( length
== got
, "only got %u of %u available\n", got
, length
);
897 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
899 HeapFree(GetProcessHeap(),0,buffer
);
905 res
= InternetReadFile( hor
, buffer
, 1, &got
);
906 ok( res
, "InternetReadFile failed: %u\n", GetLastError() );
907 ok( !got
, "got %u\n", got
);
914 res
= InternetCloseHandle(hor
);
915 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
918 res
= InternetCloseHandle(hi
);
919 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
923 static void InternetReadFileExA_test(int flags
)
927 const char *types
[2] = { "*", NULL
};
928 HINTERNET hi
, hic
= 0, hor
= 0;
929 INTERNET_BUFFERSA inetbuffers
;
931 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
933 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
935 trace("InternetOpenA <--\n");
936 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
937 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
938 trace("InternetOpenA -->\n");
940 if (hi
== 0x0) goto abort
;
942 pInternetSetStatusCallbackA(hi
,&callback
);
944 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
946 trace("InternetConnectA <--\n");
947 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
948 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
949 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
950 trace("InternetConnectA -->\n");
952 if (hic
== 0x0) goto abort
;
954 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
955 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
957 trace("HttpOpenRequestA <--\n");
958 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
959 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
961 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
963 * If the internet name can't be resolved we are probably behind
964 * a firewall or in some other way not directly connected to the
965 * Internet. Not enough reason to fail the test. Just ignore and
969 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
971 trace("HttpOpenRequestA -->\n");
973 if (hor
== 0x0) goto abort
;
975 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
976 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
977 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
978 if (first_connection_to_test_url
)
980 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
981 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
983 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
, 2);
984 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
985 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
986 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
987 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
988 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
989 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
990 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
991 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
992 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
993 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
994 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
995 if (flags
& INTERNET_FLAG_ASYNC
)
996 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
998 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1000 trace("HttpSendRequestA -->\n");
1001 SetLastError(0xdeadbeef);
1002 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
1003 if (flags
& INTERNET_FLAG_ASYNC
)
1004 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
1005 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
1007 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
1008 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
1009 trace("HttpSendRequestA <--\n");
1011 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
1012 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1013 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1016 if (first_connection_to_test_url
)
1018 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1019 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1023 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1024 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1026 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1027 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
1028 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1029 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1030 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1031 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1032 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
1033 if (flags
& INTERNET_FLAG_ASYNC
)
1034 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1036 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1037 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
1038 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
1039 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1040 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1042 /* tests invalid dwStructSize */
1043 inetbuffers
.dwStructSize
= sizeof(inetbuffers
)+1;
1044 inetbuffers
.lpcszHeader
= NULL
;
1045 inetbuffers
.dwHeadersLength
= 0;
1046 inetbuffers
.dwBufferLength
= 10;
1047 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
1048 inetbuffers
.dwOffsetHigh
= 1234;
1049 inetbuffers
.dwOffsetLow
= 5678;
1050 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1051 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1052 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1053 rc
? "TRUE" : "FALSE", GetLastError());
1054 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1056 test_request_flags(hor
, 0);
1058 /* tests to see whether lpcszHeader is used - it isn't */
1059 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1060 inetbuffers
.lpcszHeader
= (LPCSTR
)0xdeadbeef;
1061 inetbuffers
.dwHeadersLength
= 255;
1062 inetbuffers
.dwBufferLength
= 0;
1063 inetbuffers
.lpvBuffer
= NULL
;
1064 inetbuffers
.dwOffsetHigh
= 1234;
1065 inetbuffers
.dwOffsetLow
= 5678;
1066 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
1067 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
1068 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1069 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
1070 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1073 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1074 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1077 rc
= InternetReadFileExA(NULL
, &inetbuffers
, 0, 0xdeadcafe);
1078 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
1079 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1080 rc
? "TRUE" : "FALSE", GetLastError());
1083 trace("Entering Query loop\n");
1087 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1088 inetbuffers
.dwBufferLength
= 1024;
1089 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
1090 inetbuffers
.dwOffsetHigh
= 1234;
1091 inetbuffers
.dwOffsetLow
= 5678;
1093 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1094 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1095 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1096 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
1099 if (GetLastError() == ERROR_IO_PENDING
)
1101 trace("InternetReadFileEx -> PENDING\n");
1102 ok(flags
& INTERNET_FLAG_ASYNC
,
1103 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1104 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1105 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1106 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1107 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1108 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1112 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1118 trace("InternetReadFileEx -> SUCCEEDED\n");
1119 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1120 if (inetbuffers
.dwBufferLength
)
1123 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1124 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1129 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1130 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1131 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1135 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1136 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
1138 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
1139 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1140 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
1142 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1144 if (!inetbuffers
.dwBufferLength
)
1147 length
+= inetbuffers
.dwBufferLength
;
1149 ok(length
> 0, "failed to read any of the document\n");
1150 trace("Finished. Read %d bytes\n", length
);
1153 close_async_handle(hi
, hCompleteEvent
, 2);
1154 CloseHandle(hCompleteEvent
);
1155 first_connection_to_test_url
= FALSE
;
1158 static void InternetOpenUrlA_test(void)
1160 HINTERNET myhinternet
, myhttp
;
1162 DWORD size
, readbytes
, totalbytes
=0;
1165 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1166 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
1167 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret
, GetLastError());
1169 myhinternet
= InternetOpenA("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
1170 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
1172 ret
= InternetCanonicalizeUrlA(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1173 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1176 myhttp
= InternetOpenUrlA(myhinternet
, TEST_URL
, 0, 0,
1177 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
1178 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1179 return; /* WinXP returns this when not connected to the net */
1180 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1181 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
1182 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
1183 totalbytes
+= readbytes
;
1184 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
1185 totalbytes
+= readbytes
;
1186 trace("read 0x%08x bytes\n",totalbytes
);
1188 InternetCloseHandle(myhttp
);
1189 InternetCloseHandle(myhinternet
);
1191 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1192 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1195 static void HttpSendRequestEx_test(void)
1201 INTERNET_BUFFERSA BufferIn
;
1202 DWORD dwBytesWritten
, dwBytesRead
, error
;
1207 static char szPostData
[] = "mode=Test";
1208 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
1210 hSession
= InternetOpenA("Wine Regression Test",
1211 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1212 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1213 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1214 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1216 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1217 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1218 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1219 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1221 skip( "Network unreachable, skipping test\n" );
1224 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1226 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1228 BufferIn
.dwStructSize
= sizeof(BufferIn
);
1229 BufferIn
.Next
= (INTERNET_BUFFERSA
*)0xdeadcab;
1230 BufferIn
.lpcszHeader
= szContentType
;
1231 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1232 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1233 BufferIn
.lpvBuffer
= szPostData
;
1234 BufferIn
.dwBufferLength
= 3;
1235 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1236 BufferIn
.dwOffsetLow
= 0;
1237 BufferIn
.dwOffsetHigh
= 0;
1239 SetLastError(0xdeadbeef);
1240 ret
= HttpSendRequestExA(hRequest
, &BufferIn
, NULL
, 0 ,0);
1241 error
= GetLastError();
1242 ok(ret
, "HttpSendRequestEx Failed with error %u\n", error
);
1243 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", error
);
1245 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1247 for (i
= 3; szPostData
[i
]; i
++)
1248 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1249 "InternetWriteFile failed\n");
1251 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1253 ok(HttpEndRequestA(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1255 test_request_flags(hRequest
, 0);
1257 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1258 "Unable to read response\n");
1259 szBuffer
[dwBytesRead
] = 0;
1261 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
1262 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1264 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1266 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1267 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1270 static void InternetOpenRequest_test(void)
1272 HINTERNET session
, connect
, request
;
1273 static const char *types
[] = { "*", "", NULL
};
1274 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1275 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1278 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1279 ok(session
!= NULL
,"Unable to open Internet session\n");
1281 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1282 INTERNET_SERVICE_HTTP
, 0, 0);
1283 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1284 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1286 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1287 INTERNET_SERVICE_HTTP
, 0, 0);
1288 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1289 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1291 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1292 INTERNET_SERVICE_HTTP
, 0, 0);
1293 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1295 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1296 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1298 skip( "Network unreachable, skipping test\n" );
1301 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1303 ret
= HttpSendRequestW(request
, NULL
, 0, NULL
, 0);
1304 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1305 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1307 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1308 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1310 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1311 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1312 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1315 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1316 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1319 static void test_cache_read(void)
1321 HINTERNET session
, connection
, req
;
1322 FILETIME now
, tomorrow
, yesterday
;
1323 BYTE content
[1000], buf
[2000];
1324 char file_path
[MAX_PATH
];
1331 static const char cache_only_url
[] = "http://test.winehq.org/tests/cache-only";
1332 BYTE cache_headers
[] = "HTTP/1.1 200 OK\r\n\r\n";
1334 trace("Testing cache read...\n");
1336 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1338 for(i
= 0; i
< sizeof(content
); i
++)
1339 content
[i
] = '0' + (i
%10);
1341 GetSystemTimeAsFileTime(&now
);
1342 li
.u
.HighPart
= now
.dwHighDateTime
;
1343 li
.u
.LowPart
= now
.dwLowDateTime
;
1344 li
.QuadPart
+= (LONGLONG
)10000000 * 3600 * 24;
1345 tomorrow
.dwHighDateTime
= li
.u
.HighPart
;
1346 tomorrow
.dwLowDateTime
= li
.u
.LowPart
;
1347 li
.QuadPart
-= (LONGLONG
)10000000 * 3600 * 24 * 2;
1348 yesterday
.dwHighDateTime
= li
.u
.HighPart
;
1349 yesterday
.dwLowDateTime
= li
.u
.LowPart
;
1351 res
= CreateUrlCacheEntryA(cache_only_url
, sizeof(content
), "", file_path
, 0);
1352 ok(res
, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1354 file
= CreateFileA(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1355 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
1357 WriteFile(file
, content
, sizeof(content
), &size
, NULL
);
1360 res
= CommitUrlCacheEntryA(cache_only_url
, file_path
, tomorrow
, yesterday
, NORMAL_CACHE_ENTRY
,
1361 cache_headers
, sizeof(cache_headers
)-1, "", 0);
1362 ok(res
, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1364 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
1365 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
1367 pInternetSetStatusCallbackA(session
, callback
);
1369 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1370 connection
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
,
1371 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1372 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
1373 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1375 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1376 req
= HttpOpenRequestA(connection
, "GET", "/tests/cache-only", NULL
, NULL
, NULL
, 0, 0xdeadbead);
1377 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
1378 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1380 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1381 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1382 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST
);
1383 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT
);
1384 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1385 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1386 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1388 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
1390 ok(res
, "HttpSendRequest failed: %u\n", GetLastError());
1394 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
1395 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1396 ok(size
== sizeof(content
), "size = %u\n", size
);
1399 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
1400 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
1401 ok(size
== sizeof(content
), "size = %u\n", size
);
1402 ok(!memcmp(content
, buf
, sizeof(content
)), "unexpected content\n");
1405 close_async_handle(session
, hCompleteEvent
, 2);
1407 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1408 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1409 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
1410 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
1411 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1412 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1413 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1415 res
= DeleteUrlCacheEntryA(cache_only_url
);
1416 ok(res
, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1418 CloseHandle(hCompleteEvent
);
1421 static void test_http_cache(void)
1423 HINTERNET session
, connect
, request
;
1424 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1425 DWORD size
, file_size
;
1430 static const char *types
[] = { "*", "", NULL
};
1432 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1433 ok(session
!= NULL
,"Unable to open Internet session\n");
1435 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1436 INTERNET_SERVICE_HTTP
, 0, 0);
1437 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1439 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1440 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1442 skip( "Network unreachable, skipping test\n" );
1444 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1445 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1449 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1452 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1453 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1454 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1456 size
= sizeof(file_name
);
1457 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1458 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1459 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1460 ok(!size
, "size = %d\n", size
);
1462 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1463 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1465 size
= sizeof(file_name
);
1466 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1467 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1469 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1470 FILE_ATTRIBUTE_NORMAL
, NULL
);
1471 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1472 file_size
= GetFileSize(file
, NULL
);
1473 ok(file_size
== 106, "file size = %u\n", file_size
);
1476 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1477 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1478 ok(size
== 100, "size = %u\n", size
);
1480 file_size
= GetFileSize(file
, NULL
);
1481 ok(file_size
== 106, "file size = %u\n", file_size
);
1484 ret
= DeleteFileA(file_name
);
1485 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1487 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1489 file
= CreateFileA(file_name
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
1490 FILE_ATTRIBUTE_NORMAL
, NULL
);
1491 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1494 /* Send the same request, requiring it to be retrieved from the cache */
1495 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1497 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1498 ok(ret
, "HttpSendRequest failed\n");
1501 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1502 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1503 ok(size
== 100, "size = %u\n", size
);
1505 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1507 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1508 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1510 size
= sizeof(file_name
);
1511 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1512 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1513 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1514 ok(!size
, "size = %d\n", size
);
1516 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1517 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1519 size
= sizeof(file_name
);
1521 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1524 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1525 FILE_ATTRIBUTE_NORMAL
, NULL
);
1526 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1532 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1535 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1536 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1537 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1542 static void InternetLockRequestFile_test(void)
1544 HINTERNET session
, connect
, request
;
1545 char file_name
[MAX_PATH
];
1550 static const char *types
[] = { "*", "", NULL
};
1552 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1553 ok(session
!= NULL
,"Unable to open Internet session\n");
1555 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1556 INTERNET_SERVICE_HTTP
, 0, 0);
1557 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1559 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
|INTERNET_FLAG_RELOAD
, 0);
1560 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1562 skip( "Network unreachable, skipping test\n" );
1564 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1565 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1569 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1571 size
= sizeof(file_name
);
1572 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1573 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1574 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1575 ok(!size
, "size = %d\n", size
);
1578 ret
= InternetLockRequestFile(request
, &lock
);
1579 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1581 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1582 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1584 size
= sizeof(file_name
);
1585 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1586 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1588 ret
= InternetLockRequestFile(request
, &lock
);
1589 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1590 ok(lock
!= NULL
, "lock == NULL\n");
1592 ret
= InternetLockRequestFile(request
, &lock2
);
1593 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1594 ok(lock
== lock2
, "lock != lock2\n");
1596 ret
= InternetUnlockRequestFile(lock2
);
1597 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1599 ret
= DeleteFileA(file_name
);
1600 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1602 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1604 ret
= DeleteFileA(file_name
);
1605 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1607 ret
= InternetUnlockRequestFile(lock
);
1608 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1610 ret
= DeleteFileA(file_name
);
1611 ok(ret
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1614 static void HttpHeaders_test(void)
1626 hSession
= InternetOpenA("Wine Regression Test",
1627 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1628 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1629 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1630 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1632 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1633 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1634 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1635 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1637 skip( "Network unreachable, skipping test\n" );
1640 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1643 len
= sizeof(buffer
);
1644 strcpy(buffer
,"Warning");
1645 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1646 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1648 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1649 "Failed to add new header\n");
1652 len
= sizeof(buffer
);
1653 strcpy(buffer
,"Warning");
1654 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1655 buffer
,&len
,&index
),"Unable to query header\n");
1656 ok(index
== 1, "Index was not incremented\n");
1657 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1658 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1659 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1660 len
= sizeof(buffer
);
1661 strcpy(buffer
,"Warning");
1662 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1663 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1666 len
= 5; /* could store the string but not the NULL terminator */
1667 strcpy(buffer
,"Warning");
1668 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1669 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1670 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1671 ok(index
== 0, "Index was incremented\n");
1672 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1673 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1675 /* a call with NULL will fail but will return the length */
1677 len
= sizeof(buffer
);
1678 SetLastError(0xdeadbeef);
1679 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1680 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1681 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1682 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1683 ok(index
== 0, "Index was incremented\n");
1685 /* even for a len that is too small */
1688 SetLastError(0xdeadbeef);
1689 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1690 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1691 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1692 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1693 ok(index
== 0, "Index was incremented\n");
1697 SetLastError(0xdeadbeef);
1698 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1699 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1700 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1701 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1702 ok(index
== 0, "Index was incremented\n");
1703 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1706 /* a working query */
1708 len
= sizeof(buffer
);
1709 memset(buffer
, 'x', sizeof(buffer
));
1710 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1711 buffer
,&len
,&index
),"Unable to query header\n");
1712 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1713 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1714 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1715 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1716 ok(strncmp(buffer
, "POST /tests/post.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1717 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1718 ok(index
== 0, "Index was incremented\n");
1720 /* Like above two tests, but for W version */
1724 SetLastError(0xdeadbeef);
1725 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1726 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1727 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1728 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1729 ok(index
== 0, "Index was incremented\n");
1730 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1732 /* a working query */
1734 len
= sizeof(wbuffer
);
1735 memset(wbuffer
, 'x', sizeof(wbuffer
));
1736 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1737 wbuffer
,&len
,&index
),"Unable to query header\n");
1738 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1739 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1740 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1741 ok(index
== 0, "Index was incremented\n");
1743 /* end of W version tests */
1745 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1747 len
= sizeof(buffer
);
1748 memset(buffer
, 'x', sizeof(buffer
));
1749 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1750 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1751 ok(len
== 2, "Expected 2, got %d\n", len
);
1752 ok(strcmp(buffer
, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer
);
1753 ok(index
== 0, "Index was incremented\n");
1755 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1756 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1759 len
= sizeof(buffer
);
1760 strcpy(buffer
,"Warning");
1761 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1762 buffer
,&len
,&index
),"Unable to query header\n");
1763 ok(index
== 1, "Index was not incremented\n");
1764 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1765 len
= sizeof(buffer
);
1766 strcpy(buffer
,"Warning");
1767 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1768 buffer
,&len
,&index
),"Failed to get second header\n");
1769 ok(index
== 2, "Index was not incremented\n");
1770 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1771 len
= sizeof(buffer
);
1772 strcpy(buffer
,"Warning");
1773 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1774 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1776 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1779 len
= sizeof(buffer
);
1780 strcpy(buffer
,"Warning");
1781 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1782 buffer
,&len
,&index
),"Unable to query header\n");
1783 ok(index
== 1, "Index was not incremented\n");
1784 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1785 len
= sizeof(buffer
);
1786 strcpy(buffer
,"Warning");
1787 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1788 buffer
,&len
,&index
),"Failed to get second header\n");
1789 ok(index
== 2, "Index was not incremented\n");
1790 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1791 len
= sizeof(buffer
);
1792 strcpy(buffer
,"Warning");
1793 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1794 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1796 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1799 len
= sizeof(buffer
);
1800 strcpy(buffer
,"Warning");
1801 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1802 buffer
,&len
,&index
),"Unable to query header\n");
1803 ok(index
== 1, "Index was not incremented\n");
1804 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1805 len
= sizeof(buffer
);
1806 strcpy(buffer
,"Warning");
1807 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1808 buffer
,&len
,&index
),"Failed to get second header\n");
1809 ok(index
== 2, "Index was not incremented\n");
1810 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1811 len
= sizeof(buffer
);
1812 strcpy(buffer
,"Warning");
1813 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1814 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1816 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1819 len
= sizeof(buffer
);
1820 strcpy(buffer
,"Warning");
1821 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1822 buffer
,&len
,&index
),"Unable to query header\n");
1823 ok(index
== 1, "Index was not incremented\n");
1824 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1825 len
= sizeof(buffer
);
1826 strcpy(buffer
,"Warning");
1827 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1828 ok(index
== 2, "Index was not incremented\n");
1829 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1830 len
= sizeof(buffer
);
1831 strcpy(buffer
,"Warning");
1832 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1834 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1837 len
= sizeof(buffer
);
1838 strcpy(buffer
,"Warning");
1839 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1840 ok(index
== 1, "Index was not incremented\n");
1841 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1842 len
= sizeof(buffer
);
1843 strcpy(buffer
,"Warning");
1844 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1845 ok(index
== 2, "Index was not incremented\n");
1846 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1847 len
= sizeof(buffer
);
1848 strcpy(buffer
,"Warning");
1849 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1851 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1854 len
= sizeof(buffer
);
1855 strcpy(buffer
,"Warning");
1856 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1857 ok(index
== 1, "Index was not incremented\n");
1858 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1859 len
= sizeof(buffer
);
1860 strcpy(buffer
,"Warning");
1861 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1862 ok(index
== 2, "Index was not incremented\n");
1863 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1864 len
= sizeof(buffer
);
1865 strcpy(buffer
,"Warning");
1866 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1868 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");
1871 len
= sizeof(buffer
);
1872 strcpy(buffer
,"Warning");
1873 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1874 ok(index
== 1, "Index was not incremented\n");
1875 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1876 len
= sizeof(buffer
);
1877 strcpy(buffer
,"Warning");
1878 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1879 ok(index
== 2, "Index was not incremented\n");
1880 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1881 len
= sizeof(buffer
);
1882 strcpy(buffer
,"Warning");
1883 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1885 /* Ensure that blank headers are ignored and don't cause a failure */
1886 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");
1889 len
= sizeof(buffer
);
1890 strcpy(buffer
,"BlankTest");
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 /* Ensure that malformed header separators are ignored and don't cause a failure */
1896 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
),
1897 "Failed to add header with malformed entries in list\n");
1900 len
= sizeof(buffer
);
1901 strcpy(buffer
,"MalformedTest");
1902 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1903 ok(index
== 1, "Index was not incremented\n");
1904 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1906 len
= sizeof(buffer
);
1907 strcpy(buffer
,"MalformedTestTwo");
1908 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1909 ok(index
== 1, "Index was not incremented\n");
1910 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
1912 len
= sizeof(buffer
);
1913 strcpy(buffer
,"MalformedTestThree");
1914 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1915 ok(index
== 1, "Index was not incremented\n");
1916 ok(strcmp(buffer
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
1918 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD
);
1919 ok(ret
, "unable to add header %u\n", GetLastError());
1923 len
= sizeof(buffer
);
1924 ret
= HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
);
1925 ok(ret
, "unable to query header %u\n", GetLastError());
1926 ok(index
== 1, "index was not incremented\n");
1927 ok(!strcmp(buffer
, "Basic"), "incorrect string was returned (%s)\n", buffer
);
1929 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE
);
1930 ok(ret
, "unable to remove header %u\n", GetLastError());
1933 len
= sizeof(buffer
);
1934 SetLastError(0xdeadbeef);
1935 ok(!HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
),
1936 "header still present\n");
1937 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "got %u\n", GetLastError());
1939 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1941 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1942 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1945 static const char garbagemsg
[] =
1946 "Garbage: Header\r\n";
1948 static const char contmsg
[] =
1949 "HTTP/1.1 100 Continue\r\n";
1951 static const char expandcontmsg
[] =
1952 "HTTP/1.1 100 Continue\r\n"
1953 "Server: winecontinue\r\n"
1954 "Tag: something witty\r\n"
1957 static const char okmsg
[] =
1958 "HTTP/1.1 200 OK\r\n"
1959 "Server: winetest\r\n"
1962 static const char okmsg2
[] =
1963 "HTTP/1.1 200 OK\r\n"
1964 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1965 "Server: winetest\r\n"
1966 "Content-Length: 0\r\n"
1967 "Set-Cookie: one\r\n"
1968 "Set-Cookie: two\r\n"
1971 static const char notokmsg
[] =
1972 "HTTP/1.1 400 Bad Request\r\n"
1973 "Server: winetest\r\n"
1976 static const char noauthmsg
[] =
1977 "HTTP/1.1 401 Unauthorized\r\n"
1978 "Server: winetest\r\n"
1979 "Connection: close\r\n"
1980 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1983 static const char noauthmsg2
[] =
1984 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
1985 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
1987 "Server: winetest\r\n";
1989 static const char proxymsg
[] =
1990 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1991 "Server: winetest\r\n"
1992 "Proxy-Connection: close\r\n"
1993 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1996 static const char page1
[] =
1998 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1999 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
2002 static const char ok_with_length
[] =
2003 "HTTP/1.1 200 OK\r\n"
2004 "Connection: Keep-Alive\r\n"
2005 "Content-Length: 18\r\n\r\n"
2006 "HTTP/1.1 211 OK\r\n\r\n";
2008 static const char ok_with_length2
[] =
2009 "HTTP/1.1 210 OK\r\n"
2010 "Connection: Keep-Alive\r\n"
2011 "Content-Length: 19\r\n\r\n"
2012 "HTTP/1.1 211 OK\r\n\r\n";
2014 struct server_info
{
2019 static int test_cache_gzip
;
2020 static const char *send_buffer
;
2022 static DWORD CALLBACK
server_thread(LPVOID param
)
2024 struct server_info
*si
= param
;
2025 int r
, c
= -1, i
, on
, count
= 0;
2027 struct sockaddr_in sa
;
2030 int last_request
= 0;
2031 char host_header
[22];
2032 static BOOL test_b
= FALSE
;
2033 static int test_no_cache
= 0;
2035 WSAStartup(MAKEWORD(1,1), &wsaData
);
2037 s
= socket(AF_INET
, SOCK_STREAM
, 0);
2038 if (s
== INVALID_SOCKET
)
2042 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
2044 memset(&sa
, 0, sizeof sa
);
2045 sa
.sin_family
= AF_INET
;
2046 sa
.sin_port
= htons(si
->port
);
2047 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
2049 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
2055 SetEvent(si
->hEvent
);
2057 sprintf(host_header
, "Host: localhost:%d", si
->port
);
2062 c
= accept(s
, NULL
, NULL
);
2064 memset(buffer
, 0, sizeof buffer
);
2065 for(i
=0; i
<(sizeof buffer
-1); i
++)
2067 r
= recv(c
, &buffer
[i
], 1, 0);
2071 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
2072 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
2075 if (strstr(buffer
, "GET /test1"))
2077 if (!strstr(buffer
, "Content-Length: 0"))
2079 send(c
, okmsg
, sizeof okmsg
-1, 0);
2080 send(c
, page1
, sizeof page1
-1, 0);
2083 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2085 if (strstr(buffer
, "/test2"))
2087 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2089 send(c
, okmsg
, sizeof okmsg
-1, 0);
2090 send(c
, page1
, sizeof page1
-1, 0);
2093 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2095 if (strstr(buffer
, "/test3"))
2097 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2098 send(c
, okmsg
, sizeof okmsg
-1, 0);
2100 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2102 if (strstr(buffer
, "/test4"))
2104 if (strstr(buffer
, "Connection: Close"))
2105 send(c
, okmsg
, sizeof okmsg
-1, 0);
2107 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2109 if (strstr(buffer
, "POST /test5") ||
2110 strstr(buffer
, "RPC_IN_DATA /test5") ||
2111 strstr(buffer
, "RPC_OUT_DATA /test5"))
2113 if (strstr(buffer
, "Content-Length: 0"))
2115 send(c
, okmsg
, sizeof okmsg
-1, 0);
2116 send(c
, page1
, sizeof page1
-1, 0);
2119 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2121 if (strstr(buffer
, "GET /test6"))
2123 send(c
, contmsg
, sizeof contmsg
-1, 0);
2124 send(c
, contmsg
, sizeof contmsg
-1, 0);
2125 send(c
, okmsg
, sizeof okmsg
-1, 0);
2126 send(c
, page1
, sizeof page1
-1, 0);
2128 if (strstr(buffer
, "POST /test7"))
2130 if (strstr(buffer
, "Content-Length: 100"))
2132 send(c
, okmsg
, sizeof okmsg
-1, 0);
2133 send(c
, page1
, sizeof page1
-1, 0);
2136 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2138 if (strstr(buffer
, "/test8"))
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
, "/test9"))
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 (strstr(buffer
, "/testA"))
2162 if (!strstr(buffer
, "Connection: Close") &&
2163 !strstr(buffer
, "Connection: Keep-Alive") &&
2164 (strstr(buffer
, "Cache-Control: no-cache") ||
2165 strstr(buffer
, "Pragma: no-cache")) &&
2166 strstr(buffer
, host_header
))
2167 send(c
, okmsg
, sizeof okmsg
-1, 0);
2169 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2171 if (!test_b
&& strstr(buffer
, "/testB HTTP/1.1"))
2174 send(c
, okmsg
, sizeof okmsg
-1, 0);
2175 recvfrom(c
, buffer
, sizeof buffer
, 0, NULL
, NULL
);
2176 send(c
, okmsg
, sizeof okmsg
-1, 0);
2178 if (strstr(buffer
, "/testC"))
2180 if (strstr(buffer
, "Cookie: cookie=biscuit"))
2181 send(c
, okmsg
, sizeof okmsg
-1, 0);
2183 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2185 if (strstr(buffer
, "/testD"))
2187 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
2189 if (strstr(buffer
, "/testE"))
2191 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
2193 if (strstr(buffer
, "GET /quit"))
2195 send(c
, okmsg
, sizeof okmsg
-1, 0);
2196 send(c
, page1
, sizeof page1
-1, 0);
2199 if (strstr(buffer
, "GET /testF"))
2201 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
2202 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2203 send(c
, contmsg
, sizeof contmsg
-1, 0);
2204 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2205 send(c
, okmsg
, sizeof okmsg
-1, 0);
2206 send(c
, page1
, sizeof page1
-1, 0);
2208 if (strstr(buffer
, "GET /testG"))
2210 send(c
, page1
, sizeof page1
-1, 0);
2213 if (strstr(buffer
, "GET /testJ"))
2218 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2222 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2226 if (strstr(buffer
, "GET /testH"))
2228 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2229 recvfrom(c
, buffer
, sizeof(buffer
), 0, NULL
, NULL
);
2230 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2233 if (strstr(buffer
, "GET /test_no_content"))
2235 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2236 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2238 if (strstr(buffer
, "GET /test_conn_close"))
2240 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2241 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
2242 WaitForSingleObject(conn_close_event
, INFINITE
);
2243 trace("closing connection\n");
2245 if (strstr(buffer
, "GET /test_cache_control_no_cache"))
2247 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2248 if(!test_no_cache
++)
2249 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2251 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2253 if (strstr(buffer
, "GET /test_cache_control_no_store"))
2255 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2256 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2258 if (strstr(buffer
, "GET /test_cache_gzip"))
2260 static const char gzip_response
[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2261 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2262 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2263 if(!test_cache_gzip
++)
2264 send(c
, gzip_response
, sizeof(gzip_response
), 0);
2266 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2268 if (strstr(buffer
, "HEAD /test_head")) {
2269 static const char head_response
[] =
2270 "HTTP/1.1 200 OK\r\n"
2271 "Connection: Keep-Alive\r\n"
2272 "Content-Length: 100\r\n"
2275 send(c
, head_response
, sizeof(head_response
), 0);
2278 if (strstr(buffer
, "GET /send_from_buffer"))
2279 send(c
, send_buffer
, strlen(send_buffer
), 0);
2280 if (strstr(buffer
, "/test_cache_control_verb"))
2282 if (!memcmp(buffer
, "GET ", sizeof("GET ")-1) &&
2283 !strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2284 else if (strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2285 else send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2287 if (strstr(buffer
, "GET /test_premature_disconnect"))
2288 trace("closing connection\n");
2293 } while (!last_request
);
2300 static void test_basic_request(int port
, const char *verb
, const char *url
)
2302 HINTERNET hi
, hc
, hr
;
2303 DWORD r
, count
, error
;
2306 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2307 ok(hi
!= NULL
, "open failed\n");
2309 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2310 ok(hc
!= NULL
, "connect failed\n");
2312 hr
= HttpOpenRequestA(hc
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
2313 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2315 SetLastError(0xdeadbeef);
2316 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2317 error
= GetLastError();
2318 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
2319 ok(r
, "HttpSendRequest failed\n");
2322 memset(buffer
, 0, sizeof buffer
);
2323 SetLastError(0xdeadbeef);
2324 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
2325 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2326 ok(count
== sizeof page1
- 1, "count was wrong\n");
2327 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2329 InternetCloseHandle(hr
);
2330 InternetCloseHandle(hc
);
2331 InternetCloseHandle(hi
);
2334 static void test_proxy_indirect(int port
)
2336 HINTERNET hi
, hc
, hr
;
2340 hi
= InternetOpenA(NULL
, 0, NULL
, NULL
, 0);
2341 ok(hi
!= NULL
, "open failed\n");
2343 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2344 ok(hc
!= NULL
, "connect failed\n");
2346 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2347 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2349 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2350 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2353 r
= HttpQueryInfoA(hr
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2354 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
2357 skip("missing proxy header, not testing remaining proxy headers\n");
2360 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2362 test_status_code(hr
, 407);
2363 test_request_flags(hr
, 0);
2366 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2367 ok(r
, "HttpQueryInfo failed\n");
2368 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2371 r
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2372 ok(r
, "HttpQueryInfo failed\n");
2373 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2376 r
= HttpQueryInfoA(hr
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2377 ok(r
, "HttpQueryInfo failed\n");
2378 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2381 r
= HttpQueryInfoA(hr
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2382 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2383 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2386 InternetCloseHandle(hr
);
2387 InternetCloseHandle(hc
);
2388 InternetCloseHandle(hi
);
2391 static void test_proxy_direct(int port
)
2393 HINTERNET hi
, hc
, hr
;
2395 char buffer
[0x40], *url
;
2396 WCHAR bufferW
[0x40];
2397 static const char url_fmt
[] = "http://test.winehq.org:%u/test2";
2398 static CHAR username
[] = "mike",
2399 password
[] = "1101",
2400 useragent
[] = "winetest";
2401 static const WCHAR usernameW
[] = {'m','i','k','e',0},
2402 passwordW
[] = {'1','1','0','1',0},
2403 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2405 /* specify proxy type without the proxy and bypass */
2406 SetLastError(0xdeadbeef);
2407 hi
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2408 error
= GetLastError();
2409 ok(error
== ERROR_INVALID_PARAMETER
||
2410 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %u\n", error
);
2411 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2413 sprintf(buffer
, "localhost:%d\n", port
);
2414 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2415 ok(hi
!= NULL
, "open failed\n");
2417 /* try connect without authorization */
2418 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2419 ok(hc
!= NULL
, "connect failed\n");
2421 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2422 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2425 SetLastError(0xdeadbeef);
2426 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
2427 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2428 ok(!r
, "unexpected success\n");
2429 ok(sz
== 1, "got %u\n", sz
);
2432 SetLastError(0xdeadbeef);
2433 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
2434 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2435 ok(!r
, "unexpected success\n");
2436 ok(sz
== 1, "got %u\n", sz
);
2438 sz
= sizeof(buffer
);
2439 SetLastError(0xdeadbeef);
2440 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2441 ok(r
, "unexpected failure %u\n", GetLastError());
2442 ok(!sz
, "got %u\n", sz
);
2444 sz
= sizeof(buffer
);
2445 SetLastError(0xdeadbeef);
2446 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2447 ok(r
, "unexpected failure %u\n", GetLastError());
2448 ok(!sz
, "got %u\n", sz
);
2451 SetLastError(0xdeadbeef);
2452 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
2453 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2454 ok(!r
, "unexpected success\n");
2455 ok(sz
== 1, "got %u\n", sz
);
2458 SetLastError(0xdeadbeef);
2459 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
2460 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2461 ok(!r
, "unexpected success\n");
2462 ok(sz
== 1, "got %u\n", sz
);
2464 sz
= sizeof(buffer
);
2465 SetLastError(0xdeadbeef);
2466 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2467 ok(r
, "unexpected failure %u\n", GetLastError());
2468 ok(!sz
, "got %u\n", sz
);
2470 sz
= sizeof(buffer
);
2471 SetLastError(0xdeadbeef);
2472 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2473 ok(r
, "unexpected failure %u\n", GetLastError());
2474 ok(!sz
, "got %u\n", sz
);
2477 SetLastError(0xdeadbeef);
2478 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
2479 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2480 ok(!r
, "unexpected success\n");
2481 ok(sz
== 34, "got %u\n", sz
);
2483 sz
= sizeof(buffer
);
2484 SetLastError(0xdeadbeef);
2485 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2486 ok(r
, "unexpected failure %u\n", GetLastError());
2487 ok(sz
== 33, "got %u\n", sz
);
2489 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2490 ok(r
|| broken(!r
), "HttpSendRequest failed %u\n", GetLastError());
2493 win_skip("skipping proxy tests on broken wininet\n");
2497 test_status_code(hr
, 407);
2499 /* set the user + password then try again */
2500 r
= InternetSetOptionA(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2501 ok(!r
, "unexpected success\n");
2503 r
= InternetSetOptionA(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2504 ok(r
, "failed to set user\n");
2506 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2507 ok(r
, "failed to set user\n");
2511 SetLastError(0xdeadbeef);
2512 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2513 ok(!r
, "unexpected failure %u\n", GetLastError());
2514 ok(!buffer
[0], "got %s\n", buffer
);
2515 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2519 SetLastError(0xdeadbeef);
2520 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2521 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2522 ok(!r
, "unexpected success\n");
2523 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2527 SetLastError(0xdeadbeef);
2528 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2529 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2530 ok(!r
, "unexpected success\n");
2531 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2534 sz
= sizeof(buffer
);
2535 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2536 ok(r
, "failed to get username\n");
2537 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2538 ok(sz
== strlen(username
), "got %u\n", sz
);
2541 sz
= sizeof(bufferW
);
2542 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2543 ok(r
, "failed to get username\n");
2544 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
2545 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2547 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
2548 ok(r
, "failed to set user\n");
2551 sz
= sizeof(buffer
);
2552 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2553 ok(r
, "failed to get username\n");
2554 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2555 ok(sz
== strlen(username
), "got %u\n", sz
);
2557 r
= InternetSetOptionA(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
2558 ok(r
, "failed to set useragent\n");
2562 SetLastError(0xdeadbeef);
2563 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2564 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2565 ok(!r
, "unexpected success\n");
2566 ok(sz
== strlen(useragent
) + 1, "got %u\n", sz
);
2569 sz
= sizeof(buffer
);
2570 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2571 ok(r
, "failed to get user agent\n");
2572 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
2573 ok(sz
== strlen(useragent
), "got %u\n", sz
);
2577 SetLastError(0xdeadbeef);
2578 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2579 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2580 ok(!r
, "unexpected success\n");
2581 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2584 sz
= sizeof(bufferW
);
2585 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2586 ok(r
, "failed to get user agent\n");
2587 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
2588 ok(sz
== lstrlenW(useragentW
), "got %u\n", sz
);
2590 r
= InternetSetOptionA(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
2591 ok(r
, "failed to set user\n");
2595 SetLastError(0xdeadbeef);
2596 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2597 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2598 ok(!r
, "unexpected success\n");
2599 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2602 sz
= sizeof(buffer
);
2603 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2604 ok(r
, "failed to get user\n");
2605 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2606 ok(sz
== strlen(username
), "got %u\n", sz
);
2610 SetLastError(0xdeadbeef);
2611 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2612 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2613 ok(!r
, "unexpected success\n");
2614 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2617 sz
= sizeof(bufferW
);
2618 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2619 ok(r
, "failed to get user\n");
2620 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
2621 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2623 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
2624 ok(r
, "failed to set password\n");
2628 SetLastError(0xdeadbeef);
2629 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2630 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2631 ok(!r
, "unexpected success\n");
2632 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2635 sz
= sizeof(buffer
);
2636 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2637 ok(r
, "failed to get password\n");
2638 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2639 ok(sz
== strlen(password
), "got %u\n", sz
);
2643 SetLastError(0xdeadbeef);
2644 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2645 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2646 ok(!r
, "unexpected success\n");
2647 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2650 sz
= sizeof(bufferW
);
2651 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2652 ok(r
, "failed to get password\n");
2653 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2654 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2656 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
2657 sprintf(url
, url_fmt
, port
);
2660 SetLastError(0xdeadbeef);
2661 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2662 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2663 ok(!r
, "unexpected success\n");
2664 ok(sz
== strlen(url
) + 1, "got %u\n", sz
);
2667 sz
= sizeof(buffer
);
2668 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2669 ok(r
, "failed to get url\n");
2670 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
2671 ok(sz
== strlen(url
), "got %u\n", sz
);
2675 SetLastError(0xdeadbeef);
2676 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2677 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2678 ok(!r
, "unexpected success\n");
2679 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2682 sz
= sizeof(bufferW
);
2683 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2684 ok(r
, "failed to get url\n");
2685 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
2686 ok(sz
== strlen(url
), "got %u\n", sz
);
2687 HeapFree(GetProcessHeap(), 0, url
);
2689 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2690 ok(r
, "failed to set password\n");
2694 SetLastError(0xdeadbeef);
2695 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2696 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2697 ok(!r
, "unexpected success\n");
2698 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2701 sz
= sizeof(buffer
);
2702 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2703 ok(r
, "failed to get password\n");
2704 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2705 ok(sz
== strlen(password
), "got %u\n", sz
);
2709 SetLastError(0xdeadbeef);
2710 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2711 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2712 ok(!r
, "unexpected success\n");
2713 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2716 sz
= sizeof(bufferW
);
2717 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2718 ok(r
, "failed to get password\n");
2719 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2720 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2722 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2725 win_skip("skipping proxy tests on broken wininet\n");
2728 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2730 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2731 ok(r
, "HttpQueryInfo failed\n");
2732 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2735 InternetCloseHandle(hr
);
2736 InternetCloseHandle(hc
);
2737 InternetCloseHandle(hi
);
2740 static void test_header_handling_order(int port
)
2742 static const char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
2743 static const char connection
[] = "Connection: Close";
2744 static const char *types
[2] = { "*", NULL
};
2746 HINTERNET session
, connect
, request
;
2747 DWORD size
, status
, data_len
;
2750 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2751 ok(session
!= NULL
, "InternetOpen failed\n");
2753 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2754 ok(connect
!= NULL
, "InternetConnect failed\n");
2756 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2757 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2759 ret
= HttpAddRequestHeadersA(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
2760 ok(ret
, "HttpAddRequestHeaders failed\n");
2762 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
2763 ok(ret
, "HttpSendRequest failed\n");
2765 test_status_code(request
, 200);
2766 test_request_flags(request
, 0);
2768 InternetCloseHandle(request
);
2770 request
= HttpOpenRequestA(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2771 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2773 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2774 ok(ret
, "HttpSendRequest failed\n");
2777 size
= sizeof(status
);
2778 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2779 ok(ret
, "HttpQueryInfo failed\n");
2780 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2782 InternetCloseHandle(request
);
2783 InternetCloseHandle(connect
);
2785 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2786 ok(connect
!= NULL
, "InternetConnect failed\n");
2788 request
= HttpOpenRequestA(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2789 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2791 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2792 ok(ret
, "HttpAddRequestHeaders failed\n");
2794 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2795 ok(ret
, "HttpSendRequest failed\n");
2798 size
= sizeof(status
);
2799 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2800 ok(ret
, "HttpQueryInfo failed\n");
2801 ok(status
== 200, "got status %u, expected 200\n", status
);
2803 InternetCloseHandle(request
);
2804 InternetCloseHandle(connect
);
2806 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2807 ok(connect
!= NULL
, "InternetConnect failed\n");
2809 request
= HttpOpenRequestA(connect
, "POST", "/test7b", NULL
, NULL
, types
, 0, 0);
2810 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2812 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2813 ok(ret
, "HttpAddRequestHeaders failed\n");
2815 data_len
= sizeof(data
);
2816 memset(data
, 'a', sizeof(data
));
2817 ret
= HttpSendRequestA(request
, connection
, ~0u, data
, data_len
);
2818 ok(ret
, "HttpSendRequest failed\n");
2821 size
= sizeof(status
);
2822 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2823 ok(ret
, "HttpQueryInfo failed\n");
2824 ok(status
== 200, "got status %u, expected 200\n", status
);
2826 InternetCloseHandle(request
);
2827 InternetCloseHandle(connect
);
2828 InternetCloseHandle(session
);
2831 static void test_connection_header(int port
)
2833 HINTERNET ses
, con
, req
;
2836 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2837 ok(ses
!= NULL
, "InternetOpen failed\n");
2839 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2840 ok(con
!= NULL
, "InternetConnect failed\n");
2842 req
= HttpOpenRequestA(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2843 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2845 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2846 ok(ret
, "HttpSendRequest failed\n");
2848 test_status_code(req
, 200);
2850 InternetCloseHandle(req
);
2852 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
2853 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2855 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2856 ok(ret
, "HttpSendRequest failed\n");
2858 test_status_code(req
, 200);
2860 InternetCloseHandle(req
);
2862 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2863 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2865 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2866 ok(ret
, "HttpSendRequest failed\n");
2868 test_status_code(req
, 200);
2870 InternetCloseHandle(req
);
2872 req
= HttpOpenRequestA(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2873 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2875 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2876 ok(ret
, "HttpSendRequest failed\n");
2878 test_status_code(req
, 200);
2880 InternetCloseHandle(req
);
2881 InternetCloseHandle(con
);
2882 InternetCloseHandle(ses
);
2885 static void test_http1_1(int port
)
2887 HINTERNET ses
, con
, req
;
2890 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2891 ok(ses
!= NULL
, "InternetOpen failed\n");
2893 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2894 ok(con
!= NULL
, "InternetConnect failed\n");
2896 req
= HttpOpenRequestA(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2897 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2899 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2902 InternetCloseHandle(req
);
2904 req
= HttpOpenRequestA(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2905 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2907 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2908 ok(ret
, "HttpSendRequest failed\n");
2911 InternetCloseHandle(req
);
2912 InternetCloseHandle(con
);
2913 InternetCloseHandle(ses
);
2916 static void test_connection_closing(int port
)
2918 HINTERNET session
, connection
, req
;
2921 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2923 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2924 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2926 pInternetSetStatusCallbackA(session
, callback
);
2928 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2929 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2930 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2931 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2933 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2934 req
= HttpOpenRequestA(connection
, "GET", "/testJ", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
2935 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2936 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2938 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2939 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2940 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2941 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2942 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2943 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2944 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2945 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2946 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
2947 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
2948 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2950 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2951 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2952 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2953 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2954 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2956 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2957 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2958 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2959 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2960 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2961 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2962 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2963 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2964 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2965 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2966 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2968 test_status_code(req
, 200);
2970 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2971 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2972 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2973 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2974 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2975 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2976 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2977 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2978 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2980 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2981 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2982 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2983 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2984 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2986 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2987 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2988 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2989 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2990 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2991 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2992 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2993 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2994 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2996 test_status_code(req
, 210);
2998 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2999 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3000 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3001 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3002 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3003 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3004 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3005 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3006 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3007 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3008 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3010 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3011 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3012 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3013 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3014 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3016 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3017 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3018 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3019 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3020 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3021 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3022 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3023 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3024 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3025 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3026 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3028 test_status_code(req
, 200);
3030 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3031 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3033 close_async_handle(session
, hCompleteEvent
, 2);
3034 CloseHandle(hCompleteEvent
);
3037 static void test_successive_HttpSendRequest(int port
)
3039 HINTERNET session
, connection
, req
;
3042 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3044 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3045 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3047 pInternetSetStatusCallbackA(session
, callback
);
3049 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3050 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3051 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3052 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3054 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3055 req
= HttpOpenRequestA(connection
, "GET", "/testH", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3056 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3057 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3059 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3060 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3061 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3062 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3063 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3064 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3065 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3066 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3067 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3069 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3070 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3071 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3072 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3073 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3075 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3076 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3077 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3078 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3079 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3080 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3081 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3082 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3083 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3085 test_status_code(req
, 210);
3087 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3088 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3089 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3090 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3091 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3092 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3093 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3094 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3095 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3097 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3098 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3099 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3100 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3101 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3103 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3104 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3105 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3106 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3107 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3108 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3109 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3110 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3111 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3113 test_status_code(req
, 200);
3115 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3116 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3118 close_async_handle(session
, hCompleteEvent
, 2);
3119 CloseHandle(hCompleteEvent
);
3122 static void test_no_content(int port
)
3124 HINTERNET session
, connection
, req
;
3127 trace("Testing 204 no content response...\n");
3129 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3131 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3132 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3134 pInternetSetStatusCallbackA(session
, callback
);
3136 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3137 connection
= InternetConnectA(session
, "localhost", port
,
3138 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3139 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3140 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3142 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3143 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
3144 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3145 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3146 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3148 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3149 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3150 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3151 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3152 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3153 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3154 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3155 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3156 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3157 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3159 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3160 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3161 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3162 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3163 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3165 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3166 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3167 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3168 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3169 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3170 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3171 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3172 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3174 close_async_handle(session
, hCompleteEvent
, 2);
3175 CloseHandle(hCompleteEvent
);
3178 * The connection should be closed before closing handle. This is true for most
3179 * wininet versions (including Wine), but some old win2k versions fail to do that.
3181 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3182 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3185 static void test_conn_close(int port
)
3187 HINTERNET session
, connection
, req
;
3188 DWORD res
, avail
, size
;
3191 trace("Testing connection close connection...\n");
3193 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3194 conn_close_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3196 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3197 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3199 pInternetSetStatusCallbackA(session
, callback
);
3201 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3202 connection
= InternetConnectA(session
, "localhost", port
,
3203 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3204 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3205 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3207 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3208 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
3209 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3210 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3211 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3213 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3214 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3215 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3216 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3217 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3218 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3219 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3220 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3222 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3223 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3224 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3225 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3226 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3228 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3229 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3230 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3231 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3232 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3233 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3234 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3235 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3238 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3239 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3240 ok(avail
!= 0, "avail = 0\n");
3243 res
= InternetReadFile(req
, buf
, avail
, &size
);
3244 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3246 /* IE11 calls those in InternetQueryDataAvailable call. */
3247 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
3248 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
3250 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3251 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3252 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3253 ok(!avail
, "avail = %u, expected 0\n", avail
);
3255 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3257 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3258 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3259 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3260 SetEvent(conn_close_event
);
3261 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3262 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3263 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3264 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3265 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3266 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3268 close_async_handle(session
, hCompleteEvent
, 2);
3269 CloseHandle(hCompleteEvent
);
3272 static void test_no_cache(int port
)
3274 static const char cache_control_no_cache
[] = "/test_cache_control_no_cache";
3275 static const char cache_control_no_store
[] = "/test_cache_control_no_store";
3276 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3278 char cache_url
[256], buf
[256];
3279 HINTERNET ses
, con
, req
;
3283 trace("Testing no-cache header\n");
3285 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3286 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3288 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3289 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3291 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3292 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3294 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_cache
);
3295 DeleteUrlCacheEntryA(cache_url
);
3297 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3298 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3300 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3302 ok(size
== 12, "read %d bytes of data\n", size
);
3303 InternetCloseHandle(req
);
3305 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3306 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3308 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3309 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3311 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3313 ok(size
== 0, "read %d bytes of data\n", size
);
3314 InternetCloseHandle(req
);
3315 DeleteUrlCacheEntryA(cache_url
);
3317 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_store
, NULL
, NULL
, NULL
, 0, 0);
3318 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3320 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_store
);
3321 DeleteUrlCacheEntryA(cache_url
);
3323 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3324 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3326 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3328 ok(size
== 12, "read %d bytes of data\n", size
);
3329 InternetCloseHandle(req
);
3331 ret
= DeleteUrlCacheEntryA(cache_url
);
3332 ok(!ret
&& GetLastError()==ERROR_FILE_NOT_FOUND
, "cache entry should not exist\n");
3334 InternetCloseHandle(con
);
3335 InternetCloseHandle(ses
);
3338 static void test_cache_read_gzipped(int port
)
3340 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3341 static const char get_gzip
[] = "/test_cache_gzip";
3342 static const char content
[] = "gzip test\n";
3343 static const char text_html
[] = "text/html";
3344 static const char raw_header
[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3346 HINTERNET ses
, con
, req
;
3348 char cache_url
[256], buf
[256];
3351 trace("Testing reading compressed content from cache\n");
3353 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3354 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3356 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3357 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3359 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3360 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3363 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3364 if(!ret
&& GetLastError()==ERROR_INTERNET_INVALID_OPTION
) {
3365 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3366 InternetCloseHandle(req
);
3367 InternetCloseHandle(con
);
3368 InternetCloseHandle(ses
);
3371 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3373 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3374 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3376 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-size
, &read
) && read
)
3378 ok(size
== 10, "read %d bytes of data\n", size
);
3380 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3382 size
= sizeof(buf
)-1;
3383 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3384 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3386 ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3388 size
= sizeof(buf
)-1;
3389 ret
= HttpQueryInfoA(req
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &size
, 0);
3390 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3392 ok(!strncmp(raw_header
, buf
, size
), "buf = %s\n", buf
);
3393 InternetCloseHandle(req
);
3395 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3396 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3399 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3400 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3402 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3403 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3405 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3407 todo_wine
ok(size
== 10, "read %d bytes of data\n", size
);
3409 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3412 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3413 ok(!ret
&& GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND
,
3414 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3415 ret
, GetLastError());
3417 size
= sizeof(buf
)-1;
3418 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3419 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3421 todo_wine
ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3422 InternetCloseHandle(req
);
3424 /* Decompression doesn't work while reading from cache */
3425 test_cache_gzip
= 0;
3426 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3427 DeleteUrlCacheEntryA(cache_url
);
3429 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3430 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3432 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3433 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3435 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3437 ok(size
== 31, "read %d bytes of data\n", size
);
3438 InternetCloseHandle(req
);
3440 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3441 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3444 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3445 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3447 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3448 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3450 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3452 todo_wine
ok(size
== 31, "read %d bytes of data\n", size
);
3455 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3456 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3457 InternetCloseHandle(req
);
3459 InternetCloseHandle(con
);
3460 InternetCloseHandle(ses
);
3462 DeleteUrlCacheEntryA(cache_url
);
3465 static void test_HttpSendRequestW(int port
)
3467 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3468 HINTERNET ses
, con
, req
;
3472 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3473 ok(ses
!= NULL
, "InternetOpen failed\n");
3475 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3476 ok(con
!= NULL
, "InternetConnect failed\n");
3478 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3479 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3481 SetLastError(0xdeadbeef);
3482 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
3483 error
= GetLastError();
3484 ok(!ret
, "HttpSendRequestW succeeded\n");
3485 ok(error
== ERROR_IO_PENDING
||
3486 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
3487 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
3488 "got %u expected ERROR_IO_PENDING\n", error
);
3490 InternetCloseHandle(req
);
3491 InternetCloseHandle(con
);
3492 InternetCloseHandle(ses
);
3495 static void test_cookie_header(int port
)
3497 HINTERNET ses
, con
, req
;
3502 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3503 ok(ses
!= NULL
, "InternetOpen failed\n");
3505 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3506 ok(con
!= NULL
, "InternetConnect failed\n");
3508 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3510 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3511 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3514 size
= sizeof(buffer
);
3515 SetLastError(0xdeadbeef);
3516 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3517 error
= GetLastError();
3518 ok(!ret
, "HttpQueryInfo succeeded\n");
3519 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3521 ret
= HttpAddRequestHeadersA(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
3522 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3525 size
= sizeof(buffer
);
3526 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3527 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3528 ok(!strcmp(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
3530 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3531 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3533 test_status_code(req
, 200);
3536 size
= sizeof(buffer
);
3537 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3538 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3539 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
3541 InternetCloseHandle(req
);
3542 InternetCloseHandle(con
);
3543 InternetCloseHandle(ses
);
3546 static void test_basic_authentication(int port
)
3548 HINTERNET session
, connect
, request
;
3551 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3552 ok(session
!= NULL
, "InternetOpen failed\n");
3554 connect
= InternetConnectA(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
3555 ok(connect
!= NULL
, "InternetConnect failed\n");
3557 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
3558 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3560 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3561 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3563 test_status_code(request
, 200);
3564 test_request_flags(request
, 0);
3566 InternetCloseHandle(request
);
3567 InternetCloseHandle(connect
);
3568 InternetCloseHandle(session
);
3571 static void test_premature_disconnect(int port
)
3573 HINTERNET session
, connect
, request
;
3577 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3578 ok(session
!= NULL
, "InternetOpen failed\n");
3580 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3581 ok(connect
!= NULL
, "InternetConnect failed\n");
3583 request
= HttpOpenRequestA(connect
, NULL
, "/premature_disconnect", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3584 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3586 SetLastError(0xdeadbeef);
3587 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3588 err
= GetLastError();
3589 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
3590 todo_wine
ok(err
== ERROR_HTTP_INVALID_SERVER_RESPONSE
, "got %u\n", err
);
3592 InternetCloseHandle(request
);
3593 InternetCloseHandle(connect
);
3594 InternetCloseHandle(session
);
3597 static void test_invalid_response_headers(int port
)
3599 HINTERNET session
, connect
, request
;
3604 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3605 ok(session
!= NULL
, "InternetOpen failed\n");
3607 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3608 ok(connect
!= NULL
, "InternetConnect failed\n");
3610 request
= HttpOpenRequestA(connect
, NULL
, "/testE", NULL
, NULL
, NULL
, 0, 0);
3611 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3613 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3614 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3616 test_status_code(request
, 401);
3617 test_request_flags(request
, 0);
3620 size
= sizeof(buffer
);
3621 ret
= HttpQueryInfoA( request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3622 ok(ret
, "HttpQueryInfo failed\n");
3623 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
3624 "headers wrong \"%s\"\n", buffer
);
3627 size
= sizeof(buffer
);
3628 ret
= HttpQueryInfoA( request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
3629 ok(ret
, "HttpQueryInfo failed\n");
3630 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
3632 InternetCloseHandle(request
);
3633 InternetCloseHandle(connect
);
3634 InternetCloseHandle(session
);
3637 static void test_response_without_headers(int port
)
3639 HINTERNET hi
, hc
, hr
;
3640 DWORD r
, count
, size
;
3643 SetLastError(0xdeadbeef);
3644 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3645 ok(hi
!= NULL
, "open failed %u\n", GetLastError());
3647 SetLastError(0xdeadbeef);
3648 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3649 ok(hc
!= NULL
, "connect failed %u\n", GetLastError());
3651 SetLastError(0xdeadbeef);
3652 hr
= HttpOpenRequestA(hc
, NULL
, "/testG", NULL
, NULL
, NULL
, 0, 0);
3653 ok(hr
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError());
3655 test_request_flags(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3657 SetLastError(0xdeadbeef);
3658 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
3659 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
3661 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3664 memset(buffer
, 0, sizeof buffer
);
3665 SetLastError(0xdeadbeef);
3666 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
3667 ok(r
, "InternetReadFile failed %u\n", GetLastError());
3668 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
3669 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
3671 test_status_code(hr
, 200);
3672 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3675 size
= sizeof(buffer
);
3676 SetLastError(0xdeadbeef);
3677 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
3678 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3679 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
3682 size
= sizeof(buffer
);
3683 SetLastError(0xdeadbeef);
3684 r
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
3685 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3686 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
3689 size
= sizeof(buffer
);
3690 SetLastError(0xdeadbeef);
3691 r
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3692 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3693 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
3695 InternetCloseHandle(hr
);
3696 InternetCloseHandle(hc
);
3697 InternetCloseHandle(hi
);
3700 static void test_head_request(int port
)
3702 DWORD len
, content_length
;
3703 HINTERNET ses
, con
, req
;
3707 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3708 ok(ses
!= NULL
, "InternetOpen failed\n");
3710 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3711 ok(con
!= NULL
, "InternetConnect failed\n");
3713 req
= HttpOpenRequestA(con
, "HEAD", "/test_head", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3714 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3716 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3717 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3719 len
= sizeof(content_length
);
3720 content_length
= -1;
3721 ret
= HttpQueryInfoA(req
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
, &content_length
, &len
, 0);
3722 ok(ret
, "HttpQueryInfo dailed: %u\n", GetLastError());
3723 ok(len
== sizeof(DWORD
), "len = %u\n", len
);
3724 ok(content_length
== 100, "content_length = %u\n", content_length
);
3727 ret
= InternetReadFile(req
, buf
, sizeof(buf
), &len
);
3728 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
3731 ret
= InternetReadFile(req
, buf
, sizeof(buf
), &len
);
3732 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
3734 InternetCloseHandle(req
);
3735 InternetCloseHandle(con
);
3736 InternetCloseHandle(ses
);
3739 static void test_HttpQueryInfo(int port
)
3741 HINTERNET hi
, hc
, hr
;
3742 DWORD size
, index
, error
;
3746 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3747 ok(hi
!= NULL
, "InternetOpen failed\n");
3749 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3750 ok(hc
!= NULL
, "InternetConnect failed\n");
3752 hr
= HttpOpenRequestA(hc
, NULL
, "/testD", NULL
, NULL
, NULL
, 0, 0);
3753 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
3755 size
= sizeof(buffer
);
3756 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3757 error
= GetLastError();
3758 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
3759 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3761 ret
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
3762 ok(ret
, "HttpSendRequest failed\n");
3765 size
= sizeof(buffer
);
3766 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
3767 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3768 ok(index
== 1, "expected 1 got %u\n", index
);
3771 size
= sizeof(buffer
);
3772 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
3773 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3774 ok(index
== 1, "expected 1 got %u\n", index
);
3777 size
= sizeof(buffer
);
3778 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, 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_RAW_HEADERS
, buffer
, &size
, &index
);
3784 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3785 ok(index
== 0, "expected 0 got %u\n", index
);
3787 index
= 0xdeadbeef; /* invalid start index */
3788 size
= sizeof(buffer
);
3789 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3790 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
3791 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
3792 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
3795 size
= sizeof(buffer
);
3796 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
3797 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3798 ok(index
== 0, "expected 0 got %u\n", index
);
3800 size
= sizeof(buffer
);
3801 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3802 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3803 ok(index
== 0, "expected 0 got %u\n", index
);
3805 size
= sizeof(buffer
);
3806 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
3807 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3808 ok(index
== 0, "expected 0 got %u\n", index
);
3810 test_status_code(hr
, 200);
3813 size
= sizeof(buffer
);
3814 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
3815 ok(!ret
, "HttpQueryInfo succeeded\n");
3816 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
3819 size
= sizeof(buffer
);
3820 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
3821 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3822 ok(index
== 1, "expected 1 got %u\n", index
);
3825 size
= sizeof(buffer
);
3826 strcpy(buffer
, "Server");
3827 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
3828 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3829 ok(index
== 1, "expected 1 got %u\n", index
);
3832 size
= sizeof(buffer
);
3833 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
3834 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3835 ok(index
== 1, "expected 1 got %u\n", index
);
3837 size
= sizeof(buffer
);
3838 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
3839 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3840 ok(index
== 2, "expected 2 got %u\n", index
);
3842 InternetCloseHandle(hr
);
3843 InternetCloseHandle(hc
);
3844 InternetCloseHandle(hi
);
3847 static void test_options(int port
)
3849 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi
;
3850 HINTERNET ses
, con
, req
;
3855 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3856 ok(ses
!= NULL
, "InternetOpen failed\n");
3858 SetLastError(0xdeadbeef);
3859 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
3860 error
= GetLastError();
3861 ok(!ret
, "InternetSetOption succeeded\n");
3862 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3864 SetLastError(0xdeadbeef);
3865 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
3866 ok(!ret
, "InternetSetOption succeeded\n");
3867 error
= GetLastError();
3868 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3870 SetLastError(0xdeadbeef);
3871 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
3872 ok(!ret
, "InternetSetOption succeeded\n");
3873 error
= GetLastError();
3874 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3877 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3878 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3880 SetLastError(0xdeadbeef);
3881 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
3882 error
= GetLastError();
3883 ok(!ret
, "InternetQueryOption succeeded\n");
3884 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3886 SetLastError(0xdeadbeef);
3887 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
3888 error
= GetLastError();
3889 ok(!ret
, "InternetQueryOption succeeded\n");
3890 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3893 SetLastError(0xdeadbeef);
3894 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
3895 error
= GetLastError();
3896 ok(!ret
, "InternetQueryOption succeeded\n");
3897 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
3900 SetLastError(0xdeadbeef);
3901 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3902 error
= GetLastError();
3903 ok(!ret
, "InternetQueryOption succeeded\n");
3904 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
3908 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3909 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3910 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
3912 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3913 ok(con
!= NULL
, "InternetConnect failed\n");
3917 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3918 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3919 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
3922 ret
= InternetSetOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3923 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3927 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3928 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3929 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
3931 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3932 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3936 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3937 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3938 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
3941 ret
= InternetSetOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3942 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3946 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3947 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3948 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
3950 size
= sizeof(idsi
);
3951 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO
, &idsi
, &size
);
3952 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3955 SetLastError(0xdeadbeef);
3956 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
3957 error
= GetLastError();
3958 ok(!ret
, "InternetQueryOption succeeded\n");
3959 ok(error
== ERROR_INTERNET_INVALID_OPERATION
, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error
);
3961 /* INTERNET_OPTION_PROXY */
3962 SetLastError(0xdeadbeef);
3963 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
3964 error
= GetLastError();
3965 ok(!ret
, "InternetQueryOption succeeded\n");
3966 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3968 SetLastError(0xdeadbeef);
3969 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
3970 error
= GetLastError();
3971 ok(!ret
, "InternetQueryOption succeeded\n");
3972 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3975 SetLastError(0xdeadbeef);
3976 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
3977 error
= GetLastError();
3978 ok(!ret
, "InternetQueryOption succeeded\n");
3979 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
3980 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
3982 InternetCloseHandle(req
);
3983 InternetCloseHandle(con
);
3984 InternetCloseHandle(ses
);
3988 const char *response_text
;
3990 const char *status_text
;
3991 const char *raw_headers
;
3992 } http_status_test_t
;
3994 static const http_status_test_t http_status_tests
[] = {
3996 "HTTP/1.1 200 OK\r\n"
3997 "Content-Length: 1\r\n"
4003 "HTTP/1.1 404 Fail\r\n"
4004 "Content-Length: 1\r\n"
4011 "Content-Length: 1\r\n"
4018 "Content-Length: 1\r\n"
4025 static void test_http_status(int port
)
4027 HINTERNET ses
, con
, req
;
4032 for(i
=0; i
< sizeof(http_status_tests
)/sizeof(*http_status_tests
); i
++) {
4033 send_buffer
= http_status_tests
[i
].response_text
;
4035 ses
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4036 ok(ses
!= NULL
, "InternetOpen failed\n");
4038 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4039 ok(con
!= NULL
, "InternetConnect failed\n");
4041 req
= HttpOpenRequestA(con
, NULL
, "/send_from_buffer", NULL
, NULL
, NULL
, 0, 0);
4042 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4044 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4045 ok(res
, "HttpSendRequest failed\n");
4047 test_status_code(req
, http_status_tests
[i
].status_code
);
4050 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_TEXT
, buf
, &size
, NULL
);
4051 ok(res
, "HttpQueryInfo failed: %u\n", GetLastError());
4052 ok(!strcmp(buf
, http_status_tests
[i
].status_text
), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
4053 i
, buf
, http_status_tests
[i
].status_text
);
4055 InternetCloseHandle(req
);
4056 InternetCloseHandle(con
);
4057 InternetCloseHandle(ses
);
4061 static void test_cache_control_verb(int port
)
4063 HINTERNET session
, connect
, request
;
4066 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4067 ok(session
!= NULL
, "InternetOpen failed\n");
4069 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4070 ok(connect
!= NULL
, "InternetConnect failed\n");
4072 request
= HttpOpenRequestA(connect
, "RPC_OUT_DATA", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4073 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4074 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4075 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4076 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4077 test_status_code(request
, 200);
4078 InternetCloseHandle(request
);
4080 request
= HttpOpenRequestA(connect
, "POST", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4081 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4082 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4083 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4084 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4085 test_status_code(request
, 200);
4086 InternetCloseHandle(request
);
4088 request
= HttpOpenRequestA(connect
, "HEAD", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4089 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4090 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4091 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4092 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4093 test_status_code(request
, 200);
4094 InternetCloseHandle(request
);
4096 request
= HttpOpenRequestA(connect
, "GET", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4097 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4098 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4099 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4100 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4101 test_status_code(request
, 200);
4102 InternetCloseHandle(request
);
4104 InternetCloseHandle(connect
);
4105 InternetCloseHandle(session
);
4108 static void test_http_connection(void)
4110 struct server_info si
;
4114 si
.hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
4117 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
4118 ok( hThread
!= NULL
, "create thread failed\n");
4120 r
= WaitForSingleObject(si
.hEvent
, 10000);
4121 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
4122 if (r
!= WAIT_OBJECT_0
)
4125 test_basic_request(si
.port
, "GET", "/test1");
4126 test_proxy_indirect(si
.port
);
4127 test_proxy_direct(si
.port
);
4128 test_header_handling_order(si
.port
);
4129 test_basic_request(si
.port
, "POST", "/test5");
4130 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
4131 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
4132 test_basic_request(si
.port
, "GET", "/test6");
4133 test_basic_request(si
.port
, "GET", "/testF");
4134 test_connection_header(si
.port
);
4135 test_http1_1(si
.port
);
4136 test_cookie_header(si
.port
);
4137 test_basic_authentication(si
.port
);
4138 test_invalid_response_headers(si
.port
);
4139 test_response_without_headers(si
.port
);
4140 test_HttpQueryInfo(si
.port
);
4141 test_HttpSendRequestW(si
.port
);
4142 test_options(si
.port
);
4143 test_no_content(si
.port
);
4144 test_conn_close(si
.port
);
4145 test_no_cache(si
.port
);
4146 test_cache_read_gzipped(si
.port
);
4147 test_http_status(si
.port
);
4148 test_premature_disconnect(si
.port
);
4149 test_connection_closing(si
.port
);
4150 test_cache_control_verb(si
.port
);
4151 test_successive_HttpSendRequest(si
.port
);
4152 test_head_request(si
.port
);
4154 /* send the basic request again to shutdown the server thread */
4155 test_basic_request(si
.port
, "GET", "/quit");
4157 r
= WaitForSingleObject(hThread
, 3000);
4158 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
4159 CloseHandle(hThread
);
4162 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
4164 LocalFree(info
->lpszSubjectInfo
);
4165 LocalFree(info
->lpszIssuerInfo
);
4166 LocalFree(info
->lpszProtocolName
);
4167 LocalFree(info
->lpszSignatureAlgName
);
4168 LocalFree(info
->lpszEncryptionAlgName
);
4172 const char *ex_subject
;
4173 const char *ex_issuer
;
4174 } cert_struct_test_t
;
4176 static const cert_struct_test_t test_winehq_org_cert
= {
4177 "6JcR7G3G8tgjkeoMcitK-bTbzcpumDSy\r\n"
4179 "See www.rapidssl.com/resources/cps (c)14\r\n"
4180 "Domain Control Validated - RapidSSL(R)\r\n"
4184 "\"GeoTrust, Inc.\"\r\n"
4188 static const cert_struct_test_t test_winehq_com_cert
= {
4193 "test.winehq.com\r\n"
4194 "webmaster@winehq.org",
4199 "test.winehq.com\r\n"
4200 "webmaster@winehq.org"
4203 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
4205 INTERNET_CERTIFICATE_INFOA info
;
4209 memset(&info
, 0x5, sizeof(info
));
4211 size
= sizeof(info
);
4212 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
4213 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
4214 ok(size
== sizeof(info
), "size = %u\n", size
);
4216 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
4217 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
4218 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
4219 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
4220 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
4221 ok(info
.dwKeySize
== 128, "dwKeySize = %u\n", info
.dwKeySize
);
4223 release_cert_info(&info
);
4226 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
4227 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
4229 char url
[INTERNET_MAX_URL_LENGTH
];
4230 const CERT_CHAIN_CONTEXT
*chain
;
4234 if(!pInternetGetSecurityInfoByURLA
) {
4235 win_skip("pInternetGetSecurityInfoByURLA not available\n");
4240 chain
= (void*)0xdeadbeef;
4242 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
4243 if(error
== ERROR_SUCCESS
) {
4244 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
4245 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
4246 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
4247 CertFreeCertificateChain(chain
);
4249 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
4250 "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res
, GetLastError(), error
);
4254 #define test_secflags_option(a,b) _test_secflags_option(__LINE__,a,b)
4255 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
)
4261 size
= sizeof(flags
);
4262 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4263 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4264 ok_(__FILE__
,line
)(flags
== ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n", flags
, ex_flags
);
4266 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
4268 size
= sizeof(flags
);
4269 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4270 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
4271 ok_(__FILE__
,line
)(flags
== ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n", flags
, ex_flags
);
4274 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
4275 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
4279 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
4280 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4283 static void test_security_flags(void)
4285 INTERNET_CERTIFICATE_INFOA
*cert
;
4286 HINTERNET ses
, conn
, req
;
4291 trace("Testing security flags...\n");
4293 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4295 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4296 ok(ses
!= NULL
, "InternetOpen failed\n");
4298 pInternetSetStatusCallbackA(ses
, &callback
);
4300 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4301 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
4302 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
4303 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
4304 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4306 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4307 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4308 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4310 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4311 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4314 size
= sizeof(flags
);
4315 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4316 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
4317 win_skip("Incomplete security flags support, skipping\n");
4319 close_async_handle(ses
, hCompleteEvent
, 2);
4320 CloseHandle(hCompleteEvent
);
4324 test_secflags_option(req
, 0);
4325 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4327 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4328 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
);
4330 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4331 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4333 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4334 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4336 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
4337 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
4338 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
4340 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
4341 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
4342 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4343 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4344 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
4345 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
4346 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
4347 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
4348 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4349 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4350 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4351 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4352 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4353 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4354 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4356 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4357 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4359 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4360 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4362 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
4363 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
4364 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
4365 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
4366 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4367 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4368 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4369 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4370 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4371 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4372 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4373 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4374 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4376 test_request_flags(req
, 0);
4377 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4378 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
);
4380 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4381 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4382 ok(size
, "size = 0\n");
4384 /* Collect all existing persistent connections */
4385 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4386 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4388 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4389 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4390 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4392 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4393 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4395 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
4396 res
= InternetSetOptionA(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
4397 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
4399 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4400 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4401 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
4402 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
4403 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
4404 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
4405 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4406 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4407 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4408 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4409 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4411 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4412 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4414 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4415 ok(req_error
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| broken(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
),
4416 "req_error = %d\n", req_error
);
4419 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
4420 ok(res
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4421 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %u\n", size
);
4422 cert
= HeapAlloc(GetProcessHeap(), 0, size
);
4423 cert
->lpszSubjectInfo
= NULL
;
4424 cert
->lpszIssuerInfo
= NULL
;
4425 cert
->lpszSignatureAlgName
= (char *)0xdeadbeef;
4426 cert
->lpszEncryptionAlgName
= (char *)0xdeadbeef;
4427 cert
->lpszProtocolName
= (char *)0xdeadbeef;
4428 cert
->dwKeySize
= 0xdeadbeef;
4429 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, cert
, &size
);
4430 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
4433 ok(cert
->lpszSubjectInfo
&& strlen(cert
->lpszSubjectInfo
) > 1, "expected a non-empty subject name\n");
4434 ok(cert
->lpszIssuerInfo
&& strlen(cert
->lpszIssuerInfo
) > 1, "expected a non-empty issuer name\n");
4435 ok(!cert
->lpszSignatureAlgName
, "unexpected signature algorithm name\n");
4436 ok(!cert
->lpszEncryptionAlgName
, "unexpected encryption algorithm name\n");
4437 ok(!cert
->lpszProtocolName
, "unexpected protocol name\n");
4438 ok(cert
->dwKeySize
!= 0xdeadbeef, "unexpected key size\n");
4440 HeapFree(GetProcessHeap(), 0, cert
);
4442 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
4443 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
4444 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
4445 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
4446 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4447 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4448 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4450 if(req_error
!= ERROR_INTERNET_SEC_CERT_REV_FAILED
) {
4451 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error
);
4453 close_async_handle(ses
, hCompleteEvent
, 3);
4454 CloseHandle(hCompleteEvent
);
4459 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
4460 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
4462 test_request_flags(req
, 8);
4463 test_secflags_option(req
, 0x800000);
4465 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4466 test_secflags_option(req
, 0x800000|SECURITY_FLAG_IGNORE_REVOCATION
);
4468 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4469 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4470 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4471 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4472 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4473 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4474 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4476 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4477 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4479 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4480 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
4482 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4483 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4484 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4485 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4486 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4487 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4488 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4490 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
4491 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4492 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4494 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4495 test_secflags_option(req
, 0x1800000|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4496 |SECURITY_FLAG_IGNORE_REVOCATION
);
4497 test_http_version(req
);
4499 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4500 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4501 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
4502 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
4503 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
4504 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
4505 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4506 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4507 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4508 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4509 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4510 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4511 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4513 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4514 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4516 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4517 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4519 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
4520 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
4521 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4522 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4523 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4524 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4525 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4526 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4527 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4528 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4529 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4531 test_request_flags(req
, 0);
4532 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
4533 |SECURITY_FLAG_STRENGTH_STRONG
|0x1800000);
4535 test_cert_struct(req
, &test_winehq_com_cert
);
4536 test_security_info("https://test.winehq.com/data/some_file.html?q", 0, 0x1800000);
4538 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4539 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4540 ok(size
, "size = 0\n");
4542 close_async_handle(ses
, hCompleteEvent
, 3);
4544 /* Collect all existing persistent connections */
4545 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4546 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4548 /* Make another request, without setting security flags */
4550 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4551 ok(ses
!= NULL
, "InternetOpen failed\n");
4553 pInternetSetStatusCallbackA(ses
, &callback
);
4555 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4556 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
4557 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
4558 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
4559 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4561 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4562 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4563 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4565 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4566 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4568 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
4569 |SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4570 test_http_version(req
);
4572 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4573 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4574 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
4575 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
4576 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
4577 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
4578 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4579 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4580 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4581 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4582 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4583 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4585 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4586 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4588 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4589 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4591 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
4592 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
4593 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4594 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4595 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4596 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4597 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4598 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4599 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4600 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4602 test_request_flags(req
, 0);
4603 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
4604 |SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4606 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4607 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4608 ok(size
, "size = 0\n");
4610 close_async_handle(ses
, hCompleteEvent
, 2);
4612 CloseHandle(hCompleteEvent
);
4614 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4615 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4616 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4619 static void test_secure_connection(void)
4621 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
4622 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
4623 static const WCHAR get
[] = {'G','E','T',0};
4624 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
4625 HINTERNET ses
, con
, req
;
4627 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
4628 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
4631 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4632 ok(ses
!= NULL
, "InternetOpen failed\n");
4634 con
= InternetConnectA(ses
, "test.winehq.org",
4635 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
4636 INTERNET_SERVICE_HTTP
, 0, 0);
4637 ok(con
!= NULL
, "InternetConnect failed\n");
4639 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4640 INTERNET_FLAG_SECURE
, 0);
4641 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4643 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4644 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
4646 size
= sizeof(flags
);
4647 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4648 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4649 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
4651 test_cert_struct(req
, &test_winehq_org_cert
);
4653 /* Querying the same option through InternetQueryOptionW still results in
4654 * ASCII strings being returned.
4657 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4659 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4660 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
4661 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
4662 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4663 certificate_structW
, &size
);
4664 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
4665 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4668 ok(certificate_structA
->lpszSubjectInfo
&&
4669 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4670 "expected a non-empty subject name\n");
4671 ok(certificate_structA
->lpszIssuerInfo
&&
4672 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4673 "expected a non-empty issuer name\n");
4674 ok(!certificate_structA
->lpszSignatureAlgName
,
4675 "unexpected signature algorithm name\n");
4676 ok(!certificate_structA
->lpszEncryptionAlgName
,
4677 "unexpected encryption algorithm name\n");
4678 ok(!certificate_structA
->lpszProtocolName
,
4679 "unexpected protocol name\n");
4680 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4681 release_cert_info(certificate_structA
);
4683 HeapFree(GetProcessHeap(), 0, certificate_structW
);
4685 InternetCloseHandle(req
);
4686 InternetCloseHandle(con
);
4687 InternetCloseHandle(ses
);
4689 /* Repeating the tests with the W functions has the same result: */
4690 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4691 ok(ses
!= NULL
, "InternetOpen failed\n");
4693 con
= InternetConnectW(ses
, testsite
,
4694 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
4695 INTERNET_SERVICE_HTTP
, 0, 0);
4696 ok(con
!= NULL
, "InternetConnect failed\n");
4698 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
4699 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
4700 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4702 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4703 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
4705 size
= sizeof(flags
);
4706 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4707 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4708 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %x\n", flags
);
4710 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4712 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4713 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
4714 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
4715 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4716 certificate_structA
, &size
);
4717 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4720 ok(certificate_structA
->lpszSubjectInfo
&&
4721 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4722 "expected a non-empty subject name\n");
4723 ok(certificate_structA
->lpszIssuerInfo
&&
4724 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4725 "expected a non-empty issuer name\n");
4726 ok(!certificate_structA
->lpszSignatureAlgName
,
4727 "unexpected signature algorithm name\n");
4728 ok(!certificate_structA
->lpszEncryptionAlgName
,
4729 "unexpected encryption algorithm name\n");
4730 ok(!certificate_structA
->lpszProtocolName
,
4731 "unexpected protocol name\n");
4732 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4733 release_cert_info(certificate_structA
);
4735 HeapFree(GetProcessHeap(), 0, certificate_structA
);
4737 /* Again, querying the same option through InternetQueryOptionW still
4738 * results in ASCII strings being returned.
4741 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4743 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4744 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
4745 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
4746 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4747 certificate_structW
, &size
);
4748 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
4749 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4752 ok(certificate_structA
->lpszSubjectInfo
&&
4753 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4754 "expected a non-empty subject name\n");
4755 ok(certificate_structA
->lpszIssuerInfo
&&
4756 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4757 "expected a non-empty issuer name\n");
4758 ok(!certificate_structA
->lpszSignatureAlgName
,
4759 "unexpected signature algorithm name\n");
4760 ok(!certificate_structA
->lpszEncryptionAlgName
,
4761 "unexpected encryption algorithm name\n");
4762 ok(!certificate_structA
->lpszProtocolName
,
4763 "unexpected protocol name\n");
4764 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4765 release_cert_info(certificate_structA
);
4767 HeapFree(GetProcessHeap(), 0, certificate_structW
);
4769 InternetCloseHandle(req
);
4770 InternetCloseHandle(con
);
4771 InternetCloseHandle(ses
);
4774 static void test_user_agent_header(void)
4776 HINTERNET ses
, con
, req
;
4781 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4782 ok(ses
!= NULL
, "InternetOpen failed\n");
4784 con
= InternetConnectA(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4785 ok(con
!= NULL
, "InternetConnect failed\n");
4787 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
4788 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4790 size
= sizeof(buffer
);
4791 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4792 err
= GetLastError();
4793 ok(!ret
, "HttpQueryInfo succeeded\n");
4794 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4796 ret
= HttpAddRequestHeadersA(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
4797 ok(ret
, "HttpAddRequestHeaders succeeded\n");
4799 size
= sizeof(buffer
);
4800 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4801 err
= GetLastError();
4802 ok(ret
, "HttpQueryInfo failed\n");
4803 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4805 InternetCloseHandle(req
);
4807 req
= HttpOpenRequestA(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
4808 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4810 size
= sizeof(buffer
);
4811 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4812 err
= GetLastError();
4813 ok(!ret
, "HttpQueryInfo succeeded\n");
4814 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4816 ret
= HttpAddRequestHeadersA(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
4817 ok(ret
, "HttpAddRequestHeaders failed\n");
4820 size
= sizeof(buffer
);
4821 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4822 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
4823 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
4825 InternetCloseHandle(req
);
4826 InternetCloseHandle(con
);
4827 InternetCloseHandle(ses
);
4830 static void test_bogus_accept_types_array(void)
4832 HINTERNET ses
, con
, req
;
4833 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
4838 ses
= InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
4839 con
= InternetConnectA(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4840 req
= HttpOpenRequestA(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
4842 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
4845 size
= sizeof(buffer
);
4846 SetLastError(0xdeadbeef);
4847 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4848 error
= GetLastError();
4849 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
4850 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
4851 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
4852 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
4853 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
4855 InternetCloseHandle(req
);
4856 InternetCloseHandle(con
);
4857 InternetCloseHandle(ses
);
4866 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
4868 INTERNET_ASYNC_RESULT
*result
= info
;
4869 struct context
*ctx
= (struct context
*)context
;
4871 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
4874 case INTERNET_STATUS_REQUEST_COMPLETE
:
4875 trace("request handle: 0x%08lx\n", result
->dwResult
);
4876 ctx
->req
= (HINTERNET
)result
->dwResult
;
4877 SetEvent(ctx
->event
);
4879 case INTERNET_STATUS_HANDLE_CLOSING
: {
4880 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
4882 if (InternetQueryOptionA(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
4883 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
4884 SetEvent(ctx
->event
);
4887 case INTERNET_STATUS_NAME_RESOLVED
:
4888 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
4889 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
4891 ok(str
[0] && str
[1], "Got string: %s\n", str
);
4892 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
4897 static void test_open_url_async(void)
4905 /* Collect all existing persistent connections */
4906 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4907 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4910 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
4911 * other versions never do. They also hang of following tests. We disable it for everything older
4914 if(!pInternetGetSecurityInfoByURLA
) {
4915 win_skip("Skipping async open on too old wininet version.\n");
4920 ctx
.event
= CreateEventA(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
4922 ses
= InternetOpenA("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4923 ok(ses
!= NULL
, "InternetOpen failed\n");
4925 SetLastError(0xdeadbeef);
4926 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
4927 error
= GetLastError();
4928 ok(!ret
, "InternetSetOptionA succeeded\n");
4929 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
4931 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
4932 error
= GetLastError();
4933 ok(!ret
, "InternetSetOptionA failed\n");
4934 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
4936 pInternetSetStatusCallbackW(ses
, cb
);
4937 ResetEvent(ctx
.event
);
4939 req
= InternetOpenUrlA(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
4940 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
4942 WaitForSingleObject(ctx
.event
, INFINITE
);
4945 size
= sizeof(type
);
4946 ret
= InternetQueryOptionA(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
4947 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
4948 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
4949 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
4952 ret
= HttpQueryInfoA(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
4953 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
4954 ok(size
> 0, "expected size > 0\n");
4956 ResetEvent(ctx
.event
);
4957 InternetCloseHandle(ctx
.req
);
4958 WaitForSingleObject(ctx
.event
, INFINITE
);
4960 InternetCloseHandle(ses
);
4961 CloseHandle(ctx
.event
);
4966 internet_connect
= 1,
4968 http_send_request_ex
,
4971 internet_close_handle
4976 enum api function
; /* api responsible for notification */
4977 unsigned int status
; /* status received */
4978 BOOL async
; /* delivered from another thread? */
4986 const struct notification
*test
;
4992 DWORD expect_result
;
4996 static CRITICAL_SECTION notification_cs
;
4998 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
5000 BOOL status_ok
, function_ok
;
5001 struct info
*info
= (struct info
*)context
;
5004 EnterCriticalSection( ¬ification_cs
);
5006 if(info
->is_aborted
) {
5007 LeaveCriticalSection(¬ification_cs
);
5011 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
5013 DWORD size
= sizeof(struct info
*);
5014 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
5015 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
5016 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
5018 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
5019 if(info
->expect_result
== ERROR_SUCCESS
) {
5020 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
5022 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
5023 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
5028 if (i
>= info
->count
)
5030 LeaveCriticalSection( ¬ification_cs
);
5034 while (info
->test
[i
].status
!= status
&&
5035 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
5036 i
< info
->count
- 1 &&
5037 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
5042 status_ok
= (info
->test
[i
].status
== status
);
5043 function_ok
= (info
->test
[i
].function
== info
->function
);
5045 if (!info
->test
[i
].todo
)
5047 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
5048 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
5050 if (info
->test
[i
].async
)
5051 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
5052 info
->line
, info
->thread
, GetCurrentThreadId());
5056 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
5058 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
5060 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
5063 LeaveCriticalSection( ¬ification_cs
);
5066 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
5068 info
->function
= function
;
5070 info
->expect_result
= expect_result
;
5073 struct notification_data
5075 const struct notification
*test
;
5076 const unsigned int count
;
5081 BOOL expect_conn_failure
;
5084 static const struct notification async_send_request_ex_test
[] =
5086 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5087 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5088 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5089 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
5090 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
5091 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
5092 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
5093 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
5094 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
5095 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
5096 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5097 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, FALSE
},
5098 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, FALSE
},
5099 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
5100 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
5101 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5102 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
5103 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
5104 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
5105 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
5108 static const struct notification async_send_request_ex_test2
[] =
5110 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5111 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5112 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5113 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
5114 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
5115 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
5116 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
, TRUE
},
5117 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
, TRUE
},
5118 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
5119 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
5120 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5121 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
5122 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
5123 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5124 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
5125 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
5126 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
5127 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
5130 static const struct notification async_send_request_ex_resolve_failure_test
[] =
5132 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5133 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5134 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5135 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
},
5136 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5137 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5138 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5139 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
5140 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
5141 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
5142 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
5145 static const struct notification async_send_request_ex_chunked_test
[] =
5147 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
},
5148 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
},
5149 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5150 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
5151 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
5152 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
5153 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
5154 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
5155 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
5156 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
5157 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5158 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
5159 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
5160 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5161 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
},
5162 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
},
5163 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
},
5164 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
}
5167 static const struct notification_data notification_data
[] = {
5169 async_send_request_ex_chunked_test
,
5170 sizeof(async_send_request_ex_chunked_test
)/sizeof(async_send_request_ex_chunked_test
[0]),
5176 async_send_request_ex_test
,
5177 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
5181 "Public ID=codeweavers"
5184 async_send_request_ex_test2
,
5185 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
5191 async_send_request_ex_resolve_failure_test
,
5192 sizeof(async_send_request_ex_resolve_failure_test
)/sizeof(async_send_request_ex_resolve_failure_test
[0]),
5201 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
5204 HINTERNET ses
, req
, con
;
5206 DWORD size
, written
, error
;
5207 INTERNET_BUFFERSA b
;
5208 static const char *accept
[2] = {"*/*", NULL
};
5211 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
5213 InitializeCriticalSection( ¬ification_cs
);
5215 info
.test
= nd
->test
;
5216 info
.count
= nd
->count
;
5218 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
5219 info
.thread
= GetCurrentThreadId();
5220 info
.is_aborted
= FALSE
;
5222 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5223 ok( ses
!= NULL
, "InternetOpen failed\n" );
5225 pInternetSetStatusCallbackA( ses
, check_notification
);
5227 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
5228 con
= InternetConnectA( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
5229 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
5231 WaitForSingleObject( info
.wait
, 10000 );
5233 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
5234 req
= HttpOpenRequestA( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
5235 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
5237 WaitForSingleObject( info
.wait
, 10000 );
5240 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
5241 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
5242 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
5243 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
5244 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
5247 setup_test( &info
, http_send_request_ex
, __LINE__
,
5248 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
5249 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
5250 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
5252 error
= WaitForSingleObject( info
.wait
, 10000 );
5253 if(error
!= WAIT_OBJECT_0
) {
5254 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
5255 info
.is_aborted
= TRUE
;
5259 size
= sizeof(buffer
);
5260 SetLastError( 0xdeadbeef );
5261 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
5262 error
= GetLastError();
5263 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
5264 if(nd
->expect_conn_failure
) {
5265 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
5268 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
5269 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
5275 size
= strlen( nd
->data
);
5276 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
5277 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
5278 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
5279 ok( written
== size
, "expected %u got %u\n", written
, size
);
5281 WaitForSingleObject( info
.wait
, 10000 );
5283 SetLastError( 0xdeadbeef );
5284 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
5285 error
= GetLastError();
5286 ok( !ret
, "HttpEndRequestA succeeded\n" );
5287 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
5290 SetLastError( 0xdeadbeef );
5291 setup_test( &info
, http_end_request
, __LINE__
,
5292 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
5293 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
5294 error
= GetLastError();
5295 ok( !ret
, "HttpEndRequestA succeeded\n" );
5296 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
5298 WaitForSingleObject( info
.wait
, 10000 );
5300 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
5302 InternetCloseHandle( req
);
5303 InternetCloseHandle( con
);
5304 InternetCloseHandle( ses
);
5306 WaitForSingleObject( info
.wait
, 10000 );
5308 CloseHandle( info
.wait
);
5311 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
5312 static BOOL closetest_closed
;
5314 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
5315 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
5320 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
5322 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
5323 "Unexpected hInternet %p\n", hInternet
);
5324 if(!closetest_closed
)
5328 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
5329 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
5330 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5331 closetest_req
, res
, GetLastError());
5334 static void test_InternetCloseHandle(void)
5339 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5340 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
5342 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
5344 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
5345 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
5346 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
5348 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
5349 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
5351 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
5352 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
5353 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
5355 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
5357 res
= InternetCloseHandle(closetest_session
);
5358 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
5359 closetest_closed
= TRUE
;
5360 trace("Closed session handle\n");
5362 res
= InternetCloseHandle(closetest_conn
);
5363 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
5364 res
, GetLastError());
5366 res
= InternetCloseHandle(closetest_req
);
5367 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
5368 res
, GetLastError());
5370 len
= sizeof(flags
);
5371 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
5372 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
5373 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5374 closetest_req
, res
, GetLastError());
5377 static void test_connection_failure(void)
5379 HINTERNET session
, connect
, request
;
5383 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5384 ok(session
!= NULL
, "failed to get session handle\n");
5386 connect
= InternetConnectA(session
, "localhost", 1, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5387 ok(connect
!= NULL
, "failed to get connection handle\n");
5389 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
5390 ok(request
!= NULL
, "failed to get request handle\n");
5392 SetLastError(0xdeadbeef);
5393 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
5394 error
= GetLastError();
5395 ok(!ret
, "unexpected success\n");
5396 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
5398 InternetCloseHandle(request
);
5399 InternetCloseHandle(connect
);
5400 InternetCloseHandle(session
);
5403 static void test_default_service_port(void)
5405 HINTERNET session
, connect
, request
;
5409 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
5410 ok(session
!= NULL
, "InternetOpen failed\n");
5412 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
5413 INTERNET_SERVICE_HTTP
, 0, 0);
5414 ok(connect
!= NULL
, "InternetConnect failed\n");
5416 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
5417 ok(request
!= NULL
, "HttpOpenRequest failed\n");
5419 SetLastError(0xdeadbeef);
5420 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
5421 error
= GetLastError();
5422 ok(!ret
, "HttpSendRequest succeeded\n");
5423 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
5426 InternetCloseHandle(request
);
5427 InternetCloseHandle(connect
);
5428 InternetCloseHandle(session
);
5431 static void init_status_tests(void)
5433 memset(expect
, 0, sizeof(expect
));
5434 memset(optional
, 0, sizeof(optional
));
5435 memset(wine_allow
, 0, sizeof(wine_allow
));
5436 memset(notified
, 0, sizeof(notified
));
5437 memset(status_string
, 0, sizeof(status_string
));
5439 #define STATUS_STRING(status) status_string[status] = #status
5440 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
5441 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
5442 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5443 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5444 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
5445 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
5446 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
5447 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
5448 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
5449 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
5450 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
5451 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
5452 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
5453 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
5454 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
5455 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
5456 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
5457 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
5458 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
5459 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
5460 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
5461 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
5462 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
5463 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
5464 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
5465 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
5466 #undef STATUS_STRING
5472 hdll
= GetModuleHandleA("wininet.dll");
5474 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
5475 win_skip("Too old IE (older than 6.0)\n");
5479 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
5480 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
5481 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
5483 init_status_tests();
5484 test_InternetCloseHandle();
5485 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
5486 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
5487 InternetReadFile_test(0, &test_data
[1]);
5488 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
5489 test_security_flags();
5490 InternetReadFile_test(0, &test_data
[2]);
5491 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
5492 test_open_url_async();
5493 test_async_HttpSendRequestEx(¬ification_data
[0]);
5494 test_async_HttpSendRequestEx(¬ification_data
[1]);
5495 test_async_HttpSendRequestEx(¬ification_data
[2]);
5496 test_async_HttpSendRequestEx(¬ification_data
[3]);
5497 InternetOpenRequest_test();
5499 InternetLockRequestFile_test();
5500 InternetOpenUrlA_test();
5502 test_http_connection();
5503 test_secure_connection();
5504 test_user_agent_header();
5505 test_bogus_accept_types_array();
5506 InternetReadFile_chunked_test();
5507 HttpSendRequestEx_test();
5508 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
5509 test_connection_failure();
5510 test_default_service_port();