4 * Copyright 2002 Aric Stewart
5 * Copyright 2004 Mike McCormack
6 * Copyright 2005 Hans Leidekker
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/test.h"
35 #define TEST_URL "http://test.winehq.org/tests/hello.html"
37 static BOOL first_connection_to_test_url
= TRUE
;
39 /* Adapted from dlls/urlmon/tests/protocol.c */
41 #define SET_EXPECT2(status, num) \
44 #define SET_EXPECT(status) \
45 SET_EXPECT2(status, 1)
47 #define SET_OPTIONAL2(status, num) \
48 optional[status] = num
50 #define SET_OPTIONAL(status) \
51 SET_OPTIONAL2(status, 1)
53 /* SET_WINE_ALLOW's should be used with an appropriate
54 * todo_wine CHECK_NOTIFIED at a later point in the code */
55 #define SET_WINE_ALLOW2(status, num) \
56 wine_allow[status] = num
58 #define SET_WINE_ALLOW(status) \
59 SET_WINE_ALLOW2(status, 1)
61 #define CHECK_EXPECT(status) \
63 if (!expect[status] && !optional[status] && wine_allow[status]) \
65 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
66 status < MAX_INTERNET_STATUS && status_string[status] ? \
67 status_string[status] : "unknown"); \
68 wine_allow[status]--; \
72 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
73 status < MAX_INTERNET_STATUS && status_string[status] ? \
74 status_string[status] : "unknown"); \
75 if (expect[status]) expect[status]--; \
76 else optional[status]--; \
81 /* CLEAR_NOTIFIED used in cases when notification behavior
82 * differs between Windows versions */
83 #define CLEAR_NOTIFIED(status) \
84 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
86 #define CHECK_NOTIFIED2(status, num) \
88 ok(notified[status] + optional[status] == (num), \
89 "expected status %d (%s) %d times, received %d times\n", \
90 status, status < MAX_INTERNET_STATUS && status_string[status] ? \
91 status_string[status] : "unknown", (num), notified[status]); \
92 CLEAR_NOTIFIED(status); \
95 #define CHECK_NOTIFIED(status) \
96 CHECK_NOTIFIED2(status, 1)
98 #define CHECK_NOT_NOTIFIED(status) \
99 CHECK_NOTIFIED2(status, 0)
101 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
102 static int expect
[MAX_INTERNET_STATUS
], optional
[MAX_INTERNET_STATUS
],
103 wine_allow
[MAX_INTERNET_STATUS
], notified
[MAX_INTERNET_STATUS
];
104 static const char *status_string
[MAX_INTERNET_STATUS
];
106 static HANDLE hCompleteEvent
, conn_close_event
;
107 static DWORD req_error
;
109 #define TESTF_REDIRECT 0x01
110 #define TESTF_COMPRESSED 0x02
111 #define TESTF_CHUNKED 0x04
115 const char *redirected_url
;
120 const char *post_data
;
124 static const test_data_t test_data
[] = {
126 "http://test.winehq.org/tests/data.php",
127 "http://test.winehq.org/tests/data.php",
134 "http://test.winehq.org/tests/redirect",
135 "http://test.winehq.org/tests/hello.html",
142 "http://www.codeweavers.com/",
143 "http://www.codeweavers.com/",
144 "www.codeweavers.com",
146 "Accept-Encoding: gzip, deflate",
150 "http://test.winehq.org/tests/post.php",
151 "http://test.winehq.org/tests/post.php",
154 "Content-Type: application/x-www-form-urlencoded",
161 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackA
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
162 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackW
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
163 static BOOL (WINAPI
*pInternetGetSecurityInfoByURLA
)(LPSTR
,PCCERT_CHAIN_CONTEXT
*,DWORD
*);
165 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
168 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
169 return lstrcmpW(strw
, buf
);
172 static BOOL
proxy_active(void)
174 HKEY internet_settings
;
178 if (RegOpenKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
179 0, KEY_QUERY_VALUE
, &internet_settings
) != ERROR_SUCCESS
)
182 size
= sizeof(DWORD
);
183 if (RegQueryValueExA(internet_settings
, "ProxyEnable", NULL
, NULL
, (LPBYTE
) &proxy_enable
, &size
) != ERROR_SUCCESS
)
186 RegCloseKey(internet_settings
);
188 return proxy_enable
!= 0;
191 #define test_status_code(a,b) _test_status_code(__LINE__,a,b, FALSE)
192 #define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)
193 static void _test_status_code(unsigned line
, HINTERNET req
, DWORD excode
, BOOL is_todo
)
195 DWORD code
, size
, index
;
196 char exbuf
[10], bufa
[10];
202 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, NULL
);
203 ok_(__FILE__
,line
)(res
, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
205 todo_wine
ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
207 ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
208 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
213 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
214 ok_(__FILE__
,line
)(res
, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
216 todo_wine
ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
218 ok_(__FILE__
,line
)(!index
, "index = %d, expected 0\n", code
);
219 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
221 sprintf(exbuf
, "%u", excode
);
224 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, bufa
, &size
, NULL
);
225 ok_(__FILE__
,line
)(res
, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
227 todo_wine
ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
229 ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
230 ok_(__FILE__
,line
)(size
== strlen(exbuf
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
233 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
234 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
235 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
236 ok_(__FILE__
,line
)(size
== strlen(exbuf
)+1, "unexpected size %d for \"%s\"\n", size
, exbuf
);
239 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
240 ok_(__FILE__
,line
)(res
, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
242 todo_wine
ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
244 ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
245 ok_(__FILE__
,line
)(size
== strlen(exbuf
)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
248 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
249 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
250 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
251 ok_(__FILE__
,line
)(size
== (strlen(exbuf
)+1)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
255 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
256 ok(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
257 ok(size
== sizeof(bufw
), "unexpected size %d\n", size
);
263 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
264 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
265 "[7] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
269 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, &code
, &size
, NULL
);
270 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST
,
271 "[8] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
274 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
275 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
276 static void _test_request_flags(unsigned line
, HINTERNET req
, DWORD exflags
, BOOL is_todo
)
282 size
= sizeof(flags
);
283 res
= InternetQueryOptionW(req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &size
);
284 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
286 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
287 flags
&= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED
;
289 ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
291 todo_wine
ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
294 #define test_http_version(a) _test_http_version(__LINE__,a)
295 static void _test_http_version(unsigned line
, HINTERNET req
)
297 HTTP_VERSION_INFO v
= {0xdeadbeef, 0xdeadbeef};
302 res
= InternetQueryOptionW(req
, INTERNET_OPTION_HTTP_VERSION
, &v
, &size
);
303 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
304 ok_(__FILE__
,line
)(v
.dwMajorVersion
== 1, "dwMajorVersion = %d\n", v
.dwMajorVersion
);
305 ok_(__FILE__
,line
)(v
.dwMinorVersion
== 1, "dwMinorVersion = %d\n", v
.dwMinorVersion
);
308 static int close_handle_cnt
;
310 static VOID WINAPI
callback(
313 DWORD dwInternetStatus
,
314 LPVOID lpvStatusInformation
,
315 DWORD dwStatusInformationLength
318 CHECK_EXPECT(dwInternetStatus
);
319 switch (dwInternetStatus
)
321 case INTERNET_STATUS_RESOLVING_NAME
:
322 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
323 GetCurrentThreadId(), hInternet
, dwContext
,
324 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
325 *(LPSTR
)lpvStatusInformation
= '\0';
327 case INTERNET_STATUS_NAME_RESOLVED
:
328 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
329 GetCurrentThreadId(), hInternet
, dwContext
,
330 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
331 *(LPSTR
)lpvStatusInformation
= '\0';
333 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
334 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
335 GetCurrentThreadId(), hInternet
, dwContext
,
336 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
337 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
338 dwStatusInformationLength
);
339 *(LPSTR
)lpvStatusInformation
= '\0';
341 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
342 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
343 GetCurrentThreadId(), hInternet
, dwContext
,
344 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
345 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
346 dwStatusInformationLength
);
347 *(LPSTR
)lpvStatusInformation
= '\0';
349 case INTERNET_STATUS_SENDING_REQUEST
:
350 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
351 GetCurrentThreadId(), hInternet
, dwContext
,
352 lpvStatusInformation
,dwStatusInformationLength
);
354 case INTERNET_STATUS_REQUEST_SENT
:
355 ok(dwStatusInformationLength
== sizeof(DWORD
),
356 "info length should be sizeof(DWORD) instead of %d\n",
357 dwStatusInformationLength
);
358 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
359 GetCurrentThreadId(), hInternet
, dwContext
,
360 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
362 case INTERNET_STATUS_RECEIVING_RESPONSE
:
363 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
364 GetCurrentThreadId(), hInternet
, dwContext
,
365 lpvStatusInformation
,dwStatusInformationLength
);
367 case INTERNET_STATUS_RESPONSE_RECEIVED
:
368 ok(dwStatusInformationLength
== sizeof(DWORD
),
369 "info length should be sizeof(DWORD) instead of %d\n",
370 dwStatusInformationLength
);
371 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
372 GetCurrentThreadId(), hInternet
, dwContext
,
373 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
375 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
376 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
377 GetCurrentThreadId(), hInternet
,dwContext
,
378 lpvStatusInformation
,dwStatusInformationLength
);
380 case INTERNET_STATUS_PREFETCH
:
381 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
382 GetCurrentThreadId(), hInternet
, dwContext
,
383 lpvStatusInformation
,dwStatusInformationLength
);
385 case INTERNET_STATUS_CLOSING_CONNECTION
:
386 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
387 GetCurrentThreadId(), hInternet
, dwContext
,
388 lpvStatusInformation
,dwStatusInformationLength
);
390 case INTERNET_STATUS_CONNECTION_CLOSED
:
391 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
392 GetCurrentThreadId(), hInternet
, dwContext
,
393 lpvStatusInformation
,dwStatusInformationLength
);
395 case INTERNET_STATUS_HANDLE_CREATED
:
396 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
397 "info length should be sizeof(HINTERNET) instead of %d\n",
398 dwStatusInformationLength
);
399 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
400 GetCurrentThreadId(), hInternet
, dwContext
,
401 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
402 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
403 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
405 case INTERNET_STATUS_HANDLE_CLOSING
:
406 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
407 "info length should be sizeof(HINTERNET) instead of %d\n",
408 dwStatusInformationLength
);
409 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
410 GetCurrentThreadId(), hInternet
, dwContext
,
411 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
412 if(!InterlockedDecrement(&close_handle_cnt
))
413 SetEvent(hCompleteEvent
);
415 case INTERNET_STATUS_REQUEST_COMPLETE
:
417 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
418 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
419 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
420 dwStatusInformationLength
);
421 ok(iar
->dwResult
== 1 || iar
->dwResult
== 0, "iar->dwResult = %ld\n", iar
->dwResult
);
422 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
423 GetCurrentThreadId(), hInternet
, dwContext
,
424 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
425 req_error
= iar
->dwError
;
426 if(!close_handle_cnt
)
427 SetEvent(hCompleteEvent
);
430 case INTERNET_STATUS_REDIRECT
:
431 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
432 GetCurrentThreadId(), hInternet
, dwContext
,
433 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
434 *(LPSTR
)lpvStatusInformation
= '\0';
435 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
436 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
438 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
439 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
440 GetCurrentThreadId(), hInternet
, dwContext
,
441 lpvStatusInformation
, dwStatusInformationLength
);
444 trace("%04x:Callback %p 0x%lx %d %p %d\n",
445 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
446 lpvStatusInformation
, dwStatusInformationLength
);
450 static void close_async_handle(HINTERNET handle
, HANDLE complete_event
, int handle_cnt
)
454 close_handle_cnt
= handle_cnt
;
456 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
457 res
= InternetCloseHandle(handle
);
458 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
459 WaitForSingleObject(hCompleteEvent
, INFINITE
);
460 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
463 static void InternetReadFile_test(int flags
, const test_data_t
*test
)
465 char *post_data
= NULL
;
466 BOOL res
, on_async
= TRUE
;
468 DWORD length
, exlen
= 0, post_len
= 0;
469 const char *types
[2] = { "*", NULL
};
470 HINTERNET hi
, hic
= 0, hor
= 0;
472 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
474 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags
,test
->url
);
476 trace("InternetOpenA <--\n");
477 hi
= InternetOpenA((test
->flags
& TESTF_COMPRESSED
) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
478 INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
479 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
480 trace("InternetOpenA -->\n");
482 if (hi
== 0x0) goto abort
;
484 pInternetSetStatusCallbackA(hi
,&callback
);
486 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
488 trace("InternetConnectA <--\n");
489 hic
=InternetConnectA(hi
, test
->host
, INTERNET_INVALID_PORT_NUMBER
,
490 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
491 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
492 trace("InternetConnectA -->\n");
494 if (hic
== 0x0) goto abort
;
496 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
497 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
499 trace("HttpOpenRequestA <--\n");
500 hor
= HttpOpenRequestA(hic
, test
->post_data
? "POST" : "GET", test
->path
, NULL
, NULL
, types
,
501 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
503 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
505 * If the internet name can't be resolved we are probably behind
506 * a firewall or in some other way not directly connected to the
507 * Internet. Not enough reason to fail the test. Just ignore and
511 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
513 trace("HttpOpenRequestA -->\n");
515 if (hor
== 0x0) goto abort
;
517 test_request_flags(hor
, INTERNET_REQFLAG_NO_HEADERS
);
519 length
= sizeof(buffer
);
520 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
521 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
522 ok(!strcmp(buffer
, test
->url
), "Wrong URL %s, expected %s\n", buffer
, test
->url
);
524 length
= sizeof(buffer
);
525 res
= HttpQueryInfoA(hor
, HTTP_QUERY_RAW_HEADERS
, buffer
, &length
, 0x0);
526 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
527 ok(length
== 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length
);
528 ok(!strcmp(buffer
, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer
);
530 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
531 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
532 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
533 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
,2);
534 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED
,2);
535 if (first_connection_to_test_url
)
537 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
538 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
540 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
541 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
542 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
543 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
544 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
545 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
546 if(test
->flags
& TESTF_REDIRECT
) {
547 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
548 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
550 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
551 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
552 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
553 if (flags
& INTERNET_FLAG_ASYNC
)
554 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
556 if(test
->flags
& TESTF_COMPRESSED
) {
559 res
= InternetSetOptionA(hor
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
560 ok(res
|| broken(!res
&& GetLastError() == ERROR_INTERNET_INVALID_OPTION
),
561 "InternetSetOption failed: %u\n", GetLastError());
566 test_status_code(hor
, 0);
568 trace("HttpSendRequestA -->\n");
569 if(test
->post_data
) {
570 post_len
= strlen(test
->post_data
);
571 post_data
= HeapAlloc(GetProcessHeap(), 0, post_len
);
572 memcpy(post_data
, test
->post_data
, post_len
);
574 SetLastError(0xdeadbeef);
575 res
= HttpSendRequestA(hor
, test
->headers
, -1, post_data
, post_len
);
576 if (flags
& INTERNET_FLAG_ASYNC
)
577 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
578 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
580 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
581 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
582 trace("HttpSendRequestA <--\n");
584 if (flags
& INTERNET_FLAG_ASYNC
) {
585 WaitForSingleObject(hCompleteEvent
, INFINITE
);
586 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
588 HeapFree(GetProcessHeap(), 0, post_data
);
590 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
591 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED
);
592 if (first_connection_to_test_url
)
594 if (! proxy_active())
596 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
597 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
601 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
602 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
607 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
608 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
610 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
611 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
612 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
613 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
614 if(test
->flags
& TESTF_REDIRECT
)
615 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
616 if (flags
& INTERNET_FLAG_ASYNC
)
617 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
618 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
619 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
620 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
622 test_request_flags(hor
, 0);
625 res
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
626 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
628 length
= sizeof(buffer
)-1;
629 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
630 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
633 length
= sizeof(buffer
);
634 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
635 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
636 ok(!strcmp(buffer
, test
->redirected_url
), "Wrong URL %s\n", buffer
);
639 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
640 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res
,buffer
,GetLastError());
641 if(test
->flags
& TESTF_COMPRESSED
)
642 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
643 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res
, GetLastError());
646 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
648 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res
,buffer
);
651 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_ENCODING
,buffer
,&length
,0x0);
653 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res
,buffer
);
655 SetLastError(0xdeadbeef);
656 res
= InternetReadFile(NULL
, buffer
, 100, &length
);
657 ok(!res
, "InternetReadFile should have failed\n");
658 ok(GetLastError() == ERROR_INVALID_HANDLE
,
659 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
663 trace("Entering Query loop\n");
667 if (flags
& INTERNET_FLAG_ASYNC
)
668 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
670 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
671 if (flags
& INTERNET_FLAG_ASYNC
)
675 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
677 ok(length
>= exlen
, "length %u < exlen %u\n", length
, exlen
);
681 else if (GetLastError() == ERROR_IO_PENDING
)
684 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
685 if(!(test
->flags
& TESTF_CHUNKED
))
686 ok(!length
, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length
);
687 WaitForSingleObject(hCompleteEvent
, INFINITE
);
689 ok(exlen
, "length = 0\n");
690 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
691 ok(req_error
, "req_error = 0\n");
694 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
697 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
699 trace("LENGTH %d\n", length
);
700 if(test
->flags
& TESTF_CHUNKED
)
701 ok(length
<= 8192, "length = %d, expected <= 8192\n", length
);
705 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
707 res
= InternetReadFile(hor
,buffer
,length
,&length
);
711 trace("ReadFile -> %s %i\n",res
?"TRUE":"FALSE",length
);
714 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
715 HeapFree(GetProcessHeap(),0,buffer
);
717 ok(!on_async
, "Returned zero size in response to request complete\n");
722 if(test
->flags
& TESTF_REDIRECT
) {
723 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
724 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
728 close_async_handle(hi
, hCompleteEvent
, 2);
729 CloseHandle(hCompleteEvent
);
730 first_connection_to_test_url
= FALSE
;
733 static void InternetReadFile_chunked_test(void)
738 const char *types
[2] = { "*", NULL
};
739 HINTERNET hi
, hic
= 0, hor
= 0;
741 trace("Starting InternetReadFile chunked test\n");
743 trace("InternetOpenA <--\n");
744 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
745 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
746 trace("InternetOpenA -->\n");
748 if (hi
== 0x0) goto abort
;
750 trace("InternetConnectA <--\n");
751 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
752 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
753 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
754 trace("InternetConnectA -->\n");
756 if (hic
== 0x0) goto abort
;
758 trace("HttpOpenRequestA <--\n");
759 hor
= HttpOpenRequestA(hic
, "GET", "/tests/chunked", NULL
, NULL
, types
,
760 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
762 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
764 * If the internet name can't be resolved we are probably behind
765 * a firewall or in some other way not directly connected to the
766 * Internet. Not enough reason to fail the test. Just ignore and
770 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
772 trace("HttpOpenRequestA -->\n");
774 if (hor
== 0x0) goto abort
;
776 trace("HttpSendRequestA -->\n");
777 SetLastError(0xdeadbeef);
778 res
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
779 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
780 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
781 trace("HttpSendRequestA <--\n");
783 test_request_flags(hor
, 0);
786 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
788 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
790 SetLastError( 0xdeadbeef );
792 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
794 trace("Option TRANSFER_ENCODING -> %i %s\n",res
,buffer
);
795 ok( res
|| ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
796 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
797 ok( !strcmp( buffer
, "chunked" ) || ( ! res
&& proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
798 "Wrong transfer encoding '%s'\n", buffer
);
800 SetLastError( 0xdeadbeef );
802 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
803 ok( !res
, "Found CONTENT_LENGTH option '%s'\n", buffer
);
804 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Wrong error %u\n", GetLastError() );
807 trace("Entering Query loop\n");
811 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
812 ok(!(!res
&& length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
813 ok(res
, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
814 trace("got %u available\n",length
);
817 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
819 res
= InternetReadFile(hor
,buffer
,length
,&got
);
822 trace("ReadFile -> %i %i\n",res
,got
);
823 ok( length
== got
, "only got %u of %u available\n", got
, length
);
824 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
826 HeapFree(GetProcessHeap(),0,buffer
);
832 res
= InternetReadFile( hor
, buffer
, 1, &got
);
833 ok( res
, "InternetReadFile failed: %u\n", GetLastError() );
834 ok( !got
, "got %u\n", got
);
841 res
= InternetCloseHandle(hor
);
842 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
845 res
= InternetCloseHandle(hi
);
846 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
850 static void InternetReadFileExA_test(int flags
)
854 const char *types
[2] = { "*", NULL
};
855 HINTERNET hi
, hic
= 0, hor
= 0;
856 INTERNET_BUFFERSA inetbuffers
;
858 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
860 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
862 trace("InternetOpenA <--\n");
863 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
864 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
865 trace("InternetOpenA -->\n");
867 if (hi
== 0x0) goto abort
;
869 pInternetSetStatusCallbackA(hi
,&callback
);
871 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
873 trace("InternetConnectA <--\n");
874 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
875 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
876 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
877 trace("InternetConnectA -->\n");
879 if (hic
== 0x0) goto abort
;
881 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
882 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
884 trace("HttpOpenRequestA <--\n");
885 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
886 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
888 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
890 * If the internet name can't be resolved we are probably behind
891 * a firewall or in some other way not directly connected to the
892 * Internet. Not enough reason to fail the test. Just ignore and
896 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
898 trace("HttpOpenRequestA -->\n");
900 if (hor
== 0x0) goto abort
;
902 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
903 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
904 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
905 if (first_connection_to_test_url
)
907 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
908 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
910 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
, 2);
911 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
912 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
913 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
914 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
915 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
916 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
917 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
918 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
919 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
920 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
921 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
922 if (flags
& INTERNET_FLAG_ASYNC
)
923 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
925 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
927 trace("HttpSendRequestA -->\n");
928 SetLastError(0xdeadbeef);
929 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
930 if (flags
& INTERNET_FLAG_ASYNC
)
931 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
932 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
934 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
935 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
936 trace("HttpSendRequestA <--\n");
938 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
939 WaitForSingleObject(hCompleteEvent
, INFINITE
);
940 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
943 if (first_connection_to_test_url
)
945 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
946 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
950 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
951 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
953 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
954 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
955 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
956 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
957 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
958 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
959 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
960 if (flags
& INTERNET_FLAG_ASYNC
)
961 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
963 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
964 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
965 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
966 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
967 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
969 /* tests invalid dwStructSize */
970 inetbuffers
.dwStructSize
= sizeof(inetbuffers
)+1;
971 inetbuffers
.lpcszHeader
= NULL
;
972 inetbuffers
.dwHeadersLength
= 0;
973 inetbuffers
.dwBufferLength
= 10;
974 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
975 inetbuffers
.dwOffsetHigh
= 1234;
976 inetbuffers
.dwOffsetLow
= 5678;
977 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
978 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
979 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
980 rc
? "TRUE" : "FALSE", GetLastError());
981 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
983 test_request_flags(hor
, 0);
985 /* tests to see whether lpcszHeader is used - it isn't */
986 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
987 inetbuffers
.lpcszHeader
= (LPCSTR
)0xdeadbeef;
988 inetbuffers
.dwHeadersLength
= 255;
989 inetbuffers
.dwBufferLength
= 0;
990 inetbuffers
.lpvBuffer
= NULL
;
991 inetbuffers
.dwOffsetHigh
= 1234;
992 inetbuffers
.dwOffsetLow
= 5678;
993 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
994 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
995 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
996 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
997 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1000 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1001 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1004 rc
= InternetReadFileExA(NULL
, &inetbuffers
, 0, 0xdeadcafe);
1005 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
1006 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1007 rc
? "TRUE" : "FALSE", GetLastError());
1010 trace("Entering Query loop\n");
1014 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1015 inetbuffers
.dwBufferLength
= 1024;
1016 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
1017 inetbuffers
.dwOffsetHigh
= 1234;
1018 inetbuffers
.dwOffsetLow
= 5678;
1020 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1021 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1022 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1023 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
1026 if (GetLastError() == ERROR_IO_PENDING
)
1028 trace("InternetReadFileEx -> PENDING\n");
1029 ok(flags
& INTERNET_FLAG_ASYNC
,
1030 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1031 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1032 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1033 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1034 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1035 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1039 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1045 trace("InternetReadFileEx -> SUCCEEDED\n");
1046 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1047 if (inetbuffers
.dwBufferLength
)
1050 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1051 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1056 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1057 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1058 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1062 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1063 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
1065 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
1066 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1067 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
1069 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1071 if (!inetbuffers
.dwBufferLength
)
1074 length
+= inetbuffers
.dwBufferLength
;
1076 ok(length
> 0, "failed to read any of the document\n");
1077 trace("Finished. Read %d bytes\n", length
);
1080 close_async_handle(hi
, hCompleteEvent
, 2);
1081 CloseHandle(hCompleteEvent
);
1082 first_connection_to_test_url
= FALSE
;
1085 static void InternetOpenUrlA_test(void)
1087 HINTERNET myhinternet
, myhttp
;
1089 DWORD size
, readbytes
, totalbytes
=0;
1092 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1093 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
1094 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret
, GetLastError());
1096 myhinternet
= InternetOpenA("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
1097 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
1099 ret
= InternetCanonicalizeUrlA(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1100 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1103 myhttp
= InternetOpenUrlA(myhinternet
, TEST_URL
, 0, 0,
1104 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
1105 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1106 return; /* WinXP returns this when not connected to the net */
1107 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1108 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
1109 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
1110 totalbytes
+= readbytes
;
1111 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
1112 totalbytes
+= readbytes
;
1113 trace("read 0x%08x bytes\n",totalbytes
);
1115 InternetCloseHandle(myhttp
);
1116 InternetCloseHandle(myhinternet
);
1118 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1119 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1122 static void HttpSendRequestEx_test(void)
1128 INTERNET_BUFFERSA BufferIn
;
1129 DWORD dwBytesWritten
, dwBytesRead
, error
;
1134 static char szPostData
[] = "mode=Test";
1135 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
1137 hSession
= InternetOpenA("Wine Regression Test",
1138 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1139 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1140 hConnect
= InternetConnectA(hSession
, "crossover.codeweavers.com",
1141 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1143 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
1144 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/posttest.php",
1145 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1146 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1148 skip( "Network unreachable, skipping test\n" );
1151 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1153 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1155 BufferIn
.dwStructSize
= sizeof(BufferIn
);
1156 BufferIn
.Next
= (INTERNET_BUFFERSA
*)0xdeadcab;
1157 BufferIn
.lpcszHeader
= szContentType
;
1158 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1159 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1160 BufferIn
.lpvBuffer
= szPostData
;
1161 BufferIn
.dwBufferLength
= 3;
1162 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1163 BufferIn
.dwOffsetLow
= 0;
1164 BufferIn
.dwOffsetHigh
= 0;
1166 SetLastError(0xdeadbeef);
1167 ret
= HttpSendRequestExA(hRequest
, &BufferIn
, NULL
, 0 ,0);
1168 error
= GetLastError();
1169 ok(ret
, "HttpSendRequestEx Failed with error %u\n", error
);
1170 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", error
);
1172 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1174 for (i
= 3; szPostData
[i
]; i
++)
1175 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1176 "InternetWriteFile failed\n");
1178 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1180 ok(HttpEndRequestA(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1182 test_request_flags(hRequest
, 0);
1184 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1185 "Unable to read response\n");
1186 szBuffer
[dwBytesRead
] = 0;
1188 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
1189 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1191 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1193 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1194 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1197 static void InternetOpenRequest_test(void)
1199 HINTERNET session
, connect
, request
;
1200 static const char *types
[] = { "*", "", NULL
};
1201 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1202 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1205 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1206 ok(session
!= NULL
,"Unable to open Internet session\n");
1208 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1209 INTERNET_SERVICE_HTTP
, 0, 0);
1210 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1211 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1213 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1214 INTERNET_SERVICE_HTTP
, 0, 0);
1215 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1216 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1218 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1219 INTERNET_SERVICE_HTTP
, 0, 0);
1220 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1222 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1223 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1225 skip( "Network unreachable, skipping test\n" );
1228 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1230 ret
= HttpSendRequestW(request
, NULL
, 0, NULL
, 0);
1231 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1232 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1234 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1235 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1237 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1238 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1239 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1242 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1243 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1246 static void test_cache_read(void)
1248 HINTERNET session
, connection
, req
;
1249 FILETIME now
, tomorrow
, yesterday
;
1250 BYTE content
[1000], buf
[2000];
1251 char file_path
[MAX_PATH
];
1258 static const char cache_only_url
[] = "http://test.winehq.org/tests/cache-only";
1259 BYTE cache_headers
[] = "HTTP/1.1 200 OK\r\n\r\n";
1261 trace("Testing cache read...\n");
1263 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1265 for(i
= 0; i
< sizeof(content
); i
++)
1266 content
[i
] = '0' + (i
%10);
1268 GetSystemTimeAsFileTime(&now
);
1269 li
.u
.HighPart
= now
.dwHighDateTime
;
1270 li
.u
.LowPart
= now
.dwLowDateTime
;
1271 li
.QuadPart
+= (LONGLONG
)10000000 * 3600 * 24;
1272 tomorrow
.dwHighDateTime
= li
.u
.HighPart
;
1273 tomorrow
.dwLowDateTime
= li
.u
.LowPart
;
1274 li
.QuadPart
-= (LONGLONG
)10000000 * 3600 * 24 * 2;
1275 yesterday
.dwHighDateTime
= li
.u
.HighPart
;
1276 yesterday
.dwLowDateTime
= li
.u
.LowPart
;
1278 res
= CreateUrlCacheEntryA(cache_only_url
, sizeof(content
), "", file_path
, 0);
1279 ok(res
, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1281 file
= CreateFileA(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1282 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
1284 WriteFile(file
, content
, sizeof(content
), &size
, NULL
);
1287 res
= CommitUrlCacheEntryA(cache_only_url
, file_path
, tomorrow
, yesterday
, NORMAL_CACHE_ENTRY
,
1288 cache_headers
, sizeof(cache_headers
)-1, "", 0);
1289 ok(res
, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1291 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
1292 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
1294 pInternetSetStatusCallbackA(session
, callback
);
1296 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1297 connection
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
,
1298 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1299 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
1300 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1302 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1303 req
= HttpOpenRequestA(connection
, "GET", "/tests/cache-only", NULL
, NULL
, NULL
, 0, 0xdeadbead);
1304 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
1305 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1307 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1308 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1309 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST
);
1310 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT
);
1311 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1312 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1313 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1315 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
1317 ok(res
, "HttpSendRequest failed: %u\n", GetLastError());
1321 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
1322 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1323 ok(size
== sizeof(content
), "size = %u\n", size
);
1326 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
1327 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
1328 ok(size
== sizeof(content
), "size = %u\n", size
);
1329 ok(!memcmp(content
, buf
, sizeof(content
)), "unexpected content\n");
1332 close_async_handle(session
, hCompleteEvent
, 2);
1334 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1335 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1336 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
1337 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
1338 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1339 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1340 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1342 res
= DeleteUrlCacheEntryA(cache_only_url
);
1343 ok(res
, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1345 CloseHandle(hCompleteEvent
);
1348 static void test_http_cache(void)
1350 HINTERNET session
, connect
, request
;
1351 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1352 DWORD size
, file_size
;
1357 static const char *types
[] = { "*", "", NULL
};
1359 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1360 ok(session
!= NULL
,"Unable to open Internet session\n");
1362 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1363 INTERNET_SERVICE_HTTP
, 0, 0);
1364 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1366 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1367 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1369 skip( "Network unreachable, skipping test\n" );
1371 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1372 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1376 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1379 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1380 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1381 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1383 size
= sizeof(file_name
);
1384 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1385 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1386 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1387 ok(!size
, "size = %d\n", size
);
1389 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1390 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1392 size
= sizeof(file_name
);
1393 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1394 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1396 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1397 FILE_ATTRIBUTE_NORMAL
, NULL
);
1398 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1399 file_size
= GetFileSize(file
, NULL
);
1400 ok(file_size
== 106, "file size = %u\n", file_size
);
1403 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1404 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1405 ok(size
== 100, "size = %u\n", size
);
1407 file_size
= GetFileSize(file
, NULL
);
1408 ok(file_size
== 106, "file size = %u\n", file_size
);
1411 ret
= DeleteFileA(file_name
);
1412 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1414 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1416 file
= CreateFileA(file_name
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
1417 FILE_ATTRIBUTE_NORMAL
, NULL
);
1418 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1421 /* Send the same request, requiring it to be retrieved from the cache */
1422 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1424 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1425 ok(ret
, "HttpSendRequest failed\n");
1428 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1429 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1430 ok(size
== 100, "size = %u\n", size
);
1432 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1434 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1435 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1437 size
= sizeof(file_name
);
1438 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1439 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1440 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1441 ok(!size
, "size = %d\n", size
);
1443 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1444 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1446 size
= sizeof(file_name
);
1448 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1451 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1452 FILE_ATTRIBUTE_NORMAL
, NULL
);
1453 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1459 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1462 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1463 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1464 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1469 static void InternetLockRequestFile_test(void)
1471 HINTERNET session
, connect
, request
;
1472 char file_name
[MAX_PATH
];
1477 static const char *types
[] = { "*", "", NULL
};
1479 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1480 ok(session
!= NULL
,"Unable to open Internet session\n");
1482 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1483 INTERNET_SERVICE_HTTP
, 0, 0);
1484 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1486 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
|INTERNET_FLAG_RELOAD
, 0);
1487 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1489 skip( "Network unreachable, skipping test\n" );
1491 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1492 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1496 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1498 size
= sizeof(file_name
);
1499 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1500 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1501 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1502 ok(!size
, "size = %d\n", size
);
1505 ret
= InternetLockRequestFile(request
, &lock
);
1506 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1508 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1509 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1511 size
= sizeof(file_name
);
1512 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1513 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1515 ret
= InternetLockRequestFile(request
, &lock
);
1516 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1517 ok(lock
!= NULL
, "lock == NULL\n");
1519 ret
= InternetLockRequestFile(request
, &lock2
);
1520 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1521 ok(lock
== lock2
, "lock != lock2\n");
1523 ret
= InternetUnlockRequestFile(lock2
);
1524 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1526 ret
= DeleteFileA(file_name
);
1527 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1529 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1531 ret
= DeleteFileA(file_name
);
1532 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1534 ret
= InternetUnlockRequestFile(lock
);
1535 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1537 ret
= DeleteFileA(file_name
);
1538 ok(ret
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1541 static void HttpHeaders_test(void)
1553 hSession
= InternetOpenA("Wine Regression Test",
1554 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1555 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1556 hConnect
= InternetConnectA(hSession
, "crossover.codeweavers.com",
1557 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1559 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
1560 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/posttest.php",
1561 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1562 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1564 skip( "Network unreachable, skipping test\n" );
1567 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1570 len
= sizeof(buffer
);
1571 strcpy(buffer
,"Warning");
1572 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1573 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1575 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1576 "Failed to add new header\n");
1579 len
= sizeof(buffer
);
1580 strcpy(buffer
,"Warning");
1581 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1582 buffer
,&len
,&index
),"Unable to query header\n");
1583 ok(index
== 1, "Index was not incremented\n");
1584 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1585 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1586 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1587 len
= sizeof(buffer
);
1588 strcpy(buffer
,"Warning");
1589 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1590 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1593 len
= 5; /* could store the string but not the NULL terminator */
1594 strcpy(buffer
,"Warning");
1595 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1596 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1597 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1598 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1600 /* a call with NULL will fail but will return the length */
1602 len
= sizeof(buffer
);
1603 SetLastError(0xdeadbeef);
1604 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1605 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1606 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1607 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1608 ok(index
== 0, "Index was incremented\n");
1610 /* even for a len that is too small */
1613 SetLastError(0xdeadbeef);
1614 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1615 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1616 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1617 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1618 ok(index
== 0, "Index was incremented\n");
1622 SetLastError(0xdeadbeef);
1623 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1624 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1625 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1626 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1627 ok(index
== 0, "Index was incremented\n");
1628 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1631 /* a working query */
1633 len
= sizeof(buffer
);
1634 memset(buffer
, 'x', sizeof(buffer
));
1635 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1636 buffer
,&len
,&index
),"Unable to query header\n");
1637 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1638 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1639 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1640 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1641 ok(strncmp(buffer
, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1642 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1643 ok(index
== 0, "Index was incremented\n");
1645 /* Like above two tests, but for W version */
1649 SetLastError(0xdeadbeef);
1650 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1651 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1652 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1653 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1654 ok(index
== 0, "Index was incremented\n");
1655 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1657 /* a working query */
1659 len
= sizeof(wbuffer
);
1660 memset(wbuffer
, 'x', sizeof(wbuffer
));
1661 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1662 wbuffer
,&len
,&index
),"Unable to query header\n");
1663 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1664 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1665 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1666 ok(index
== 0, "Index was incremented\n");
1668 /* end of W version tests */
1670 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1672 len
= sizeof(buffer
);
1673 memset(buffer
, 'x', sizeof(buffer
));
1674 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1675 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1676 ok(len
== 2, "Expected 2, got %d\n", len
);
1677 ok(strcmp(buffer
, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer
);
1678 ok(index
== 0, "Index was incremented\n");
1680 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1681 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1684 len
= sizeof(buffer
);
1685 strcpy(buffer
,"Warning");
1686 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1687 buffer
,&len
,&index
),"Unable to query header\n");
1688 ok(index
== 1, "Index was not incremented\n");
1689 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1690 len
= sizeof(buffer
);
1691 strcpy(buffer
,"Warning");
1692 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1693 buffer
,&len
,&index
),"Failed to get second header\n");
1694 ok(index
== 2, "Index was not incremented\n");
1695 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1696 len
= sizeof(buffer
);
1697 strcpy(buffer
,"Warning");
1698 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1699 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1701 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1704 len
= sizeof(buffer
);
1705 strcpy(buffer
,"Warning");
1706 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1707 buffer
,&len
,&index
),"Unable to query header\n");
1708 ok(index
== 1, "Index was not incremented\n");
1709 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1710 len
= sizeof(buffer
);
1711 strcpy(buffer
,"Warning");
1712 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1713 buffer
,&len
,&index
),"Failed to get second header\n");
1714 ok(index
== 2, "Index was not incremented\n");
1715 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1716 len
= sizeof(buffer
);
1717 strcpy(buffer
,"Warning");
1718 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1719 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1721 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1724 len
= sizeof(buffer
);
1725 strcpy(buffer
,"Warning");
1726 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1727 buffer
,&len
,&index
),"Unable to query header\n");
1728 ok(index
== 1, "Index was not incremented\n");
1729 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1730 len
= sizeof(buffer
);
1731 strcpy(buffer
,"Warning");
1732 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1733 buffer
,&len
,&index
),"Failed to get second header\n");
1734 ok(index
== 2, "Index was not incremented\n");
1735 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1736 len
= sizeof(buffer
);
1737 strcpy(buffer
,"Warning");
1738 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1739 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1741 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1744 len
= sizeof(buffer
);
1745 strcpy(buffer
,"Warning");
1746 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1747 buffer
,&len
,&index
),"Unable to query header\n");
1748 ok(index
== 1, "Index was not incremented\n");
1749 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1750 len
= sizeof(buffer
);
1751 strcpy(buffer
,"Warning");
1752 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1753 ok(index
== 2, "Index was not incremented\n");
1754 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1755 len
= sizeof(buffer
);
1756 strcpy(buffer
,"Warning");
1757 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1759 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1762 len
= sizeof(buffer
);
1763 strcpy(buffer
,"Warning");
1764 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1765 ok(index
== 1, "Index was not incremented\n");
1766 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1767 len
= sizeof(buffer
);
1768 strcpy(buffer
,"Warning");
1769 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1770 ok(index
== 2, "Index was not incremented\n");
1771 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1772 len
= sizeof(buffer
);
1773 strcpy(buffer
,"Warning");
1774 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1776 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1779 len
= sizeof(buffer
);
1780 strcpy(buffer
,"Warning");
1781 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1782 ok(index
== 1, "Index was not incremented\n");
1783 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1784 len
= sizeof(buffer
);
1785 strcpy(buffer
,"Warning");
1786 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1787 ok(index
== 2, "Index was not incremented\n");
1788 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1789 len
= sizeof(buffer
);
1790 strcpy(buffer
,"Warning");
1791 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1793 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");
1796 len
= sizeof(buffer
);
1797 strcpy(buffer
,"Warning");
1798 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1799 ok(index
== 1, "Index was not incremented\n");
1800 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1801 len
= sizeof(buffer
);
1802 strcpy(buffer
,"Warning");
1803 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1804 ok(index
== 2, "Index was not incremented\n");
1805 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1806 len
= sizeof(buffer
);
1807 strcpy(buffer
,"Warning");
1808 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1810 /* Ensure that blank headers are ignored and don't cause a failure */
1811 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");
1814 len
= sizeof(buffer
);
1815 strcpy(buffer
,"BlankTest");
1816 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1817 ok(index
== 1, "Index was not incremented\n");
1818 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1820 /* Ensure that malformed header separators are ignored and don't cause a failure */
1821 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
),
1822 "Failed to add header with malformed entries in list\n");
1825 len
= sizeof(buffer
);
1826 strcpy(buffer
,"MalformedTest");
1827 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1828 ok(index
== 1, "Index was not incremented\n");
1829 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1831 len
= sizeof(buffer
);
1832 strcpy(buffer
,"MalformedTestTwo");
1833 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1834 ok(index
== 1, "Index was not incremented\n");
1835 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
1837 len
= sizeof(buffer
);
1838 strcpy(buffer
,"MalformedTestThree");
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
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
1843 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD
);
1844 ok(ret
, "unable to add header %u\n", GetLastError());
1848 len
= sizeof(buffer
);
1849 ret
= HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
);
1850 ok(ret
, "unable to query header %u\n", GetLastError());
1851 ok(index
== 1, "index was not incremented\n");
1852 ok(!strcmp(buffer
, "Basic"), "incorrect string was returned (%s)\n", buffer
);
1854 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE
);
1855 ok(ret
, "unable to remove header %u\n", GetLastError());
1858 len
= sizeof(buffer
);
1859 SetLastError(0xdeadbeef);
1860 ok(!HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
),
1861 "header still present\n");
1862 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "got %u\n", GetLastError());
1864 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1866 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1867 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1870 static const char garbagemsg
[] =
1871 "Garbage: Header\r\n";
1873 static const char contmsg
[] =
1874 "HTTP/1.1 100 Continue\r\n";
1876 static const char expandcontmsg
[] =
1877 "HTTP/1.1 100 Continue\r\n"
1878 "Server: winecontinue\r\n"
1879 "Tag: something witty\r\n"
1882 static const char okmsg
[] =
1883 "HTTP/1.1 200 OK\r\n"
1884 "Server: winetest\r\n"
1887 static const char okmsg2
[] =
1888 "HTTP/1.1 200 OK\r\n"
1889 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1890 "Server: winetest\r\n"
1891 "Content-Length: 0\r\n"
1892 "Set-Cookie: one\r\n"
1893 "Set-Cookie: two\r\n"
1896 static const char notokmsg
[] =
1897 "HTTP/1.1 400 Bad Request\r\n"
1898 "Server: winetest\r\n"
1901 static const char noauthmsg
[] =
1902 "HTTP/1.1 401 Unauthorized\r\n"
1903 "Server: winetest\r\n"
1904 "Connection: close\r\n"
1905 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1908 static const char noauthmsg2
[] =
1909 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
1910 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
1912 "Server: winetest\r\n";
1914 static const char proxymsg
[] =
1915 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1916 "Server: winetest\r\n"
1917 "Proxy-Connection: close\r\n"
1918 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1921 static const char page1
[] =
1923 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1924 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1927 static const char ok_with_length
[] =
1928 "HTTP/1.1 200 OK\r\n"
1929 "Connection: Keep-Alive\r\n"
1930 "Content-Length: 23\r\n\r\n"
1931 "abc\r\nHTTP/1.1 211 OK\r\n\r\n";
1933 static const char ok_with_length2
[] =
1934 "HTTP/1.1 210 OK\r\n"
1935 "Connection: Keep-Alive\r\n"
1936 "Content-Length: 24\r\n\r\n"
1937 "abc\r\nHTTP/1.1 211 OK\r\n\r\n";
1939 struct server_info
{
1944 static int test_cache_gzip
;
1945 static const char *send_buffer
;
1947 static DWORD CALLBACK
server_thread(LPVOID param
)
1949 struct server_info
*si
= param
;
1950 int r
, c
, i
, on
, count
= 0;
1952 struct sockaddr_in sa
;
1955 int last_request
= 0;
1956 char host_header
[22];
1957 static int test_b
= 0;
1958 static int test_no_cache
= 0;
1960 WSAStartup(MAKEWORD(1,1), &wsaData
);
1962 s
= socket(AF_INET
, SOCK_STREAM
, 0);
1963 if (s
== INVALID_SOCKET
)
1967 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
1969 memset(&sa
, 0, sizeof sa
);
1970 sa
.sin_family
= AF_INET
;
1971 sa
.sin_port
= htons(si
->port
);
1972 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
1974 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
1980 SetEvent(si
->hEvent
);
1982 sprintf(host_header
, "Host: localhost:%d", si
->port
);
1986 c
= accept(s
, NULL
, NULL
);
1988 memset(buffer
, 0, sizeof buffer
);
1989 for(i
=0; i
<(sizeof buffer
-1); i
++)
1991 r
= recv(c
, &buffer
[i
], 1, 0);
1995 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
1996 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
1999 if (strstr(buffer
, "GET /test1"))
2001 if (!strstr(buffer
, "Content-Length: 0"))
2003 send(c
, okmsg
, sizeof okmsg
-1, 0);
2004 send(c
, page1
, sizeof page1
-1, 0);
2007 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2009 if (strstr(buffer
, "/test2"))
2011 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2013 send(c
, okmsg
, sizeof okmsg
-1, 0);
2014 send(c
, page1
, sizeof page1
-1, 0);
2017 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2019 if (strstr(buffer
, "/test3"))
2021 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2022 send(c
, okmsg
, sizeof okmsg
-1, 0);
2024 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2026 if (strstr(buffer
, "/test4"))
2028 if (strstr(buffer
, "Connection: Close"))
2029 send(c
, okmsg
, sizeof okmsg
-1, 0);
2031 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2033 if (strstr(buffer
, "POST /test5") ||
2034 strstr(buffer
, "RPC_IN_DATA /test5") ||
2035 strstr(buffer
, "RPC_OUT_DATA /test5"))
2037 if (strstr(buffer
, "Content-Length: 0"))
2039 send(c
, okmsg
, sizeof okmsg
-1, 0);
2040 send(c
, page1
, sizeof page1
-1, 0);
2043 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2045 if (strstr(buffer
, "GET /test6"))
2047 send(c
, contmsg
, sizeof contmsg
-1, 0);
2048 send(c
, contmsg
, sizeof contmsg
-1, 0);
2049 send(c
, okmsg
, sizeof okmsg
-1, 0);
2050 send(c
, page1
, sizeof page1
-1, 0);
2052 if (strstr(buffer
, "POST /test7"))
2054 if (strstr(buffer
, "Content-Length: 100"))
2056 send(c
, okmsg
, sizeof okmsg
-1, 0);
2057 send(c
, page1
, sizeof page1
-1, 0);
2060 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2062 if (strstr(buffer
, "/test8"))
2064 if (!strstr(buffer
, "Connection: Close") &&
2065 strstr(buffer
, "Connection: Keep-Alive") &&
2066 !strstr(buffer
, "Cache-Control: no-cache") &&
2067 !strstr(buffer
, "Pragma: no-cache") &&
2068 strstr(buffer
, host_header
))
2069 send(c
, okmsg
, sizeof okmsg
-1, 0);
2071 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2073 if (strstr(buffer
, "/test9"))
2075 if (!strstr(buffer
, "Connection: Close") &&
2076 !strstr(buffer
, "Connection: Keep-Alive") &&
2077 !strstr(buffer
, "Cache-Control: no-cache") &&
2078 !strstr(buffer
, "Pragma: no-cache") &&
2079 strstr(buffer
, host_header
))
2080 send(c
, okmsg
, sizeof okmsg
-1, 0);
2082 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2084 if (strstr(buffer
, "/testA"))
2086 if (!strstr(buffer
, "Connection: Close") &&
2087 !strstr(buffer
, "Connection: Keep-Alive") &&
2088 (strstr(buffer
, "Cache-Control: no-cache") ||
2089 strstr(buffer
, "Pragma: no-cache")) &&
2090 strstr(buffer
, host_header
))
2091 send(c
, okmsg
, sizeof okmsg
-1, 0);
2093 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2095 if (!test_b
&& strstr(buffer
, "/testB HTTP/1.1"))
2098 send(c
, okmsg
, sizeof okmsg
-1, 0);
2099 recvfrom(c
, buffer
, sizeof buffer
, 0, NULL
, NULL
);
2100 send(c
, okmsg
, sizeof okmsg
-1, 0);
2102 if (strstr(buffer
, "/testC"))
2104 if (strstr(buffer
, "Cookie: cookie=biscuit"))
2105 send(c
, okmsg
, sizeof okmsg
-1, 0);
2107 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2109 if (strstr(buffer
, "/testD"))
2111 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
2113 if (strstr(buffer
, "/testE"))
2115 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
2117 if (strstr(buffer
, "GET /quit"))
2119 send(c
, okmsg
, sizeof okmsg
-1, 0);
2120 send(c
, page1
, sizeof page1
-1, 0);
2123 if (strstr(buffer
, "GET /testF"))
2125 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
2126 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2127 send(c
, contmsg
, sizeof contmsg
-1, 0);
2128 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2129 send(c
, okmsg
, sizeof okmsg
-1, 0);
2130 send(c
, page1
, sizeof page1
-1, 0);
2132 if (strstr(buffer
, "GET /testG"))
2134 send(c
, page1
, sizeof page1
-1, 0);
2137 if (strstr(buffer
, "GET /testJ"))
2142 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2146 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2151 if (strstr(buffer
, "GET /test_no_content"))
2153 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2154 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2156 if (strstr(buffer
, "GET /test_conn_close"))
2158 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2159 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
2160 WaitForSingleObject(conn_close_event
, INFINITE
);
2161 trace("closing connection\n");
2163 if (strstr(buffer
, "GET /test_cache_control_no_cache"))
2165 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2166 if(!test_no_cache
++)
2167 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2169 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2171 if (strstr(buffer
, "GET /test_cache_control_no_store"))
2173 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2174 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2176 if (strstr(buffer
, "GET /test_cache_gzip"))
2178 static const char gzip_response
[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2179 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2180 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2181 if(!test_cache_gzip
++)
2182 send(c
, gzip_response
, sizeof(gzip_response
), 0);
2184 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2186 if (strstr(buffer
, "GET /send_from_buffer"))
2187 send(c
, send_buffer
, strlen(send_buffer
), 0);
2188 if (strstr(buffer
, "/test_cache_control_verb"))
2190 if (!memcmp(buffer
, "GET ", sizeof("GET ")-1) &&
2191 !strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2192 else if (strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2193 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2195 if (strstr(buffer
, "GET /test_premature_disconnect"))
2196 trace("closing connection\n");
2200 } while (!last_request
);
2207 static void test_basic_request(int port
, const char *verb
, const char *url
)
2209 HINTERNET hi
, hc
, hr
;
2213 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2214 ok(hi
!= NULL
, "open failed\n");
2216 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2217 ok(hc
!= NULL
, "connect failed\n");
2219 hr
= HttpOpenRequestA(hc
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
2220 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2222 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2223 ok(r
, "HttpSendRequest failed\n");
2226 memset(buffer
, 0, sizeof buffer
);
2227 SetLastError(0xdeadbeef);
2228 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
2229 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2230 ok(count
== sizeof page1
- 1, "count was wrong\n");
2231 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2233 InternetCloseHandle(hr
);
2234 InternetCloseHandle(hc
);
2235 InternetCloseHandle(hi
);
2238 static void test_last_error(int port
)
2240 HINTERNET hi
, hc
, hr
;
2244 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2245 ok(hi
!= NULL
, "open failed\n");
2247 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2248 ok(hc
!= NULL
, "connect failed\n");
2250 hr
= HttpOpenRequestA(hc
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
2251 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2253 SetLastError(0xdeadbeef);
2254 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2255 error
= GetLastError();
2256 ok(r
, "HttpSendRequest failed\n");
2257 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
2259 InternetCloseHandle(hr
);
2260 InternetCloseHandle(hc
);
2261 InternetCloseHandle(hi
);
2264 static void test_proxy_indirect(int port
)
2266 HINTERNET hi
, hc
, hr
;
2270 hi
= InternetOpenA(NULL
, 0, NULL
, NULL
, 0);
2271 ok(hi
!= NULL
, "open failed\n");
2273 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2274 ok(hc
!= NULL
, "connect failed\n");
2276 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2277 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2279 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2280 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2283 r
= HttpQueryInfoA(hr
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2284 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
2287 skip("missing proxy header, not testing remaining proxy headers\n");
2290 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2292 test_status_code(hr
, 407);
2293 test_request_flags(hr
, 0);
2296 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2297 ok(r
, "HttpQueryInfo failed\n");
2298 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2301 r
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2302 ok(r
, "HttpQueryInfo failed\n");
2303 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2306 r
= HttpQueryInfoA(hr
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2307 ok(r
, "HttpQueryInfo failed\n");
2308 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2311 r
= HttpQueryInfoA(hr
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2312 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2313 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2316 InternetCloseHandle(hr
);
2317 InternetCloseHandle(hc
);
2318 InternetCloseHandle(hi
);
2321 static void test_proxy_direct(int port
)
2323 HINTERNET hi
, hc
, hr
;
2325 char buffer
[0x40], *url
;
2326 WCHAR bufferW
[0x40];
2327 static CHAR username
[] = "mike",
2328 password
[] = "1101",
2329 useragent
[] = "winetest",
2330 url_fmt
[] = "http://test.winehq.org:%u/test2";
2331 static WCHAR usernameW
[] = {'m','i','k','e',0},
2332 passwordW
[] = {'1','1','0','1',0},
2333 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2335 /* specify proxy type without the proxy and bypass */
2336 SetLastError(0xdeadbeef);
2337 hi
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2338 error
= GetLastError();
2339 ok(error
== ERROR_INVALID_PARAMETER
||
2340 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %u\n", error
);
2341 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2343 sprintf(buffer
, "localhost:%d\n", port
);
2344 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2345 ok(hi
!= NULL
, "open failed\n");
2347 /* try connect without authorization */
2348 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2349 ok(hc
!= NULL
, "connect failed\n");
2351 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2352 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2355 SetLastError(0xdeadbeef);
2356 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
2357 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2358 ok(!r
, "unexpected success\n");
2359 ok(sz
== 1, "got %u\n", sz
);
2362 SetLastError(0xdeadbeef);
2363 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
2364 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2365 ok(!r
, "unexpected success\n");
2366 ok(sz
== 1, "got %u\n", sz
);
2368 sz
= sizeof(buffer
);
2369 SetLastError(0xdeadbeef);
2370 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2371 ok(r
, "unexpected failure %u\n", GetLastError());
2372 ok(!sz
, "got %u\n", sz
);
2374 sz
= sizeof(buffer
);
2375 SetLastError(0xdeadbeef);
2376 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2377 ok(r
, "unexpected failure %u\n", GetLastError());
2378 ok(!sz
, "got %u\n", sz
);
2381 SetLastError(0xdeadbeef);
2382 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
2383 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2384 ok(!r
, "unexpected success\n");
2385 ok(sz
== 1, "got %u\n", sz
);
2388 SetLastError(0xdeadbeef);
2389 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
2390 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2391 ok(!r
, "unexpected success\n");
2392 ok(sz
== 1, "got %u\n", sz
);
2394 sz
= sizeof(buffer
);
2395 SetLastError(0xdeadbeef);
2396 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2397 ok(r
, "unexpected failure %u\n", GetLastError());
2398 ok(!sz
, "got %u\n", sz
);
2400 sz
= sizeof(buffer
);
2401 SetLastError(0xdeadbeef);
2402 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2403 ok(r
, "unexpected failure %u\n", GetLastError());
2404 ok(!sz
, "got %u\n", sz
);
2407 SetLastError(0xdeadbeef);
2408 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
2409 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2410 ok(!r
, "unexpected success\n");
2411 ok(sz
== 34, "got %u\n", sz
);
2413 sz
= sizeof(buffer
);
2414 SetLastError(0xdeadbeef);
2415 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2416 ok(r
, "unexpected failure %u\n", GetLastError());
2417 ok(sz
== 33, "got %u\n", sz
);
2419 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2420 ok(r
|| broken(!r
), "HttpSendRequest failed %u\n", GetLastError());
2423 win_skip("skipping proxy tests on broken wininet\n");
2427 test_status_code(hr
, 407);
2429 /* set the user + password then try again */
2430 r
= InternetSetOptionA(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2431 ok(!r
, "unexpected success\n");
2433 r
= InternetSetOptionA(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2434 ok(r
, "failed to set user\n");
2436 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2437 ok(r
, "failed to set user\n");
2441 SetLastError(0xdeadbeef);
2442 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2443 ok(!r
, "unexpected failure %u\n", GetLastError());
2444 ok(!buffer
[0], "got %s\n", buffer
);
2445 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2449 SetLastError(0xdeadbeef);
2450 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2451 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2452 ok(!r
, "unexpected success\n");
2453 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2457 SetLastError(0xdeadbeef);
2458 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2459 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2460 ok(!r
, "unexpected success\n");
2461 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2464 sz
= sizeof(buffer
);
2465 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2466 ok(r
, "failed to get username\n");
2467 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2468 ok(sz
== strlen(username
), "got %u\n", sz
);
2471 sz
= sizeof(bufferW
);
2472 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2473 ok(r
, "failed to get username\n");
2474 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
2475 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2477 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
2478 ok(r
, "failed to set user\n");
2481 sz
= sizeof(buffer
);
2482 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2483 ok(r
, "failed to get username\n");
2484 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2485 ok(sz
== strlen(username
), "got %u\n", sz
);
2487 r
= InternetSetOptionA(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
2488 ok(r
, "failed to set useragent\n");
2492 SetLastError(0xdeadbeef);
2493 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2494 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2495 ok(!r
, "unexpected success\n");
2496 ok(sz
== strlen(useragent
) + 1, "got %u\n", sz
);
2499 sz
= sizeof(buffer
);
2500 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2501 ok(r
, "failed to get user agent\n");
2502 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
2503 ok(sz
== strlen(useragent
), "got %u\n", sz
);
2507 SetLastError(0xdeadbeef);
2508 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2509 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2510 ok(!r
, "unexpected success\n");
2511 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2514 sz
= sizeof(bufferW
);
2515 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2516 ok(r
, "failed to get user agent\n");
2517 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
2518 ok(sz
== lstrlenW(useragentW
), "got %u\n", sz
);
2520 r
= InternetSetOptionA(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
2521 ok(r
, "failed to set user\n");
2525 SetLastError(0xdeadbeef);
2526 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2527 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2528 ok(!r
, "unexpected success\n");
2529 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2532 sz
= sizeof(buffer
);
2533 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2534 ok(r
, "failed to get user\n");
2535 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2536 ok(sz
== strlen(username
), "got %u\n", sz
);
2540 SetLastError(0xdeadbeef);
2541 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2542 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2543 ok(!r
, "unexpected success\n");
2544 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2547 sz
= sizeof(bufferW
);
2548 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2549 ok(r
, "failed to get user\n");
2550 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
2551 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2553 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
2554 ok(r
, "failed to set password\n");
2558 SetLastError(0xdeadbeef);
2559 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2560 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2561 ok(!r
, "unexpected success\n");
2562 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2565 sz
= sizeof(buffer
);
2566 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2567 ok(r
, "failed to get password\n");
2568 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2569 ok(sz
== strlen(password
), "got %u\n", sz
);
2573 SetLastError(0xdeadbeef);
2574 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2575 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2576 ok(!r
, "unexpected success\n");
2577 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2580 sz
= sizeof(bufferW
);
2581 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2582 ok(r
, "failed to get password\n");
2583 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2584 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2586 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
2587 sprintf(url
, url_fmt
, port
);
2590 SetLastError(0xdeadbeef);
2591 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2592 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2593 ok(!r
, "unexpected success\n");
2594 ok(sz
== strlen(url
) + 1, "got %u\n", sz
);
2597 sz
= sizeof(buffer
);
2598 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2599 ok(r
, "failed to get url\n");
2600 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
2601 ok(sz
== strlen(url
), "got %u\n", sz
);
2605 SetLastError(0xdeadbeef);
2606 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2607 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2608 ok(!r
, "unexpected success\n");
2609 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2612 sz
= sizeof(bufferW
);
2613 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2614 ok(r
, "failed to get url\n");
2615 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
2616 ok(sz
== strlen(url
), "got %u\n", sz
);
2617 HeapFree(GetProcessHeap(), 0, url
);
2619 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2620 ok(r
, "failed to set password\n");
2624 SetLastError(0xdeadbeef);
2625 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2626 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2627 ok(!r
, "unexpected success\n");
2628 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2631 sz
= sizeof(buffer
);
2632 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2633 ok(r
, "failed to get password\n");
2634 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2635 ok(sz
== strlen(password
), "got %u\n", sz
);
2639 SetLastError(0xdeadbeef);
2640 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2641 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2642 ok(!r
, "unexpected success\n");
2643 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2646 sz
= sizeof(bufferW
);
2647 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2648 ok(r
, "failed to get password\n");
2649 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2650 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2652 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2655 win_skip("skipping proxy tests on broken wininet\n");
2658 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2660 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2661 ok(r
, "HttpQueryInfo failed\n");
2662 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2665 InternetCloseHandle(hr
);
2666 InternetCloseHandle(hc
);
2667 InternetCloseHandle(hi
);
2670 static void test_header_handling_order(int port
)
2672 static char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
2673 static char connection
[] = "Connection: Close";
2675 static const char *types
[2] = { "*", NULL
};
2676 HINTERNET session
, connect
, request
;
2680 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2681 ok(session
!= NULL
, "InternetOpen failed\n");
2683 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2684 ok(connect
!= NULL
, "InternetConnect failed\n");
2686 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2687 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2689 ret
= HttpAddRequestHeadersA(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
2690 ok(ret
, "HttpAddRequestHeaders failed\n");
2692 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
2693 ok(ret
, "HttpSendRequest failed\n");
2695 test_status_code(request
, 200);
2696 test_request_flags(request
, 0);
2698 InternetCloseHandle(request
);
2700 request
= HttpOpenRequestA(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2701 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2703 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2704 ok(ret
, "HttpSendRequest failed\n");
2707 size
= sizeof(status
);
2708 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2709 ok(ret
, "HttpQueryInfo failed\n");
2710 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2712 InternetCloseHandle(request
);
2714 request
= HttpOpenRequestA(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2715 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2717 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2718 ok(ret
, "HttpAddRequestHeaders failed\n");
2720 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2721 ok(ret
, "HttpSendRequest failed\n");
2724 size
= sizeof(status
);
2725 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2726 ok(ret
, "HttpQueryInfo failed\n");
2727 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2729 InternetCloseHandle(request
);
2730 InternetCloseHandle(connect
);
2731 InternetCloseHandle(session
);
2734 static void test_connection_header(int port
)
2736 HINTERNET ses
, con
, req
;
2739 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2740 ok(ses
!= NULL
, "InternetOpen failed\n");
2742 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2743 ok(con
!= NULL
, "InternetConnect failed\n");
2745 req
= HttpOpenRequestA(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2746 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2748 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2749 ok(ret
, "HttpSendRequest failed\n");
2751 test_status_code(req
, 200);
2753 InternetCloseHandle(req
);
2755 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
2756 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2758 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2759 ok(ret
, "HttpSendRequest failed\n");
2761 test_status_code(req
, 200);
2763 InternetCloseHandle(req
);
2765 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2766 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2768 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2769 ok(ret
, "HttpSendRequest failed\n");
2771 test_status_code(req
, 200);
2773 InternetCloseHandle(req
);
2775 req
= HttpOpenRequestA(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2776 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2778 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2779 ok(ret
, "HttpSendRequest failed\n");
2781 test_status_code(req
, 200);
2783 InternetCloseHandle(req
);
2784 InternetCloseHandle(con
);
2785 InternetCloseHandle(ses
);
2788 static void test_http1_1(int port
)
2790 HINTERNET ses
, con
, req
;
2793 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2794 ok(ses
!= NULL
, "InternetOpen failed\n");
2796 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2797 ok(con
!= NULL
, "InternetConnect failed\n");
2799 req
= HttpOpenRequestA(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2800 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2802 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2805 InternetCloseHandle(req
);
2807 req
= HttpOpenRequestA(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2808 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2810 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2811 ok(ret
, "HttpSendRequest failed\n");
2814 InternetCloseHandle(req
);
2815 InternetCloseHandle(con
);
2816 InternetCloseHandle(ses
);
2819 static void test_connection_closing(int port
)
2821 HINTERNET session
, connection
, req
;
2824 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2826 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2827 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2829 pInternetSetStatusCallbackA(session
, callback
);
2831 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2832 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2833 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2834 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2836 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2837 req
= HttpOpenRequestA(connection
, "GET", "/testJ", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
2838 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2839 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2841 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2842 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2843 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2844 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2845 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2846 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2847 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2848 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2849 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
2850 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
2851 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2853 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2854 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2855 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2856 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2857 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2859 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2860 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2861 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2862 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2863 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2864 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2865 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2866 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2867 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2868 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2869 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2871 test_status_code(req
, 200);
2873 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2874 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2875 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2876 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2877 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2878 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2879 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2880 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2881 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2883 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2884 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2885 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2886 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2887 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2889 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2890 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2891 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2892 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2893 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2894 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2895 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2896 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2897 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2899 test_status_code(req
, 210);
2901 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2902 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2903 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2904 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2905 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2906 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2907 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2908 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2909 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
2910 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
2911 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2913 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2914 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2915 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2916 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2917 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2919 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2920 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2921 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2922 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2923 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2924 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2925 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2926 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2927 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2928 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2929 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2931 test_status_code(req
, 200);
2933 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
2934 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
2936 close_async_handle(session
, hCompleteEvent
, 2);
2937 CloseHandle(hCompleteEvent
);
2941 static void test_no_content(int port
)
2943 HINTERNET session
, connection
, req
;
2946 trace("Testing 204 no content response...\n");
2948 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2950 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2951 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2953 pInternetSetStatusCallbackA(session
, callback
);
2955 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2956 connection
= InternetConnectA(session
, "localhost", port
,
2957 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2958 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2959 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2961 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2962 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
2963 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
2964 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2965 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2967 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2968 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2969 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2970 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2971 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2972 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2973 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2974 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
2975 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
2976 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2978 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
2979 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2980 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2981 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2982 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2984 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2985 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2986 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2987 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2988 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2989 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2990 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2991 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2992 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2993 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2995 close_async_handle(session
, hCompleteEvent
, 2);
2996 CloseHandle(hCompleteEvent
);
2999 static void test_conn_close(int port
)
3001 HINTERNET session
, connection
, req
;
3002 DWORD res
, avail
, size
;
3005 trace("Testing connection close connection...\n");
3007 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3008 conn_close_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3010 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3011 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3013 pInternetSetStatusCallbackA(session
, callback
);
3015 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3016 connection
= InternetConnectA(session
, "localhost", port
,
3017 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3018 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3019 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3021 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3022 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
3023 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3024 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3025 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3027 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3028 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3029 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3030 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3031 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3032 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3033 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3034 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3036 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3037 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3038 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3039 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3040 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3042 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3043 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3044 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3045 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3046 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3047 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3048 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3049 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3052 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3053 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3054 ok(avail
!= 0, "avail = 0\n");
3057 res
= InternetReadFile(req
, buf
, avail
, &size
);
3058 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3060 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3061 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3062 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3063 ok(!avail
, "avail = %u, expected 0\n", avail
);
3065 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3066 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3067 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3068 SetEvent(conn_close_event
);
3069 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3070 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3071 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3072 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3073 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3075 close_async_handle(session
, hCompleteEvent
, 2);
3076 CloseHandle(hCompleteEvent
);
3079 static void test_no_cache(int port
)
3081 static const char cache_control_no_cache
[] = "/test_cache_control_no_cache";
3082 static const char cache_control_no_store
[] = "/test_cache_control_no_store";
3083 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3085 char cache_url
[256], buf
[256];
3086 HINTERNET ses
, con
, req
;
3090 trace("Testing no-cache header\n");
3092 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3093 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3095 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3096 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3098 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3099 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3101 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_cache
);
3102 DeleteUrlCacheEntryA(cache_url
);
3104 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3105 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3107 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3109 ok(size
== 12, "read %d bytes of data\n", size
);
3110 InternetCloseHandle(req
);
3112 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3113 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3115 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3116 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3118 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3120 ok(size
== 0, "read %d bytes of data\n", size
);
3121 InternetCloseHandle(req
);
3122 DeleteUrlCacheEntryA(cache_url
);
3124 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_store
, NULL
, NULL
, NULL
, 0, 0);
3125 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3127 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_store
);
3128 DeleteUrlCacheEntryA(cache_url
);
3130 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3131 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3133 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3135 ok(size
== 12, "read %d bytes of data\n", size
);
3136 InternetCloseHandle(req
);
3138 ret
= DeleteUrlCacheEntryA(cache_url
);
3139 ok(!ret
&& GetLastError()==ERROR_FILE_NOT_FOUND
, "cache entry should not exist\n");
3141 InternetCloseHandle(con
);
3142 InternetCloseHandle(ses
);
3145 static void test_cache_read_gzipped(int port
)
3147 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3148 static const char get_gzip
[] = "/test_cache_gzip";
3149 static const char content
[] = "gzip test\n";
3150 static const char text_html
[] = "text/html";
3151 static const char raw_header
[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3153 HINTERNET ses
, con
, req
;
3155 char cache_url
[256], buf
[256];
3158 trace("Testing reading compressed content from cache\n");
3160 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3161 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3163 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3164 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3166 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3167 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3170 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3171 if(!ret
&& GetLastError()==ERROR_INTERNET_INVALID_OPTION
) {
3172 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3173 InternetCloseHandle(req
);
3174 InternetCloseHandle(con
);
3175 InternetCloseHandle(ses
);
3178 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3180 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3181 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3183 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-size
, &read
) && read
)
3185 ok(size
== 10, "read %d bytes of data\n", size
);
3187 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3189 size
= sizeof(buf
)-1;
3190 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3191 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3193 ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3195 size
= sizeof(buf
)-1;
3196 ret
= HttpQueryInfoA(req
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &size
, 0);
3197 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3199 ok(!strncmp(raw_header
, buf
, size
), "buf = %s\n", buf
);
3200 InternetCloseHandle(req
);
3202 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3203 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3206 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3207 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3209 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3210 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3212 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3214 todo_wine
ok(size
== 10, "read %d bytes of data\n", size
);
3216 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3219 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3220 ok(!ret
&& GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND
,
3221 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3222 ret
, GetLastError());
3224 size
= sizeof(buf
)-1;
3225 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3226 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3228 todo_wine
ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3229 InternetCloseHandle(req
);
3231 /* Decompression doesn't work while reading from cache */
3232 test_cache_gzip
= 0;
3233 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3234 DeleteUrlCacheEntryA(cache_url
);
3236 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3237 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3239 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3240 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3242 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3244 ok(size
== 31, "read %d bytes of data\n", size
);
3245 InternetCloseHandle(req
);
3247 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3248 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3251 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3252 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3254 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3255 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3257 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3259 todo_wine
ok(size
== 31, "read %d bytes of data\n", size
);
3262 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3263 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3264 InternetCloseHandle(req
);
3266 InternetCloseHandle(con
);
3267 InternetCloseHandle(ses
);
3269 DeleteUrlCacheEntryA(cache_url
);
3272 static void test_HttpSendRequestW(int port
)
3274 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3275 HINTERNET ses
, con
, req
;
3279 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3280 ok(ses
!= NULL
, "InternetOpen failed\n");
3282 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3283 ok(con
!= NULL
, "InternetConnect failed\n");
3285 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3286 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3288 SetLastError(0xdeadbeef);
3289 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
3290 error
= GetLastError();
3291 ok(!ret
, "HttpSendRequestW succeeded\n");
3292 ok(error
== ERROR_IO_PENDING
||
3293 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
3294 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
3295 "got %u expected ERROR_IO_PENDING\n", error
);
3297 InternetCloseHandle(req
);
3298 InternetCloseHandle(con
);
3299 InternetCloseHandle(ses
);
3302 static void test_cookie_header(int port
)
3304 HINTERNET ses
, con
, req
;
3309 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3310 ok(ses
!= NULL
, "InternetOpen failed\n");
3312 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3313 ok(con
!= NULL
, "InternetConnect failed\n");
3315 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3317 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3318 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3321 size
= sizeof(buffer
);
3322 SetLastError(0xdeadbeef);
3323 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3324 error
= GetLastError();
3325 ok(!ret
, "HttpQueryInfo succeeded\n");
3326 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3328 ret
= HttpAddRequestHeadersA(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
3329 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3332 size
= sizeof(buffer
);
3333 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3334 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3335 ok(!strcmp(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
3337 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3338 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3340 test_status_code(req
, 200);
3343 size
= sizeof(buffer
);
3344 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3345 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3346 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
3348 InternetCloseHandle(req
);
3349 InternetCloseHandle(con
);
3350 InternetCloseHandle(ses
);
3353 static void test_basic_authentication(int port
)
3355 HINTERNET session
, connect
, request
;
3358 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3359 ok(session
!= NULL
, "InternetOpen failed\n");
3361 connect
= InternetConnectA(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
3362 ok(connect
!= NULL
, "InternetConnect failed\n");
3364 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
3365 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3367 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3368 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3370 test_status_code(request
, 200);
3371 test_request_flags(request
, 0);
3373 InternetCloseHandle(request
);
3374 InternetCloseHandle(connect
);
3375 InternetCloseHandle(session
);
3378 static void test_premature_disconnect(int port
)
3380 HINTERNET session
, connect
, request
;
3384 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3385 ok(session
!= NULL
, "InternetOpen failed\n");
3387 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3388 ok(connect
!= NULL
, "InternetConnect failed\n");
3390 request
= HttpOpenRequestA(connect
, NULL
, "/premature_disconnect", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3391 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3393 SetLastError(0xdeadbeef);
3394 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3395 err
= GetLastError();
3396 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
3397 todo_wine
ok(err
== ERROR_HTTP_INVALID_SERVER_RESPONSE
, "got %u\n", err
);
3399 InternetCloseHandle(request
);
3400 InternetCloseHandle(connect
);
3401 InternetCloseHandle(session
);
3404 static void test_invalid_response_headers(int port
)
3406 HINTERNET session
, connect
, request
;
3411 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3412 ok(session
!= NULL
, "InternetOpen failed\n");
3414 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3415 ok(connect
!= NULL
, "InternetConnect failed\n");
3417 request
= HttpOpenRequestA(connect
, NULL
, "/testE", NULL
, NULL
, NULL
, 0, 0);
3418 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3420 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3421 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3423 test_status_code(request
, 401);
3424 test_request_flags(request
, 0);
3427 size
= sizeof(buffer
);
3428 ret
= HttpQueryInfoA( request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3429 ok(ret
, "HttpQueryInfo failed\n");
3430 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
3431 "headers wrong \"%s\"\n", buffer
);
3434 size
= sizeof(buffer
);
3435 ret
= HttpQueryInfoA( request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
3436 ok(ret
, "HttpQueryInfo failed\n");
3437 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
3439 InternetCloseHandle(request
);
3440 InternetCloseHandle(connect
);
3441 InternetCloseHandle(session
);
3444 static void test_response_without_headers(int port
)
3446 HINTERNET hi
, hc
, hr
;
3447 DWORD r
, count
, size
;
3450 SetLastError(0xdeadbeef);
3451 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3452 ok(hi
!= NULL
, "open failed %u\n", GetLastError());
3454 SetLastError(0xdeadbeef);
3455 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3456 ok(hc
!= NULL
, "connect failed %u\n", GetLastError());
3458 SetLastError(0xdeadbeef);
3459 hr
= HttpOpenRequestA(hc
, NULL
, "/testG", NULL
, NULL
, NULL
, 0, 0);
3460 ok(hr
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError());
3462 test_request_flags(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3464 SetLastError(0xdeadbeef);
3465 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
3466 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
3468 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3471 memset(buffer
, 0, sizeof buffer
);
3472 SetLastError(0xdeadbeef);
3473 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
3474 ok(r
, "InternetReadFile failed %u\n", GetLastError());
3475 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
3476 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
3478 test_status_code(hr
, 200);
3479 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3482 size
= sizeof(buffer
);
3483 SetLastError(0xdeadbeef);
3484 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
3485 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3486 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
3489 size
= sizeof(buffer
);
3490 SetLastError(0xdeadbeef);
3491 r
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
3492 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3493 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
3496 size
= sizeof(buffer
);
3497 SetLastError(0xdeadbeef);
3498 r
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3499 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3500 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
3502 InternetCloseHandle(hr
);
3503 InternetCloseHandle(hc
);
3504 InternetCloseHandle(hi
);
3507 static void test_HttpQueryInfo(int port
)
3509 HINTERNET hi
, hc
, hr
;
3514 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3515 ok(hi
!= NULL
, "InternetOpen failed\n");
3517 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3518 ok(hc
!= NULL
, "InternetConnect failed\n");
3520 hr
= HttpOpenRequestA(hc
, NULL
, "/testD", NULL
, NULL
, NULL
, 0, 0);
3521 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
3523 size
= sizeof(buffer
);
3524 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3525 ok(!ret
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed %u\n", GetLastError());
3527 ret
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
3528 ok(ret
, "HttpSendRequest failed\n");
3531 size
= sizeof(buffer
);
3532 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
3533 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3534 ok(index
== 1, "expected 1 got %u\n", index
);
3537 size
= sizeof(buffer
);
3538 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
3539 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3540 ok(index
== 1, "expected 1 got %u\n", index
);
3543 size
= sizeof(buffer
);
3544 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3545 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3546 ok(index
== 0, "expected 0 got %u\n", index
);
3548 size
= sizeof(buffer
);
3549 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3550 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3551 ok(index
== 0, "expected 0 got %u\n", index
);
3553 index
= 0xdeadbeef; /* invalid start index */
3554 size
= sizeof(buffer
);
3555 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3556 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
3557 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
3558 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
3561 size
= sizeof(buffer
);
3562 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
3563 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3564 ok(index
== 0, "expected 0 got %u\n", index
);
3566 size
= sizeof(buffer
);
3567 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3568 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3569 ok(index
== 0, "expected 0 got %u\n", index
);
3571 size
= sizeof(buffer
);
3572 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
3573 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3574 ok(index
== 0, "expected 0 got %u\n", index
);
3576 test_status_code(hr
, 200);
3579 size
= sizeof(buffer
);
3580 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
3581 ok(!ret
, "HttpQueryInfo succeeded\n");
3582 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
3585 size
= sizeof(buffer
);
3586 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
3587 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3588 ok(index
== 1, "expected 1 got %u\n", index
);
3591 size
= sizeof(buffer
);
3592 strcpy(buffer
, "Server");
3593 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
3594 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3595 ok(index
== 1, "expected 1 got %u\n", index
);
3598 size
= sizeof(buffer
);
3599 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
3600 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3601 ok(index
== 1, "expected 1 got %u\n", index
);
3603 size
= sizeof(buffer
);
3604 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
3605 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3606 ok(index
== 2, "expected 2 got %u\n", index
);
3608 InternetCloseHandle(hr
);
3609 InternetCloseHandle(hc
);
3610 InternetCloseHandle(hi
);
3613 static void test_options(int port
)
3615 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi
;
3616 HINTERNET ses
, con
, req
;
3621 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3622 ok(ses
!= NULL
, "InternetOpen failed\n");
3624 SetLastError(0xdeadbeef);
3625 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
3626 error
= GetLastError();
3627 ok(!ret
, "InternetSetOption succeeded\n");
3628 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3630 SetLastError(0xdeadbeef);
3631 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
3632 ok(!ret
, "InternetSetOption succeeded\n");
3633 error
= GetLastError();
3634 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3636 SetLastError(0xdeadbeef);
3637 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
3638 ok(!ret
, "InternetSetOption succeeded\n");
3639 error
= GetLastError();
3640 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3643 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3644 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3646 SetLastError(0xdeadbeef);
3647 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
3648 error
= GetLastError();
3649 ok(!ret
, "InternetQueryOption succeeded\n");
3650 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3652 SetLastError(0xdeadbeef);
3653 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
3654 error
= GetLastError();
3655 ok(!ret
, "InternetQueryOption succeeded\n");
3656 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3659 SetLastError(0xdeadbeef);
3660 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
3661 error
= GetLastError();
3662 ok(!ret
, "InternetQueryOption succeeded\n");
3663 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
3666 SetLastError(0xdeadbeef);
3667 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3668 error
= GetLastError();
3669 ok(!ret
, "InternetQueryOption succeeded\n");
3670 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
3674 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3675 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3676 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
3678 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3679 ok(con
!= NULL
, "InternetConnect failed\n");
3683 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3684 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3685 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
3688 ret
= InternetSetOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3689 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3693 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3694 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3695 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
3697 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3698 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3702 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3703 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3704 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
3707 ret
= InternetSetOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3708 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3712 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3713 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3714 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
3716 size
= sizeof(idsi
);
3717 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO
, &idsi
, &size
);
3718 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3721 SetLastError(0xdeadbeef);
3722 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
3723 error
= GetLastError();
3724 ok(!ret
, "InternetQueryOption succeeded\n");
3725 ok(error
== ERROR_INTERNET_INVALID_OPERATION
, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error
);
3727 /* INTERNET_OPTION_PROXY */
3728 SetLastError(0xdeadbeef);
3729 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
3730 error
= GetLastError();
3731 ok(!ret
, "InternetQueryOption succeeded\n");
3732 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3734 SetLastError(0xdeadbeef);
3735 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
3736 error
= GetLastError();
3737 ok(!ret
, "InternetQueryOption succeeded\n");
3738 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3741 SetLastError(0xdeadbeef);
3742 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
3743 error
= GetLastError();
3744 ok(!ret
, "InternetQueryOption succeeded\n");
3745 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
3746 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
3748 InternetCloseHandle(req
);
3749 InternetCloseHandle(con
);
3750 InternetCloseHandle(ses
);
3754 const char *response_text
;
3756 const char *status_text
;
3757 const char *raw_headers
;
3758 } http_status_test_t
;
3760 static const http_status_test_t http_status_tests
[] = {
3762 "HTTP/1.1 200 OK\r\n"
3763 "Content-Length: 1\r\n"
3769 "HTTP/1.1 404 Fail\r\n"
3770 "Content-Length: 1\r\n"
3777 "Content-Length: 1\r\n"
3784 "Content-Length: 1\r\n"
3791 static void test_http_status(int port
)
3793 HINTERNET ses
, con
, req
;
3798 for(i
=0; i
< sizeof(http_status_tests
)/sizeof(*http_status_tests
); i
++) {
3799 send_buffer
= http_status_tests
[i
].response_text
;
3801 ses
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3802 ok(ses
!= NULL
, "InternetOpen failed\n");
3804 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3805 ok(con
!= NULL
, "InternetConnect failed\n");
3807 req
= HttpOpenRequestA(con
, NULL
, "/send_from_buffer", NULL
, NULL
, NULL
, 0, 0);
3808 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3810 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3811 ok(res
, "HttpSendRequest failed\n");
3813 test_status_code(req
, http_status_tests
[i
].status_code
);
3816 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_TEXT
, buf
, &size
, NULL
);
3817 ok(res
, "HttpQueryInfo failed: %u\n", GetLastError());
3818 ok(!strcmp(buf
, http_status_tests
[i
].status_text
), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
3819 i
, buf
, http_status_tests
[i
].status_text
);
3821 InternetCloseHandle(req
);
3822 InternetCloseHandle(con
);
3823 InternetCloseHandle(ses
);
3827 static void test_cache_control_verb(int port
)
3829 HINTERNET session
, connect
, request
;
3832 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3833 ok(session
!= NULL
, "InternetOpen failed\n");
3835 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3836 ok(connect
!= NULL
, "InternetConnect failed\n");
3838 request
= HttpOpenRequestA(connect
, "RPC_OUT_DATA", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3839 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3840 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3841 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3842 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3843 test_status_code(request
, 200);
3845 request
= HttpOpenRequestA(connect
, "POST", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3846 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3847 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3848 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3849 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3850 test_status_code(request
, 200);
3852 request
= HttpOpenRequestA(connect
, "HEAD", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3853 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3854 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3855 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3856 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3857 test_status_code(request
, 200);
3859 request
= HttpOpenRequestA(connect
, "GET", "/test_cache_control_verb", NULL
, NULL
, NULL
,
3860 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3861 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3862 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3863 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3864 test_status_code(request
, 200);
3866 InternetCloseHandle(request
);
3867 InternetCloseHandle(connect
);
3868 InternetCloseHandle(session
);
3871 static void test_http_connection(void)
3873 struct server_info si
;
3877 si
.hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
3880 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
3881 ok( hThread
!= NULL
, "create thread failed\n");
3883 r
= WaitForSingleObject(si
.hEvent
, 10000);
3884 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
3885 if (r
!= WAIT_OBJECT_0
)
3888 test_basic_request(si
.port
, "GET", "/test1");
3889 test_proxy_indirect(si
.port
);
3890 test_proxy_direct(si
.port
);
3891 test_header_handling_order(si
.port
);
3892 test_basic_request(si
.port
, "POST", "/test5");
3893 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
3894 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
3895 test_basic_request(si
.port
, "GET", "/test6");
3896 test_basic_request(si
.port
, "GET", "/testF");
3897 test_connection_header(si
.port
);
3898 test_http1_1(si
.port
);
3899 test_cookie_header(si
.port
);
3900 test_basic_authentication(si
.port
);
3901 test_invalid_response_headers(si
.port
);
3902 test_response_without_headers(si
.port
);
3903 test_HttpQueryInfo(si
.port
);
3904 test_HttpSendRequestW(si
.port
);
3905 test_last_error(si
.port
);
3906 test_options(si
.port
);
3907 test_no_content(si
.port
);
3908 test_conn_close(si
.port
);
3909 test_no_cache(si
.port
);
3910 test_cache_read_gzipped(si
.port
);
3911 test_http_status(si
.port
);
3912 test_premature_disconnect(si
.port
);
3913 test_connection_closing(si
.port
);
3914 test_cache_control_verb(si
.port
);
3916 /* send the basic request again to shutdown the server thread */
3917 test_basic_request(si
.port
, "GET", "/quit");
3919 r
= WaitForSingleObject(hThread
, 3000);
3920 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
3921 CloseHandle(hThread
);
3924 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
3926 LocalFree(info
->lpszSubjectInfo
);
3927 LocalFree(info
->lpszIssuerInfo
);
3928 LocalFree(info
->lpszProtocolName
);
3929 LocalFree(info
->lpszSignatureAlgName
);
3930 LocalFree(info
->lpszEncryptionAlgName
);
3934 const char *ex_subject
;
3935 const char *ex_issuer
;
3936 } cert_struct_test_t
;
3938 static const cert_struct_test_t test_winehq_org_cert
= {
3939 "0mJuv1t-1CFypQkyTZwfvjHHBAbnUndG\r\n"
3941 "See www.rapidssl.com/resources/cps (c)13\r\n"
3942 "Domain Control Validated - RapidSSL(R)\r\n"
3946 "\"GeoTrust, Inc.\"\r\n"
3950 static const cert_struct_test_t test_winehq_com_cert
= {
3955 "test.winehq.com\r\n"
3956 "webmaster@winehq.org",
3961 "test.winehq.com\r\n"
3962 "webmaster@winehq.org"
3965 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
3967 INTERNET_CERTIFICATE_INFOA info
;
3971 memset(&info
, 0x5, sizeof(info
));
3973 size
= sizeof(info
);
3974 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
3975 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
3976 ok(size
== sizeof(info
), "size = %u\n", size
);
3978 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
3979 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
3980 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
3981 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
3982 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
3983 ok(info
.dwKeySize
== 128, "dwKeySize = %u\n", info
.dwKeySize
);
3985 release_cert_info(&info
);
3988 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
3989 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
3991 char url
[INTERNET_MAX_URL_LENGTH
];
3992 const CERT_CHAIN_CONTEXT
*chain
;
3996 if(!pInternetGetSecurityInfoByURLA
) {
3997 win_skip("pInternetGetSecurityInfoByURLA not available\n");
4002 chain
= (void*)0xdeadbeef;
4004 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
4005 if(error
== ERROR_SUCCESS
) {
4006 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
4007 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
4008 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
4009 CertFreeCertificateChain(chain
);
4011 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
4012 "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res
, GetLastError(), error
);
4016 #define test_secflags_option(a,b) _test_secflags_option(__LINE__,a,b)
4017 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
)
4023 size
= sizeof(flags
);
4024 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4025 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4026 ok_(__FILE__
,line
)(flags
== ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n", flags
, ex_flags
);
4028 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
4030 size
= sizeof(flags
);
4031 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4032 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
4033 ok_(__FILE__
,line
)(flags
== ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n", flags
, ex_flags
);
4036 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
4037 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
4041 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
4042 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4045 static void test_security_flags(void)
4047 HINTERNET ses
, conn
, req
;
4052 trace("Testing security flags...\n");
4054 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4056 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4057 ok(ses
!= NULL
, "InternetOpen failed\n");
4059 pInternetSetStatusCallbackA(ses
, &callback
);
4061 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4062 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
4063 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
4064 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
4065 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4067 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4068 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4069 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4071 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4072 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4075 size
= sizeof(flags
);
4076 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4077 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
4078 win_skip("Incomplete security flags support, skipping\n");
4080 close_async_handle(ses
, hCompleteEvent
, 2);
4081 CloseHandle(hCompleteEvent
);
4085 test_secflags_option(req
, 0);
4086 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4088 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4089 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
);
4091 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4092 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4094 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4095 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4097 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
4098 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
4099 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
4101 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
4102 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
4103 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4104 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4105 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4106 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4107 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4108 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4109 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4110 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4111 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4113 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4114 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4116 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4117 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4119 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
4120 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
4121 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4122 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4123 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4124 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4125 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4126 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4127 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4128 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4129 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4131 test_request_flags(req
, 0);
4132 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4133 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
);
4135 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4136 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4137 ok(size
, "size = 0\n");
4139 /* Collect all existing persistent connections */
4140 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4141 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4143 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4144 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4145 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4147 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4148 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4150 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
4151 res
= InternetSetOptionA(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
4152 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
4154 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4155 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4156 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4157 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4158 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4159 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4160 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4162 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4163 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4165 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4166 ok(req_error
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| broken(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
),
4167 "req_error = %d\n", req_error
);
4169 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4170 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4171 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4172 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4173 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4174 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4175 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4177 if(req_error
!= ERROR_INTERNET_SEC_CERT_REV_FAILED
) {
4178 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error
);
4180 close_async_handle(ses
, hCompleteEvent
, 3);
4181 CloseHandle(hCompleteEvent
);
4186 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
4187 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
4189 test_request_flags(req
, 8);
4190 test_secflags_option(req
, 0x800000);
4192 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4193 test_secflags_option(req
, 0x800000|SECURITY_FLAG_IGNORE_REVOCATION
);
4195 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4196 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4197 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4198 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4199 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4200 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4201 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4203 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4204 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4206 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4207 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
4209 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4210 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4211 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4212 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4213 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4214 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4215 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4217 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
4218 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4219 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4221 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4222 test_secflags_option(req
, 0x1800000|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4223 |SECURITY_FLAG_IGNORE_REVOCATION
);
4224 test_http_version(req
);
4226 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4227 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4228 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4229 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4230 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4231 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4232 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4233 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4234 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4236 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4237 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4239 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4240 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4242 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4243 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4244 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4245 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4246 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4247 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4248 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4249 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4250 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4252 test_request_flags(req
, 0);
4253 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
4254 |SECURITY_FLAG_STRENGTH_STRONG
|0x1800000);
4256 test_cert_struct(req
, &test_winehq_com_cert
);
4257 test_security_info("https://test.winehq.com/data/some_file.html?q", 0, 0x1800000);
4259 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4260 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4261 ok(size
, "size = 0\n");
4263 close_async_handle(ses
, hCompleteEvent
, 3);
4265 /* Collect all existing persistent connections */
4266 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4267 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4269 /* Make another request, without setting security flags */
4271 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4272 ok(ses
!= NULL
, "InternetOpen failed\n");
4274 pInternetSetStatusCallbackA(ses
, &callback
);
4276 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4277 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
4278 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
4279 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
4280 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4282 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4283 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4284 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4286 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4287 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4289 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
4290 |SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4291 test_http_version(req
);
4293 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4294 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4295 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4296 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4297 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4298 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4299 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4300 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4302 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4303 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4305 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4306 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4308 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4309 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4310 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4311 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4312 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4313 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4314 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4315 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4317 test_request_flags(req
, 0);
4318 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
4319 |SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
4321 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4322 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4323 ok(size
, "size = 0\n");
4325 close_async_handle(ses
, hCompleteEvent
, 2);
4327 CloseHandle(hCompleteEvent
);
4329 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4330 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4331 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4334 static void test_secure_connection(void)
4336 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
4337 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
4338 static const WCHAR get
[] = {'G','E','T',0};
4339 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
4340 HINTERNET ses
, con
, req
;
4342 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
4343 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
4346 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4347 ok(ses
!= NULL
, "InternetOpen failed\n");
4349 con
= InternetConnectA(ses
, "test.winehq.org",
4350 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
4351 INTERNET_SERVICE_HTTP
, 0, 0);
4352 ok(con
!= NULL
, "InternetConnect failed\n");
4354 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4355 INTERNET_FLAG_SECURE
, 0);
4356 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4358 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4359 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
4361 size
= sizeof(flags
);
4362 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4363 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4364 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
4366 test_cert_struct(req
, &test_winehq_org_cert
);
4368 /* Querying the same option through InternetQueryOptionW still results in
4369 * ASCII strings being returned.
4372 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4374 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4375 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
4376 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
4377 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4378 certificate_structW
, &size
);
4379 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
4380 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4383 ok(certificate_structA
->lpszSubjectInfo
&&
4384 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4385 "expected a non-empty subject name\n");
4386 ok(certificate_structA
->lpszIssuerInfo
&&
4387 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4388 "expected a non-empty issuer name\n");
4389 ok(!certificate_structA
->lpszSignatureAlgName
,
4390 "unexpected signature algorithm name\n");
4391 ok(!certificate_structA
->lpszEncryptionAlgName
,
4392 "unexpected encryption algorithm name\n");
4393 ok(!certificate_structA
->lpszProtocolName
,
4394 "unexpected protocol name\n");
4395 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4396 release_cert_info(certificate_structA
);
4398 HeapFree(GetProcessHeap(), 0, certificate_structW
);
4400 InternetCloseHandle(req
);
4401 InternetCloseHandle(con
);
4402 InternetCloseHandle(ses
);
4404 /* Repeating the tests with the W functions has the same result: */
4405 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4406 ok(ses
!= NULL
, "InternetOpen failed\n");
4408 con
= InternetConnectW(ses
, testsite
,
4409 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
4410 INTERNET_SERVICE_HTTP
, 0, 0);
4411 ok(con
!= NULL
, "InternetConnect failed\n");
4413 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
4414 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
4415 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4417 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4418 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
4420 size
= sizeof(flags
);
4421 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4422 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4423 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %x\n", flags
);
4425 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4427 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4428 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
4429 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
4430 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4431 certificate_structA
, &size
);
4432 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4435 ok(certificate_structA
->lpszSubjectInfo
&&
4436 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4437 "expected a non-empty subject name\n");
4438 ok(certificate_structA
->lpszIssuerInfo
&&
4439 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4440 "expected a non-empty issuer name\n");
4441 ok(!certificate_structA
->lpszSignatureAlgName
,
4442 "unexpected signature algorithm name\n");
4443 ok(!certificate_structA
->lpszEncryptionAlgName
,
4444 "unexpected encryption algorithm name\n");
4445 ok(!certificate_structA
->lpszProtocolName
,
4446 "unexpected protocol name\n");
4447 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4448 release_cert_info(certificate_structA
);
4450 HeapFree(GetProcessHeap(), 0, certificate_structA
);
4452 /* Again, querying the same option through InternetQueryOptionW still
4453 * results in ASCII strings being returned.
4456 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4458 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4459 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
4460 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
4461 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4462 certificate_structW
, &size
);
4463 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
4464 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4467 ok(certificate_structA
->lpszSubjectInfo
&&
4468 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4469 "expected a non-empty subject name\n");
4470 ok(certificate_structA
->lpszIssuerInfo
&&
4471 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4472 "expected a non-empty issuer name\n");
4473 ok(!certificate_structA
->lpszSignatureAlgName
,
4474 "unexpected signature algorithm name\n");
4475 ok(!certificate_structA
->lpszEncryptionAlgName
,
4476 "unexpected encryption algorithm name\n");
4477 ok(!certificate_structA
->lpszProtocolName
,
4478 "unexpected protocol name\n");
4479 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4480 release_cert_info(certificate_structA
);
4482 HeapFree(GetProcessHeap(), 0, certificate_structW
);
4484 InternetCloseHandle(req
);
4485 InternetCloseHandle(con
);
4486 InternetCloseHandle(ses
);
4489 static void test_user_agent_header(void)
4491 HINTERNET ses
, con
, req
;
4496 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4497 ok(ses
!= NULL
, "InternetOpen failed\n");
4499 con
= InternetConnectA(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4500 ok(con
!= NULL
, "InternetConnect failed\n");
4502 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
4503 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4505 size
= sizeof(buffer
);
4506 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4507 err
= GetLastError();
4508 ok(!ret
, "HttpQueryInfo succeeded\n");
4509 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4511 ret
= HttpAddRequestHeadersA(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
4512 ok(ret
, "HttpAddRequestHeaders succeeded\n");
4514 size
= sizeof(buffer
);
4515 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4516 err
= GetLastError();
4517 ok(ret
, "HttpQueryInfo failed\n");
4518 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4520 InternetCloseHandle(req
);
4522 req
= HttpOpenRequestA(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
4523 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4525 size
= sizeof(buffer
);
4526 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4527 err
= GetLastError();
4528 ok(!ret
, "HttpQueryInfo succeeded\n");
4529 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4531 ret
= HttpAddRequestHeadersA(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
4532 ok(ret
, "HttpAddRequestHeaders failed\n");
4535 size
= sizeof(buffer
);
4536 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4537 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
4538 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
4540 InternetCloseHandle(req
);
4541 InternetCloseHandle(con
);
4542 InternetCloseHandle(ses
);
4545 static void test_bogus_accept_types_array(void)
4547 HINTERNET ses
, con
, req
;
4548 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
4553 ses
= InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
4554 con
= InternetConnectA(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4555 req
= HttpOpenRequestA(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
4557 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
4560 size
= sizeof(buffer
);
4561 SetLastError(0xdeadbeef);
4562 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4563 error
= GetLastError();
4564 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
4565 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
4566 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
4567 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
4568 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
4570 InternetCloseHandle(req
);
4571 InternetCloseHandle(con
);
4572 InternetCloseHandle(ses
);
4581 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
4583 INTERNET_ASYNC_RESULT
*result
= info
;
4584 struct context
*ctx
= (struct context
*)context
;
4586 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
4589 case INTERNET_STATUS_REQUEST_COMPLETE
:
4590 trace("request handle: 0x%08lx\n", result
->dwResult
);
4591 ctx
->req
= (HINTERNET
)result
->dwResult
;
4592 SetEvent(ctx
->event
);
4594 case INTERNET_STATUS_HANDLE_CLOSING
: {
4595 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
4597 if (InternetQueryOptionA(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
4598 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
4599 SetEvent(ctx
->event
);
4602 case INTERNET_STATUS_NAME_RESOLVED
:
4603 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
4604 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
4606 ok(str
[0] && str
[1], "Got string: %s\n", str
);
4607 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
4612 static void test_open_url_async(void)
4620 /* Collect all existing persistent connections */
4621 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4622 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4625 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
4626 * other versions never do. They also hang of following tests. We disable it for everything older
4629 if(!pInternetGetSecurityInfoByURLA
) {
4630 win_skip("Skipping async open on too old wininet version.\n");
4635 ctx
.event
= CreateEventA(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
4637 ses
= InternetOpenA("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4638 ok(ses
!= NULL
, "InternetOpen failed\n");
4640 SetLastError(0xdeadbeef);
4641 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
4642 error
= GetLastError();
4643 ok(!ret
, "InternetSetOptionA succeeded\n");
4644 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
4646 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
4647 error
= GetLastError();
4648 ok(!ret
, "InternetSetOptionA failed\n");
4649 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
4651 pInternetSetStatusCallbackW(ses
, cb
);
4652 ResetEvent(ctx
.event
);
4654 req
= InternetOpenUrlA(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
4655 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
4657 WaitForSingleObject(ctx
.event
, INFINITE
);
4660 size
= sizeof(type
);
4661 ret
= InternetQueryOptionA(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
4662 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
4663 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
4664 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
4667 ret
= HttpQueryInfoA(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
4668 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
4669 ok(size
> 0, "expected size > 0\n");
4671 ResetEvent(ctx
.event
);
4672 InternetCloseHandle(ctx
.req
);
4673 WaitForSingleObject(ctx
.event
, INFINITE
);
4675 InternetCloseHandle(ses
);
4676 CloseHandle(ctx
.event
);
4681 internet_connect
= 1,
4683 http_send_request_ex
,
4686 internet_close_handle
4691 enum api function
; /* api responsible for notification */
4692 unsigned int status
; /* status received */
4693 int async
; /* delivered from another thread? */
4701 const struct notification
*test
;
4707 DWORD expect_result
;
4711 static CRITICAL_SECTION notification_cs
;
4713 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
4715 BOOL status_ok
, function_ok
;
4716 struct info
*info
= (struct info
*)context
;
4719 EnterCriticalSection( ¬ification_cs
);
4721 if(info
->is_aborted
) {
4722 LeaveCriticalSection(¬ification_cs
);
4726 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
4728 DWORD size
= sizeof(struct info
*);
4729 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
4730 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
4731 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
4733 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
4734 if(info
->expect_result
== ERROR_SUCCESS
) {
4735 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
4737 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
4738 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
4743 if (i
>= info
->count
)
4745 LeaveCriticalSection( ¬ification_cs
);
4749 while (info
->test
[i
].status
!= status
&&
4750 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
4751 i
< info
->count
- 1 &&
4752 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
4757 status_ok
= (info
->test
[i
].status
== status
);
4758 function_ok
= (info
->test
[i
].function
== info
->function
);
4760 if (!info
->test
[i
].todo
)
4762 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
4763 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
4765 if (info
->test
[i
].async
)
4766 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
4767 info
->line
, info
->thread
, GetCurrentThreadId());
4771 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
4773 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
4775 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
4778 LeaveCriticalSection( ¬ification_cs
);
4781 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
4783 info
->function
= function
;
4785 info
->expect_result
= expect_result
;
4788 struct notification_data
4790 const struct notification
*test
;
4791 const unsigned int count
;
4796 BOOL expect_conn_failure
;
4799 static const struct notification async_send_request_ex_test
[] =
4801 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
4802 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
4803 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
4804 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, 1, 0, 1 },
4805 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, 1, 0, 1 },
4806 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, 1, 0, 1 },
4807 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, 1 },
4808 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, 1 },
4809 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, 1 },
4810 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, 1 },
4811 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
4812 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, 0 },
4813 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, 0 },
4814 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, 1 },
4815 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, 1 },
4816 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
4817 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0, 1 },
4818 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0, 1 },
4819 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, },
4820 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, }
4823 static const struct notification async_send_request_ex_test2
[] =
4825 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
4826 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
4827 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
4828 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, 1, 0, 1 },
4829 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, 1, 0, 1 },
4830 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, 1, 0, 1 },
4831 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, 1, 1 },
4832 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, 1, 1 },
4833 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, 1 },
4834 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, 1 },
4835 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
4836 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, 1 },
4837 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, 1 },
4838 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
4839 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0, 1 },
4840 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0, 1 },
4841 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, },
4842 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, }
4845 static const struct notification async_send_request_ex_resolve_failure_test
[] =
4847 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
4848 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
4849 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
4850 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, 1 },
4851 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
4852 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
4853 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
4854 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0, 1 },
4855 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0, 1 },
4856 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, },
4857 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, }
4860 static const struct notification async_send_request_ex_chunked_test
[] =
4862 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
},
4863 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
},
4864 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
4865 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, 1, 0, 1 },
4866 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, 1, 0, 1 },
4867 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, 1, 0, 1 },
4868 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, 1 },
4869 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, 1 },
4870 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, 1 },
4871 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, 1 },
4872 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
4873 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, 1 },
4874 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, 1 },
4875 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
4876 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
},
4877 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
},
4878 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
},
4879 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
}
4882 static const struct notification_data notification_data
[] = {
4884 async_send_request_ex_chunked_test
,
4885 sizeof(async_send_request_ex_chunked_test
)/sizeof(async_send_request_ex_chunked_test
[0]),
4891 async_send_request_ex_test
,
4892 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
4895 "tests/posttest.php",
4896 "Public ID=codeweavers"
4899 async_send_request_ex_test2
,
4900 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
4903 "tests/posttest.php"
4906 async_send_request_ex_resolve_failure_test
,
4907 sizeof(async_send_request_ex_resolve_failure_test
)/sizeof(async_send_request_ex_resolve_failure_test
[0]),
4916 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
4919 HINTERNET ses
, req
, con
;
4921 DWORD size
, written
, error
;
4922 INTERNET_BUFFERSA b
;
4923 static const char *accept
[2] = {"*/*", NULL
};
4926 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
4928 InitializeCriticalSection( ¬ification_cs
);
4930 info
.test
= nd
->test
;
4931 info
.count
= nd
->count
;
4933 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
4934 info
.thread
= GetCurrentThreadId();
4935 info
.is_aborted
= FALSE
;
4937 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4938 ok( ses
!= NULL
, "InternetOpen failed\n" );
4940 pInternetSetStatusCallbackA( ses
, check_notification
);
4942 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
4943 con
= InternetConnectA( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
4944 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
4946 WaitForSingleObject( info
.wait
, 10000 );
4948 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
4949 req
= HttpOpenRequestA( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
4950 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
4952 WaitForSingleObject( info
.wait
, 10000 );
4955 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
4956 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
4957 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
4958 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
4959 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
4962 setup_test( &info
, http_send_request_ex
, __LINE__
,
4963 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
4964 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
4965 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
4967 error
= WaitForSingleObject( info
.wait
, 10000 );
4968 if(error
!= WAIT_OBJECT_0
) {
4969 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
4970 info
.is_aborted
= TRUE
;
4974 size
= sizeof(buffer
);
4975 SetLastError( 0xdeadbeef );
4976 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
4977 error
= GetLastError();
4978 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4979 if(nd
->expect_conn_failure
) {
4980 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
4983 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
4984 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
4990 size
= strlen( nd
->data
);
4991 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
4992 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
4993 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
4994 ok( written
== size
, "expected %u got %u\n", written
, size
);
4996 WaitForSingleObject( info
.wait
, 10000 );
4998 SetLastError( 0xdeadbeef );
4999 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
5000 error
= GetLastError();
5001 ok( !ret
, "HttpEndRequestA succeeded\n" );
5002 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
5005 SetLastError( 0xdeadbeef );
5006 setup_test( &info
, http_end_request
, __LINE__
,
5007 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
5008 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
5009 error
= GetLastError();
5010 ok( !ret
, "HttpEndRequestA succeeded\n" );
5011 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
5013 WaitForSingleObject( info
.wait
, 10000 );
5015 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
5017 InternetCloseHandle( req
);
5018 InternetCloseHandle( con
);
5019 InternetCloseHandle( ses
);
5021 WaitForSingleObject( info
.wait
, 10000 );
5023 CloseHandle( info
.wait
);
5026 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
5027 static BOOL closetest_closed
;
5029 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
5030 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
5035 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
5037 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
5038 "Unexpected hInternet %p\n", hInternet
);
5039 if(!closetest_closed
)
5043 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
5044 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
5045 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5046 closetest_req
, res
, GetLastError());
5049 static void test_InternetCloseHandle(void)
5054 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5055 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
5057 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
5059 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
5060 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
5061 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
5063 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
5064 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
5066 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
5067 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
5068 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
5070 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
5072 res
= InternetCloseHandle(closetest_session
);
5073 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
5074 closetest_closed
= TRUE
;
5075 trace("Closed session handle\n");
5077 res
= InternetCloseHandle(closetest_conn
);
5078 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
5079 res
, GetLastError());
5081 res
= InternetCloseHandle(closetest_req
);
5082 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
5083 res
, GetLastError());
5085 len
= sizeof(flags
);
5086 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
5087 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
5088 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5089 closetest_req
, res
, GetLastError());
5092 static void test_connection_failure(void)
5094 HINTERNET session
, connect
, request
;
5098 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5099 ok(session
!= NULL
, "failed to get session handle\n");
5101 connect
= InternetConnectA(session
, "localhost", 1, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5102 ok(connect
!= NULL
, "failed to get connection handle\n");
5104 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
5105 ok(request
!= NULL
, "failed to get request handle\n");
5107 SetLastError(0xdeadbeef);
5108 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
5109 error
= GetLastError();
5110 ok(!ret
, "unexpected success\n");
5111 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
5113 InternetCloseHandle(request
);
5114 InternetCloseHandle(connect
);
5115 InternetCloseHandle(session
);
5118 static void test_default_service_port(void)
5120 HINTERNET session
, connect
, request
;
5124 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
5125 ok(session
!= NULL
, "InternetOpen failed\n");
5127 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
5128 INTERNET_SERVICE_HTTP
, 0, 0);
5129 ok(connect
!= NULL
, "InternetConnect failed\n");
5131 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
5132 ok(request
!= NULL
, "HttpOpenRequest failed\n");
5134 SetLastError(0xdeadbeef);
5135 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
5136 error
= GetLastError();
5137 ok(!ret
, "HttpSendRequest succeeded\n");
5138 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
5141 InternetCloseHandle(request
);
5142 InternetCloseHandle(connect
);
5143 InternetCloseHandle(session
);
5146 static void init_status_tests(void)
5148 memset(expect
, 0, sizeof(expect
));
5149 memset(optional
, 0, sizeof(optional
));
5150 memset(wine_allow
, 0, sizeof(wine_allow
));
5151 memset(notified
, 0, sizeof(notified
));
5152 memset(status_string
, 0, sizeof(status_string
));
5154 #define STATUS_STRING(status) status_string[status] = #status
5155 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
5156 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
5157 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5158 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5159 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
5160 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
5161 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
5162 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
5163 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
5164 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
5165 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
5166 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
5167 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
5168 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
5169 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
5170 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
5171 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
5172 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
5173 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
5174 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
5175 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
5176 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
5177 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
5178 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
5179 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
5180 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
5181 #undef STATUS_STRING
5187 hdll
= GetModuleHandleA("wininet.dll");
5189 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
5190 win_skip("Too old IE (older than 6.0)\n");
5194 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
5195 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
5196 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
5198 init_status_tests();
5199 test_InternetCloseHandle();
5200 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
5201 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
5202 InternetReadFile_test(0, &test_data
[1]);
5203 first_connection_to_test_url
= TRUE
;
5204 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
5205 test_security_flags();
5206 InternetReadFile_test(0, &test_data
[2]);
5207 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
5208 test_open_url_async();
5209 test_async_HttpSendRequestEx(¬ification_data
[0]);
5210 test_async_HttpSendRequestEx(¬ification_data
[1]);
5211 test_async_HttpSendRequestEx(¬ification_data
[2]);
5212 test_async_HttpSendRequestEx(¬ification_data
[3]);
5213 InternetOpenRequest_test();
5215 InternetLockRequestFile_test();
5216 InternetOpenUrlA_test();
5218 test_http_connection();
5219 test_secure_connection();
5220 test_user_agent_header();
5221 test_bogus_accept_types_array();
5222 InternetReadFile_chunked_test();
5223 HttpSendRequestEx_test();
5224 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
5225 test_connection_failure();
5226 test_default_service_port();