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)
192 static void _test_status_code(unsigned line
, HINTERNET req
, DWORD excode
)
194 DWORD code
, size
, index
;
195 char exbuf
[10], bufa
[10];
201 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, NULL
);
202 ok_(__FILE__
,line
)(res
, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
203 ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
204 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
209 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
210 ok_(__FILE__
,line
)(res
, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
211 ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
212 ok_(__FILE__
,line
)(!index
, "index = %d, expected 0\n", code
);
213 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
215 sprintf(exbuf
, "%u", excode
);
218 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, bufa
, &size
, NULL
);
219 ok_(__FILE__
,line
)(res
, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
220 ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
221 ok_(__FILE__
,line
)(size
== strlen(exbuf
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
224 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
225 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
226 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
227 ok_(__FILE__
,line
)(size
== strlen(exbuf
)+1, "unexpected size %d for \"%s\"\n", size
, exbuf
);
230 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
231 ok_(__FILE__
,line
)(res
, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
232 ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
233 ok_(__FILE__
,line
)(size
== strlen(exbuf
)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
236 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
237 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
238 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
239 ok_(__FILE__
,line
)(size
== (strlen(exbuf
)+1)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
243 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
244 ok(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
245 ok(size
== sizeof(bufw
), "unexpected size %d\n", size
);
251 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
252 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
253 "[7] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
257 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, &code
, &size
, NULL
);
258 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST
,
259 "[8] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
262 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
263 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
264 static void _test_request_flags(unsigned line
, HINTERNET req
, DWORD exflags
, BOOL is_todo
)
270 size
= sizeof(flags
);
271 res
= InternetQueryOptionW(req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &size
);
272 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
274 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
275 flags
&= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED
;
277 ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
279 todo_wine
ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
282 #define test_http_version(a) _test_http_version(__LINE__,a)
283 static void _test_http_version(unsigned line
, HINTERNET req
)
285 HTTP_VERSION_INFO v
= {0xdeadbeef, 0xdeadbeef};
290 res
= InternetQueryOptionW(req
, INTERNET_OPTION_HTTP_VERSION
, &v
, &size
);
291 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
292 ok_(__FILE__
,line
)(v
.dwMajorVersion
== 1, "dwMajorVersion = %d\n", v
.dwMajorVersion
);
293 ok_(__FILE__
,line
)(v
.dwMinorVersion
== 1, "dwMinorVersion = %d\n", v
.dwMinorVersion
);
296 static int close_handle_cnt
;
298 static VOID WINAPI
callback(
301 DWORD dwInternetStatus
,
302 LPVOID lpvStatusInformation
,
303 DWORD dwStatusInformationLength
306 CHECK_EXPECT(dwInternetStatus
);
307 switch (dwInternetStatus
)
309 case INTERNET_STATUS_RESOLVING_NAME
:
310 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
311 GetCurrentThreadId(), hInternet
, dwContext
,
312 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
313 *(LPSTR
)lpvStatusInformation
= '\0';
315 case INTERNET_STATUS_NAME_RESOLVED
:
316 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
317 GetCurrentThreadId(), hInternet
, dwContext
,
318 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
319 *(LPSTR
)lpvStatusInformation
= '\0';
321 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
322 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
323 GetCurrentThreadId(), hInternet
, dwContext
,
324 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
325 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
326 dwStatusInformationLength
);
327 *(LPSTR
)lpvStatusInformation
= '\0';
329 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
330 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
331 GetCurrentThreadId(), hInternet
, dwContext
,
332 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
333 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
334 dwStatusInformationLength
);
335 *(LPSTR
)lpvStatusInformation
= '\0';
337 case INTERNET_STATUS_SENDING_REQUEST
:
338 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
339 GetCurrentThreadId(), hInternet
, dwContext
,
340 lpvStatusInformation
,dwStatusInformationLength
);
342 case INTERNET_STATUS_REQUEST_SENT
:
343 ok(dwStatusInformationLength
== sizeof(DWORD
),
344 "info length should be sizeof(DWORD) instead of %d\n",
345 dwStatusInformationLength
);
346 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
347 GetCurrentThreadId(), hInternet
, dwContext
,
348 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
350 case INTERNET_STATUS_RECEIVING_RESPONSE
:
351 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
352 GetCurrentThreadId(), hInternet
, dwContext
,
353 lpvStatusInformation
,dwStatusInformationLength
);
355 case INTERNET_STATUS_RESPONSE_RECEIVED
:
356 ok(dwStatusInformationLength
== sizeof(DWORD
),
357 "info length should be sizeof(DWORD) instead of %d\n",
358 dwStatusInformationLength
);
359 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
360 GetCurrentThreadId(), hInternet
, dwContext
,
361 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
363 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
364 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
365 GetCurrentThreadId(), hInternet
,dwContext
,
366 lpvStatusInformation
,dwStatusInformationLength
);
368 case INTERNET_STATUS_PREFETCH
:
369 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
370 GetCurrentThreadId(), hInternet
, dwContext
,
371 lpvStatusInformation
,dwStatusInformationLength
);
373 case INTERNET_STATUS_CLOSING_CONNECTION
:
374 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
375 GetCurrentThreadId(), hInternet
, dwContext
,
376 lpvStatusInformation
,dwStatusInformationLength
);
378 case INTERNET_STATUS_CONNECTION_CLOSED
:
379 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
380 GetCurrentThreadId(), hInternet
, dwContext
,
381 lpvStatusInformation
,dwStatusInformationLength
);
383 case INTERNET_STATUS_HANDLE_CREATED
:
384 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
385 "info length should be sizeof(HINTERNET) instead of %d\n",
386 dwStatusInformationLength
);
387 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
388 GetCurrentThreadId(), hInternet
, dwContext
,
389 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
390 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
391 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
393 case INTERNET_STATUS_HANDLE_CLOSING
:
394 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
395 "info length should be sizeof(HINTERNET) instead of %d\n",
396 dwStatusInformationLength
);
397 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
398 GetCurrentThreadId(), hInternet
, dwContext
,
399 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
400 if(!--close_handle_cnt
)
401 SetEvent(hCompleteEvent
);
403 case INTERNET_STATUS_REQUEST_COMPLETE
:
405 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
406 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
407 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
408 dwStatusInformationLength
);
409 ok(iar
->dwResult
== 1 || iar
->dwResult
== 0, "iar->dwResult = %ld\n", iar
->dwResult
);
410 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
411 GetCurrentThreadId(), hInternet
, dwContext
,
412 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
413 req_error
= iar
->dwError
;
414 SetEvent(hCompleteEvent
);
417 case INTERNET_STATUS_REDIRECT
:
418 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
419 GetCurrentThreadId(), hInternet
, dwContext
,
420 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
421 *(LPSTR
)lpvStatusInformation
= '\0';
422 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
423 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
425 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
426 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
427 GetCurrentThreadId(), hInternet
, dwContext
,
428 lpvStatusInformation
, dwStatusInformationLength
);
431 trace("%04x:Callback %p 0x%lx %d %p %d\n",
432 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
433 lpvStatusInformation
, dwStatusInformationLength
);
437 static void close_async_handle(HINTERNET handle
, HANDLE complete_event
, int handle_cnt
)
441 close_handle_cnt
= handle_cnt
;
443 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
444 res
= InternetCloseHandle(handle
);
445 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
446 WaitForSingleObject(hCompleteEvent
, INFINITE
);
447 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
448 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
451 static void InternetReadFile_test(int flags
, const test_data_t
*test
)
453 char *post_data
= NULL
;
454 BOOL res
, on_async
= TRUE
;
456 DWORD length
, exlen
= 0, post_len
= 0;
457 const char *types
[2] = { "*", NULL
};
458 HINTERNET hi
, hic
= 0, hor
= 0;
460 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
462 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags
,test
->url
);
464 trace("InternetOpenA <--\n");
465 hi
= InternetOpenA((test
->flags
& TESTF_COMPRESSED
) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
466 INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
467 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
468 trace("InternetOpenA -->\n");
470 if (hi
== 0x0) goto abort
;
472 pInternetSetStatusCallbackA(hi
,&callback
);
474 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
476 trace("InternetConnectA <--\n");
477 hic
=InternetConnectA(hi
, test
->host
, INTERNET_INVALID_PORT_NUMBER
,
478 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
479 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
480 trace("InternetConnectA -->\n");
482 if (hic
== 0x0) goto abort
;
484 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
485 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
487 trace("HttpOpenRequestA <--\n");
488 hor
= HttpOpenRequestA(hic
, test
->post_data
? "POST" : "GET", test
->path
, NULL
, NULL
, types
,
489 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
491 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
493 * If the internet name can't be resolved we are probably behind
494 * a firewall or in some other way not directly connected to the
495 * Internet. Not enough reason to fail the test. Just ignore and
499 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
501 trace("HttpOpenRequestA -->\n");
503 if (hor
== 0x0) goto abort
;
505 test_request_flags(hor
, INTERNET_REQFLAG_NO_HEADERS
);
507 length
= sizeof(buffer
);
508 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
509 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
510 ok(!strcmp(buffer
, test
->url
), "Wrong URL %s, expected %s\n", buffer
, test
->url
);
512 length
= sizeof(buffer
);
513 res
= HttpQueryInfoA(hor
, HTTP_QUERY_RAW_HEADERS
, buffer
, &length
, 0x0);
514 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
515 ok(length
== 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length
);
516 ok(!strcmp(buffer
, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer
);
518 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
519 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
520 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
521 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
,2);
522 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED
,2);
523 if (first_connection_to_test_url
)
525 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
526 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
528 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
529 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
530 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
531 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
532 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
533 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
534 if(test
->flags
& TESTF_REDIRECT
) {
535 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
536 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
538 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
539 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
540 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
541 if (flags
& INTERNET_FLAG_ASYNC
)
542 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
544 if(test
->flags
& TESTF_COMPRESSED
) {
547 res
= InternetSetOption(hor
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
548 ok(res
|| broken(!res
&& GetLastError() == ERROR_INTERNET_INVALID_OPTION
),
549 "InternetSetOption failed: %u\n", GetLastError());
554 test_status_code(hor
, 0);
556 trace("HttpSendRequestA -->\n");
557 if(test
->post_data
) {
558 post_len
= strlen(test
->post_data
);
559 post_data
= HeapAlloc(GetProcessHeap(), 0, post_len
);
560 memcpy(post_data
, test
->post_data
, post_len
);
562 SetLastError(0xdeadbeef);
563 res
= HttpSendRequestA(hor
, test
->headers
, -1, post_data
, post_len
);
564 if (flags
& INTERNET_FLAG_ASYNC
)
565 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
566 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
568 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
569 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
570 trace("HttpSendRequestA <--\n");
572 if (flags
& INTERNET_FLAG_ASYNC
) {
573 WaitForSingleObject(hCompleteEvent
, INFINITE
);
574 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
576 HeapFree(GetProcessHeap(), 0, post_data
);
578 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
579 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED
);
580 if (first_connection_to_test_url
)
582 if (! proxy_active())
584 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
585 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
589 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
590 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
595 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
596 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
598 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
599 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
600 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
601 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
602 if(test
->flags
& TESTF_REDIRECT
)
603 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
604 if (flags
& INTERNET_FLAG_ASYNC
)
605 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
606 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
607 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
608 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
610 test_request_flags(hor
, 0);
613 res
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
614 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
616 length
= sizeof(buffer
);
617 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
618 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
621 length
= sizeof(buffer
);
622 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
623 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
624 ok(!strcmp(buffer
, test
->redirected_url
), "Wrong URL %s\n", buffer
);
627 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
628 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res
,buffer
,GetLastError());
629 if(test
->flags
& TESTF_COMPRESSED
)
630 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
631 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res
, GetLastError());
634 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
636 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res
,buffer
);
639 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_ENCODING
,buffer
,&length
,0x0);
641 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res
,buffer
);
643 SetLastError(0xdeadbeef);
644 res
= InternetReadFile(NULL
, buffer
, 100, &length
);
645 ok(!res
, "InternetReadFile should have failed\n");
646 ok(GetLastError() == ERROR_INVALID_HANDLE
,
647 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
651 trace("Entering Query loop\n");
655 if (flags
& INTERNET_FLAG_ASYNC
)
656 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
658 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
659 if (flags
& INTERNET_FLAG_ASYNC
)
663 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
665 ok(length
>= exlen
, "length %u < exlen %u\n", length
, exlen
);
669 else if (GetLastError() == ERROR_IO_PENDING
)
672 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
673 if(!(test
->flags
& TESTF_CHUNKED
))
674 ok(!length
, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length
);
675 WaitForSingleObject(hCompleteEvent
, INFINITE
);
677 ok(exlen
, "length = 0\n");
678 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
679 ok(req_error
, "req_error = 0\n");
682 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
685 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
687 trace("LENGTH %d\n", length
);
688 if(test
->flags
& TESTF_CHUNKED
)
689 ok(length
<= 8192, "length = %d, expected <= 8192\n", length
);
693 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
695 res
= InternetReadFile(hor
,buffer
,length
,&length
);
699 trace("ReadFile -> %s %i\n",res
?"TRUE":"FALSE",length
);
702 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
703 HeapFree(GetProcessHeap(),0,buffer
);
705 ok(!on_async
, "Returned zero size in response to request complete\n");
710 if(test
->flags
& TESTF_REDIRECT
) {
711 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
712 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
716 close_async_handle(hi
, hCompleteEvent
, 2);
717 CloseHandle(hCompleteEvent
);
718 first_connection_to_test_url
= FALSE
;
721 static void InternetReadFile_chunked_test(void)
726 const char *types
[2] = { "*", NULL
};
727 HINTERNET hi
, hic
= 0, hor
= 0;
729 trace("Starting InternetReadFile chunked test\n");
731 trace("InternetOpenA <--\n");
732 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
733 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
734 trace("InternetOpenA -->\n");
736 if (hi
== 0x0) goto abort
;
738 trace("InternetConnectA <--\n");
739 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
740 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
741 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
742 trace("InternetConnectA -->\n");
744 if (hic
== 0x0) goto abort
;
746 trace("HttpOpenRequestA <--\n");
747 hor
= HttpOpenRequestA(hic
, "GET", "/tests/chunked", NULL
, NULL
, types
,
748 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
750 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
752 * If the internet name can't be resolved we are probably behind
753 * a firewall or in some other way not directly connected to the
754 * Internet. Not enough reason to fail the test. Just ignore and
758 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
760 trace("HttpOpenRequestA -->\n");
762 if (hor
== 0x0) goto abort
;
764 trace("HttpSendRequestA -->\n");
765 SetLastError(0xdeadbeef);
766 res
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
767 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
768 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
769 trace("HttpSendRequestA <--\n");
771 test_request_flags(hor
, 0);
774 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
776 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
778 SetLastError( 0xdeadbeef );
780 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
782 trace("Option TRANSFER_ENCODING -> %i %s\n",res
,buffer
);
783 ok( res
|| ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
784 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
785 ok( !strcmp( buffer
, "chunked" ) || ( ! res
&& proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
786 "Wrong transfer encoding '%s'\n", buffer
);
788 SetLastError( 0xdeadbeef );
790 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
791 ok( !res
, "Found CONTENT_LENGTH option '%s'\n", buffer
);
792 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Wrong error %u\n", GetLastError() );
795 trace("Entering Query loop\n");
799 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
800 ok(!(!res
&& length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
801 ok(res
, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
802 trace("got %u available\n",length
);
806 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
808 res
= InternetReadFile(hor
,buffer
,length
,&got
);
811 trace("ReadFile -> %i %i\n",res
,got
);
812 ok( length
== got
, "only got %u of %u available\n", got
, length
);
813 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
815 HeapFree(GetProcessHeap(),0,buffer
);
824 res
= InternetCloseHandle(hor
);
825 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
828 res
= InternetCloseHandle(hi
);
829 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
833 static void InternetReadFileExA_test(int flags
)
837 const char *types
[2] = { "*", NULL
};
838 HINTERNET hi
, hic
= 0, hor
= 0;
839 INTERNET_BUFFERS inetbuffers
;
841 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
843 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
845 trace("InternetOpenA <--\n");
846 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
847 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
848 trace("InternetOpenA -->\n");
850 if (hi
== 0x0) goto abort
;
852 pInternetSetStatusCallbackA(hi
,&callback
);
854 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
856 trace("InternetConnectA <--\n");
857 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
858 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
859 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
860 trace("InternetConnectA -->\n");
862 if (hic
== 0x0) goto abort
;
864 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
865 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
867 trace("HttpOpenRequestA <--\n");
868 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
869 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
871 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
873 * If the internet name can't be resolved we are probably behind
874 * a firewall or in some other way not directly connected to the
875 * Internet. Not enough reason to fail the test. Just ignore and
879 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
881 trace("HttpOpenRequestA -->\n");
883 if (hor
== 0x0) goto abort
;
885 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
886 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
887 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
888 if (first_connection_to_test_url
)
890 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
891 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
893 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
, 2);
894 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
895 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
896 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
897 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
898 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
899 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
900 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
901 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
902 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
903 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
904 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
905 if (flags
& INTERNET_FLAG_ASYNC
)
906 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
908 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
910 trace("HttpSendRequestA -->\n");
911 SetLastError(0xdeadbeef);
912 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
913 if (flags
& INTERNET_FLAG_ASYNC
)
914 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
915 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
917 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
918 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
919 trace("HttpSendRequestA <--\n");
921 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
922 WaitForSingleObject(hCompleteEvent
, INFINITE
);
923 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
926 if (first_connection_to_test_url
)
928 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
929 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
933 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
934 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
936 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
937 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
938 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
939 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
940 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
941 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
942 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
943 if (flags
& INTERNET_FLAG_ASYNC
)
944 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
946 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
947 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
948 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
949 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
950 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
952 /* tests invalid dwStructSize */
953 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
)+1;
954 inetbuffers
.lpcszHeader
= NULL
;
955 inetbuffers
.dwHeadersLength
= 0;
956 inetbuffers
.dwBufferLength
= 10;
957 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
958 inetbuffers
.dwOffsetHigh
= 1234;
959 inetbuffers
.dwOffsetLow
= 5678;
960 rc
= InternetReadFileEx(hor
, &inetbuffers
, 0, 0xdeadcafe);
961 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
962 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
963 rc
? "TRUE" : "FALSE", GetLastError());
964 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
966 test_request_flags(hor
, 0);
968 /* tests to see whether lpcszHeader is used - it isn't */
969 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
);
970 inetbuffers
.lpcszHeader
= (LPCTSTR
)0xdeadbeef;
971 inetbuffers
.dwHeadersLength
= 255;
972 inetbuffers
.dwBufferLength
= 0;
973 inetbuffers
.lpvBuffer
= NULL
;
974 inetbuffers
.dwOffsetHigh
= 1234;
975 inetbuffers
.dwOffsetLow
= 5678;
976 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
977 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
978 rc
= InternetReadFileEx(hor
, &inetbuffers
, 0, 0xdeadcafe);
979 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
980 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
983 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
984 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
987 rc
= InternetReadFileEx(NULL
, &inetbuffers
, 0, 0xdeadcafe);
988 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
989 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
990 rc
? "TRUE" : "FALSE", GetLastError());
993 trace("Entering Query loop\n");
997 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
);
998 inetbuffers
.dwBufferLength
= 1024;
999 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
1000 inetbuffers
.dwOffsetHigh
= 1234;
1001 inetbuffers
.dwOffsetLow
= 5678;
1003 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1004 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1005 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1006 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
1009 if (GetLastError() == ERROR_IO_PENDING
)
1011 trace("InternetReadFileEx -> PENDING\n");
1012 ok(flags
& INTERNET_FLAG_ASYNC
,
1013 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1014 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1015 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1016 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1017 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1018 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1022 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1028 trace("InternetReadFileEx -> SUCCEEDED\n");
1029 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1030 if (inetbuffers
.dwBufferLength
)
1033 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1034 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1039 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1040 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1041 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1045 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1046 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
1048 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
1049 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1050 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
1052 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1054 if (!inetbuffers
.dwBufferLength
)
1057 length
+= inetbuffers
.dwBufferLength
;
1059 ok(length
> 0, "failed to read any of the document\n");
1060 trace("Finished. Read %d bytes\n", length
);
1063 close_async_handle(hi
, hCompleteEvent
, 2);
1064 CloseHandle(hCompleteEvent
);
1065 first_connection_to_test_url
= FALSE
;
1068 static void InternetOpenUrlA_test(void)
1070 HINTERNET myhinternet
, myhttp
;
1072 DWORD size
, readbytes
, totalbytes
=0;
1075 myhinternet
= InternetOpen("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
1076 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
1078 ret
= InternetCanonicalizeUrl(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1079 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1082 myhttp
= InternetOpenUrl(myhinternet
, TEST_URL
, 0, 0,
1083 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
1084 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1085 return; /* WinXP returns this when not connected to the net */
1086 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1087 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
1088 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
1089 totalbytes
+= readbytes
;
1090 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
1091 totalbytes
+= readbytes
;
1092 trace("read 0x%08x bytes\n",totalbytes
);
1094 InternetCloseHandle(myhttp
);
1095 InternetCloseHandle(myhinternet
);
1098 static void HttpSendRequestEx_test(void)
1104 INTERNET_BUFFERS BufferIn
;
1105 DWORD dwBytesWritten
, dwBytesRead
, error
;
1110 static char szPostData
[] = "mode=Test";
1111 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
1113 hSession
= InternetOpen("Wine Regression Test",
1114 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1115 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1116 hConnect
= InternetConnect(hSession
, "crossover.codeweavers.com",
1117 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1119 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
1120 hRequest
= HttpOpenRequest(hConnect
, "POST", "/posttest.php",
1121 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1122 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1124 skip( "Network unreachable, skipping test\n" );
1127 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1129 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1131 BufferIn
.dwStructSize
= sizeof( INTERNET_BUFFERS
);
1132 BufferIn
.Next
= (LPINTERNET_BUFFERS
)0xdeadcab;
1133 BufferIn
.lpcszHeader
= szContentType
;
1134 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1135 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1136 BufferIn
.lpvBuffer
= szPostData
;
1137 BufferIn
.dwBufferLength
= 3;
1138 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1139 BufferIn
.dwOffsetLow
= 0;
1140 BufferIn
.dwOffsetHigh
= 0;
1142 SetLastError(0xdeadbeef);
1143 ret
= HttpSendRequestEx(hRequest
, &BufferIn
, NULL
, 0 ,0);
1144 error
= GetLastError();
1145 ok(ret
, "HttpSendRequestEx Failed with error %u\n", error
);
1146 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", error
);
1148 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1150 for (i
= 3; szPostData
[i
]; i
++)
1151 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1152 "InternetWriteFile failed\n");
1154 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1156 ok(HttpEndRequest(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1158 test_request_flags(hRequest
, 0);
1160 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1161 "Unable to read response\n");
1162 szBuffer
[dwBytesRead
] = 0;
1164 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
1165 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1167 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1169 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1170 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1173 static void InternetOpenRequest_test(void)
1175 HINTERNET session
, connect
, request
;
1176 static const char *types
[] = { "*", "", NULL
};
1177 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1178 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1181 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1182 ok(session
!= NULL
,"Unable to open Internet session\n");
1184 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1185 INTERNET_SERVICE_HTTP
, 0, 0);
1186 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1187 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1189 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1190 INTERNET_SERVICE_HTTP
, 0, 0);
1191 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1192 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1194 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1195 INTERNET_SERVICE_HTTP
, 0, 0);
1196 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1198 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1199 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1201 skip( "Network unreachable, skipping test\n" );
1204 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1206 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1207 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1208 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1210 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1211 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1213 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1214 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1215 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1218 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1219 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1222 static void test_http_cache(void)
1224 HINTERNET session
, connect
, request
;
1225 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1226 DWORD size
, file_size
;
1231 static const char *types
[] = { "*", "", NULL
};
1233 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1234 ok(session
!= NULL
,"Unable to open Internet session\n");
1236 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1237 INTERNET_SERVICE_HTTP
, 0, 0);
1238 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1240 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1241 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1243 skip( "Network unreachable, skipping test\n" );
1245 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1246 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1250 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1253 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1254 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1255 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1257 size
= sizeof(file_name
);
1258 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1259 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1260 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1261 ok(!size
, "size = %d\n", size
);
1263 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1264 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1266 size
= sizeof(file_name
);
1267 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1268 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1270 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1271 FILE_ATTRIBUTE_NORMAL
, NULL
);
1272 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1273 file_size
= GetFileSize(file
, NULL
);
1274 ok(file_size
== 106, "file size = %u\n", file_size
);
1277 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1278 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1279 ok(size
== 100, "size = %u\n", size
);
1281 file_size
= GetFileSize(file
, NULL
);
1282 ok(file_size
== 106, "file size = %u\n", file_size
);
1285 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1287 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1288 FILE_ATTRIBUTE_NORMAL
, NULL
);
1289 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1292 /* Send the same request, requiring it to be retrieved from the cache */
1293 request
= HttpOpenRequest(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1295 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1296 ok(ret
, "HttpSendRequest failed\n");
1299 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1300 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1301 ok(size
== 100, "size = %u\n", size
);
1303 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1305 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1306 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1308 size
= sizeof(file_name
);
1309 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1310 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1311 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1312 ok(!size
, "size = %d\n", size
);
1314 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1315 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1317 size
= sizeof(file_name
);
1319 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1322 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1323 FILE_ATTRIBUTE_NORMAL
, NULL
);
1324 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1330 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1333 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1334 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1335 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1338 static void HttpHeaders_test(void)
1349 hSession
= InternetOpen("Wine Regression Test",
1350 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1351 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1352 hConnect
= InternetConnect(hSession
, "crossover.codeweavers.com",
1353 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1355 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
1356 hRequest
= HttpOpenRequest(hConnect
, "POST", "/posttest.php",
1357 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1358 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1360 skip( "Network unreachable, skipping test\n" );
1363 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1366 len
= sizeof(buffer
);
1367 strcpy(buffer
,"Warning");
1368 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1369 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1371 ok(HttpAddRequestHeaders(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1372 "Failed to add new header\n");
1375 len
= sizeof(buffer
);
1376 strcpy(buffer
,"Warning");
1377 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1378 buffer
,&len
,&index
),"Unable to query header\n");
1379 ok(index
== 1, "Index was not incremented\n");
1380 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1381 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1382 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1383 len
= sizeof(buffer
);
1384 strcpy(buffer
,"Warning");
1385 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1386 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1389 len
= 5; /* could store the string but not the NULL terminator */
1390 strcpy(buffer
,"Warning");
1391 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1392 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1393 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1394 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1396 /* a call with NULL will fail but will return the length */
1398 len
= sizeof(buffer
);
1399 SetLastError(0xdeadbeef);
1400 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1401 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1402 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1403 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1404 ok(index
== 0, "Index was incremented\n");
1406 /* even for a len that is too small */
1409 SetLastError(0xdeadbeef);
1410 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1411 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1412 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1413 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1414 ok(index
== 0, "Index was incremented\n");
1418 SetLastError(0xdeadbeef);
1419 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1420 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1421 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1422 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1423 ok(index
== 0, "Index was incremented\n");
1424 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1427 /* a working query */
1429 len
= sizeof(buffer
);
1430 memset(buffer
, 'x', sizeof(buffer
));
1431 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1432 buffer
,&len
,&index
),"Unable to query header\n");
1433 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1434 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1435 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1436 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1437 ok(strncmp(buffer
, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1438 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1439 ok(index
== 0, "Index was incremented\n");
1441 /* Like above two tests, but for W version */
1445 SetLastError(0xdeadbeef);
1446 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1447 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1448 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1449 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1450 ok(index
== 0, "Index was incremented\n");
1451 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1453 /* a working query */
1455 len
= sizeof(wbuffer
);
1456 memset(wbuffer
, 'x', sizeof(wbuffer
));
1457 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1458 wbuffer
,&len
,&index
),"Unable to query header\n");
1459 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1460 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1461 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1462 ok(index
== 0, "Index was incremented\n");
1464 /* end of W version tests */
1466 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1468 len
= sizeof(buffer
);
1469 memset(buffer
, 'x', sizeof(buffer
));
1470 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1471 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1472 ok(len
== 2, "Expected 2, got %d\n", len
);
1473 ok(strcmp(buffer
, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer
);
1474 ok(index
== 0, "Index was incremented\n");
1476 ok(HttpAddRequestHeaders(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1477 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1480 len
= sizeof(buffer
);
1481 strcpy(buffer
,"Warning");
1482 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1483 buffer
,&len
,&index
),"Unable to query header\n");
1484 ok(index
== 1, "Index was not incremented\n");
1485 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1486 len
= sizeof(buffer
);
1487 strcpy(buffer
,"Warning");
1488 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1489 buffer
,&len
,&index
),"Failed to get second header\n");
1490 ok(index
== 2, "Index was not incremented\n");
1491 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1492 len
= sizeof(buffer
);
1493 strcpy(buffer
,"Warning");
1494 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1495 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1497 ok(HttpAddRequestHeaders(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1500 len
= sizeof(buffer
);
1501 strcpy(buffer
,"Warning");
1502 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1503 buffer
,&len
,&index
),"Unable to query header\n");
1504 ok(index
== 1, "Index was not incremented\n");
1505 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1506 len
= sizeof(buffer
);
1507 strcpy(buffer
,"Warning");
1508 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1509 buffer
,&len
,&index
),"Failed to get second header\n");
1510 ok(index
== 2, "Index was not incremented\n");
1511 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1512 len
= sizeof(buffer
);
1513 strcpy(buffer
,"Warning");
1514 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1515 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1517 ok(HttpAddRequestHeaders(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1520 len
= sizeof(buffer
);
1521 strcpy(buffer
,"Warning");
1522 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1523 buffer
,&len
,&index
),"Unable to query header\n");
1524 ok(index
== 1, "Index was not incremented\n");
1525 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1526 len
= sizeof(buffer
);
1527 strcpy(buffer
,"Warning");
1528 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1529 buffer
,&len
,&index
),"Failed to get second header\n");
1530 ok(index
== 2, "Index was not incremented\n");
1531 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1532 len
= sizeof(buffer
);
1533 strcpy(buffer
,"Warning");
1534 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1535 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1537 ok(HttpAddRequestHeaders(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1540 len
= sizeof(buffer
);
1541 strcpy(buffer
,"Warning");
1542 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1543 buffer
,&len
,&index
),"Unable to query header\n");
1544 ok(index
== 1, "Index was not incremented\n");
1545 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1546 len
= sizeof(buffer
);
1547 strcpy(buffer
,"Warning");
1548 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1549 ok(index
== 2, "Index was not incremented\n");
1550 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1551 len
= sizeof(buffer
);
1552 strcpy(buffer
,"Warning");
1553 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1555 ok(HttpAddRequestHeaders(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1558 len
= sizeof(buffer
);
1559 strcpy(buffer
,"Warning");
1560 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1561 ok(index
== 1, "Index was not incremented\n");
1562 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1563 len
= sizeof(buffer
);
1564 strcpy(buffer
,"Warning");
1565 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1566 ok(index
== 2, "Index was not incremented\n");
1567 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1568 len
= sizeof(buffer
);
1569 strcpy(buffer
,"Warning");
1570 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1572 ok(HttpAddRequestHeaders(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1575 len
= sizeof(buffer
);
1576 strcpy(buffer
,"Warning");
1577 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1578 ok(index
== 1, "Index was not incremented\n");
1579 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1580 len
= sizeof(buffer
);
1581 strcpy(buffer
,"Warning");
1582 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1583 ok(index
== 2, "Index was not incremented\n");
1584 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1585 len
= sizeof(buffer
);
1586 strcpy(buffer
,"Warning");
1587 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1589 ok(HttpAddRequestHeaders(hRequest
,"Warning:test7",-1, HTTP_ADDREQ_FLAG_ADD
|HTTP_ADDREQ_FLAG_REPLACE
), "HTTP_ADDREQ_FLAG_ADD with HTTP_ADDREQ_FLAG_REPALCE Did not work\n");
1592 len
= sizeof(buffer
);
1593 strcpy(buffer
,"Warning");
1594 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1595 ok(index
== 1, "Index was not incremented\n");
1596 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1597 len
= sizeof(buffer
);
1598 strcpy(buffer
,"Warning");
1599 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1600 ok(index
== 2, "Index was not incremented\n");
1601 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1602 len
= sizeof(buffer
);
1603 strcpy(buffer
,"Warning");
1604 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1606 /* Ensure that blank headers are ignored and don't cause a failure */
1607 ok(HttpAddRequestHeaders(hRequest
,"\r\nBlankTest:value\r\n\r\n",-1, HTTP_ADDREQ_FLAG_ADD_IF_NEW
), "Failed to add header with blank entries in list\n");
1610 len
= sizeof(buffer
);
1611 strcpy(buffer
,"BlankTest");
1612 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1613 ok(index
== 1, "Index was not incremented\n");
1614 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1616 /* Ensure that malformed header separators are ignored and don't cause a failure */
1617 ok(HttpAddRequestHeaders(hRequest
,"\r\rMalformedTest:value\n\nMalformedTestTwo: value2\rMalformedTestThree: value3\n\n\r\r\n",-1, HTTP_ADDREQ_FLAG_ADD
|HTTP_ADDREQ_FLAG_REPLACE
),
1618 "Failed to add header with malformed entries in list\n");
1621 len
= sizeof(buffer
);
1622 strcpy(buffer
,"MalformedTest");
1623 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1624 ok(index
== 1, "Index was not incremented\n");
1625 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1627 len
= sizeof(buffer
);
1628 strcpy(buffer
,"MalformedTestTwo");
1629 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1630 ok(index
== 1, "Index was not incremented\n");
1631 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
1633 len
= sizeof(buffer
);
1634 strcpy(buffer
,"MalformedTestThree");
1635 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1636 ok(index
== 1, "Index was not incremented\n");
1637 ok(strcmp(buffer
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
1639 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1641 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1642 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1645 static const char garbagemsg
[] =
1646 "Garbage: Header\r\n";
1648 static const char contmsg
[] =
1649 "HTTP/1.1 100 Continue\r\n";
1651 static const char expandcontmsg
[] =
1652 "HTTP/1.1 100 Continue\r\n"
1653 "Server: winecontinue\r\n"
1654 "Tag: something witty\r\n"
1657 static const char okmsg
[] =
1658 "HTTP/1.1 200 OK\r\n"
1659 "Server: winetest\r\n"
1662 static const char okmsg2
[] =
1663 "HTTP/1.1 200 OK\r\n"
1664 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1665 "Server: winetest\r\n"
1666 "Content-Length: 0\r\n"
1667 "Set-Cookie: one\r\n"
1668 "Set-Cookie: two\r\n"
1671 static const char notokmsg
[] =
1672 "HTTP/1.1 400 Bad Request\r\n"
1673 "Server: winetest\r\n"
1676 static const char noauthmsg
[] =
1677 "HTTP/1.1 401 Unauthorized\r\n"
1678 "Server: winetest\r\n"
1679 "Connection: close\r\n"
1680 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1683 static const char noauthmsg2
[] =
1684 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
1685 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
1687 "Server: winetest\r\n";
1689 static const char proxymsg
[] =
1690 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1691 "Server: winetest\r\n"
1692 "Proxy-Connection: close\r\n"
1693 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1696 static const char page1
[] =
1698 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1699 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1702 struct server_info
{
1707 static DWORD CALLBACK
server_thread(LPVOID param
)
1709 struct server_info
*si
= param
;
1712 struct sockaddr_in sa
;
1715 int last_request
= 0;
1716 char host_header
[22];
1717 static int test_b
= 0;
1719 WSAStartup(MAKEWORD(1,1), &wsaData
);
1721 s
= socket(AF_INET
, SOCK_STREAM
, 0);
1722 if (s
== INVALID_SOCKET
)
1726 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
1728 memset(&sa
, 0, sizeof sa
);
1729 sa
.sin_family
= AF_INET
;
1730 sa
.sin_port
= htons(si
->port
);
1731 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
1733 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
1739 SetEvent(si
->hEvent
);
1741 sprintf(host_header
, "Host: localhost:%d", si
->port
);
1745 c
= accept(s
, NULL
, NULL
);
1747 memset(buffer
, 0, sizeof buffer
);
1748 for(i
=0; i
<(sizeof buffer
-1); i
++)
1750 r
= recv(c
, &buffer
[i
], 1, 0);
1754 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
1755 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
1758 if (strstr(buffer
, "GET /test1"))
1760 if (!strstr(buffer
, "Content-Length: 0"))
1762 send(c
, okmsg
, sizeof okmsg
-1, 0);
1763 send(c
, page1
, sizeof page1
-1, 0);
1766 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1768 if (strstr(buffer
, "/test2"))
1770 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
1772 send(c
, okmsg
, sizeof okmsg
-1, 0);
1773 send(c
, page1
, sizeof page1
-1, 0);
1776 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
1778 if (strstr(buffer
, "/test3"))
1780 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
1781 send(c
, okmsg
, sizeof okmsg
-1, 0);
1783 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
1785 if (strstr(buffer
, "/test4"))
1787 if (strstr(buffer
, "Connection: Close"))
1788 send(c
, okmsg
, sizeof okmsg
-1, 0);
1790 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1792 if (strstr(buffer
, "POST /test5") ||
1793 strstr(buffer
, "RPC_IN_DATA /test5") ||
1794 strstr(buffer
, "RPC_OUT_DATA /test5"))
1796 if (strstr(buffer
, "Content-Length: 0"))
1798 send(c
, okmsg
, sizeof okmsg
-1, 0);
1799 send(c
, page1
, sizeof page1
-1, 0);
1802 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1804 if (strstr(buffer
, "GET /test6"))
1806 send(c
, contmsg
, sizeof contmsg
-1, 0);
1807 send(c
, contmsg
, sizeof contmsg
-1, 0);
1808 send(c
, okmsg
, sizeof okmsg
-1, 0);
1809 send(c
, page1
, sizeof page1
-1, 0);
1811 if (strstr(buffer
, "POST /test7"))
1813 if (strstr(buffer
, "Content-Length: 100"))
1815 send(c
, okmsg
, sizeof okmsg
-1, 0);
1816 send(c
, page1
, sizeof page1
-1, 0);
1819 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1821 if (strstr(buffer
, "/test8"))
1823 if (!strstr(buffer
, "Connection: Close") &&
1824 strstr(buffer
, "Connection: Keep-Alive") &&
1825 !strstr(buffer
, "Cache-Control: no-cache") &&
1826 !strstr(buffer
, "Pragma: no-cache") &&
1827 strstr(buffer
, host_header
))
1828 send(c
, okmsg
, sizeof okmsg
-1, 0);
1830 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1832 if (strstr(buffer
, "/test9"))
1834 if (!strstr(buffer
, "Connection: Close") &&
1835 !strstr(buffer
, "Connection: Keep-Alive") &&
1836 !strstr(buffer
, "Cache-Control: no-cache") &&
1837 !strstr(buffer
, "Pragma: no-cache") &&
1838 strstr(buffer
, host_header
))
1839 send(c
, okmsg
, sizeof okmsg
-1, 0);
1841 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1843 if (strstr(buffer
, "/testA"))
1845 if (!strstr(buffer
, "Connection: Close") &&
1846 !strstr(buffer
, "Connection: Keep-Alive") &&
1847 (strstr(buffer
, "Cache-Control: no-cache") ||
1848 strstr(buffer
, "Pragma: no-cache")) &&
1849 strstr(buffer
, host_header
))
1850 send(c
, okmsg
, sizeof okmsg
-1, 0);
1852 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1854 if (!test_b
&& strstr(buffer
, "/testB HTTP/1.1"))
1857 send(c
, okmsg
, sizeof okmsg
-1, 0);
1858 recvfrom(c
, buffer
, sizeof buffer
, 0, NULL
, NULL
);
1859 send(c
, okmsg
, sizeof okmsg
-1, 0);
1861 if (strstr(buffer
, "/testC"))
1863 if (strstr(buffer
, "Cookie: cookie=biscuit"))
1864 send(c
, okmsg
, sizeof okmsg
-1, 0);
1866 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1868 if (strstr(buffer
, "/testD"))
1870 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
1872 if (strstr(buffer
, "/testE"))
1874 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
1876 if (strstr(buffer
, "GET /quit"))
1878 send(c
, okmsg
, sizeof okmsg
-1, 0);
1879 send(c
, page1
, sizeof page1
-1, 0);
1882 if (strstr(buffer
, "GET /testF"))
1884 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
1885 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
1886 send(c
, contmsg
, sizeof contmsg
-1, 0);
1887 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
1888 send(c
, okmsg
, sizeof okmsg
-1, 0);
1889 send(c
, page1
, sizeof page1
-1, 0);
1891 if (strstr(buffer
, "GET /testG"))
1893 send(c
, page1
, sizeof page1
-1, 0);
1895 if (strstr(buffer
, "GET /test_no_content"))
1897 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
1898 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
1900 if (strstr(buffer
, "GET /test_conn_close"))
1902 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
1903 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
1904 WaitForSingleObject(conn_close_event
, INFINITE
);
1905 trace("closing connection\n");
1910 } while (!last_request
);
1917 static void test_basic_request(int port
, const char *verb
, const char *url
)
1919 HINTERNET hi
, hc
, hr
;
1923 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1924 ok(hi
!= NULL
, "open failed\n");
1926 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1927 ok(hc
!= NULL
, "connect failed\n");
1929 hr
= HttpOpenRequest(hc
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
1930 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1932 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1933 ok(r
, "HttpSendRequest failed\n");
1936 memset(buffer
, 0, sizeof buffer
);
1937 SetLastError(0xdeadbeef);
1938 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
1939 ok(r
, "InternetReadFile failed %u\n", GetLastError());
1940 ok(count
== sizeof page1
- 1, "count was wrong\n");
1941 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
1943 InternetCloseHandle(hr
);
1944 InternetCloseHandle(hc
);
1945 InternetCloseHandle(hi
);
1948 static void test_last_error(int port
)
1950 HINTERNET hi
, hc
, hr
;
1954 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1955 ok(hi
!= NULL
, "open failed\n");
1957 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1958 ok(hc
!= NULL
, "connect failed\n");
1960 hr
= HttpOpenRequest(hc
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
1961 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1963 SetLastError(0xdeadbeef);
1964 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1965 error
= GetLastError();
1966 ok(r
, "HttpSendRequest failed\n");
1967 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
1969 InternetCloseHandle(hr
);
1970 InternetCloseHandle(hc
);
1971 InternetCloseHandle(hi
);
1974 static void test_proxy_indirect(int port
)
1976 HINTERNET hi
, hc
, hr
;
1980 hi
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
1981 ok(hi
!= NULL
, "open failed\n");
1983 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1984 ok(hc
!= NULL
, "connect failed\n");
1986 hr
= HttpOpenRequest(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
1987 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1989 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1990 ok(r
, "HttpSendRequest failed\n");
1993 r
= HttpQueryInfo(hr
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
1994 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
1997 skip("missing proxy header, not testing remaining proxy headers\n");
2000 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2002 test_status_code(hr
, 407);
2003 test_request_flags(hr
, 0);
2006 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2007 ok(r
, "HttpQueryInfo failed\n");
2008 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2011 r
= HttpQueryInfo(hr
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2012 ok(r
, "HttpQueryInfo failed\n");
2013 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2016 r
= HttpQueryInfo(hr
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2017 ok(r
, "HttpQueryInfo failed\n");
2018 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2021 r
= HttpQueryInfo(hr
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2022 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2023 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2026 InternetCloseHandle(hr
);
2027 InternetCloseHandle(hc
);
2028 InternetCloseHandle(hi
);
2031 static void test_proxy_direct(int port
)
2033 HINTERNET hi
, hc
, hr
;
2036 static CHAR username
[] = "mike",
2037 password
[] = "1101";
2039 sprintf(buffer
, "localhost:%d\n", port
);
2040 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2041 ok(hi
!= NULL
, "open failed\n");
2043 /* try connect without authorization */
2044 hc
= InternetConnect(hi
, "test.winehq.org/", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2045 ok(hc
!= NULL
, "connect failed\n");
2047 hr
= HttpOpenRequest(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2048 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2050 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
2051 ok(r
, "HttpSendRequest failed\n");
2053 test_status_code(hr
, 407);
2055 /* set the user + password then try again */
2057 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2058 ok(r
, "failed to set user\n");
2060 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2061 ok(r
, "failed to set password\n");
2064 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
2065 ok(r
, "HttpSendRequest failed\n");
2067 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2068 ok(r
, "HttpQueryInfo failed\n");
2070 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2074 InternetCloseHandle(hr
);
2075 InternetCloseHandle(hc
);
2076 InternetCloseHandle(hi
);
2079 static void test_header_handling_order(int port
)
2081 static char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
2082 static char connection
[] = "Connection: Close";
2084 static const char *types
[2] = { "*", NULL
};
2085 HINTERNET session
, connect
, request
;
2089 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2090 ok(session
!= NULL
, "InternetOpen failed\n");
2092 connect
= InternetConnect(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2093 ok(connect
!= NULL
, "InternetConnect failed\n");
2095 request
= HttpOpenRequest(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2096 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2098 ret
= HttpAddRequestHeaders(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
2099 ok(ret
, "HttpAddRequestHeaders failed\n");
2101 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
2102 ok(ret
, "HttpSendRequest failed\n");
2104 test_status_code(request
, 200);
2105 test_request_flags(request
, 0);
2107 InternetCloseHandle(request
);
2109 request
= HttpOpenRequest(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2110 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2112 ret
= HttpSendRequest(request
, connection
, ~0u, NULL
, 0);
2113 ok(ret
, "HttpSendRequest failed\n");
2116 size
= sizeof(status
);
2117 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2118 ok(ret
, "HttpQueryInfo failed\n");
2119 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2121 InternetCloseHandle(request
);
2123 request
= HttpOpenRequest(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2124 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2126 ret
= HttpAddRequestHeaders(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2127 ok(ret
, "HttpAddRequestHeaders failed\n");
2129 ret
= HttpSendRequest(request
, connection
, ~0u, NULL
, 0);
2130 ok(ret
, "HttpSendRequest failed\n");
2133 size
= sizeof(status
);
2134 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2135 ok(ret
, "HttpQueryInfo failed\n");
2136 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2138 InternetCloseHandle(request
);
2139 InternetCloseHandle(connect
);
2140 InternetCloseHandle(session
);
2143 static void test_connection_header(int port
)
2145 HINTERNET ses
, con
, req
;
2148 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2149 ok(ses
!= NULL
, "InternetOpen failed\n");
2151 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2152 ok(con
!= NULL
, "InternetConnect failed\n");
2154 req
= HttpOpenRequest(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2155 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2157 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2158 ok(ret
, "HttpSendRequest failed\n");
2160 test_status_code(req
, 200);
2162 InternetCloseHandle(req
);
2164 req
= HttpOpenRequest(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
2165 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2167 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2168 ok(ret
, "HttpSendRequest failed\n");
2170 test_status_code(req
, 200);
2172 InternetCloseHandle(req
);
2174 req
= HttpOpenRequest(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2175 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2177 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2178 ok(ret
, "HttpSendRequest failed\n");
2180 test_status_code(req
, 200);
2182 InternetCloseHandle(req
);
2184 req
= HttpOpenRequest(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2185 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2187 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2188 ok(ret
, "HttpSendRequest failed\n");
2190 test_status_code(req
, 200);
2192 InternetCloseHandle(req
);
2193 InternetCloseHandle(con
);
2194 InternetCloseHandle(ses
);
2197 static void test_http1_1(int port
)
2199 HINTERNET ses
, con
, req
;
2202 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2203 ok(ses
!= NULL
, "InternetOpen failed\n");
2205 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2206 ok(con
!= NULL
, "InternetConnect failed\n");
2208 req
= HttpOpenRequest(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2209 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2211 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2214 InternetCloseHandle(req
);
2216 req
= HttpOpenRequest(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2217 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2219 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2220 ok(ret
, "HttpSendRequest failed\n");
2223 InternetCloseHandle(req
);
2224 InternetCloseHandle(con
);
2225 InternetCloseHandle(ses
);
2228 static void test_no_content(int port
)
2230 HINTERNET session
, connection
, req
;
2233 trace("Testing 204 no content response...\n");
2235 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2237 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2238 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2240 pInternetSetStatusCallbackA(session
, callback
);
2242 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2243 connection
= InternetConnectA(session
, "localhost", port
,
2244 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2245 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2246 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2248 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2249 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
2250 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
2251 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2252 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2254 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2255 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2256 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2257 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2258 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2259 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2260 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2261 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
2262 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
2263 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2265 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
2266 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2267 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2268 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2269 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2271 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2272 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2273 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2274 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2275 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2276 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2277 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2278 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2279 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2280 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2282 close_async_handle(session
, hCompleteEvent
, 2);
2283 CloseHandle(hCompleteEvent
);
2286 static void test_conn_close(int port
)
2288 HINTERNET session
, connection
, req
;
2289 DWORD res
, avail
, size
;
2292 trace("Testing connection close connection...\n");
2294 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2295 conn_close_event
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2297 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2298 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2300 pInternetSetStatusCallbackA(session
, callback
);
2302 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2303 connection
= InternetConnectA(session
, "localhost", port
,
2304 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2305 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2306 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2308 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2309 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
2310 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
2311 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2312 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2314 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2315 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2316 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2317 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2318 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2319 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2320 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2321 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2323 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
2324 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2325 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2326 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2327 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2329 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2330 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2331 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2332 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2333 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2334 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2335 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2336 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2339 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
2340 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
2341 ok(avail
!= 0, "avail = 0\n");
2344 res
= InternetReadFile(req
, buf
, avail
, &size
);
2345 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
2347 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
2348 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2349 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2350 ok(!avail
, "avail = %u, expected 0\n", avail
);
2352 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
2353 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
2354 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2355 SetEvent(conn_close_event
);
2356 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2357 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2358 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2359 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2360 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2362 close_async_handle(session
, hCompleteEvent
, 2);
2363 CloseHandle(hCompleteEvent
);
2366 static void test_HttpSendRequestW(int port
)
2368 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
2369 HINTERNET ses
, con
, req
;
2373 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2374 ok(ses
!= NULL
, "InternetOpen failed\n");
2376 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2377 ok(con
!= NULL
, "InternetConnect failed\n");
2379 req
= HttpOpenRequest(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
2380 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2382 SetLastError(0xdeadbeef);
2383 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
2384 error
= GetLastError();
2385 ok(!ret
, "HttpSendRequestW succeeded\n");
2386 ok(error
== ERROR_IO_PENDING
||
2387 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
2388 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
2389 "got %u expected ERROR_IO_PENDING\n", error
);
2391 InternetCloseHandle(req
);
2392 InternetCloseHandle(con
);
2393 InternetCloseHandle(ses
);
2396 static void test_cookie_header(int port
)
2398 HINTERNET ses
, con
, req
;
2403 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2404 ok(ses
!= NULL
, "InternetOpen failed\n");
2406 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2407 ok(con
!= NULL
, "InternetConnect failed\n");
2409 InternetSetCookie("http://localhost", "cookie", "biscuit");
2411 req
= HttpOpenRequest(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2412 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2415 size
= sizeof(buffer
);
2416 SetLastError(0xdeadbeef);
2417 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
2418 error
= GetLastError();
2419 ok(!ret
, "HttpQueryInfo succeeded\n");
2420 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
2422 ret
= HttpAddRequestHeaders(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
2423 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
2426 size
= sizeof(buffer
);
2427 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
2428 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
2429 ok(!strcmp(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
2431 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2432 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
2434 test_status_code(req
, 200);
2437 size
= sizeof(buffer
);
2438 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
2439 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
2440 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
2442 InternetCloseHandle(req
);
2443 InternetCloseHandle(con
);
2444 InternetCloseHandle(ses
);
2447 static void test_basic_authentication(int port
)
2449 HINTERNET session
, connect
, request
;
2452 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2453 ok(session
!= NULL
, "InternetOpen failed\n");
2455 connect
= InternetConnect(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
2456 ok(connect
!= NULL
, "InternetConnect failed\n");
2458 request
= HttpOpenRequest(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
2459 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2461 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
2462 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
2464 test_status_code(request
, 200);
2465 test_request_flags(request
, 0);
2467 InternetCloseHandle(request
);
2468 InternetCloseHandle(connect
);
2469 InternetCloseHandle(session
);
2472 static void test_invalid_response_headers(int port
)
2474 HINTERNET session
, connect
, request
;
2479 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2480 ok(session
!= NULL
, "InternetOpen failed\n");
2482 connect
= InternetConnect(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2483 ok(connect
!= NULL
, "InternetConnect failed\n");
2485 request
= HttpOpenRequest(connect
, NULL
, "/testE", NULL
, NULL
, NULL
, 0, 0);
2486 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2488 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
2489 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
2491 test_status_code(request
, 401);
2492 test_request_flags(request
, 0);
2495 size
= sizeof(buffer
);
2496 ret
= HttpQueryInfo( request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
2497 ok(ret
, "HttpQueryInfo failed\n");
2498 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
2499 "headers wrong \"%s\"\n", buffer
);
2502 size
= sizeof(buffer
);
2503 ret
= HttpQueryInfo( request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
2504 ok(ret
, "HttpQueryInfo failed\n");
2505 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
2507 InternetCloseHandle(request
);
2508 InternetCloseHandle(connect
);
2509 InternetCloseHandle(session
);
2512 static void test_response_without_headers(int port
)
2514 HINTERNET hi
, hc
, hr
;
2515 DWORD r
, count
, size
;
2518 SetLastError(0xdeadbeef);
2519 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2520 ok(hi
!= NULL
, "open failed %u\n", GetLastError());
2522 SetLastError(0xdeadbeef);
2523 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2524 ok(hc
!= NULL
, "connect failed %u\n", GetLastError());
2526 SetLastError(0xdeadbeef);
2527 hr
= HttpOpenRequest(hc
, NULL
, "/testG", NULL
, NULL
, NULL
, 0, 0);
2528 ok(hr
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError());
2530 test_request_flags(hr
, INTERNET_REQFLAG_NO_HEADERS
);
2532 SetLastError(0xdeadbeef);
2533 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
2534 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2536 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
2539 memset(buffer
, 0, sizeof buffer
);
2540 SetLastError(0xdeadbeef);
2541 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
2542 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2543 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
2544 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
2546 test_status_code(hr
, 200);
2547 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
2550 size
= sizeof(buffer
);
2551 SetLastError(0xdeadbeef);
2552 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
2553 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
2554 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
2557 size
= sizeof(buffer
);
2558 SetLastError(0xdeadbeef);
2559 r
= HttpQueryInfo(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
2560 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
2561 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
2564 size
= sizeof(buffer
);
2565 SetLastError(0xdeadbeef);
2566 r
= HttpQueryInfo(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
2567 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
2568 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
2570 InternetCloseHandle(hr
);
2571 InternetCloseHandle(hc
);
2572 InternetCloseHandle(hi
);
2575 static void test_HttpQueryInfo(int port
)
2577 HINTERNET hi
, hc
, hr
;
2582 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2583 ok(hi
!= NULL
, "InternetOpen failed\n");
2585 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2586 ok(hc
!= NULL
, "InternetConnect failed\n");
2588 hr
= HttpOpenRequest(hc
, NULL
, "/testD", NULL
, NULL
, NULL
, 0, 0);
2589 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2591 ret
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
2592 ok(ret
, "HttpSendRequest failed\n");
2595 size
= sizeof(buffer
);
2596 ret
= HttpQueryInfo(hr
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
2597 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2598 ok(index
== 1, "expected 1 got %u\n", index
);
2601 size
= sizeof(buffer
);
2602 ret
= HttpQueryInfo(hr
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
2603 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2604 ok(index
== 1, "expected 1 got %u\n", index
);
2607 size
= sizeof(buffer
);
2608 ret
= HttpQueryInfo(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
2609 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2610 ok(index
== 0, "expected 0 got %u\n", index
);
2612 size
= sizeof(buffer
);
2613 ret
= HttpQueryInfo(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
2614 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2615 ok(index
== 0, "expected 0 got %u\n", index
);
2617 index
= 0xdeadbeef; /* invalid start index */
2618 size
= sizeof(buffer
);
2619 ret
= HttpQueryInfo(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
2620 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
2621 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
2622 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
2625 size
= sizeof(buffer
);
2626 ret
= HttpQueryInfo(hr
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
2627 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2628 ok(index
== 0, "expected 0 got %u\n", index
);
2630 size
= sizeof(buffer
);
2631 ret
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
2632 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2633 ok(index
== 0, "expected 0 got %u\n", index
);
2635 size
= sizeof(buffer
);
2636 ret
= HttpQueryInfo(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
2637 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2638 ok(index
== 0, "expected 0 got %u\n", index
);
2640 test_status_code(hr
, 200);
2643 size
= sizeof(buffer
);
2644 ret
= HttpQueryInfo(hr
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
2645 ok(!ret
, "HttpQueryInfo succeeded\n");
2646 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
2649 size
= sizeof(buffer
);
2650 ret
= HttpQueryInfo(hr
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
2651 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2652 ok(index
== 1, "expected 1 got %u\n", index
);
2655 size
= sizeof(buffer
);
2656 strcpy(buffer
, "Server");
2657 ret
= HttpQueryInfo(hr
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
2658 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2659 ok(index
== 1, "expected 1 got %u\n", index
);
2662 size
= sizeof(buffer
);
2663 ret
= HttpQueryInfo(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
2664 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2665 ok(index
== 1, "expected 1 got %u\n", index
);
2667 size
= sizeof(buffer
);
2668 ret
= HttpQueryInfo(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
2669 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2670 ok(index
== 2, "expected 2 got %u\n", index
);
2672 InternetCloseHandle(hr
);
2673 InternetCloseHandle(hc
);
2674 InternetCloseHandle(hi
);
2677 static void test_options(int port
)
2679 HINTERNET ses
, con
, req
;
2684 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2685 ok(ses
!= NULL
, "InternetOpen failed\n");
2687 SetLastError(0xdeadbeef);
2688 ret
= InternetSetOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
2689 error
= GetLastError();
2690 ok(!ret
, "InternetSetOption succeeded\n");
2691 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
2693 SetLastError(0xdeadbeef);
2694 ret
= InternetSetOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
2695 ok(!ret
, "InternetSetOption succeeded\n");
2696 error
= GetLastError();
2697 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
2699 SetLastError(0xdeadbeef);
2700 ret
= InternetSetOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
2701 ok(!ret
, "InternetSetOption succeeded\n");
2702 error
= GetLastError();
2703 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
2706 ret
= InternetSetOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
2707 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
2709 SetLastError(0xdeadbeef);
2710 ret
= InternetQueryOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
2711 error
= GetLastError();
2712 ok(!ret
, "InternetQueryOption succeeded\n");
2713 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
2715 SetLastError(0xdeadbeef);
2716 ret
= InternetQueryOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
2717 error
= GetLastError();
2718 ok(!ret
, "InternetQueryOption succeeded\n");
2719 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
2722 SetLastError(0xdeadbeef);
2723 ret
= InternetQueryOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
2724 error
= GetLastError();
2725 ok(!ret
, "InternetQueryOption succeeded\n");
2726 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
2729 SetLastError(0xdeadbeef);
2730 ret
= InternetQueryOption(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
2731 error
= GetLastError();
2732 ok(!ret
, "InternetQueryOption succeeded\n");
2733 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
2737 ret
= InternetQueryOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
2738 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
2739 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
2741 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2742 ok(con
!= NULL
, "InternetConnect failed\n");
2746 ret
= InternetQueryOption(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
2747 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
2748 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
2751 ret
= InternetSetOption(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
2752 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
2756 ret
= InternetQueryOption(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
2757 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
2758 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
2760 req
= HttpOpenRequest(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
2761 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2765 ret
= InternetQueryOption(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
2766 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
2767 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
2770 ret
= InternetSetOption(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
2771 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
2775 ret
= InternetQueryOption(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
2776 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
2777 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
2779 /* INTERNET_OPTION_PROXY */
2780 SetLastError(0xdeadbeef);
2781 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
2782 error
= GetLastError();
2783 ok(!ret
, "InternetQueryOption succeeded\n");
2784 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
2786 SetLastError(0xdeadbeef);
2787 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
2788 error
= GetLastError();
2789 ok(!ret
, "InternetQueryOption succeeded\n");
2790 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
2793 SetLastError(0xdeadbeef);
2794 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
2795 error
= GetLastError();
2796 ok(!ret
, "InternetQueryOption succeeded\n");
2797 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
2798 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
2800 InternetCloseHandle(req
);
2801 InternetCloseHandle(con
);
2802 InternetCloseHandle(ses
);
2805 static void test_http_connection(void)
2807 struct server_info si
;
2811 si
.hEvent
= CreateEvent(NULL
, 0, 0, NULL
);
2814 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
2815 ok( hThread
!= NULL
, "create thread failed\n");
2817 r
= WaitForSingleObject(si
.hEvent
, 10000);
2818 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
2819 if (r
!= WAIT_OBJECT_0
)
2822 test_basic_request(si
.port
, "GET", "/test1");
2823 test_proxy_indirect(si
.port
);
2824 test_proxy_direct(si
.port
);
2825 test_header_handling_order(si
.port
);
2826 test_basic_request(si
.port
, "POST", "/test5");
2827 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
2828 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
2829 test_basic_request(si
.port
, "GET", "/test6");
2830 test_basic_request(si
.port
, "GET", "/testF");
2831 test_connection_header(si
.port
);
2832 test_http1_1(si
.port
);
2833 test_cookie_header(si
.port
);
2834 test_basic_authentication(si
.port
);
2835 test_invalid_response_headers(si
.port
);
2836 test_response_without_headers(si
.port
);
2837 test_HttpQueryInfo(si
.port
);
2838 test_HttpSendRequestW(si
.port
);
2839 test_last_error(si
.port
);
2840 test_options(si
.port
);
2841 test_no_content(si
.port
);
2842 test_conn_close(si
.port
);
2844 /* send the basic request again to shutdown the server thread */
2845 test_basic_request(si
.port
, "GET", "/quit");
2847 r
= WaitForSingleObject(hThread
, 3000);
2848 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
2849 CloseHandle(hThread
);
2852 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
2854 LocalFree(info
->lpszSubjectInfo
);
2855 LocalFree(info
->lpszIssuerInfo
);
2856 LocalFree(info
->lpszProtocolName
);
2857 LocalFree(info
->lpszSignatureAlgName
);
2858 LocalFree(info
->lpszEncryptionAlgName
);
2861 static void test_cert_struct(HINTERNET req
)
2863 INTERNET_CERTIFICATE_INFOA info
;
2867 static const char ex_subject
[] =
2872 "test.winehq.org\r\n"
2873 "webmaster@winehq.org";
2875 static const char ex_issuer
[] =
2879 "test.winehq.org\r\n"
2880 "webmaster@winehq.org";
2882 memset(&info
, 0x5, sizeof(info
));
2884 size
= sizeof(info
);
2885 res
= InternetQueryOption(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
2886 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
2887 ok(size
== sizeof(info
), "size = %u\n", size
);
2889 ok(!strcmp(info
.lpszSubjectInfo
, ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
2890 ok(!strcmp(info
.lpszIssuerInfo
, ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
2891 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
2892 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
2893 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
2895 ok(info
.dwKeySize
== 128, "dwKeySize = %u\n", info
.dwKeySize
);
2897 release_cert_info(&info
);
2900 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
2901 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
2903 char url
[INTERNET_MAX_URL_LENGTH
];
2904 const CERT_CHAIN_CONTEXT
*chain
;
2908 if(!pInternetGetSecurityInfoByURLA
) {
2909 win_skip("pInternetGetSecurityInfoByURLA not available\n");
2914 chain
= (void*)0xdeadbeef;
2916 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
2917 if(error
== ERROR_SUCCESS
) {
2918 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
2919 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
2920 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
2921 CertFreeCertificateChain(chain
);
2923 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
2924 "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res
, GetLastError(), error
);
2928 #define test_secflags_option(a,b) _test_secflags_option(__LINE__,a,b)
2929 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
)
2935 size
= sizeof(flags
);
2936 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
2937 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
2938 ok_(__FILE__
,line
)(flags
== ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n", flags
, ex_flags
);
2940 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
2942 size
= sizeof(flags
);
2943 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
2944 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
2945 ok_(__FILE__
,line
)(flags
== ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n", flags
, ex_flags
);
2948 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
2949 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
2953 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
2954 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
2957 static void test_security_flags(void)
2959 HINTERNET ses
, conn
, req
;
2964 trace("Testing security flags...\n");
2966 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2968 ses
= InternetOpen("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2969 ok(ses
!= NULL
, "InternetOpen failed\n");
2971 pInternetSetStatusCallbackA(ses
, &callback
);
2973 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2974 conn
= InternetConnectA(ses
, "test.winehq.org", INTERNET_DEFAULT_HTTPS_PORT
,
2975 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
2976 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
2977 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2979 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2980 req
= HttpOpenRequest(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
2981 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
2983 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2984 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2987 size
= sizeof(flags
);
2988 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
2989 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
2990 win_skip("Incomplete security flags support, skipping\n");
2992 close_async_handle(ses
, hCompleteEvent
, 2);
2993 CloseHandle(hCompleteEvent
);
2997 test_secflags_option(req
, 0);
2998 test_security_info("https://test.winehq.org/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
3000 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
3001 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
);
3003 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
3004 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
3006 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
3007 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
3009 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
3010 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
3011 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
3013 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
3014 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
3015 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3016 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3017 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3018 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3019 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3020 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3021 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3022 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3023 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3025 res
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
3026 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
3028 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3029 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
3031 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
3032 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
3033 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3034 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3035 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3036 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3037 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3038 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3039 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3040 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3041 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3043 test_request_flags(req
, 0);
3044 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
3045 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
);
3047 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
3048 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3049 ok(size
, "size = 0\n");
3051 /* Collect all existing persistent connections */
3052 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
3053 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
3055 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3056 req
= HttpOpenRequest(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
3057 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
3059 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3060 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3062 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
3063 res
= InternetSetOption(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
3064 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
3066 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3067 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3068 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3069 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3070 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3071 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3072 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3074 res
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
3075 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
3077 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3078 ok(req_error
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| broken(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
),
3079 "req_error = %d\n", req_error
);
3081 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3082 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3083 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3084 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3085 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3086 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3087 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3089 if(req_error
!= ERROR_INTERNET_SEC_CERT_REV_FAILED
) {
3090 win_skip("Unexpected cert errors, skipping security flags tests\n");
3092 close_async_handle(ses
, hCompleteEvent
, 3);
3093 CloseHandle(hCompleteEvent
);
3098 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3099 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
3101 test_request_flags(req
, 8);
3102 test_secflags_option(req
, 0x800000);
3104 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
3105 test_secflags_option(req
, 0x800000|SECURITY_FLAG_IGNORE_REVOCATION
);
3107 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3108 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3109 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3110 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3111 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3112 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3113 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3115 res
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
3116 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
3118 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3119 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
3121 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3122 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3123 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3124 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3125 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3126 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3127 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3129 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
3130 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
3131 test_security_info("https://test.winehq.org/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
3133 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
3134 test_secflags_option(req
, 0x1800000|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
3135 |SECURITY_FLAG_IGNORE_REVOCATION
);
3136 test_http_version(req
);
3138 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3139 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3140 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3141 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3142 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3143 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3144 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3145 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3146 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3148 res
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
3149 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
3151 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3152 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
3154 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3155 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3156 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3157 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3158 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3159 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3160 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3161 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3162 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3164 test_request_flags(req
, 0);
3165 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
3166 |SECURITY_FLAG_STRENGTH_STRONG
|0x1800000);
3168 test_cert_struct(req
);
3169 test_security_info("https://test.winehq.org/data/some_file.html?q", 0, 0x1800000);
3171 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
3172 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3173 ok(size
, "size = 0\n");
3175 close_async_handle(ses
, hCompleteEvent
, 3);
3177 /* Collect all existing persistent connections */
3178 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
3179 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
3181 /* Make another request, without setting security flags */
3183 ses
= InternetOpen("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3184 ok(ses
!= NULL
, "InternetOpen failed\n");
3186 pInternetSetStatusCallbackA(ses
, &callback
);
3188 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3189 conn
= InternetConnectA(ses
, "test.winehq.org", INTERNET_DEFAULT_HTTPS_PORT
,
3190 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
3191 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3192 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3194 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3195 req
= HttpOpenRequest(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
3196 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
3198 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3199 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3201 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
3202 |SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
3203 test_http_version(req
);
3205 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3206 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3207 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3208 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3209 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3210 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3211 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3212 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3214 res
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
3215 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
3217 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3218 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
3220 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3221 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3222 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3223 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3224 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3225 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3226 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3227 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3229 test_request_flags(req
, 0);
3230 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
3231 |SECURITY_FLAG_IGNORE_REVOCATION
|0x1800000);
3233 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
3234 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3235 ok(size
, "size = 0\n");
3237 close_async_handle(ses
, hCompleteEvent
, 2);
3239 CloseHandle(hCompleteEvent
);
3241 test_security_info("http://test.winehq.org/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
3242 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
3243 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
3246 static void test_secure_connection(void)
3248 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
3249 static const WCHAR testbot
[] = {'t','e','s','t','b','o','t','.','w','i','n','e','h','q','.','o','r','g',0};
3250 static const WCHAR get
[] = {'G','E','T',0};
3251 static const WCHAR slash
[] = {'/',0};
3252 HINTERNET ses
, con
, req
;
3254 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
3255 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
3258 ses
= InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
3259 ok(ses
!= NULL
, "InternetOpen failed\n");
3261 con
= InternetConnect(ses
, "testbot.winehq.org",
3262 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
3263 INTERNET_SERVICE_HTTP
, 0, 0);
3264 ok(con
!= NULL
, "InternetConnect failed\n");
3266 req
= HttpOpenRequest(con
, "GET", "/", NULL
, NULL
, NULL
,
3267 INTERNET_FLAG_SECURE
, 0);
3268 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3270 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
3271 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
3273 size
= sizeof(flags
);
3274 ret
= InternetQueryOption(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
3275 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
3276 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
3278 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
3280 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
3281 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
3282 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
3283 ret
= InternetQueryOption(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
3284 certificate_structA
, &size
);
3285 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
3288 ok(certificate_structA
->lpszSubjectInfo
&&
3289 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
3290 "expected a non-empty subject name\n");
3291 ok(certificate_structA
->lpszIssuerInfo
&&
3292 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
3293 "expected a non-empty issuer name\n");
3294 ok(!certificate_structA
->lpszSignatureAlgName
,
3295 "unexpected signature algorithm name\n");
3296 ok(!certificate_structA
->lpszEncryptionAlgName
,
3297 "unexpected encryption algorithm name\n");
3298 ok(!certificate_structA
->lpszProtocolName
,
3299 "unexpected protocol name\n");
3300 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
3301 release_cert_info(certificate_structA
);
3303 HeapFree(GetProcessHeap(), 0, certificate_structA
);
3305 /* Querying the same option through InternetQueryOptionW still results in
3306 * ASCII strings being returned.
3309 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
3311 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
3312 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
3313 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
3314 ret
= InternetQueryOption(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
3315 certificate_structW
, &size
);
3316 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
3317 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
3320 ok(certificate_structA
->lpszSubjectInfo
&&
3321 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
3322 "expected a non-empty subject name\n");
3323 ok(certificate_structA
->lpszIssuerInfo
&&
3324 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
3325 "expected a non-empty issuer name\n");
3326 ok(!certificate_structA
->lpszSignatureAlgName
,
3327 "unexpected signature algorithm name\n");
3328 ok(!certificate_structA
->lpszEncryptionAlgName
,
3329 "unexpected encryption algorithm name\n");
3330 ok(!certificate_structA
->lpszProtocolName
,
3331 "unexpected protocol name\n");
3332 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
3333 release_cert_info(certificate_structA
);
3335 HeapFree(GetProcessHeap(), 0, certificate_structW
);
3337 InternetCloseHandle(req
);
3338 InternetCloseHandle(con
);
3339 InternetCloseHandle(ses
);
3341 /* Repeating the tests with the W functions has the same result: */
3342 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
3343 ok(ses
!= NULL
, "InternetOpen failed\n");
3345 con
= InternetConnectW(ses
, testbot
,
3346 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
3347 INTERNET_SERVICE_HTTP
, 0, 0);
3348 ok(con
!= NULL
, "InternetConnect failed\n");
3350 req
= HttpOpenRequestW(con
, get
, slash
, NULL
, NULL
, NULL
,
3351 INTERNET_FLAG_SECURE
, 0);
3352 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3354 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
3355 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
3357 size
= sizeof(flags
);
3358 ret
= InternetQueryOption(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
3359 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
3360 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
3362 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
3364 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
3365 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
3366 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
3367 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
3368 certificate_structA
, &size
);
3369 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
3372 ok(certificate_structA
->lpszSubjectInfo
&&
3373 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
3374 "expected a non-empty subject name\n");
3375 ok(certificate_structA
->lpszIssuerInfo
&&
3376 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
3377 "expected a non-empty issuer name\n");
3378 ok(!certificate_structA
->lpszSignatureAlgName
,
3379 "unexpected signature algorithm name\n");
3380 ok(!certificate_structA
->lpszEncryptionAlgName
,
3381 "unexpected encryption algorithm name\n");
3382 ok(!certificate_structA
->lpszProtocolName
,
3383 "unexpected protocol name\n");
3384 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
3385 release_cert_info(certificate_structA
);
3387 HeapFree(GetProcessHeap(), 0, certificate_structA
);
3389 /* Again, querying the same option through InternetQueryOptionW still
3390 * results in ASCII strings being returned.
3393 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
3395 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
3396 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
3397 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
3398 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
3399 certificate_structW
, &size
);
3400 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
3401 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
3404 ok(certificate_structA
->lpszSubjectInfo
&&
3405 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
3406 "expected a non-empty subject name\n");
3407 ok(certificate_structA
->lpszIssuerInfo
&&
3408 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
3409 "expected a non-empty issuer name\n");
3410 ok(!certificate_structA
->lpszSignatureAlgName
,
3411 "unexpected signature algorithm name\n");
3412 ok(!certificate_structA
->lpszEncryptionAlgName
,
3413 "unexpected encryption algorithm name\n");
3414 ok(!certificate_structA
->lpszProtocolName
,
3415 "unexpected protocol name\n");
3416 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
3417 release_cert_info(certificate_structA
);
3419 HeapFree(GetProcessHeap(), 0, certificate_structW
);
3421 InternetCloseHandle(req
);
3422 InternetCloseHandle(con
);
3423 InternetCloseHandle(ses
);
3426 static void test_user_agent_header(void)
3428 HINTERNET ses
, con
, req
;
3433 ses
= InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
3434 ok(ses
!= NULL
, "InternetOpen failed\n");
3436 con
= InternetConnect(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3437 ok(con
!= NULL
, "InternetConnect failed\n");
3439 req
= HttpOpenRequest(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
3440 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3442 size
= sizeof(buffer
);
3443 ret
= HttpQueryInfo(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3444 err
= GetLastError();
3445 ok(!ret
, "HttpQueryInfo succeeded\n");
3446 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
3448 ret
= HttpAddRequestHeaders(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
3449 ok(ret
, "HttpAddRequestHeaders succeeded\n");
3451 size
= sizeof(buffer
);
3452 ret
= HttpQueryInfo(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3453 err
= GetLastError();
3454 ok(ret
, "HttpQueryInfo failed\n");
3455 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
3457 InternetCloseHandle(req
);
3459 req
= HttpOpenRequest(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
3460 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3462 size
= sizeof(buffer
);
3463 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3464 err
= GetLastError();
3465 ok(!ret
, "HttpQueryInfo succeeded\n");
3466 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
3468 ret
= HttpAddRequestHeaders(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
3469 ok(ret
, "HttpAddRequestHeaders failed\n");
3472 size
= sizeof(buffer
);
3473 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3474 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3475 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
3477 InternetCloseHandle(req
);
3478 InternetCloseHandle(con
);
3479 InternetCloseHandle(ses
);
3482 static void test_bogus_accept_types_array(void)
3484 HINTERNET ses
, con
, req
;
3485 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
3490 ses
= InternetOpen("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
3491 con
= InternetConnect(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3492 req
= HttpOpenRequest(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
3494 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3497 size
= sizeof(buffer
);
3498 SetLastError(0xdeadbeef);
3499 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3500 error
= GetLastError();
3501 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
3502 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
3503 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
3504 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
3505 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
3507 InternetCloseHandle(req
);
3508 InternetCloseHandle(con
);
3509 InternetCloseHandle(ses
);
3518 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
3520 INTERNET_ASYNC_RESULT
*result
= info
;
3521 struct context
*ctx
= (struct context
*)context
;
3523 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
3526 case INTERNET_STATUS_REQUEST_COMPLETE
:
3527 trace("request handle: 0x%08lx\n", result
->dwResult
);
3528 ctx
->req
= (HINTERNET
)result
->dwResult
;
3529 SetEvent(ctx
->event
);
3531 case INTERNET_STATUS_HANDLE_CLOSING
: {
3532 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
3534 if (InternetQueryOption(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
3535 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
3536 SetEvent(ctx
->event
);
3539 case INTERNET_STATUS_NAME_RESOLVED
:
3540 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
3541 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
3543 ok(str
[0] && str
[1], "Got string: %s\n", str
);
3544 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
3549 static void test_open_url_async(void)
3557 /* Collect all existing persistent connections */
3558 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
3559 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
3562 ctx
.event
= CreateEvent(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
3564 ses
= InternetOpen("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3565 ok(ses
!= NULL
, "InternetOpen failed\n");
3567 SetLastError(0xdeadbeef);
3568 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
3569 error
= GetLastError();
3570 ok(!ret
, "InternetSetOptionA succeeded\n");
3571 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
3573 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
3574 error
= GetLastError();
3575 ok(!ret
, "InternetSetOptionA failed\n");
3576 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
3578 pInternetSetStatusCallbackW(ses
, cb
);
3579 ResetEvent(ctx
.event
);
3581 req
= InternetOpenUrl(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
3582 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
3584 WaitForSingleObject(ctx
.event
, INFINITE
);
3587 size
= sizeof(type
);
3588 ret
= InternetQueryOption(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
3589 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
3590 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
3591 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
3594 ret
= HttpQueryInfo(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
3595 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
3596 ok(size
> 0, "expected size > 0\n");
3598 ResetEvent(ctx
.event
);
3599 InternetCloseHandle(ctx
.req
);
3600 WaitForSingleObject(ctx
.event
, INFINITE
);
3602 InternetCloseHandle(ses
);
3603 CloseHandle(ctx
.event
);
3608 internet_connect
= 1,
3610 http_send_request_ex
,
3613 internet_close_handle
3618 enum api function
; /* api responsible for notification */
3619 unsigned int status
; /* status received */
3620 int async
; /* delivered from another thread? */
3628 const struct notification
*test
;
3634 DWORD expect_result
;
3638 static CRITICAL_SECTION notification_cs
;
3640 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
3642 BOOL status_ok
, function_ok
;
3643 struct info
*info
= (struct info
*)context
;
3646 EnterCriticalSection( ¬ification_cs
);
3648 if(info
->is_aborted
) {
3649 LeaveCriticalSection(¬ification_cs
);
3653 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
3655 DWORD size
= sizeof(struct info
*);
3656 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
3657 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
3658 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
3660 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
3661 if(info
->expect_result
== ERROR_SUCCESS
) {
3662 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
3664 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
3665 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
3670 if (i
>= info
->count
)
3672 LeaveCriticalSection( ¬ification_cs
);
3676 while (info
->test
[i
].status
!= status
&&
3677 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
3678 i
< info
->count
- 1 &&
3679 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
3684 status_ok
= (info
->test
[i
].status
== status
);
3685 function_ok
= (info
->test
[i
].function
== info
->function
);
3687 if (!info
->test
[i
].todo
)
3689 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
3690 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
3692 if (info
->test
[i
].async
)
3693 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
3694 info
->line
, info
->thread
, GetCurrentThreadId());
3698 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
3700 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
3702 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
3705 LeaveCriticalSection( ¬ification_cs
);
3708 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
3710 info
->function
= function
;
3712 info
->expect_result
= expect_result
;
3715 struct notification_data
3717 const struct notification
*test
;
3718 const unsigned int count
;
3723 BOOL expect_conn_failure
;
3726 static const struct notification async_send_request_ex_test
[] =
3728 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
3729 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
3730 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
3731 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, 1, 0, 1 },
3732 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, 1, 0, 1 },
3733 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, 1, 0, 1 },
3734 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, 1 },
3735 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, 1 },
3736 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, 1 },
3737 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, 1 },
3738 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
3739 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, 0 },
3740 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, 0 },
3741 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, 1 },
3742 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, 1 },
3743 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
3744 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0, 1 },
3745 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0, 1 },
3746 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, },
3747 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, }
3750 static const struct notification async_send_request_ex_test2
[] =
3752 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
3753 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
3754 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
3755 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, 1, 0, 1 },
3756 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, 1, 0, 1 },
3757 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, 1, 0, 1 },
3758 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, 1, 1 },
3759 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, 1, 1 },
3760 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, 1 },
3761 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, 1 },
3762 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
3763 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, 1 },
3764 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, 1 },
3765 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
3766 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0, 1 },
3767 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0, 1 },
3768 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, },
3769 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, }
3772 static const struct notification async_send_request_ex_resolve_failure_test
[] =
3774 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
3775 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
3776 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
3777 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, 1 },
3778 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
3779 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
3780 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
3781 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0, 1 },
3782 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0, 1 },
3783 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, },
3784 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, }
3787 static const struct notification_data notification_data
[] = {
3789 async_send_request_ex_test
,
3790 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
3793 "tests/posttest.php",
3794 "Public ID=codeweavers"
3797 async_send_request_ex_test2
,
3798 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
3801 "tests/posttest.php"
3804 async_send_request_ex_resolve_failure_test
,
3805 sizeof(async_send_request_ex_resolve_failure_test
)/sizeof(async_send_request_ex_resolve_failure_test
[0]),
3814 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
3817 HINTERNET ses
, req
, con
;
3819 DWORD size
, written
, error
;
3820 INTERNET_BUFFERSA b
;
3821 static const char *accept
[2] = {"*/*", NULL
};
3824 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
3826 InitializeCriticalSection( ¬ification_cs
);
3828 info
.test
= nd
->test
;
3829 info
.count
= nd
->count
;
3831 info
.wait
= CreateEvent( NULL
, FALSE
, FALSE
, NULL
);
3832 info
.thread
= GetCurrentThreadId();
3833 info
.is_aborted
= FALSE
;
3835 ses
= InternetOpen( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3836 ok( ses
!= NULL
, "InternetOpen failed\n" );
3838 pInternetSetStatusCallbackA( ses
, check_notification
);
3840 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
3841 con
= InternetConnect( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
3842 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
3844 WaitForSingleObject( info
.wait
, 10000 );
3846 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
3847 req
= HttpOpenRequest( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
3848 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
3850 WaitForSingleObject( info
.wait
, 10000 );
3853 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
3854 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
3855 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
3856 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
3857 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
3860 setup_test( &info
, http_send_request_ex
, __LINE__
,
3861 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
3862 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
3863 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
3865 error
= WaitForSingleObject( info
.wait
, 10000 );
3866 if(error
!= WAIT_OBJECT_0
) {
3867 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
3868 info
.is_aborted
= TRUE
;
3872 size
= sizeof(buffer
);
3873 SetLastError( 0xdeadbeef );
3874 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
3875 error
= GetLastError();
3876 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
3877 if(nd
->expect_conn_failure
) {
3878 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
3881 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
3882 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
3888 size
= strlen( nd
->data
);
3889 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
3890 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
3891 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
3892 ok( written
== size
, "expected %u got %u\n", written
, size
);
3894 WaitForSingleObject( info
.wait
, 10000 );
3896 SetLastError( 0xdeadbeef );
3897 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
3898 error
= GetLastError();
3899 ok( !ret
, "HttpEndRequestA succeeded\n" );
3900 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
3903 SetLastError( 0xdeadbeef );
3904 setup_test( &info
, http_end_request
, __LINE__
,
3905 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
3906 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
3907 error
= GetLastError();
3908 ok( !ret
, "HttpEndRequestA succeeded\n" );
3909 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
3911 WaitForSingleObject( info
.wait
, 10000 );
3913 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
3915 InternetCloseHandle( req
);
3916 InternetCloseHandle( con
);
3917 InternetCloseHandle( ses
);
3919 WaitForSingleObject( info
.wait
, 10000 );
3921 CloseHandle( info
.wait
);
3924 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
3925 static BOOL closetest_closed
;
3927 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
3928 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
3933 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
3935 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
3936 "Unexpected hInternet %p\n", hInternet
);
3937 if(!closetest_closed
)
3941 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
3942 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
3943 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
3944 closetest_req
, res
, GetLastError());
3947 static void test_InternetCloseHandle(void)
3952 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3953 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3955 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
3957 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
3958 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3959 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3961 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
3962 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3964 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
3965 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3966 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3968 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
3970 res
= InternetCloseHandle(closetest_session
);
3971 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
3972 closetest_closed
= TRUE
;
3973 trace("Closed session handle\n");
3975 res
= InternetCloseHandle(closetest_conn
);
3976 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
3977 res
, GetLastError());
3979 res
= InternetCloseHandle(closetest_req
);
3980 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
3981 res
, GetLastError());
3983 len
= sizeof(flags
);
3984 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
3985 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
3986 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
3987 closetest_req
, res
, GetLastError());
3990 static void test_connection_failure(void)
3992 HINTERNET session
, connect
, request
;
3996 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
3997 ok(session
!= NULL
, "failed to get session handle\n");
3999 connect
= InternetConnectA(session
, "localhost", 1, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4000 ok(connect
!= NULL
, "failed to get connection handle\n");
4002 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
4003 ok(request
!= NULL
, "failed to get request handle\n");
4005 SetLastError(0xdeadbeef);
4006 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
4007 error
= GetLastError();
4008 ok(!ret
, "unexpected success\n");
4009 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
4011 InternetCloseHandle(request
);
4012 InternetCloseHandle(connect
);
4013 InternetCloseHandle(session
);
4016 static void test_default_service_port(void)
4018 HINTERNET session
, connect
, request
;
4022 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4023 ok(session
!= NULL
, "InternetOpen failed\n");
4025 connect
= InternetConnect(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
4026 INTERNET_SERVICE_HTTP
, 0, 0);
4027 ok(connect
!= NULL
, "InternetConnect failed\n");
4029 request
= HttpOpenRequest(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
4030 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4032 SetLastError(0xdeadbeef);
4033 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
4034 error
= GetLastError();
4035 ok(!ret
, "HttpSendRequest succeeded\n");
4036 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
4039 InternetCloseHandle(request
);
4040 InternetCloseHandle(connect
);
4041 InternetCloseHandle(session
);
4044 static void init_status_tests(void)
4046 memset(expect
, 0, sizeof(expect
));
4047 memset(optional
, 0, sizeof(optional
));
4048 memset(wine_allow
, 0, sizeof(wine_allow
));
4049 memset(notified
, 0, sizeof(notified
));
4050 memset(status_string
, 0, sizeof(status_string
));
4052 #define STATUS_STRING(status) status_string[status] = #status
4053 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
4054 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
4055 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4056 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4057 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
4058 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
4059 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
4060 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
4061 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
4062 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
4063 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
4064 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
4065 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
4066 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
4067 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
4068 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
4069 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
4070 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
4071 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
4072 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
4073 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
4074 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
4075 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
4076 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
4077 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
4078 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
4079 #undef STATUS_STRING
4085 hdll
= GetModuleHandleA("wininet.dll");
4087 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
4088 win_skip("Too old IE (older than 6.0)\n");
4092 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
4093 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
4094 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
4096 init_status_tests();
4097 test_InternetCloseHandle();
4098 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
4099 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
4100 InternetReadFile_test(0, &test_data
[1]);
4101 first_connection_to_test_url
= TRUE
;
4102 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
4103 test_security_flags();
4104 InternetReadFile_test(0, &test_data
[2]);
4105 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
4106 test_open_url_async();
4107 test_async_HttpSendRequestEx(¬ification_data
[0]);
4108 test_async_HttpSendRequestEx(¬ification_data
[1]);
4109 test_async_HttpSendRequestEx(¬ification_data
[2]);
4110 InternetOpenRequest_test();
4112 InternetOpenUrlA_test();
4114 test_http_connection();
4115 test_secure_connection();
4116 test_user_agent_header();
4117 test_bogus_accept_types_array();
4118 InternetReadFile_chunked_test();
4119 HttpSendRequestEx_test();
4120 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
4121 test_connection_failure();
4122 test_default_service_port();