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 /* Undocumented security flags */
36 #define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
37 #define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
38 #define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
39 #define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
41 #define TEST_URL "http://test.winehq.org/tests/hello.html"
43 static BOOL first_connection_to_test_url
= TRUE
;
45 /* Adapted from dlls/urlmon/tests/protocol.c */
47 #define SET_EXPECT2(status, num) \
50 #define SET_EXPECT(status) \
51 SET_EXPECT2(status, 1)
53 #define SET_OPTIONAL2(status, num) \
54 optional[status] = num
56 #define SET_OPTIONAL(status) \
57 SET_OPTIONAL2(status, 1)
59 /* SET_WINE_ALLOW's should be used with an appropriate
60 * todo_wine CHECK_NOTIFIED at a later point in the code */
61 #define SET_WINE_ALLOW2(status, num) \
62 wine_allow[status] = num
64 #define SET_WINE_ALLOW(status) \
65 SET_WINE_ALLOW2(status, 1)
67 #define CHECK_EXPECT(status) \
69 if (!expect[status] && !optional[status] && wine_allow[status]) \
71 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
72 status < MAX_INTERNET_STATUS && status_string[status] ? \
73 status_string[status] : "unknown"); \
74 wine_allow[status]--; \
78 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
79 status < MAX_INTERNET_STATUS && status_string[status] ? \
80 status_string[status] : "unknown"); \
81 if (expect[status]) expect[status]--; \
82 else if(optional[status]) optional[status]--; \
87 /* CLEAR_NOTIFIED used in cases when notification behavior
88 * differs between Windows versions */
89 #define CLEAR_NOTIFIED(status) \
90 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
92 #define CHECK_NOTIFIED2(status, num) \
94 ok(notified[status] + optional[status] == (num), \
95 "expected status %d (%s) %d times, received %d times\n", \
96 status, status < MAX_INTERNET_STATUS && status_string[status] ? \
97 status_string[status] : "unknown", (num), notified[status]); \
98 CLEAR_NOTIFIED(status); \
101 #define CHECK_NOTIFIED(status) \
102 CHECK_NOTIFIED2(status, 1)
104 #define CHECK_NOT_NOTIFIED(status) \
105 CHECK_NOTIFIED2(status, 0)
107 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
108 static int expect
[MAX_INTERNET_STATUS
], optional
[MAX_INTERNET_STATUS
],
109 wine_allow
[MAX_INTERNET_STATUS
], notified
[MAX_INTERNET_STATUS
];
110 static const char *status_string
[MAX_INTERNET_STATUS
];
112 static HANDLE hCompleteEvent
, conn_close_event
;
113 static DWORD req_error
;
115 #define TESTF_REDIRECT 0x01
116 #define TESTF_COMPRESSED 0x02
117 #define TESTF_CHUNKED 0x04
121 const char *redirected_url
;
126 const char *post_data
;
130 static const test_data_t test_data
[] = {
132 "http://test.winehq.org/tests/data.php",
133 "http://test.winehq.org/tests/data.php",
140 "http://test.winehq.org/tests/redirect",
141 "http://test.winehq.org/tests/hello.html",
148 "http://test.winehq.org/tests/gzip.php",
149 "http://test.winehq.org/tests/gzip.php",
152 "Accept-Encoding: gzip, deflate",
156 "http://test.winehq.org/tests/post.php",
157 "http://test.winehq.org/tests/post.php",
160 "Content-Type: application/x-www-form-urlencoded",
167 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackA
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
168 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackW
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
169 static BOOL (WINAPI
*pInternetGetSecurityInfoByURLA
)(LPSTR
,PCCERT_CHAIN_CONTEXT
*,DWORD
*);
171 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
174 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
175 return lstrcmpW(strw
, buf
);
178 static BOOL
proxy_active(void)
180 HKEY internet_settings
;
184 if (RegOpenKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
185 0, KEY_QUERY_VALUE
, &internet_settings
) != ERROR_SUCCESS
)
188 size
= sizeof(DWORD
);
189 if (RegQueryValueExA(internet_settings
, "ProxyEnable", NULL
, NULL
, (LPBYTE
) &proxy_enable
, &size
) != ERROR_SUCCESS
)
192 RegCloseKey(internet_settings
);
194 return proxy_enable
!= 0;
197 #define test_status_code(a,b) _test_status_code(__LINE__,a,b, FALSE)
198 #define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)
199 static void _test_status_code(unsigned line
, HINTERNET req
, DWORD excode
, BOOL is_todo
)
201 DWORD code
, size
, index
;
202 char exbuf
[10], bufa
[10];
208 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, NULL
);
209 ok_(__FILE__
,line
)(res
, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
211 todo_wine
ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
213 ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
214 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
219 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
220 ok_(__FILE__
,line
)(res
, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
222 todo_wine
ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
224 ok_(__FILE__
,line
)(!index
, "index = %d, expected 0\n", code
);
225 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
227 sprintf(exbuf
, "%u", excode
);
230 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, bufa
, &size
, NULL
);
231 ok_(__FILE__
,line
)(res
, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
233 todo_wine
ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
235 ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
236 ok_(__FILE__
,line
)(size
== strlen(exbuf
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
239 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
240 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
241 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
242 ok_(__FILE__
,line
)(size
== strlen(exbuf
)+1, "unexpected size %d for \"%s\"\n", size
, exbuf
);
245 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
246 ok_(__FILE__
,line
)(res
, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
248 todo_wine
ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
250 ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
251 ok_(__FILE__
,line
)(size
== strlen(exbuf
)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
254 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
255 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
256 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
257 ok_(__FILE__
,line
)(size
== (strlen(exbuf
)+1)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
261 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
262 ok(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
263 ok(size
== sizeof(bufw
), "unexpected size %d\n", size
);
269 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
270 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
271 "[7] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
275 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, &code
, &size
, NULL
);
276 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST
,
277 "[8] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
280 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
281 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
282 static void _test_request_flags(unsigned line
, HINTERNET req
, DWORD exflags
, BOOL is_todo
)
288 size
= sizeof(flags
);
289 res
= InternetQueryOptionW(req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &size
);
290 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
292 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
293 flags
&= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED
;
295 ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
297 todo_wine
ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
300 #define test_http_version(a) _test_http_version(__LINE__,a)
301 static void _test_http_version(unsigned line
, HINTERNET req
)
303 HTTP_VERSION_INFO v
= {0xdeadbeef, 0xdeadbeef};
308 res
= InternetQueryOptionW(req
, INTERNET_OPTION_HTTP_VERSION
, &v
, &size
);
309 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
310 ok_(__FILE__
,line
)(v
.dwMajorVersion
== 1, "dwMajorVersion = %d\n", v
.dwMajorVersion
);
311 ok_(__FILE__
,line
)(v
.dwMinorVersion
== 1, "dwMinorVersion = %d\n", v
.dwMinorVersion
);
314 static int close_handle_cnt
;
316 static VOID WINAPI
callback(
319 DWORD dwInternetStatus
,
320 LPVOID lpvStatusInformation
,
321 DWORD dwStatusInformationLength
324 CHECK_EXPECT(dwInternetStatus
);
325 switch (dwInternetStatus
)
327 case INTERNET_STATUS_RESOLVING_NAME
:
328 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
329 GetCurrentThreadId(), hInternet
, dwContext
,
330 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
331 *(LPSTR
)lpvStatusInformation
= '\0';
333 case INTERNET_STATUS_NAME_RESOLVED
:
334 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
335 GetCurrentThreadId(), hInternet
, dwContext
,
336 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
337 *(LPSTR
)lpvStatusInformation
= '\0';
339 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
340 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
341 GetCurrentThreadId(), hInternet
, dwContext
,
342 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
343 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
344 dwStatusInformationLength
);
345 *(LPSTR
)lpvStatusInformation
= '\0';
347 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
348 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
349 GetCurrentThreadId(), hInternet
, dwContext
,
350 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
351 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
352 dwStatusInformationLength
);
353 *(LPSTR
)lpvStatusInformation
= '\0';
355 case INTERNET_STATUS_SENDING_REQUEST
:
356 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
357 GetCurrentThreadId(), hInternet
, dwContext
,
358 lpvStatusInformation
,dwStatusInformationLength
);
360 case INTERNET_STATUS_REQUEST_SENT
:
361 ok(dwStatusInformationLength
== sizeof(DWORD
),
362 "info length should be sizeof(DWORD) instead of %d\n",
363 dwStatusInformationLength
);
364 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
365 GetCurrentThreadId(), hInternet
, dwContext
,
366 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
368 case INTERNET_STATUS_RECEIVING_RESPONSE
:
369 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
370 GetCurrentThreadId(), hInternet
, dwContext
,
371 lpvStatusInformation
,dwStatusInformationLength
);
373 case INTERNET_STATUS_RESPONSE_RECEIVED
:
374 ok(dwStatusInformationLength
== sizeof(DWORD
),
375 "info length should be sizeof(DWORD) instead of %d\n",
376 dwStatusInformationLength
);
377 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
378 GetCurrentThreadId(), hInternet
, dwContext
,
379 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
381 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
382 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
383 GetCurrentThreadId(), hInternet
,dwContext
,
384 lpvStatusInformation
,dwStatusInformationLength
);
386 case INTERNET_STATUS_PREFETCH
:
387 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
388 GetCurrentThreadId(), hInternet
, dwContext
,
389 lpvStatusInformation
,dwStatusInformationLength
);
391 case INTERNET_STATUS_CLOSING_CONNECTION
:
392 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
393 GetCurrentThreadId(), hInternet
, dwContext
,
394 lpvStatusInformation
,dwStatusInformationLength
);
396 case INTERNET_STATUS_CONNECTION_CLOSED
:
397 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
398 GetCurrentThreadId(), hInternet
, dwContext
,
399 lpvStatusInformation
,dwStatusInformationLength
);
401 case INTERNET_STATUS_HANDLE_CREATED
:
402 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
403 "info length should be sizeof(HINTERNET) instead of %d\n",
404 dwStatusInformationLength
);
405 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
406 GetCurrentThreadId(), hInternet
, dwContext
,
407 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
408 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
409 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
411 case INTERNET_STATUS_HANDLE_CLOSING
:
412 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
413 "info length should be sizeof(HINTERNET) instead of %d\n",
414 dwStatusInformationLength
);
415 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
416 GetCurrentThreadId(), hInternet
, dwContext
,
417 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
418 if(!InterlockedDecrement(&close_handle_cnt
))
419 SetEvent(hCompleteEvent
);
421 case INTERNET_STATUS_REQUEST_COMPLETE
:
423 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
424 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
425 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
426 dwStatusInformationLength
);
427 ok(iar
->dwResult
== 1 || iar
->dwResult
== 0, "iar->dwResult = %ld\n", iar
->dwResult
);
428 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
429 GetCurrentThreadId(), hInternet
, dwContext
,
430 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
431 req_error
= iar
->dwError
;
432 if(!close_handle_cnt
)
433 SetEvent(hCompleteEvent
);
436 case INTERNET_STATUS_REDIRECT
:
437 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
438 GetCurrentThreadId(), hInternet
, dwContext
,
439 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
440 *(LPSTR
)lpvStatusInformation
= '\0';
441 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
442 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
444 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
445 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
446 GetCurrentThreadId(), hInternet
, dwContext
,
447 lpvStatusInformation
, dwStatusInformationLength
);
450 trace("%04x:Callback %p 0x%lx %d %p %d\n",
451 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
452 lpvStatusInformation
, dwStatusInformationLength
);
456 static void close_async_handle(HINTERNET handle
, HANDLE complete_event
, int handle_cnt
)
460 close_handle_cnt
= handle_cnt
;
462 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
463 res
= InternetCloseHandle(handle
);
464 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
465 WaitForSingleObject(hCompleteEvent
, INFINITE
);
466 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
469 static void InternetReadFile_test(int flags
, const test_data_t
*test
)
471 char *post_data
= NULL
;
472 BOOL res
, on_async
= TRUE
;
475 DWORD length
, length2
, index
, exlen
= 0, post_len
= 0;
476 const char *types
[2] = { "*", NULL
};
477 HINTERNET hi
, hic
= 0, hor
= 0;
479 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
481 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags
,test
->url
);
483 trace("InternetOpenA <--\n");
484 hi
= InternetOpenA((test
->flags
& TESTF_COMPRESSED
) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
485 INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
486 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
487 trace("InternetOpenA -->\n");
489 if (hi
== 0x0) goto abort
;
491 pInternetSetStatusCallbackA(hi
,&callback
);
493 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
495 trace("InternetConnectA <--\n");
496 hic
=InternetConnectA(hi
, test
->host
, INTERNET_INVALID_PORT_NUMBER
,
497 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
498 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
499 trace("InternetConnectA -->\n");
501 if (hic
== 0x0) goto abort
;
503 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
504 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
506 trace("HttpOpenRequestA <--\n");
507 hor
= HttpOpenRequestA(hic
, test
->post_data
? "POST" : "GET", test
->path
, NULL
, NULL
, types
,
508 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
510 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
512 * If the internet name can't be resolved we are probably behind
513 * a firewall or in some other way not directly connected to the
514 * Internet. Not enough reason to fail the test. Just ignore and
518 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
520 trace("HttpOpenRequestA -->\n");
522 if (hor
== 0x0) goto abort
;
524 test_request_flags(hor
, INTERNET_REQFLAG_NO_HEADERS
);
526 length
= sizeof(buffer
);
527 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
528 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
529 ok(!strcmp(buffer
, test
->url
), "Wrong URL %s, expected %s\n", buffer
, test
->url
);
531 length
= sizeof(buffer
);
532 res
= HttpQueryInfoA(hor
, HTTP_QUERY_RAW_HEADERS
, buffer
, &length
, 0x0);
533 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
534 ok(length
== 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length
);
535 ok(!strcmp(buffer
, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer
);
537 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
538 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
539 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
540 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
,2);
541 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED
,2);
542 if (first_connection_to_test_url
)
544 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
545 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
547 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
548 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
549 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
550 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
551 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
552 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
553 if(test
->flags
& TESTF_REDIRECT
) {
554 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
555 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
557 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
558 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
559 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
560 if (flags
& INTERNET_FLAG_ASYNC
)
561 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
563 if(test
->flags
& TESTF_COMPRESSED
) {
566 res
= InternetSetOptionA(hor
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
567 ok(res
|| broken(!res
&& GetLastError() == ERROR_INTERNET_INVALID_OPTION
),
568 "InternetSetOption failed: %u\n", GetLastError());
573 test_status_code(hor
, 0);
575 trace("HttpSendRequestA -->\n");
576 if(test
->post_data
) {
577 post_len
= strlen(test
->post_data
);
578 post_data
= HeapAlloc(GetProcessHeap(), 0, post_len
);
579 memcpy(post_data
, test
->post_data
, post_len
);
581 SetLastError(0xdeadbeef);
582 res
= HttpSendRequestA(hor
, test
->headers
, -1, post_data
, post_len
);
583 if (flags
& INTERNET_FLAG_ASYNC
)
584 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
585 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
587 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
588 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
589 trace("HttpSendRequestA <--\n");
591 if (flags
& INTERNET_FLAG_ASYNC
) {
592 WaitForSingleObject(hCompleteEvent
, INFINITE
);
593 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
595 HeapFree(GetProcessHeap(), 0, post_data
);
597 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
598 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED
);
599 if (first_connection_to_test_url
)
601 if (! proxy_active())
603 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
604 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
608 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
609 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
614 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
615 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
617 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
618 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
619 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
620 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
621 if(test
->flags
& TESTF_REDIRECT
)
622 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
623 if (flags
& INTERNET_FLAG_ASYNC
)
624 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
625 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
626 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
627 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
629 test_request_flags(hor
, 0);
632 res
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
633 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
635 length
= sizeof(buffer
)-1;
636 memset(buffer
, 0x77, sizeof(buffer
));
637 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
638 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
639 /* show that the function writes data past the length returned */
640 ok(buffer
[length
-2], "Expected any header character, got 0x00\n");
641 ok(!buffer
[length
-1], "Expected 0x00, got %02X\n", buffer
[length
-1]);
642 ok(!buffer
[length
], "Expected 0x00, got %02X\n", buffer
[length
]);
643 ok(buffer
[length
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length
+1]);
646 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
647 ok(!res
, "Expected 0x00, got %d\n", res
);
648 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
649 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
650 /* the in length of the buffer must be +1 but the length returned does not count this */
652 memset(buffer
, 0x77, sizeof(buffer
));
653 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
654 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
655 ok(buffer
[length2
] == 0x00, "Expected 0x00, got %02X\n", buffer
[length2
]);
656 ok(buffer
[length2
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length2
+1]);
657 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
659 length
= sizeof(wbuffer
)-sizeof(WCHAR
);
660 memset(wbuffer
, 0x77, sizeof(wbuffer
));
661 res
= HttpQueryInfoW(hor
, HTTP_QUERY_RAW_HEADERS
, wbuffer
, &length
, 0x0);
662 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
663 ok(length
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length
);
664 length
/= sizeof(WCHAR
);
665 /* show that the function writes data past the length returned */
666 ok(wbuffer
[length
-2], "Expected any header character, got 0x0000\n");
667 ok(!wbuffer
[length
-1], "Expected 0x0000, got %04X\n", wbuffer
[length
-1]);
668 ok(!wbuffer
[length
], "Expected 0x0000, got %04X\n", wbuffer
[length
]);
669 ok(wbuffer
[length
+1] == 0x7777 || broken(wbuffer
[length
+1] != 0x7777),
670 "Expected 0x7777, got %04X\n", wbuffer
[length
+1]);
672 length2
= length
*sizeof(WCHAR
);
673 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
674 ok(!res
, "Expected 0x00, got %d\n", res
);
675 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
676 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
677 length2
/= sizeof(WCHAR
);
678 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
679 /* the in length of the buffer must be +1 but the length returned does not count this */
680 length2
= (length
+1)*sizeof(WCHAR
);
681 memset(wbuffer
, 0x77, sizeof(wbuffer
));
682 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
683 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
684 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
685 length2
/= sizeof(WCHAR
);
686 ok(!wbuffer
[length2
], "Expected 0x0000, got %04X\n", wbuffer
[length2
]);
687 ok(wbuffer
[length2
+1] == 0x7777, "Expected 0x7777, got %04X\n", wbuffer
[length2
+1]);
688 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
690 length
= sizeof(buffer
);
691 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
692 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
693 ok(!strcmp(buffer
, test
->redirected_url
), "Wrong URL %s\n", buffer
);
697 SetLastError(0xdeadbeef);
698 ok(HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,NULL
,&length
,&index
) == FALSE
,"Query worked\n");
699 if(test
->flags
& TESTF_COMPRESSED
)
700 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
701 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
702 ok(index
== 0, "Index was incremented\n");
706 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,&index
);
707 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res
,buffer
,GetLastError());
708 if(test
->flags
& TESTF_COMPRESSED
)
709 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
710 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res
, GetLastError());
711 ok(!res
|| index
== 1, "Index was not incremented although result is %x (index = %u)\n", res
, index
);
714 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
716 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res
,buffer
);
719 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_ENCODING
,buffer
,&length
,0x0);
721 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res
,buffer
);
723 SetLastError(0xdeadbeef);
724 res
= InternetReadFile(NULL
, buffer
, 100, &length
);
725 ok(!res
, "InternetReadFile should have failed\n");
726 ok(GetLastError() == ERROR_INVALID_HANDLE
,
727 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
731 trace("Entering Query loop\n");
735 if (flags
& INTERNET_FLAG_ASYNC
)
736 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
738 /* IE11 calls those in InternetQueryDataAvailable call. */
739 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
740 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
743 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
745 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
747 if (flags
& INTERNET_FLAG_ASYNC
)
751 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
753 ok(length
>= exlen
, "length %u < exlen %u\n", length
, exlen
);
757 else if (GetLastError() == ERROR_IO_PENDING
)
760 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
761 if(!(test
->flags
& TESTF_CHUNKED
))
762 ok(!length
, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length
);
763 WaitForSingleObject(hCompleteEvent
, INFINITE
);
765 ok(exlen
, "length = 0\n");
766 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
767 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
768 ok(req_error
, "req_error = 0\n");
771 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
774 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
776 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
778 trace("LENGTH %d\n", length
);
779 if(test
->flags
& TESTF_CHUNKED
)
780 ok(length
<= 8192, "length = %d, expected <= 8192\n", length
);
784 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
786 res
= InternetReadFile(hor
,buffer
,length
,&length
);
790 trace("ReadFile -> %s %i\n",res
?"TRUE":"FALSE",length
);
793 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
794 HeapFree(GetProcessHeap(),0,buffer
);
796 ok(!on_async
, "Returned zero size in response to request complete\n");
801 if(test
->flags
& TESTF_REDIRECT
) {
802 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
803 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
807 close_async_handle(hi
, hCompleteEvent
, 2);
808 CloseHandle(hCompleteEvent
);
809 first_connection_to_test_url
= FALSE
;
812 static void InternetReadFile_chunked_test(void)
817 const char *types
[2] = { "*", NULL
};
818 HINTERNET hi
, hic
= 0, hor
= 0;
820 trace("Starting InternetReadFile chunked test\n");
822 trace("InternetOpenA <--\n");
823 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
824 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
825 trace("InternetOpenA -->\n");
827 if (hi
== 0x0) goto abort
;
829 trace("InternetConnectA <--\n");
830 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
831 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
832 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
833 trace("InternetConnectA -->\n");
835 if (hic
== 0x0) goto abort
;
837 trace("HttpOpenRequestA <--\n");
838 hor
= HttpOpenRequestA(hic
, "GET", "/tests/chunked", NULL
, NULL
, types
,
839 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
841 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
843 * If the internet name can't be resolved we are probably behind
844 * a firewall or in some other way not directly connected to the
845 * Internet. Not enough reason to fail the test. Just ignore and
849 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
851 trace("HttpOpenRequestA -->\n");
853 if (hor
== 0x0) goto abort
;
855 trace("HttpSendRequestA -->\n");
856 SetLastError(0xdeadbeef);
857 res
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
858 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
859 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
860 trace("HttpSendRequestA <--\n");
862 test_request_flags(hor
, 0);
865 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
867 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
869 SetLastError( 0xdeadbeef );
871 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
873 trace("Option TRANSFER_ENCODING -> %i %s\n",res
,buffer
);
874 ok( res
|| ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
875 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
876 ok( !strcmp( buffer
, "chunked" ) || ( ! res
&& proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
877 "Wrong transfer encoding '%s'\n", buffer
);
879 SetLastError( 0xdeadbeef );
881 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
882 ok( !res
, "Found CONTENT_LENGTH option '%s'\n", buffer
);
883 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Wrong error %u\n", GetLastError() );
886 trace("Entering Query loop\n");
890 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
891 ok(!(!res
&& length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
892 ok(res
, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
893 trace("got %u available\n",length
);
896 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
898 res
= InternetReadFile(hor
,buffer
,length
,&got
);
901 trace("ReadFile -> %i %i\n",res
,got
);
902 ok( length
== got
, "only got %u of %u available\n", got
, length
);
903 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
905 HeapFree(GetProcessHeap(),0,buffer
);
911 res
= InternetReadFile( hor
, buffer
, 1, &got
);
912 ok( res
, "InternetReadFile failed: %u\n", GetLastError() );
913 ok( !got
, "got %u\n", got
);
920 res
= InternetCloseHandle(hor
);
921 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
924 res
= InternetCloseHandle(hi
);
925 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
929 static void InternetReadFileExA_test(int flags
)
933 const char *types
[2] = { "*", NULL
};
934 HINTERNET hi
, hic
= 0, hor
= 0;
935 INTERNET_BUFFERSA inetbuffers
;
937 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
939 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
941 trace("InternetOpenA <--\n");
942 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
943 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
944 trace("InternetOpenA -->\n");
946 if (hi
== 0x0) goto abort
;
948 pInternetSetStatusCallbackA(hi
,&callback
);
950 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
952 trace("InternetConnectA <--\n");
953 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
954 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
955 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
956 trace("InternetConnectA -->\n");
958 if (hic
== 0x0) goto abort
;
960 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
961 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
963 trace("HttpOpenRequestA <--\n");
964 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
965 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
967 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
969 * If the internet name can't be resolved we are probably behind
970 * a firewall or in some other way not directly connected to the
971 * Internet. Not enough reason to fail the test. Just ignore and
975 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
977 trace("HttpOpenRequestA -->\n");
979 if (hor
== 0x0) goto abort
;
981 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
982 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
983 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
984 if (first_connection_to_test_url
)
986 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
987 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
989 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
, 2);
990 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
991 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
992 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
993 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
994 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
995 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
996 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
997 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
998 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
999 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1000 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1001 if (flags
& INTERNET_FLAG_ASYNC
)
1002 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1004 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1006 trace("HttpSendRequestA -->\n");
1007 SetLastError(0xdeadbeef);
1008 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
1009 if (flags
& INTERNET_FLAG_ASYNC
)
1010 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
1011 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
1013 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
1014 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
1015 trace("HttpSendRequestA <--\n");
1017 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
1018 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1019 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1022 if (first_connection_to_test_url
)
1024 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1025 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1029 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1030 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1032 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1033 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
1034 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1035 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1036 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1037 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1038 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
1039 if (flags
& INTERNET_FLAG_ASYNC
)
1040 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1042 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1043 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
1044 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
1045 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1046 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1048 /* tests invalid dwStructSize */
1049 inetbuffers
.dwStructSize
= sizeof(inetbuffers
)+1;
1050 inetbuffers
.lpcszHeader
= NULL
;
1051 inetbuffers
.dwHeadersLength
= 0;
1052 inetbuffers
.dwBufferLength
= 10;
1053 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
1054 inetbuffers
.dwOffsetHigh
= 1234;
1055 inetbuffers
.dwOffsetLow
= 5678;
1056 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1057 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1058 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1059 rc
? "TRUE" : "FALSE", GetLastError());
1060 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1062 test_request_flags(hor
, 0);
1064 /* tests to see whether lpcszHeader is used - it isn't */
1065 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1066 inetbuffers
.lpcszHeader
= (LPCSTR
)0xdeadbeef;
1067 inetbuffers
.dwHeadersLength
= 255;
1068 inetbuffers
.dwBufferLength
= 0;
1069 inetbuffers
.lpvBuffer
= NULL
;
1070 inetbuffers
.dwOffsetHigh
= 1234;
1071 inetbuffers
.dwOffsetLow
= 5678;
1072 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
1073 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
1074 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1075 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
1076 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1079 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1080 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1083 rc
= InternetReadFileExA(NULL
, &inetbuffers
, 0, 0xdeadcafe);
1084 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
1085 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1086 rc
? "TRUE" : "FALSE", GetLastError());
1089 trace("Entering Query loop\n");
1093 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1094 inetbuffers
.dwBufferLength
= 1024;
1095 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
1096 inetbuffers
.dwOffsetHigh
= 1234;
1097 inetbuffers
.dwOffsetLow
= 5678;
1099 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1100 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1101 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1102 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
1105 if (GetLastError() == ERROR_IO_PENDING
)
1107 trace("InternetReadFileEx -> PENDING\n");
1108 ok(flags
& INTERNET_FLAG_ASYNC
,
1109 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1110 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1111 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1112 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1113 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1114 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1118 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1124 trace("InternetReadFileEx -> SUCCEEDED\n");
1125 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1126 if (inetbuffers
.dwBufferLength
)
1129 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1130 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1135 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1136 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1137 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1141 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1142 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
1144 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
1145 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1146 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
1148 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1150 if (!inetbuffers
.dwBufferLength
)
1153 length
+= inetbuffers
.dwBufferLength
;
1155 ok(length
> 0, "failed to read any of the document\n");
1156 trace("Finished. Read %d bytes\n", length
);
1159 close_async_handle(hi
, hCompleteEvent
, 2);
1160 CloseHandle(hCompleteEvent
);
1161 first_connection_to_test_url
= FALSE
;
1164 static void InternetOpenUrlA_test(void)
1166 HINTERNET myhinternet
, myhttp
;
1168 DWORD size
, readbytes
, totalbytes
=0;
1171 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1172 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
1173 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret
, GetLastError());
1175 myhinternet
= InternetOpenA("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
1176 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
1178 ret
= InternetCanonicalizeUrlA(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1179 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1182 myhttp
= InternetOpenUrlA(myhinternet
, TEST_URL
, 0, 0,
1183 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
1184 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1185 return; /* WinXP returns this when not connected to the net */
1186 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1187 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
1188 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
1189 totalbytes
+= readbytes
;
1190 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
1191 totalbytes
+= readbytes
;
1192 trace("read 0x%08x bytes\n",totalbytes
);
1194 InternetCloseHandle(myhttp
);
1195 InternetCloseHandle(myhinternet
);
1197 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1198 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1201 static void HttpSendRequestEx_test(void)
1207 INTERNET_BUFFERSA BufferIn
;
1208 DWORD dwBytesWritten
, dwBytesRead
, error
;
1213 static char szPostData
[] = "mode=Test";
1214 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
1216 hSession
= InternetOpenA("Wine Regression Test",
1217 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1218 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1219 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1220 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1222 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1223 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1224 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1225 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1227 skip( "Network unreachable, skipping test\n" );
1230 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1232 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1234 BufferIn
.dwStructSize
= sizeof(BufferIn
);
1235 BufferIn
.Next
= (INTERNET_BUFFERSA
*)0xdeadcab;
1236 BufferIn
.lpcszHeader
= szContentType
;
1237 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1238 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1239 BufferIn
.lpvBuffer
= szPostData
;
1240 BufferIn
.dwBufferLength
= 3;
1241 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1242 BufferIn
.dwOffsetLow
= 0;
1243 BufferIn
.dwOffsetHigh
= 0;
1245 SetLastError(0xdeadbeef);
1246 ret
= HttpSendRequestExA(hRequest
, &BufferIn
, NULL
, 0 ,0);
1247 error
= GetLastError();
1248 ok(ret
, "HttpSendRequestEx Failed with error %u\n", error
);
1249 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", error
);
1251 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1253 for (i
= 3; szPostData
[i
]; i
++)
1254 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1255 "InternetWriteFile failed\n");
1257 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1259 ok(HttpEndRequestA(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1261 test_request_flags(hRequest
, 0);
1263 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1264 "Unable to read response\n");
1265 szBuffer
[dwBytesRead
] = 0;
1267 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
1268 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1270 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1272 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1273 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1276 static void InternetOpenRequest_test(void)
1278 HINTERNET session
, connect
, request
;
1279 static const char *types
[] = { "*", "", NULL
};
1280 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1281 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1284 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1285 ok(session
!= NULL
,"Unable to open Internet session\n");
1287 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1288 INTERNET_SERVICE_HTTP
, 0, 0);
1289 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1290 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1292 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1293 INTERNET_SERVICE_HTTP
, 0, 0);
1294 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1295 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1297 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1298 INTERNET_SERVICE_HTTP
, 0, 0);
1299 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1301 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1302 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1304 skip( "Network unreachable, skipping test\n" );
1307 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1309 ret
= HttpSendRequestW(request
, NULL
, 0, NULL
, 0);
1310 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1311 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1313 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1314 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1316 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1317 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1318 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1321 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1322 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1325 static void test_cache_read(void)
1327 HINTERNET session
, connection
, req
;
1328 FILETIME now
, tomorrow
, yesterday
;
1329 BYTE content
[1000], buf
[2000];
1330 char file_path
[MAX_PATH
];
1337 static const char cache_only_url
[] = "http://test.winehq.org/tests/cache-only";
1338 BYTE cache_headers
[] = "HTTP/1.1 200 OK\r\n\r\n";
1340 trace("Testing cache read...\n");
1342 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1344 for(i
= 0; i
< sizeof(content
); i
++)
1345 content
[i
] = '0' + (i
%10);
1347 GetSystemTimeAsFileTime(&now
);
1348 li
.u
.HighPart
= now
.dwHighDateTime
;
1349 li
.u
.LowPart
= now
.dwLowDateTime
;
1350 li
.QuadPart
+= (LONGLONG
)10000000 * 3600 * 24;
1351 tomorrow
.dwHighDateTime
= li
.u
.HighPart
;
1352 tomorrow
.dwLowDateTime
= li
.u
.LowPart
;
1353 li
.QuadPart
-= (LONGLONG
)10000000 * 3600 * 24 * 2;
1354 yesterday
.dwHighDateTime
= li
.u
.HighPart
;
1355 yesterday
.dwLowDateTime
= li
.u
.LowPart
;
1357 res
= CreateUrlCacheEntryA(cache_only_url
, sizeof(content
), "", file_path
, 0);
1358 ok(res
, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1360 file
= CreateFileA(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1361 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
1363 WriteFile(file
, content
, sizeof(content
), &size
, NULL
);
1366 res
= CommitUrlCacheEntryA(cache_only_url
, file_path
, tomorrow
, yesterday
, NORMAL_CACHE_ENTRY
,
1367 cache_headers
, sizeof(cache_headers
)-1, "", 0);
1368 ok(res
, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1370 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
1371 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
1373 pInternetSetStatusCallbackA(session
, callback
);
1375 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1376 connection
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
,
1377 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1378 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
1379 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1381 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1382 req
= HttpOpenRequestA(connection
, "GET", "/tests/cache-only", NULL
, NULL
, NULL
, 0, 0xdeadbead);
1383 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
1384 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1386 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1387 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1388 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST
);
1389 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT
);
1390 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1391 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1392 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1394 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
1396 ok(res
, "HttpSendRequest failed: %u\n", GetLastError());
1400 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
1401 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1402 ok(size
== sizeof(content
), "size = %u\n", size
);
1405 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
1406 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
1407 ok(size
== sizeof(content
), "size = %u\n", size
);
1408 ok(!memcmp(content
, buf
, sizeof(content
)), "unexpected content\n");
1411 close_async_handle(session
, hCompleteEvent
, 2);
1413 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1414 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1415 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
1416 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
1417 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1418 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1419 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1421 res
= DeleteUrlCacheEntryA(cache_only_url
);
1422 ok(res
, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1424 CloseHandle(hCompleteEvent
);
1427 static void test_http_cache(void)
1429 HINTERNET session
, connect
, request
;
1430 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1431 DWORD size
, file_size
;
1436 static const char *types
[] = { "*", "", NULL
};
1438 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1439 ok(session
!= NULL
,"Unable to open Internet session\n");
1441 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1442 INTERNET_SERVICE_HTTP
, 0, 0);
1443 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1445 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1446 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1448 skip( "Network unreachable, skipping test\n" );
1450 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1451 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1455 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1458 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1459 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1460 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1462 size
= sizeof(file_name
);
1463 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1464 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1465 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1466 ok(!size
, "size = %d\n", size
);
1468 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1469 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1471 size
= sizeof(file_name
);
1472 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1473 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1475 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1476 FILE_ATTRIBUTE_NORMAL
, NULL
);
1477 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1478 file_size
= GetFileSize(file
, NULL
);
1479 ok(file_size
== 106, "file size = %u\n", file_size
);
1482 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1483 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1484 ok(size
== 100, "size = %u\n", size
);
1486 file_size
= GetFileSize(file
, NULL
);
1487 ok(file_size
== 106, "file size = %u\n", file_size
);
1490 ret
= DeleteFileA(file_name
);
1491 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1493 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1495 file
= CreateFileA(file_name
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
,
1496 FILE_ATTRIBUTE_NORMAL
, NULL
);
1497 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1500 /* Send the same request, requiring it to be retrieved from the cache */
1501 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1503 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1504 ok(ret
, "HttpSendRequest failed\n");
1507 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1508 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1509 ok(size
== 100, "size = %u\n", size
);
1511 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1513 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1514 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1516 size
= sizeof(file_name
);
1517 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1518 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1519 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1520 ok(!size
, "size = %d\n", size
);
1522 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1523 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1525 size
= sizeof(file_name
);
1527 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1530 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1531 FILE_ATTRIBUTE_NORMAL
, NULL
);
1532 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1538 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1541 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1542 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1543 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1548 static void InternetLockRequestFile_test(void)
1550 HINTERNET session
, connect
, request
;
1551 char file_name
[MAX_PATH
];
1556 static const char *types
[] = { "*", "", NULL
};
1558 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1559 ok(session
!= NULL
,"Unable to open Internet session\n");
1561 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1562 INTERNET_SERVICE_HTTP
, 0, 0);
1563 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1565 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
|INTERNET_FLAG_RELOAD
, 0);
1566 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1568 skip( "Network unreachable, skipping test\n" );
1570 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1571 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1575 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1577 size
= sizeof(file_name
);
1578 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1579 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1580 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1581 ok(!size
, "size = %d\n", size
);
1584 ret
= InternetLockRequestFile(request
, &lock
);
1585 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1587 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1588 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1590 size
= sizeof(file_name
);
1591 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1592 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1594 ret
= InternetLockRequestFile(request
, &lock
);
1595 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1596 ok(lock
!= NULL
, "lock == NULL\n");
1598 ret
= InternetLockRequestFile(request
, &lock2
);
1599 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1600 ok(lock
== lock2
, "lock != lock2\n");
1602 ret
= InternetUnlockRequestFile(lock2
);
1603 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1605 ret
= DeleteFileA(file_name
);
1606 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1608 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1610 ret
= DeleteFileA(file_name
);
1611 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1613 ret
= InternetUnlockRequestFile(lock
);
1614 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1616 ret
= DeleteFileA(file_name
);
1617 ok(ret
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1620 static void HttpHeaders_test(void)
1632 hSession
= InternetOpenA("Wine Regression Test",
1633 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1634 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1635 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1636 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1638 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1639 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1640 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1641 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1643 skip( "Network unreachable, skipping test\n" );
1646 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1649 len
= sizeof(buffer
);
1650 strcpy(buffer
,"Warning");
1651 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1652 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1654 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1655 "Failed to add new header\n");
1658 len
= sizeof(buffer
);
1659 strcpy(buffer
,"Warning");
1660 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1661 buffer
,&len
,&index
),"Unable to query header\n");
1662 ok(index
== 1, "Index was not incremented\n");
1663 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1664 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1665 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1666 len
= sizeof(buffer
);
1667 strcpy(buffer
,"Warning");
1668 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1669 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1672 len
= 5; /* could store the string but not the NULL terminator */
1673 strcpy(buffer
,"Warning");
1674 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1675 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1676 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1677 ok(index
== 0, "Index was incremented\n");
1678 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1679 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1681 /* a call with NULL will fail but will return the length */
1683 len
= sizeof(buffer
);
1684 SetLastError(0xdeadbeef);
1685 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1686 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1687 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1688 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1689 ok(index
== 0, "Index was incremented\n");
1691 /* even for a len that is too small */
1694 SetLastError(0xdeadbeef);
1695 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1696 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1697 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1698 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1699 ok(index
== 0, "Index was incremented\n");
1703 SetLastError(0xdeadbeef);
1704 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1705 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1706 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1707 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1708 ok(index
== 0, "Index was incremented\n");
1709 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1712 /* a working query */
1714 len
= sizeof(buffer
);
1715 memset(buffer
, 'x', sizeof(buffer
));
1716 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1717 buffer
,&len
,&index
),"Unable to query header\n");
1718 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1719 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1720 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1721 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1722 ok(strncmp(buffer
, "POST /tests/post.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1723 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1724 ok(index
== 0, "Index was incremented\n");
1726 /* Like above two tests, but for W version */
1730 SetLastError(0xdeadbeef);
1731 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1732 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1733 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1734 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1735 ok(index
== 0, "Index was incremented\n");
1736 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1738 /* a working query */
1740 len
= sizeof(wbuffer
);
1741 memset(wbuffer
, 'x', sizeof(wbuffer
));
1742 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1743 wbuffer
,&len
,&index
),"Unable to query header\n");
1744 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1745 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1746 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1747 ok(index
== 0, "Index was incremented\n");
1749 /* end of W version tests */
1751 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1753 len
= sizeof(buffer
);
1754 memset(buffer
, 'x', sizeof(buffer
));
1755 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1756 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1757 ok(len
== 2, "Expected 2, got %d\n", len
);
1758 ok(strcmp(buffer
, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer
);
1759 ok(index
== 0, "Index was incremented\n");
1761 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1762 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1765 len
= sizeof(buffer
);
1766 strcpy(buffer
,"Warning");
1767 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1768 buffer
,&len
,&index
),"Unable to query header\n");
1769 ok(index
== 1, "Index was not incremented\n");
1770 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1771 len
= sizeof(buffer
);
1772 strcpy(buffer
,"Warning");
1773 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1774 buffer
,&len
,&index
),"Failed to get second header\n");
1775 ok(index
== 2, "Index was not incremented\n");
1776 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1777 len
= sizeof(buffer
);
1778 strcpy(buffer
,"Warning");
1779 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1780 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1782 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1785 len
= sizeof(buffer
);
1786 strcpy(buffer
,"Warning");
1787 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1788 buffer
,&len
,&index
),"Unable to query header\n");
1789 ok(index
== 1, "Index was not incremented\n");
1790 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1791 len
= sizeof(buffer
);
1792 strcpy(buffer
,"Warning");
1793 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1794 buffer
,&len
,&index
),"Failed to get second header\n");
1795 ok(index
== 2, "Index was not incremented\n");
1796 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1797 len
= sizeof(buffer
);
1798 strcpy(buffer
,"Warning");
1799 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1800 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1802 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1805 len
= sizeof(buffer
);
1806 strcpy(buffer
,"Warning");
1807 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1808 buffer
,&len
,&index
),"Unable to query header\n");
1809 ok(index
== 1, "Index was not incremented\n");
1810 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1811 len
= sizeof(buffer
);
1812 strcpy(buffer
,"Warning");
1813 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1814 buffer
,&len
,&index
),"Failed to get second header\n");
1815 ok(index
== 2, "Index was not incremented\n");
1816 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1817 len
= sizeof(buffer
);
1818 strcpy(buffer
,"Warning");
1819 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1820 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1822 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1825 len
= sizeof(buffer
);
1826 strcpy(buffer
,"Warning");
1827 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1828 buffer
,&len
,&index
),"Unable to query header\n");
1829 ok(index
== 1, "Index was not incremented\n");
1830 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1831 len
= sizeof(buffer
);
1832 strcpy(buffer
,"Warning");
1833 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1834 ok(index
== 2, "Index was not incremented\n");
1835 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1836 len
= sizeof(buffer
);
1837 strcpy(buffer
,"Warning");
1838 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1840 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1843 len
= sizeof(buffer
);
1844 strcpy(buffer
,"Warning");
1845 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1846 ok(index
== 1, "Index was not incremented\n");
1847 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1848 len
= sizeof(buffer
);
1849 strcpy(buffer
,"Warning");
1850 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1851 ok(index
== 2, "Index was not incremented\n");
1852 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1853 len
= sizeof(buffer
);
1854 strcpy(buffer
,"Warning");
1855 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1857 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1860 len
= sizeof(buffer
);
1861 strcpy(buffer
,"Warning");
1862 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1863 ok(index
== 1, "Index was not incremented\n");
1864 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1865 len
= sizeof(buffer
);
1866 strcpy(buffer
,"Warning");
1867 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1868 ok(index
== 2, "Index was not incremented\n");
1869 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1870 len
= sizeof(buffer
);
1871 strcpy(buffer
,"Warning");
1872 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1874 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test7",-1, HTTP_ADDREQ_FLAG_ADD
|HTTP_ADDREQ_FLAG_REPLACE
), "HTTP_ADDREQ_FLAG_ADD with HTTP_ADDREQ_FLAG_REPALCE Did not work\n");
1877 len
= sizeof(buffer
);
1878 strcpy(buffer
,"Warning");
1879 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1880 ok(index
== 1, "Index was not incremented\n");
1881 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1882 len
= sizeof(buffer
);
1883 strcpy(buffer
,"Warning");
1884 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1885 ok(index
== 2, "Index was not incremented\n");
1886 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1887 len
= sizeof(buffer
);
1888 strcpy(buffer
,"Warning");
1889 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1891 /* Ensure that blank headers are ignored and don't cause a failure */
1892 ok(HttpAddRequestHeadersA(hRequest
,"\r\nBlankTest:value\r\n\r\n",-1, HTTP_ADDREQ_FLAG_ADD_IF_NEW
), "Failed to add header with blank entries in list\n");
1895 len
= sizeof(buffer
);
1896 strcpy(buffer
,"BlankTest");
1897 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1898 ok(index
== 1, "Index was not incremented\n");
1899 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1901 /* Ensure that malformed header separators are ignored and don't cause a failure */
1902 ok(HttpAddRequestHeadersA(hRequest
,"\r\rMalformedTest:value\n\nMalformedTestTwo: value2\rMalformedTestThree: value3\n\n\r\r\n",-1, HTTP_ADDREQ_FLAG_ADD
|HTTP_ADDREQ_FLAG_REPLACE
),
1903 "Failed to add header with malformed entries in list\n");
1906 len
= sizeof(buffer
);
1907 strcpy(buffer
,"MalformedTest");
1908 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1909 ok(index
== 1, "Index was not incremented\n");
1910 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1912 len
= sizeof(buffer
);
1913 strcpy(buffer
,"MalformedTestTwo");
1914 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1915 ok(index
== 1, "Index was not incremented\n");
1916 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
1918 len
= sizeof(buffer
);
1919 strcpy(buffer
,"MalformedTestThree");
1920 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1921 ok(index
== 1, "Index was not incremented\n");
1922 ok(strcmp(buffer
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
1924 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD
);
1925 ok(ret
, "unable to add header %u\n", GetLastError());
1929 len
= sizeof(buffer
);
1930 ret
= HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
);
1931 ok(ret
, "unable to query header %u\n", GetLastError());
1932 ok(index
== 1, "index was not incremented\n");
1933 ok(!strcmp(buffer
, "Basic"), "incorrect string was returned (%s)\n", buffer
);
1935 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE
);
1936 ok(ret
, "unable to remove header %u\n", GetLastError());
1939 len
= sizeof(buffer
);
1940 SetLastError(0xdeadbeef);
1941 ok(!HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
),
1942 "header still present\n");
1943 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "got %u\n", GetLastError());
1945 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1947 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1948 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1951 static const char garbagemsg
[] =
1952 "Garbage: Header\r\n";
1954 static const char contmsg
[] =
1955 "HTTP/1.1 100 Continue\r\n";
1957 static const char expandcontmsg
[] =
1958 "HTTP/1.1 100 Continue\r\n"
1959 "Server: winecontinue\r\n"
1960 "Tag: something witty\r\n"
1963 static const char okmsg
[] =
1964 "HTTP/1.1 200 OK\r\n"
1965 "Server: winetest\r\n"
1968 static const char okmsg2
[] =
1969 "HTTP/1.1 200 OK\r\n"
1970 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1971 "Server: winetest\r\n"
1972 "Content-Length: 0\r\n"
1973 "Set-Cookie: one\r\n"
1974 "Set-Cookie: two\r\n"
1977 static const char notokmsg
[] =
1978 "HTTP/1.1 400 Bad Request\r\n"
1979 "Server: winetest\r\n"
1982 static const char noauthmsg
[] =
1983 "HTTP/1.1 401 Unauthorized\r\n"
1984 "Server: winetest\r\n"
1985 "Connection: close\r\n"
1986 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1989 static const char noauthmsg2
[] =
1990 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
1991 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
1993 "Server: winetest\r\n";
1995 static const char proxymsg
[] =
1996 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1997 "Server: winetest\r\n"
1998 "Proxy-Connection: close\r\n"
1999 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
2002 static const char page1
[] =
2004 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
2005 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
2008 static const char ok_with_length
[] =
2009 "HTTP/1.1 200 OK\r\n"
2010 "Connection: Keep-Alive\r\n"
2011 "Content-Length: 18\r\n\r\n"
2012 "HTTP/1.1 211 OK\r\n\r\n";
2014 static const char ok_with_length2
[] =
2015 "HTTP/1.1 210 OK\r\n"
2016 "Connection: Keep-Alive\r\n"
2017 "Content-Length: 19\r\n\r\n"
2018 "HTTP/1.1 211 OK\r\n\r\n";
2020 struct server_info
{
2025 static int test_cache_gzip
;
2026 static const char *send_buffer
;
2028 static DWORD CALLBACK
server_thread(LPVOID param
)
2030 struct server_info
*si
= param
;
2031 int r
, c
= -1, i
, on
, count
= 0;
2033 struct sockaddr_in sa
;
2036 int last_request
= 0;
2037 char host_header
[22];
2038 static BOOL test_b
= FALSE
;
2039 static int test_no_cache
= 0;
2041 WSAStartup(MAKEWORD(1,1), &wsaData
);
2043 s
= socket(AF_INET
, SOCK_STREAM
, 0);
2044 if (s
== INVALID_SOCKET
)
2048 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
2050 memset(&sa
, 0, sizeof sa
);
2051 sa
.sin_family
= AF_INET
;
2052 sa
.sin_port
= htons(si
->port
);
2053 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
2055 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
2061 SetEvent(si
->hEvent
);
2063 sprintf(host_header
, "Host: localhost:%d", si
->port
);
2068 c
= accept(s
, NULL
, NULL
);
2070 memset(buffer
, 0, sizeof buffer
);
2071 for(i
=0; i
<(sizeof buffer
-1); i
++)
2073 r
= recv(c
, &buffer
[i
], 1, 0);
2077 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
2078 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
2081 if (strstr(buffer
, "GET /test1"))
2083 if (!strstr(buffer
, "Content-Length: 0"))
2085 send(c
, okmsg
, sizeof okmsg
-1, 0);
2086 send(c
, page1
, sizeof page1
-1, 0);
2089 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2091 if (strstr(buffer
, "/test2"))
2093 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2095 send(c
, okmsg
, sizeof okmsg
-1, 0);
2096 send(c
, page1
, sizeof page1
-1, 0);
2099 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2101 if (strstr(buffer
, "/test3"))
2103 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2104 send(c
, okmsg
, sizeof okmsg
-1, 0);
2106 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2108 if (strstr(buffer
, "/test4"))
2110 if (strstr(buffer
, "Connection: Close"))
2111 send(c
, okmsg
, sizeof okmsg
-1, 0);
2113 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2115 if (strstr(buffer
, "POST /test5") ||
2116 strstr(buffer
, "RPC_IN_DATA /test5") ||
2117 strstr(buffer
, "RPC_OUT_DATA /test5"))
2119 if (strstr(buffer
, "Content-Length: 0"))
2121 send(c
, okmsg
, sizeof okmsg
-1, 0);
2122 send(c
, page1
, sizeof page1
-1, 0);
2125 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2127 if (strstr(buffer
, "GET /test6"))
2129 send(c
, contmsg
, sizeof contmsg
-1, 0);
2130 send(c
, contmsg
, sizeof contmsg
-1, 0);
2131 send(c
, okmsg
, sizeof okmsg
-1, 0);
2132 send(c
, page1
, sizeof page1
-1, 0);
2134 if (strstr(buffer
, "POST /test7"))
2136 if (strstr(buffer
, "Content-Length: 100"))
2138 send(c
, okmsg
, sizeof okmsg
-1, 0);
2139 send(c
, page1
, sizeof page1
-1, 0);
2142 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2144 if (strstr(buffer
, "/test8"))
2146 if (!strstr(buffer
, "Connection: Close") &&
2147 strstr(buffer
, "Connection: Keep-Alive") &&
2148 !strstr(buffer
, "Cache-Control: no-cache") &&
2149 !strstr(buffer
, "Pragma: no-cache") &&
2150 strstr(buffer
, host_header
))
2151 send(c
, okmsg
, sizeof okmsg
-1, 0);
2153 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2155 if (strstr(buffer
, "/test9"))
2157 if (!strstr(buffer
, "Connection: Close") &&
2158 !strstr(buffer
, "Connection: Keep-Alive") &&
2159 !strstr(buffer
, "Cache-Control: no-cache") &&
2160 !strstr(buffer
, "Pragma: no-cache") &&
2161 strstr(buffer
, host_header
))
2162 send(c
, okmsg
, sizeof okmsg
-1, 0);
2164 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2166 if (strstr(buffer
, "/testA"))
2168 if (!strstr(buffer
, "Connection: Close") &&
2169 !strstr(buffer
, "Connection: Keep-Alive") &&
2170 (strstr(buffer
, "Cache-Control: no-cache") ||
2171 strstr(buffer
, "Pragma: no-cache")) &&
2172 strstr(buffer
, host_header
))
2173 send(c
, okmsg
, sizeof okmsg
-1, 0);
2175 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2177 if (!test_b
&& strstr(buffer
, "/testB HTTP/1.1"))
2180 send(c
, okmsg
, sizeof okmsg
-1, 0);
2181 recvfrom(c
, buffer
, sizeof buffer
, 0, NULL
, NULL
);
2182 send(c
, okmsg
, sizeof okmsg
-1, 0);
2184 if (strstr(buffer
, "/testC"))
2186 if (strstr(buffer
, "Cookie: cookie=biscuit"))
2187 send(c
, okmsg
, sizeof okmsg
-1, 0);
2189 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2191 if (strstr(buffer
, "/testD"))
2193 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
2195 if (strstr(buffer
, "/testE"))
2197 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
2199 if (strstr(buffer
, "GET /quit"))
2201 send(c
, okmsg
, sizeof okmsg
-1, 0);
2202 send(c
, page1
, sizeof page1
-1, 0);
2205 if (strstr(buffer
, "GET /testF"))
2207 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
2208 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2209 send(c
, contmsg
, sizeof contmsg
-1, 0);
2210 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2211 send(c
, okmsg
, sizeof okmsg
-1, 0);
2212 send(c
, page1
, sizeof page1
-1, 0);
2214 if (strstr(buffer
, "GET /testG"))
2216 send(c
, page1
, sizeof page1
-1, 0);
2219 if (strstr(buffer
, "GET /testJ"))
2224 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2228 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2232 if (strstr(buffer
, "GET /testH"))
2234 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2235 recvfrom(c
, buffer
, sizeof(buffer
), 0, NULL
, NULL
);
2236 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2239 if (strstr(buffer
, "GET /test_no_content"))
2241 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2242 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2244 if (strstr(buffer
, "GET /test_conn_close"))
2246 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2247 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
2248 WaitForSingleObject(conn_close_event
, INFINITE
);
2249 trace("closing connection\n");
2251 if (strstr(buffer
, "GET /test_cache_control_no_cache"))
2253 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2254 if(!test_no_cache
++)
2255 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2257 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2259 if (strstr(buffer
, "GET /test_cache_control_no_store"))
2261 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2262 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2264 if (strstr(buffer
, "GET /test_cache_gzip"))
2266 static const char gzip_response
[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2267 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2268 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2269 if(!test_cache_gzip
++)
2270 send(c
, gzip_response
, sizeof(gzip_response
), 0);
2272 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2274 if (strstr(buffer
, "HEAD /test_head")) {
2275 static const char head_response
[] =
2276 "HTTP/1.1 200 OK\r\n"
2277 "Connection: Keep-Alive\r\n"
2278 "Content-Length: 100\r\n"
2281 send(c
, head_response
, sizeof(head_response
), 0);
2284 if (strstr(buffer
, "GET /send_from_buffer"))
2285 send(c
, send_buffer
, strlen(send_buffer
), 0);
2286 if (strstr(buffer
, "/test_cache_control_verb"))
2288 if (!memcmp(buffer
, "GET ", sizeof("GET ")-1) &&
2289 !strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2290 else if (strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2291 else send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2293 if (strstr(buffer
, "/test_request_content_length"))
2295 static char msg
[] = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\n\r\n";
2296 static int seen_content_length
;
2298 if (!seen_content_length
)
2300 if (strstr(buffer
, "Content-Length: 0"))
2302 seen_content_length
= 1;
2303 send(c
, msg
, sizeof msg
-1, 0);
2305 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2306 WaitForSingleObject(hCompleteEvent
, 5000);
2310 if (strstr(buffer
, "Content-Length: 0")) send(c
, msg
, sizeof msg
-1, 0);
2311 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2312 WaitForSingleObject(hCompleteEvent
, 5000);
2315 if (strstr(buffer
, "GET /test_premature_disconnect"))
2316 trace("closing connection\n");
2317 if (strstr(buffer
, "/test_accept_encoding_http10"))
2319 if (strstr(buffer
, "Accept-Encoding: gzip"))
2320 send(c
, okmsg
, sizeof okmsg
-1, 0);
2322 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2327 } while (!last_request
);
2334 static void test_basic_request(int port
, const char *verb
, const char *url
)
2336 HINTERNET hi
, hc
, hr
;
2337 DWORD r
, count
, error
;
2340 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2341 ok(hi
!= NULL
, "open failed\n");
2343 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2344 ok(hc
!= NULL
, "connect failed\n");
2346 hr
= HttpOpenRequestA(hc
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
2347 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2349 SetLastError(0xdeadbeef);
2350 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2351 error
= GetLastError();
2352 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
2353 ok(r
, "HttpSendRequest failed\n");
2356 memset(buffer
, 0, sizeof buffer
);
2357 SetLastError(0xdeadbeef);
2358 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
2359 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2360 ok(count
== sizeof page1
- 1, "count was wrong\n");
2361 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2363 InternetCloseHandle(hr
);
2364 InternetCloseHandle(hc
);
2365 InternetCloseHandle(hi
);
2368 static void test_proxy_indirect(int port
)
2370 HINTERNET hi
, hc
, hr
;
2374 hi
= InternetOpenA(NULL
, 0, NULL
, NULL
, 0);
2375 ok(hi
!= NULL
, "open failed\n");
2377 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2378 ok(hc
!= NULL
, "connect failed\n");
2380 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2381 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2383 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2384 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2387 r
= HttpQueryInfoA(hr
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2388 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
2391 skip("missing proxy header, not testing remaining proxy headers\n");
2394 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2396 test_status_code(hr
, 407);
2397 test_request_flags(hr
, 0);
2400 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2401 ok(r
, "HttpQueryInfo failed\n");
2402 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2405 r
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2406 ok(r
, "HttpQueryInfo failed\n");
2407 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2410 r
= HttpQueryInfoA(hr
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2411 ok(r
, "HttpQueryInfo failed\n");
2412 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2415 r
= HttpQueryInfoA(hr
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2416 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2417 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2420 InternetCloseHandle(hr
);
2421 InternetCloseHandle(hc
);
2422 InternetCloseHandle(hi
);
2425 static void test_proxy_direct(int port
)
2427 HINTERNET hi
, hc
, hr
;
2429 char buffer
[0x40], *url
;
2430 WCHAR bufferW
[0x40];
2431 static const char url_fmt
[] = "http://test.winehq.org:%u/test2";
2432 static CHAR username
[] = "mike",
2433 password
[] = "1101",
2434 useragent
[] = "winetest";
2435 static const WCHAR usernameW
[] = {'m','i','k','e',0},
2436 passwordW
[] = {'1','1','0','1',0},
2437 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2439 /* specify proxy type without the proxy and bypass */
2440 SetLastError(0xdeadbeef);
2441 hi
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2442 error
= GetLastError();
2443 ok(error
== ERROR_INVALID_PARAMETER
||
2444 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %u\n", error
);
2445 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2447 sprintf(buffer
, "localhost:%d\n", port
);
2448 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2449 ok(hi
!= NULL
, "open failed\n");
2451 /* try connect without authorization */
2452 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2453 ok(hc
!= NULL
, "connect failed\n");
2455 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2456 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2459 SetLastError(0xdeadbeef);
2460 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
2461 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2462 ok(!r
, "unexpected success\n");
2463 ok(sz
== 1, "got %u\n", sz
);
2466 SetLastError(0xdeadbeef);
2467 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
2468 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2469 ok(!r
, "unexpected success\n");
2470 ok(sz
== 1, "got %u\n", sz
);
2472 sz
= sizeof(buffer
);
2473 SetLastError(0xdeadbeef);
2474 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2475 ok(r
, "unexpected failure %u\n", GetLastError());
2476 ok(!sz
, "got %u\n", sz
);
2478 sz
= sizeof(buffer
);
2479 SetLastError(0xdeadbeef);
2480 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2481 ok(r
, "unexpected failure %u\n", GetLastError());
2482 ok(!sz
, "got %u\n", sz
);
2485 SetLastError(0xdeadbeef);
2486 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
2487 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2488 ok(!r
, "unexpected success\n");
2489 ok(sz
== 1, "got %u\n", sz
);
2492 SetLastError(0xdeadbeef);
2493 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
2494 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2495 ok(!r
, "unexpected success\n");
2496 ok(sz
== 1, "got %u\n", sz
);
2498 sz
= sizeof(buffer
);
2499 SetLastError(0xdeadbeef);
2500 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2501 ok(r
, "unexpected failure %u\n", GetLastError());
2502 ok(!sz
, "got %u\n", sz
);
2504 sz
= sizeof(buffer
);
2505 SetLastError(0xdeadbeef);
2506 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2507 ok(r
, "unexpected failure %u\n", GetLastError());
2508 ok(!sz
, "got %u\n", sz
);
2511 SetLastError(0xdeadbeef);
2512 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
2513 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2514 ok(!r
, "unexpected success\n");
2515 ok(sz
== 34, "got %u\n", sz
);
2517 sz
= sizeof(buffer
);
2518 SetLastError(0xdeadbeef);
2519 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2520 ok(r
, "unexpected failure %u\n", GetLastError());
2521 ok(sz
== 33, "got %u\n", sz
);
2523 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2524 ok(r
|| broken(!r
), "HttpSendRequest failed %u\n", GetLastError());
2527 win_skip("skipping proxy tests on broken wininet\n");
2531 test_status_code(hr
, 407);
2533 /* set the user + password then try again */
2534 r
= InternetSetOptionA(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2535 ok(!r
, "unexpected success\n");
2537 r
= InternetSetOptionA(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2538 ok(r
, "failed to set user\n");
2540 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2541 ok(r
, "failed to set user\n");
2545 SetLastError(0xdeadbeef);
2546 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2547 ok(!r
, "unexpected failure %u\n", GetLastError());
2548 ok(!buffer
[0], "got %s\n", buffer
);
2549 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2553 SetLastError(0xdeadbeef);
2554 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2555 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2556 ok(!r
, "unexpected success\n");
2557 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2561 SetLastError(0xdeadbeef);
2562 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2563 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2564 ok(!r
, "unexpected success\n");
2565 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2568 sz
= sizeof(buffer
);
2569 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2570 ok(r
, "failed to get username\n");
2571 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2572 ok(sz
== strlen(username
), "got %u\n", sz
);
2575 sz
= sizeof(bufferW
);
2576 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2577 ok(r
, "failed to get username\n");
2578 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
2579 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2581 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
2582 ok(r
, "failed to set user\n");
2585 sz
= sizeof(buffer
);
2586 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2587 ok(r
, "failed to get username\n");
2588 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2589 ok(sz
== strlen(username
), "got %u\n", sz
);
2591 r
= InternetSetOptionA(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
2592 ok(r
, "failed to set useragent\n");
2596 SetLastError(0xdeadbeef);
2597 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2598 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2599 ok(!r
, "unexpected success\n");
2600 ok(sz
== strlen(useragent
) + 1, "got %u\n", sz
);
2603 sz
= sizeof(buffer
);
2604 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2605 ok(r
, "failed to get user agent\n");
2606 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
2607 ok(sz
== strlen(useragent
), "got %u\n", sz
);
2611 SetLastError(0xdeadbeef);
2612 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2613 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2614 ok(!r
, "unexpected success\n");
2615 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2618 sz
= sizeof(bufferW
);
2619 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2620 ok(r
, "failed to get user agent\n");
2621 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
2622 ok(sz
== lstrlenW(useragentW
), "got %u\n", sz
);
2624 r
= InternetSetOptionA(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
2625 ok(r
, "failed to set user\n");
2629 SetLastError(0xdeadbeef);
2630 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2631 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2632 ok(!r
, "unexpected success\n");
2633 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2636 sz
= sizeof(buffer
);
2637 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2638 ok(r
, "failed to get user\n");
2639 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2640 ok(sz
== strlen(username
), "got %u\n", sz
);
2644 SetLastError(0xdeadbeef);
2645 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2646 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2647 ok(!r
, "unexpected success\n");
2648 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2651 sz
= sizeof(bufferW
);
2652 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2653 ok(r
, "failed to get user\n");
2654 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
2655 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2657 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
2658 ok(r
, "failed to set password\n");
2662 SetLastError(0xdeadbeef);
2663 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2664 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2665 ok(!r
, "unexpected success\n");
2666 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2669 sz
= sizeof(buffer
);
2670 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2671 ok(r
, "failed to get password\n");
2672 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2673 ok(sz
== strlen(password
), "got %u\n", sz
);
2677 SetLastError(0xdeadbeef);
2678 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2679 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2680 ok(!r
, "unexpected success\n");
2681 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2684 sz
= sizeof(bufferW
);
2685 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2686 ok(r
, "failed to get password\n");
2687 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2688 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2690 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
2691 sprintf(url
, url_fmt
, port
);
2694 SetLastError(0xdeadbeef);
2695 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2696 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2697 ok(!r
, "unexpected success\n");
2698 ok(sz
== strlen(url
) + 1, "got %u\n", sz
);
2701 sz
= sizeof(buffer
);
2702 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2703 ok(r
, "failed to get url\n");
2704 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
2705 ok(sz
== strlen(url
), "got %u\n", sz
);
2709 SetLastError(0xdeadbeef);
2710 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2711 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2712 ok(!r
, "unexpected success\n");
2713 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2716 sz
= sizeof(bufferW
);
2717 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2718 ok(r
, "failed to get url\n");
2719 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
2720 ok(sz
== strlen(url
), "got %u\n", sz
);
2721 HeapFree(GetProcessHeap(), 0, url
);
2723 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2724 ok(r
, "failed to set password\n");
2728 SetLastError(0xdeadbeef);
2729 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2730 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2731 ok(!r
, "unexpected success\n");
2732 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2735 sz
= sizeof(buffer
);
2736 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2737 ok(r
, "failed to get password\n");
2738 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2739 ok(sz
== strlen(password
), "got %u\n", sz
);
2743 SetLastError(0xdeadbeef);
2744 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2745 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2746 ok(!r
, "unexpected success\n");
2747 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2750 sz
= sizeof(bufferW
);
2751 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2752 ok(r
, "failed to get password\n");
2753 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2754 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2756 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2759 win_skip("skipping proxy tests on broken wininet\n");
2762 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2764 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2765 ok(r
, "HttpQueryInfo failed\n");
2766 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2769 InternetCloseHandle(hr
);
2770 InternetCloseHandle(hc
);
2771 InternetCloseHandle(hi
);
2774 static void test_header_handling_order(int port
)
2776 static const char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
2777 static const char connection
[] = "Connection: Close";
2778 static const char *types
[2] = { "*", NULL
};
2780 HINTERNET session
, connect
, request
;
2781 DWORD size
, status
, data_len
;
2784 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2785 ok(session
!= NULL
, "InternetOpen failed\n");
2787 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2788 ok(connect
!= NULL
, "InternetConnect failed\n");
2790 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2791 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2793 ret
= HttpAddRequestHeadersA(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
2794 ok(ret
, "HttpAddRequestHeaders failed\n");
2796 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
2797 ok(ret
, "HttpSendRequest failed\n");
2799 test_status_code(request
, 200);
2800 test_request_flags(request
, 0);
2802 InternetCloseHandle(request
);
2804 request
= HttpOpenRequestA(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2805 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2807 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2808 ok(ret
, "HttpSendRequest failed\n");
2811 size
= sizeof(status
);
2812 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2813 ok(ret
, "HttpQueryInfo failed\n");
2814 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2816 InternetCloseHandle(request
);
2817 InternetCloseHandle(connect
);
2819 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2820 ok(connect
!= NULL
, "InternetConnect failed\n");
2822 request
= HttpOpenRequestA(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2823 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2825 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2826 ok(ret
, "HttpAddRequestHeaders failed\n");
2828 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2829 ok(ret
, "HttpSendRequest failed\n");
2832 size
= sizeof(status
);
2833 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2834 ok(ret
, "HttpQueryInfo failed\n");
2835 ok(status
== 200, "got status %u, expected 200\n", status
);
2837 InternetCloseHandle(request
);
2838 InternetCloseHandle(connect
);
2840 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2841 ok(connect
!= NULL
, "InternetConnect failed\n");
2843 request
= HttpOpenRequestA(connect
, "POST", "/test7b", NULL
, NULL
, types
, 0, 0);
2844 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2846 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2847 ok(ret
, "HttpAddRequestHeaders failed\n");
2849 data_len
= sizeof(data
);
2850 memset(data
, 'a', sizeof(data
));
2851 ret
= HttpSendRequestA(request
, connection
, ~0u, data
, data_len
);
2852 ok(ret
, "HttpSendRequest failed\n");
2855 size
= sizeof(status
);
2856 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2857 ok(ret
, "HttpQueryInfo failed\n");
2858 ok(status
== 200, "got status %u, expected 200\n", status
);
2860 InternetCloseHandle(request
);
2861 InternetCloseHandle(connect
);
2862 InternetCloseHandle(session
);
2865 static void test_connection_header(int port
)
2867 HINTERNET ses
, con
, req
;
2870 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2871 ok(ses
!= NULL
, "InternetOpen failed\n");
2873 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2874 ok(con
!= NULL
, "InternetConnect failed\n");
2876 req
= HttpOpenRequestA(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2877 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2879 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2880 ok(ret
, "HttpSendRequest failed\n");
2882 test_status_code(req
, 200);
2884 InternetCloseHandle(req
);
2886 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
2887 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2889 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2890 ok(ret
, "HttpSendRequest failed\n");
2892 test_status_code(req
, 200);
2894 InternetCloseHandle(req
);
2896 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2897 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2899 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2900 ok(ret
, "HttpSendRequest failed\n");
2902 test_status_code(req
, 200);
2904 InternetCloseHandle(req
);
2906 req
= HttpOpenRequestA(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2907 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2909 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2910 ok(ret
, "HttpSendRequest failed\n");
2912 test_status_code(req
, 200);
2914 InternetCloseHandle(req
);
2915 InternetCloseHandle(con
);
2916 InternetCloseHandle(ses
);
2919 static void test_http1_1(int port
)
2921 HINTERNET ses
, con
, req
;
2924 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2925 ok(ses
!= NULL
, "InternetOpen failed\n");
2927 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2928 ok(con
!= NULL
, "InternetConnect failed\n");
2930 req
= HttpOpenRequestA(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2931 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2933 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2936 InternetCloseHandle(req
);
2938 req
= HttpOpenRequestA(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2939 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2941 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2942 ok(ret
, "HttpSendRequest failed\n");
2945 InternetCloseHandle(req
);
2946 InternetCloseHandle(con
);
2947 InternetCloseHandle(ses
);
2950 static void test_connection_closing(int port
)
2952 HINTERNET session
, connection
, req
;
2955 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
2957 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2958 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2960 pInternetSetStatusCallbackA(session
, callback
);
2962 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2963 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2964 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2965 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2967 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2968 req
= HttpOpenRequestA(connection
, "GET", "/testJ", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
2969 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2970 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2972 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2973 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
2974 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2975 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2976 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2977 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2978 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2979 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2980 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
2981 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
2982 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2984 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2985 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2986 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2987 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2988 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2990 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2991 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
2992 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2993 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2994 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2995 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2996 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2997 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2998 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2999 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3000 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3002 test_status_code(req
, 200);
3004 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3005 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3006 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3007 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3008 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3009 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3010 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3011 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3012 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3014 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3015 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3016 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3017 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3018 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3020 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3021 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3022 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3023 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3024 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3025 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3026 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3027 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3028 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3030 test_status_code(req
, 210);
3032 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3033 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3034 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3035 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3036 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3037 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3038 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3039 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3040 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3041 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3042 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3044 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3045 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3046 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3047 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3048 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3050 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3051 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3052 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3053 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3054 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3055 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3056 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3057 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3058 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3059 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3060 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3062 test_status_code(req
, 200);
3064 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3065 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3067 close_async_handle(session
, hCompleteEvent
, 2);
3068 CloseHandle(hCompleteEvent
);
3071 static void test_successive_HttpSendRequest(int port
)
3073 HINTERNET session
, connection
, req
;
3076 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3078 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3079 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3081 pInternetSetStatusCallbackA(session
, callback
);
3083 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3084 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3085 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3086 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3088 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3089 req
= HttpOpenRequestA(connection
, "GET", "/testH", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3090 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3091 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3093 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3094 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3095 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3096 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3097 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3098 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3099 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3100 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3101 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3103 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3104 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3105 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3106 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3107 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3109 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3110 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3111 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3112 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3113 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3114 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3115 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3116 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3117 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3119 test_status_code(req
, 210);
3121 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3122 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3123 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3124 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3125 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3126 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3127 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3128 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3129 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3131 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3132 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3133 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3134 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3135 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3137 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3138 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3139 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3140 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3141 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3142 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3143 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3144 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3145 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3147 test_status_code(req
, 200);
3149 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3150 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3152 close_async_handle(session
, hCompleteEvent
, 2);
3153 CloseHandle(hCompleteEvent
);
3156 static void test_no_content(int port
)
3158 HINTERNET session
, connection
, req
;
3161 trace("Testing 204 no content response...\n");
3163 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3165 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3166 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3168 pInternetSetStatusCallbackA(session
, callback
);
3170 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3171 connection
= InternetConnectA(session
, "localhost", port
,
3172 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3173 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3174 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3176 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3177 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
3178 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3179 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3180 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3182 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3183 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3184 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3185 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3186 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3187 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3188 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3189 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3190 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3191 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3193 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3194 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3195 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3196 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3197 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3199 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3200 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3201 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3202 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3203 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3204 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3205 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3206 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3208 close_async_handle(session
, hCompleteEvent
, 2);
3209 CloseHandle(hCompleteEvent
);
3212 * The connection should be closed before closing handle. This is true for most
3213 * wininet versions (including Wine), but some old win2k versions fail to do that.
3215 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3216 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3219 static void test_conn_close(int port
)
3221 HINTERNET session
, connection
, req
;
3222 DWORD res
, avail
, size
;
3225 trace("Testing connection close connection...\n");
3227 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3228 conn_close_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3230 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3231 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3233 pInternetSetStatusCallbackA(session
, callback
);
3235 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3236 connection
= InternetConnectA(session
, "localhost", port
,
3237 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3238 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3239 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3241 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3242 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
3243 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3244 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3245 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3247 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3248 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3249 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3250 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3251 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3252 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3253 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3254 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3256 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3257 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3258 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3259 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3260 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3262 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3263 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3264 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3265 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3266 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3267 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3268 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3269 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3272 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3273 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3274 ok(avail
!= 0, "avail = 0\n");
3277 res
= InternetReadFile(req
, buf
, avail
, &size
);
3278 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3280 /* IE11 calls those in InternetQueryDataAvailable call. */
3281 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
3282 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
3284 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3285 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3286 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3287 ok(!avail
, "avail = %u, expected 0\n", avail
);
3289 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3291 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3292 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3293 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3294 SetEvent(conn_close_event
);
3295 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3296 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3297 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3298 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3299 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3300 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3302 close_async_handle(session
, hCompleteEvent
, 2);
3303 CloseHandle(hCompleteEvent
);
3306 static void test_no_cache(int port
)
3308 static const char cache_control_no_cache
[] = "/test_cache_control_no_cache";
3309 static const char cache_control_no_store
[] = "/test_cache_control_no_store";
3310 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3312 char cache_url
[256], buf
[256];
3313 HINTERNET ses
, con
, req
;
3317 trace("Testing no-cache header\n");
3319 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3320 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3322 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3323 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3325 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3326 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3328 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_cache
);
3329 DeleteUrlCacheEntryA(cache_url
);
3331 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3332 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3334 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3336 ok(size
== 12, "read %d bytes of data\n", size
);
3337 InternetCloseHandle(req
);
3339 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3340 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3342 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3343 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3345 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3347 ok(size
== 0, "read %d bytes of data\n", size
);
3348 InternetCloseHandle(req
);
3349 DeleteUrlCacheEntryA(cache_url
);
3351 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_store
, NULL
, NULL
, NULL
, 0, 0);
3352 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3354 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_store
);
3355 DeleteUrlCacheEntryA(cache_url
);
3357 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3358 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3360 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3362 ok(size
== 12, "read %d bytes of data\n", size
);
3363 InternetCloseHandle(req
);
3365 ret
= DeleteUrlCacheEntryA(cache_url
);
3366 ok(!ret
&& GetLastError()==ERROR_FILE_NOT_FOUND
, "cache entry should not exist\n");
3368 InternetCloseHandle(con
);
3369 InternetCloseHandle(ses
);
3372 static void test_cache_read_gzipped(int port
)
3374 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3375 static const char get_gzip
[] = "/test_cache_gzip";
3376 static const char content
[] = "gzip test\n";
3377 static const char text_html
[] = "text/html";
3378 static const char raw_header
[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3380 HINTERNET ses
, con
, req
;
3382 char cache_url
[256], buf
[256];
3385 trace("Testing reading compressed content from cache\n");
3387 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3388 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3390 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3391 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3393 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3394 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3397 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3398 if(!ret
&& GetLastError()==ERROR_INTERNET_INVALID_OPTION
) {
3399 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3400 InternetCloseHandle(req
);
3401 InternetCloseHandle(con
);
3402 InternetCloseHandle(ses
);
3405 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3407 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3408 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3410 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-size
, &read
) && read
)
3412 ok(size
== 10, "read %d bytes of data\n", size
);
3414 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3416 size
= sizeof(buf
)-1;
3417 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3418 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3420 ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3422 size
= sizeof(buf
)-1;
3423 ret
= HttpQueryInfoA(req
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &size
, 0);
3424 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3426 ok(!strncmp(raw_header
, buf
, size
), "buf = %s\n", buf
);
3427 InternetCloseHandle(req
);
3429 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3430 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3433 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3434 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3436 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3437 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3439 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3441 todo_wine
ok(size
== 10, "read %d bytes of data\n", size
);
3443 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3446 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3447 ok(!ret
&& GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND
,
3448 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3449 ret
, GetLastError());
3451 size
= sizeof(buf
)-1;
3452 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3453 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3455 todo_wine
ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3456 InternetCloseHandle(req
);
3458 /* Decompression doesn't work while reading from cache */
3459 test_cache_gzip
= 0;
3460 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3461 DeleteUrlCacheEntryA(cache_url
);
3463 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3464 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3466 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3467 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3469 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3471 ok(size
== 31, "read %d bytes of data\n", size
);
3472 InternetCloseHandle(req
);
3474 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3475 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3478 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3479 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3481 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3482 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3484 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3486 todo_wine
ok(size
== 31, "read %d bytes of data\n", size
);
3489 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3490 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3491 InternetCloseHandle(req
);
3493 InternetCloseHandle(con
);
3494 InternetCloseHandle(ses
);
3496 DeleteUrlCacheEntryA(cache_url
);
3499 static void test_HttpSendRequestW(int port
)
3501 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3502 HINTERNET ses
, con
, req
;
3506 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3507 ok(ses
!= NULL
, "InternetOpen failed\n");
3509 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3510 ok(con
!= NULL
, "InternetConnect failed\n");
3512 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3513 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3515 SetLastError(0xdeadbeef);
3516 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
3517 error
= GetLastError();
3518 ok(!ret
, "HttpSendRequestW succeeded\n");
3519 ok(error
== ERROR_IO_PENDING
||
3520 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
3521 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
3522 "got %u expected ERROR_IO_PENDING\n", error
);
3524 InternetCloseHandle(req
);
3525 InternetCloseHandle(con
);
3526 InternetCloseHandle(ses
);
3529 static void test_cookie_header(int port
)
3531 HINTERNET ses
, con
, req
;
3536 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3537 ok(ses
!= NULL
, "InternetOpen failed\n");
3539 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3540 ok(con
!= NULL
, "InternetConnect failed\n");
3542 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3544 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3545 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3548 size
= sizeof(buffer
);
3549 SetLastError(0xdeadbeef);
3550 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3551 error
= GetLastError();
3552 ok(!ret
, "HttpQueryInfo succeeded\n");
3553 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3555 ret
= HttpAddRequestHeadersA(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
3556 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3559 size
= sizeof(buffer
);
3560 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3561 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3562 ok(!strcmp(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
3564 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3565 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3567 test_status_code(req
, 200);
3570 size
= sizeof(buffer
);
3571 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3572 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3573 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
3575 InternetCloseHandle(req
);
3576 InternetCloseHandle(con
);
3577 InternetCloseHandle(ses
);
3580 static void test_basic_authentication(int port
)
3582 HINTERNET session
, connect
, request
;
3585 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3586 ok(session
!= NULL
, "InternetOpen failed\n");
3588 connect
= InternetConnectA(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
3589 ok(connect
!= NULL
, "InternetConnect failed\n");
3591 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
3592 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3594 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3595 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3597 test_status_code(request
, 200);
3598 test_request_flags(request
, 0);
3600 InternetCloseHandle(request
);
3601 InternetCloseHandle(connect
);
3602 InternetCloseHandle(session
);
3605 static void test_premature_disconnect(int port
)
3607 HINTERNET session
, connect
, request
;
3611 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3612 ok(session
!= NULL
, "InternetOpen failed\n");
3614 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3615 ok(connect
!= NULL
, "InternetConnect failed\n");
3617 request
= HttpOpenRequestA(connect
, NULL
, "/premature_disconnect", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3618 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3620 SetLastError(0xdeadbeef);
3621 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3622 err
= GetLastError();
3623 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
3624 todo_wine
ok(err
== ERROR_HTTP_INVALID_SERVER_RESPONSE
, "got %u\n", err
);
3626 InternetCloseHandle(request
);
3627 InternetCloseHandle(connect
);
3628 InternetCloseHandle(session
);
3631 static void test_invalid_response_headers(int port
)
3633 HINTERNET session
, connect
, request
;
3638 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3639 ok(session
!= NULL
, "InternetOpen failed\n");
3641 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3642 ok(connect
!= NULL
, "InternetConnect failed\n");
3644 request
= HttpOpenRequestA(connect
, NULL
, "/testE", NULL
, NULL
, NULL
, 0, 0);
3645 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3647 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
3648 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
3650 test_status_code(request
, 401);
3651 test_request_flags(request
, 0);
3654 size
= sizeof(buffer
);
3655 ret
= HttpQueryInfoA( request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3656 ok(ret
, "HttpQueryInfo failed\n");
3657 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
3658 "headers wrong \"%s\"\n", buffer
);
3661 size
= sizeof(buffer
);
3662 ret
= HttpQueryInfoA( request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
3663 ok(ret
, "HttpQueryInfo failed\n");
3664 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
3666 InternetCloseHandle(request
);
3667 InternetCloseHandle(connect
);
3668 InternetCloseHandle(session
);
3671 static void test_response_without_headers(int port
)
3673 HINTERNET hi
, hc
, hr
;
3674 DWORD r
, count
, size
;
3677 SetLastError(0xdeadbeef);
3678 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3679 ok(hi
!= NULL
, "open failed %u\n", GetLastError());
3681 SetLastError(0xdeadbeef);
3682 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3683 ok(hc
!= NULL
, "connect failed %u\n", GetLastError());
3685 SetLastError(0xdeadbeef);
3686 hr
= HttpOpenRequestA(hc
, NULL
, "/testG", NULL
, NULL
, NULL
, 0, 0);
3687 ok(hr
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError());
3689 test_request_flags(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3691 SetLastError(0xdeadbeef);
3692 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
3693 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
3695 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3698 memset(buffer
, 0, sizeof buffer
);
3699 SetLastError(0xdeadbeef);
3700 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
3701 ok(r
, "InternetReadFile failed %u\n", GetLastError());
3702 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
3703 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
3705 test_status_code(hr
, 200);
3706 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
3709 size
= sizeof(buffer
);
3710 SetLastError(0xdeadbeef);
3711 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
3712 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3713 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
3716 size
= sizeof(buffer
);
3717 SetLastError(0xdeadbeef);
3718 r
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
3719 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3720 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
3723 size
= sizeof(buffer
);
3724 SetLastError(0xdeadbeef);
3725 r
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
3726 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
3727 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
3729 InternetCloseHandle(hr
);
3730 InternetCloseHandle(hc
);
3731 InternetCloseHandle(hi
);
3734 static void test_head_request(int port
)
3736 DWORD len
, content_length
;
3737 HINTERNET ses
, con
, req
;
3741 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3742 ok(ses
!= NULL
, "InternetOpen failed\n");
3744 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3745 ok(con
!= NULL
, "InternetConnect failed\n");
3747 req
= HttpOpenRequestA(con
, "HEAD", "/test_head", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3748 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3750 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3751 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3753 len
= sizeof(content_length
);
3754 content_length
= -1;
3755 ret
= HttpQueryInfoA(req
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
, &content_length
, &len
, 0);
3756 ok(ret
, "HttpQueryInfo dailed: %u\n", GetLastError());
3757 ok(len
== sizeof(DWORD
), "len = %u\n", len
);
3758 ok(content_length
== 100, "content_length = %u\n", content_length
);
3761 ret
= InternetReadFile(req
, buf
, sizeof(buf
), &len
);
3762 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
3765 ret
= InternetReadFile(req
, buf
, sizeof(buf
), &len
);
3766 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
3768 InternetCloseHandle(req
);
3769 InternetCloseHandle(con
);
3770 InternetCloseHandle(ses
);
3773 static void test_HttpQueryInfo(int port
)
3775 HINTERNET hi
, hc
, hr
;
3776 DWORD size
, index
, error
;
3780 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3781 ok(hi
!= NULL
, "InternetOpen failed\n");
3783 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3784 ok(hc
!= NULL
, "InternetConnect failed\n");
3786 hr
= HttpOpenRequestA(hc
, NULL
, "/testD", NULL
, NULL
, NULL
, 0, 0);
3787 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
3789 size
= sizeof(buffer
);
3790 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3791 error
= GetLastError();
3792 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
3793 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3795 ret
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
3796 ok(ret
, "HttpSendRequest failed\n");
3799 size
= sizeof(buffer
);
3800 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
3801 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3802 ok(index
== 1, "expected 1 got %u\n", index
);
3805 size
= sizeof(buffer
);
3806 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
3807 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3808 ok(index
== 1, "expected 1 got %u\n", index
);
3811 size
= sizeof(buffer
);
3812 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3813 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3814 ok(index
== 0, "expected 0 got %u\n", index
);
3816 size
= sizeof(buffer
);
3817 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3818 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3819 ok(index
== 0, "expected 0 got %u\n", index
);
3821 index
= 0xdeadbeef; /* invalid start index */
3822 size
= sizeof(buffer
);
3823 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
3824 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
3825 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
3826 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
3829 size
= sizeof(buffer
);
3830 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
3831 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3832 ok(index
== 0, "expected 0 got %u\n", index
);
3834 size
= sizeof(buffer
);
3835 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
3836 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3837 ok(index
== 0, "expected 0 got %u\n", index
);
3839 size
= sizeof(buffer
);
3840 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
3841 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3842 ok(index
== 0, "expected 0 got %u\n", index
);
3844 test_status_code(hr
, 200);
3847 size
= sizeof(buffer
);
3848 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
3849 ok(!ret
, "HttpQueryInfo succeeded\n");
3850 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
3853 size
= sizeof(buffer
);
3854 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
3855 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3856 ok(index
== 1, "expected 1 got %u\n", index
);
3859 size
= sizeof(buffer
);
3860 strcpy(buffer
, "Server");
3861 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
3862 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3863 ok(index
== 1, "expected 1 got %u\n", index
);
3866 size
= sizeof(buffer
);
3867 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
3868 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3869 ok(index
== 1, "expected 1 got %u\n", index
);
3871 size
= sizeof(buffer
);
3872 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
3873 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
3874 ok(index
== 2, "expected 2 got %u\n", index
);
3876 InternetCloseHandle(hr
);
3877 InternetCloseHandle(hc
);
3878 InternetCloseHandle(hi
);
3881 static void test_options(int port
)
3883 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi
;
3884 HINTERNET ses
, con
, req
;
3889 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3890 ok(ses
!= NULL
, "InternetOpen failed\n");
3892 SetLastError(0xdeadbeef);
3893 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
3894 error
= GetLastError();
3895 ok(!ret
, "InternetSetOption succeeded\n");
3896 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3898 SetLastError(0xdeadbeef);
3899 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
3900 ok(!ret
, "InternetSetOption succeeded\n");
3901 error
= GetLastError();
3902 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3904 SetLastError(0xdeadbeef);
3905 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
3906 ok(!ret
, "InternetSetOption succeeded\n");
3907 error
= GetLastError();
3908 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3911 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3912 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3914 SetLastError(0xdeadbeef);
3915 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
3916 error
= GetLastError();
3917 ok(!ret
, "InternetQueryOption succeeded\n");
3918 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3920 SetLastError(0xdeadbeef);
3921 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
3922 error
= GetLastError();
3923 ok(!ret
, "InternetQueryOption succeeded\n");
3924 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
3927 SetLastError(0xdeadbeef);
3928 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
3929 error
= GetLastError();
3930 ok(!ret
, "InternetQueryOption succeeded\n");
3931 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
3934 SetLastError(0xdeadbeef);
3935 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3936 error
= GetLastError();
3937 ok(!ret
, "InternetQueryOption succeeded\n");
3938 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
3942 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3943 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3944 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
3946 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3947 ok(con
!= NULL
, "InternetConnect failed\n");
3951 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3952 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3953 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
3956 ret
= InternetSetOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3957 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3961 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3962 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3963 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
3965 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3966 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3970 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3971 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3972 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
3975 ret
= InternetSetOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
3976 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
3980 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
3981 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3982 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
3984 size
= sizeof(idsi
);
3985 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO
, &idsi
, &size
);
3986 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
3989 SetLastError(0xdeadbeef);
3990 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
3991 error
= GetLastError();
3992 ok(!ret
, "InternetQueryOption succeeded\n");
3993 ok(error
== ERROR_INTERNET_INVALID_OPERATION
, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error
);
3995 /* INTERNET_OPTION_PROXY */
3996 SetLastError(0xdeadbeef);
3997 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
3998 error
= GetLastError();
3999 ok(!ret
, "InternetQueryOption succeeded\n");
4000 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4002 SetLastError(0xdeadbeef);
4003 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
4004 error
= GetLastError();
4005 ok(!ret
, "InternetQueryOption succeeded\n");
4006 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4009 SetLastError(0xdeadbeef);
4010 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
4011 error
= GetLastError();
4012 ok(!ret
, "InternetQueryOption succeeded\n");
4013 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
4014 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
4016 InternetCloseHandle(req
);
4017 InternetCloseHandle(con
);
4018 InternetCloseHandle(ses
);
4022 const char *response_text
;
4024 const char *status_text
;
4025 const char *raw_headers
;
4026 } http_status_test_t
;
4028 static const http_status_test_t http_status_tests
[] = {
4030 "HTTP/1.1 200 OK\r\n"
4031 "Content-Length: 1\r\n"
4037 "HTTP/1.1 404 Fail\r\n"
4038 "Content-Length: 1\r\n"
4045 "Content-Length: 1\r\n"
4052 "Content-Length: 1\r\n"
4059 static void test_http_status(int port
)
4061 HINTERNET ses
, con
, req
;
4066 for(i
=0; i
< sizeof(http_status_tests
)/sizeof(*http_status_tests
); i
++) {
4067 send_buffer
= http_status_tests
[i
].response_text
;
4069 ses
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4070 ok(ses
!= NULL
, "InternetOpen failed\n");
4072 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4073 ok(con
!= NULL
, "InternetConnect failed\n");
4075 req
= HttpOpenRequestA(con
, NULL
, "/send_from_buffer", NULL
, NULL
, NULL
, 0, 0);
4076 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4078 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4079 ok(res
, "HttpSendRequest failed\n");
4081 test_status_code(req
, http_status_tests
[i
].status_code
);
4084 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_TEXT
, buf
, &size
, NULL
);
4085 ok(res
, "HttpQueryInfo failed: %u\n", GetLastError());
4086 ok(!strcmp(buf
, http_status_tests
[i
].status_text
), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
4087 i
, buf
, http_status_tests
[i
].status_text
);
4089 InternetCloseHandle(req
);
4090 InternetCloseHandle(con
);
4091 InternetCloseHandle(ses
);
4095 static void test_cache_control_verb(int port
)
4097 HINTERNET session
, connect
, request
;
4100 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4101 ok(session
!= NULL
, "InternetOpen failed\n");
4103 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4104 ok(connect
!= NULL
, "InternetConnect failed\n");
4106 request
= HttpOpenRequestA(connect
, "RPC_OUT_DATA", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4107 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4108 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4109 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4110 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4111 test_status_code(request
, 200);
4112 InternetCloseHandle(request
);
4114 request
= HttpOpenRequestA(connect
, "POST", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4115 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4116 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4117 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4118 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4119 test_status_code(request
, 200);
4120 InternetCloseHandle(request
);
4122 request
= HttpOpenRequestA(connect
, "HEAD", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4123 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4124 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4125 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4126 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4127 test_status_code(request
, 200);
4128 InternetCloseHandle(request
);
4130 request
= HttpOpenRequestA(connect
, "GET", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4131 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4132 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4133 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4134 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4135 test_status_code(request
, 200);
4136 InternetCloseHandle(request
);
4138 InternetCloseHandle(connect
);
4139 InternetCloseHandle(session
);
4142 static void test_request_content_length(int port
)
4144 char data
[] = {'t','e','s','t'};
4145 HINTERNET ses
, con
, req
;
4148 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4150 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4151 ok(ses
!= NULL
, "InternetOpen failed\n");
4153 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4154 ok(con
!= NULL
, "InternetConnect failed\n");
4156 req
= HttpOpenRequestA(con
, "POST", "/test_request_content_length", NULL
, NULL
, NULL
,
4157 INTERNET_FLAG_KEEP_CONNECTION
, 0);
4158 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4160 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4161 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4162 test_status_code(req
, 200);
4164 SetEvent(hCompleteEvent
);
4166 ret
= HttpSendRequestA(req
, NULL
, 0, data
, sizeof(data
));
4167 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4168 test_status_code(req
, 200);
4170 SetEvent(hCompleteEvent
);
4172 InternetCloseHandle(req
);
4173 InternetCloseHandle(con
);
4174 InternetCloseHandle(ses
);
4175 CloseHandle(hCompleteEvent
);
4178 static void test_accept_encoding(int port
)
4180 HINTERNET ses
, con
, req
;
4183 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4184 ok(ses
!= NULL
, "InternetOpen failed\n");
4186 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4187 ok(con
!= NULL
, "InternetConnect failed\n");
4189 req
= HttpOpenRequestA(con
, "GET", "/test_accept_encoding_http10", "HTTP/1.0", NULL
, NULL
, 0, 0);
4190 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4192 ret
= HttpAddRequestHeadersA(req
, "Accept-Encoding: gzip\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDREQ_FLAG_ADD
);
4193 ok(ret
, "HttpAddRequestHeaders failed\n");
4195 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4196 ok(ret
, "HttpSendRequestA failed\n");
4198 test_status_code(req
, 200);
4200 InternetCloseHandle(req
);
4202 req
= HttpOpenRequestA(con
, "GET", "/test_accept_encoding_http10", "HTTP/1.0", NULL
, NULL
, 0, 0);
4203 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4205 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", ~0u, NULL
, 0);
4206 ok(ret
, "HttpSendRequestA failed\n");
4208 test_status_code(req
, 200);
4210 InternetCloseHandle(req
);
4211 InternetCloseHandle(con
);
4212 InternetCloseHandle(ses
);
4215 static void test_http_connection(void)
4217 struct server_info si
;
4221 si
.hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
4224 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
4225 ok( hThread
!= NULL
, "create thread failed\n");
4227 r
= WaitForSingleObject(si
.hEvent
, 10000);
4228 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
4229 if (r
!= WAIT_OBJECT_0
)
4232 test_basic_request(si
.port
, "GET", "/test1");
4233 test_proxy_indirect(si
.port
);
4234 test_proxy_direct(si
.port
);
4235 test_header_handling_order(si
.port
);
4236 test_basic_request(si
.port
, "POST", "/test5");
4237 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
4238 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
4239 test_basic_request(si
.port
, "GET", "/test6");
4240 test_basic_request(si
.port
, "GET", "/testF");
4241 test_connection_header(si
.port
);
4242 test_http1_1(si
.port
);
4243 test_cookie_header(si
.port
);
4244 test_basic_authentication(si
.port
);
4245 test_invalid_response_headers(si
.port
);
4246 test_response_without_headers(si
.port
);
4247 test_HttpQueryInfo(si
.port
);
4248 test_HttpSendRequestW(si
.port
);
4249 test_options(si
.port
);
4250 test_no_content(si
.port
);
4251 test_conn_close(si
.port
);
4252 test_no_cache(si
.port
);
4253 test_cache_read_gzipped(si
.port
);
4254 test_http_status(si
.port
);
4255 test_premature_disconnect(si
.port
);
4256 test_connection_closing(si
.port
);
4257 test_cache_control_verb(si
.port
);
4258 test_successive_HttpSendRequest(si
.port
);
4259 test_head_request(si
.port
);
4260 test_request_content_length(si
.port
);
4261 test_accept_encoding(si
.port
);
4263 /* send the basic request again to shutdown the server thread */
4264 test_basic_request(si
.port
, "GET", "/quit");
4266 r
= WaitForSingleObject(hThread
, 3000);
4267 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
4268 CloseHandle(hThread
);
4271 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
4273 LocalFree(info
->lpszSubjectInfo
);
4274 LocalFree(info
->lpszIssuerInfo
);
4275 LocalFree(info
->lpszProtocolName
);
4276 LocalFree(info
->lpszSignatureAlgName
);
4277 LocalFree(info
->lpszEncryptionAlgName
);
4281 const char *ex_subject
;
4282 const char *ex_issuer
;
4283 } cert_struct_test_t
;
4285 static const cert_struct_test_t test_winehq_org_cert
= {
4287 "See www.rapidssl.com/resources/cps (c)14\r\n"
4288 "Domain Control Validated - RapidSSL(R)\r\n"
4293 "RapidSSL SHA256 CA - G3"
4296 static const cert_struct_test_t test_winehq_com_cert
= {
4301 "test.winehq.com\r\n"
4302 "webmaster@winehq.org",
4307 "test.winehq.com\r\n"
4308 "webmaster@winehq.org"
4311 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
4313 INTERNET_CERTIFICATE_INFOA info
;
4317 memset(&info
, 0x5, sizeof(info
));
4319 size
= sizeof(info
);
4320 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
4321 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
4322 ok(size
== sizeof(info
), "size = %u\n", size
);
4324 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
4325 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
4326 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
4327 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
4328 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
4329 ok(info
.dwKeySize
>= 128 && info
.dwKeySize
<= 256, "dwKeySize = %u\n", info
.dwKeySize
);
4331 release_cert_info(&info
);
4334 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
4335 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
4337 char url
[INTERNET_MAX_URL_LENGTH
];
4338 const CERT_CHAIN_CONTEXT
*chain
;
4342 if(!pInternetGetSecurityInfoByURLA
) {
4343 win_skip("pInternetGetSecurityInfoByURLA not available\n");
4348 chain
= (void*)0xdeadbeef;
4350 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
4351 if(error
== ERROR_SUCCESS
) {
4352 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
4353 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
4354 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
4355 CertFreeCertificateChain(chain
);
4357 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
4358 "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res
, GetLastError(), error
);
4362 #define test_secflags_option(a,b,c) _test_secflags_option(__LINE__,a,b,c)
4363 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
, DWORD opt_flags
)
4369 size
= sizeof(flags
);
4370 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4371 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4372 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n",
4375 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
4377 size
= sizeof(flags
);
4378 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4379 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
4380 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n",
4384 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
4385 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
4389 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
4390 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4393 static void test_security_flags(void)
4395 INTERNET_CERTIFICATE_INFOA
*cert
;
4396 HINTERNET ses
, conn
, req
;
4401 trace("Testing security flags...\n");
4403 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4405 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4406 ok(ses
!= NULL
, "InternetOpen failed\n");
4408 pInternetSetStatusCallbackA(ses
, &callback
);
4410 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4411 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
4412 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
4413 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
4414 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4416 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4417 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4418 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4420 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4421 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4424 size
= sizeof(flags
);
4425 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4426 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
4427 win_skip("Incomplete security flags support, skipping\n");
4429 close_async_handle(ses
, hCompleteEvent
, 2);
4430 CloseHandle(hCompleteEvent
);
4434 test_secflags_option(req
, 0, 0);
4435 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4437 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4438 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
, 0);
4440 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4441 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
4443 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4444 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
4446 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
4447 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
4448 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
4450 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
4451 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
4452 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4453 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4454 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
4455 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
4456 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
4457 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
4458 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4459 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4460 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4461 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4462 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4463 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4464 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4466 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4467 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4469 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4470 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4472 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
4473 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
4474 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
4475 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
4476 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4477 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4478 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4479 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4480 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4481 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4482 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4483 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4484 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4486 test_request_flags(req
, 0);
4487 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4488 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
, 0);
4490 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4491 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4492 ok(size
, "size = 0\n");
4494 /* Collect all existing persistent connections */
4495 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4496 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4498 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4499 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4500 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4502 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4503 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4505 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
4506 res
= InternetSetOptionA(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
4507 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
4509 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4510 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4511 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
4512 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
4513 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
4514 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
4515 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4516 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4517 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4518 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4519 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4521 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4522 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4524 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4525 ok(req_error
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| broken(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
),
4526 "req_error = %d\n", req_error
);
4529 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
4530 ok(res
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4531 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %u\n", size
);
4532 cert
= HeapAlloc(GetProcessHeap(), 0, size
);
4533 cert
->lpszSubjectInfo
= NULL
;
4534 cert
->lpszIssuerInfo
= NULL
;
4535 cert
->lpszSignatureAlgName
= (char *)0xdeadbeef;
4536 cert
->lpszEncryptionAlgName
= (char *)0xdeadbeef;
4537 cert
->lpszProtocolName
= (char *)0xdeadbeef;
4538 cert
->dwKeySize
= 0xdeadbeef;
4539 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, cert
, &size
);
4540 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
4543 ok(cert
->lpszSubjectInfo
&& strlen(cert
->lpszSubjectInfo
) > 1, "expected a non-empty subject name\n");
4544 ok(cert
->lpszIssuerInfo
&& strlen(cert
->lpszIssuerInfo
) > 1, "expected a non-empty issuer name\n");
4545 ok(!cert
->lpszSignatureAlgName
, "unexpected signature algorithm name\n");
4546 ok(!cert
->lpszEncryptionAlgName
, "unexpected encryption algorithm name\n");
4547 ok(!cert
->lpszProtocolName
, "unexpected protocol name\n");
4548 ok(cert
->dwKeySize
!= 0xdeadbeef, "unexpected key size\n");
4550 HeapFree(GetProcessHeap(), 0, cert
);
4552 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
4553 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
4554 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
4555 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
4556 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4557 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4558 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4560 if(req_error
!= ERROR_INTERNET_SEC_CERT_REV_FAILED
) {
4561 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error
);
4563 close_async_handle(ses
, hCompleteEvent
, 3);
4564 CloseHandle(hCompleteEvent
);
4569 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
4570 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
4572 test_request_flags(req
, 8);
4573 /* IE11 finds both rev failure and invalid CA. Previous versions required rev failure
4574 to be ignored before invalid CA was reported. */
4575 test_secflags_option(req
, _SECURITY_FLAG_CERT_REV_FAILED
, _SECURITY_FLAG_CERT_INVALID_CA
);
4577 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4578 test_secflags_option(req
, _SECURITY_FLAG_CERT_REV_FAILED
|SECURITY_FLAG_IGNORE_REVOCATION
, _SECURITY_FLAG_CERT_INVALID_CA
);
4580 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4581 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4582 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4583 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4584 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4585 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4586 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4588 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4589 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4591 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4592 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
4594 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4595 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4596 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4597 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4598 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4599 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4600 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4602 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
4603 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
4604 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4606 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4607 test_secflags_option(req
, _SECURITY_FLAG_CERT_INVALID_CA
|_SECURITY_FLAG_CERT_REV_FAILED
4608 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
, 0);
4609 test_http_version(req
);
4611 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4612 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4613 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
4614 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
4615 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
4616 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
4617 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4618 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4619 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4620 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4621 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4622 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4623 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4625 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4626 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4628 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4629 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4631 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
4632 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
4633 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4634 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4635 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4636 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4637 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4638 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4639 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4640 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4641 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4643 test_request_flags(req
, 0);
4644 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
4645 |SECURITY_FLAG_STRENGTH_STRONG
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
4647 test_cert_struct(req
, &test_winehq_com_cert
);
4648 test_security_info("https://test.winehq.com/data/some_file.html?q", 0,
4649 _SECURITY_FLAG_CERT_INVALID_CA
|_SECURITY_FLAG_CERT_REV_FAILED
);
4651 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4652 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4653 ok(size
, "size = 0\n");
4655 close_async_handle(ses
, hCompleteEvent
, 3);
4657 /* Collect all existing persistent connections */
4658 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4659 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4661 /* Make another request, without setting security flags */
4663 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4664 ok(ses
!= NULL
, "InternetOpen failed\n");
4666 pInternetSetStatusCallbackA(ses
, &callback
);
4668 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4669 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
4670 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
4671 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
4672 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4674 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4675 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4676 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4678 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4679 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4681 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
4682 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
4683 test_http_version(req
);
4685 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4686 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4687 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
4688 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
4689 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
4690 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
4691 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4692 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4693 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4694 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4695 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4696 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4698 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4699 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4701 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4702 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4704 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
4705 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
4706 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4707 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4708 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4709 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4710 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4711 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4712 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4713 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4715 test_request_flags(req
, 0);
4716 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
4717 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
4719 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4720 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4721 ok(size
, "size = 0\n");
4723 close_async_handle(ses
, hCompleteEvent
, 2);
4725 CloseHandle(hCompleteEvent
);
4727 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4728 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4729 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4732 static void test_secure_connection(void)
4734 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
4735 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
4736 static const WCHAR get
[] = {'G','E','T',0};
4737 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
4738 HINTERNET ses
, con
, req
;
4740 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
4741 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
4744 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4745 ok(ses
!= NULL
, "InternetOpen failed\n");
4747 con
= InternetConnectA(ses
, "test.winehq.org",
4748 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
4749 INTERNET_SERVICE_HTTP
, 0, 0);
4750 ok(con
!= NULL
, "InternetConnect failed\n");
4752 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4753 INTERNET_FLAG_SECURE
, 0);
4754 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4756 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4757 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
4759 size
= sizeof(flags
);
4760 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4761 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4762 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
4764 test_cert_struct(req
, &test_winehq_org_cert
);
4766 /* Querying the same option through InternetQueryOptionW still results in
4767 * ASCII strings being returned.
4770 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4772 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4773 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
4774 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
4775 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4776 certificate_structW
, &size
);
4777 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
4778 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4781 ok(certificate_structA
->lpszSubjectInfo
&&
4782 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4783 "expected a non-empty subject name\n");
4784 ok(certificate_structA
->lpszIssuerInfo
&&
4785 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4786 "expected a non-empty issuer name\n");
4787 ok(!certificate_structA
->lpszSignatureAlgName
,
4788 "unexpected signature algorithm name\n");
4789 ok(!certificate_structA
->lpszEncryptionAlgName
,
4790 "unexpected encryption algorithm name\n");
4791 ok(!certificate_structA
->lpszProtocolName
,
4792 "unexpected protocol name\n");
4793 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4794 release_cert_info(certificate_structA
);
4796 HeapFree(GetProcessHeap(), 0, certificate_structW
);
4798 InternetCloseHandle(req
);
4799 InternetCloseHandle(con
);
4800 InternetCloseHandle(ses
);
4802 /* Repeating the tests with the W functions has the same result: */
4803 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4804 ok(ses
!= NULL
, "InternetOpen failed\n");
4806 con
= InternetConnectW(ses
, testsite
,
4807 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
4808 INTERNET_SERVICE_HTTP
, 0, 0);
4809 ok(con
!= NULL
, "InternetConnect failed\n");
4811 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
4812 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
4813 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4815 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4816 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
4818 size
= sizeof(flags
);
4819 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4820 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4821 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %x\n", flags
);
4823 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4825 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4826 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
4827 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
4828 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4829 certificate_structA
, &size
);
4830 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4833 ok(certificate_structA
->lpszSubjectInfo
&&
4834 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4835 "expected a non-empty subject name\n");
4836 ok(certificate_structA
->lpszIssuerInfo
&&
4837 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4838 "expected a non-empty issuer name\n");
4839 ok(!certificate_structA
->lpszSignatureAlgName
,
4840 "unexpected signature algorithm name\n");
4841 ok(!certificate_structA
->lpszEncryptionAlgName
,
4842 "unexpected encryption algorithm name\n");
4843 ok(!certificate_structA
->lpszProtocolName
,
4844 "unexpected protocol name\n");
4845 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4846 release_cert_info(certificate_structA
);
4848 HeapFree(GetProcessHeap(), 0, certificate_structA
);
4850 /* Again, querying the same option through InternetQueryOptionW still
4851 * results in ASCII strings being returned.
4854 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4856 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
4857 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
4858 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
4859 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
4860 certificate_structW
, &size
);
4861 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
4862 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
4865 ok(certificate_structA
->lpszSubjectInfo
&&
4866 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
4867 "expected a non-empty subject name\n");
4868 ok(certificate_structA
->lpszIssuerInfo
&&
4869 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
4870 "expected a non-empty issuer name\n");
4871 ok(!certificate_structA
->lpszSignatureAlgName
,
4872 "unexpected signature algorithm name\n");
4873 ok(!certificate_structA
->lpszEncryptionAlgName
,
4874 "unexpected encryption algorithm name\n");
4875 ok(!certificate_structA
->lpszProtocolName
,
4876 "unexpected protocol name\n");
4877 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
4878 release_cert_info(certificate_structA
);
4880 HeapFree(GetProcessHeap(), 0, certificate_structW
);
4882 InternetCloseHandle(req
);
4883 InternetCloseHandle(con
);
4884 InternetCloseHandle(ses
);
4887 static void test_user_agent_header(void)
4889 HINTERNET ses
, con
, req
;
4894 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4895 ok(ses
!= NULL
, "InternetOpen failed\n");
4897 con
= InternetConnectA(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4898 ok(con
!= NULL
, "InternetConnect failed\n");
4900 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
4901 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4903 size
= sizeof(buffer
);
4904 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4905 err
= GetLastError();
4906 ok(!ret
, "HttpQueryInfo succeeded\n");
4907 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4909 ret
= HttpAddRequestHeadersA(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
4910 ok(ret
, "HttpAddRequestHeaders succeeded\n");
4912 size
= sizeof(buffer
);
4913 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4914 err
= GetLastError();
4915 ok(ret
, "HttpQueryInfo failed\n");
4917 InternetCloseHandle(req
);
4919 req
= HttpOpenRequestA(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
4920 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4922 size
= sizeof(buffer
);
4923 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4924 err
= GetLastError();
4925 ok(!ret
, "HttpQueryInfo succeeded\n");
4926 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
4928 ret
= HttpAddRequestHeadersA(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
4929 ok(ret
, "HttpAddRequestHeaders failed\n");
4932 size
= sizeof(buffer
);
4933 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4934 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
4935 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
4937 InternetCloseHandle(req
);
4938 InternetCloseHandle(con
);
4939 InternetCloseHandle(ses
);
4942 static void test_bogus_accept_types_array(void)
4944 HINTERNET ses
, con
, req
;
4945 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
4950 ses
= InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
4951 con
= InternetConnectA(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4952 req
= HttpOpenRequestA(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
4954 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
4957 size
= sizeof(buffer
);
4958 SetLastError(0xdeadbeef);
4959 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
4960 error
= GetLastError();
4961 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
4962 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
4963 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
4964 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
4965 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
4967 InternetCloseHandle(req
);
4968 InternetCloseHandle(con
);
4969 InternetCloseHandle(ses
);
4978 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
4980 INTERNET_ASYNC_RESULT
*result
= info
;
4981 struct context
*ctx
= (struct context
*)context
;
4983 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
4986 case INTERNET_STATUS_REQUEST_COMPLETE
:
4987 trace("request handle: 0x%08lx\n", result
->dwResult
);
4988 ctx
->req
= (HINTERNET
)result
->dwResult
;
4989 SetEvent(ctx
->event
);
4991 case INTERNET_STATUS_HANDLE_CLOSING
: {
4992 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
4994 if (InternetQueryOptionA(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
4995 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
4996 SetEvent(ctx
->event
);
4999 case INTERNET_STATUS_NAME_RESOLVED
:
5000 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
5001 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
5003 ok(str
[0] && str
[1], "Got string: %s\n", str
);
5004 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
5009 static void test_open_url_async(void)
5017 /* Collect all existing persistent connections */
5018 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5019 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5022 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
5023 * other versions never do. They also hang of following tests. We disable it for everything older
5026 if(!pInternetGetSecurityInfoByURLA
) {
5027 win_skip("Skipping async open on too old wininet version.\n");
5032 ctx
.event
= CreateEventA(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
5034 ses
= InternetOpenA("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5035 ok(ses
!= NULL
, "InternetOpen failed\n");
5037 SetLastError(0xdeadbeef);
5038 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
5039 error
= GetLastError();
5040 ok(!ret
, "InternetSetOptionA succeeded\n");
5041 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
5043 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
5044 error
= GetLastError();
5045 ok(!ret
, "InternetSetOptionA failed\n");
5046 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
5048 pInternetSetStatusCallbackW(ses
, cb
);
5049 ResetEvent(ctx
.event
);
5051 req
= InternetOpenUrlA(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
5052 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
5054 WaitForSingleObject(ctx
.event
, INFINITE
);
5057 size
= sizeof(type
);
5058 ret
= InternetQueryOptionA(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
5059 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
5060 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
5061 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
5064 ret
= HttpQueryInfoA(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
5065 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
5066 ok(size
> 0, "expected size > 0\n");
5068 ResetEvent(ctx
.event
);
5069 InternetCloseHandle(ctx
.req
);
5070 WaitForSingleObject(ctx
.event
, INFINITE
);
5072 InternetCloseHandle(ses
);
5073 CloseHandle(ctx
.event
);
5078 internet_connect
= 1,
5080 http_send_request_ex
,
5083 internet_close_handle
5088 enum api function
; /* api responsible for notification */
5089 unsigned int status
; /* status received */
5090 BOOL async
; /* delivered from another thread? */
5098 const struct notification
*test
;
5104 DWORD expect_result
;
5108 static CRITICAL_SECTION notification_cs
;
5110 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
5112 BOOL status_ok
, function_ok
;
5113 struct info
*info
= (struct info
*)context
;
5116 EnterCriticalSection( ¬ification_cs
);
5118 if(info
->is_aborted
) {
5119 LeaveCriticalSection(¬ification_cs
);
5123 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
5125 DWORD size
= sizeof(struct info
*);
5126 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
5127 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
5128 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
5130 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
5131 if(info
->expect_result
== ERROR_SUCCESS
) {
5132 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
5134 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
5135 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
5140 if (i
>= info
->count
)
5142 LeaveCriticalSection( ¬ification_cs
);
5146 while (info
->test
[i
].status
!= status
&&
5147 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
5148 i
< info
->count
- 1 &&
5149 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
5154 status_ok
= (info
->test
[i
].status
== status
);
5155 function_ok
= (info
->test
[i
].function
== info
->function
);
5157 if (!info
->test
[i
].todo
)
5159 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
5160 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
5162 if (info
->test
[i
].async
)
5163 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
5164 info
->line
, info
->thread
, GetCurrentThreadId());
5168 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
5170 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
5172 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
5175 LeaveCriticalSection( ¬ification_cs
);
5178 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
5180 info
->function
= function
;
5182 info
->expect_result
= expect_result
;
5185 struct notification_data
5187 const struct notification
*test
;
5188 const unsigned int count
;
5193 BOOL expect_conn_failure
;
5196 static const struct notification async_send_request_ex_test
[] =
5198 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5199 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5200 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5201 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
5202 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
5203 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
5204 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
5205 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
5206 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
5207 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
5208 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5209 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, FALSE
},
5210 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, FALSE
},
5211 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
5212 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
5213 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5214 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
5215 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
5216 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
5217 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
5220 static const struct notification async_send_request_ex_test2
[] =
5222 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5223 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5224 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5225 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
5226 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
5227 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
5228 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
, TRUE
},
5229 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
, TRUE
},
5230 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
5231 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
5232 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5233 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
5234 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
5235 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5236 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
5237 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
5238 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
5239 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
5242 static const struct notification async_send_request_ex_resolve_failure_test
[] =
5244 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5245 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5246 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5247 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
},
5248 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5249 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5250 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5251 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
5252 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
5253 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
5254 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
5257 static const struct notification async_send_request_ex_chunked_test
[] =
5259 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
},
5260 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
},
5261 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5262 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
5263 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
5264 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
5265 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
5266 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
5267 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
5268 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
5269 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5270 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
5271 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
5272 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5273 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
},
5274 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
},
5275 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
},
5276 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
}
5279 static const struct notification_data notification_data
[] = {
5281 async_send_request_ex_chunked_test
,
5282 sizeof(async_send_request_ex_chunked_test
)/sizeof(async_send_request_ex_chunked_test
[0]),
5288 async_send_request_ex_test
,
5289 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
5293 "Public ID=codeweavers"
5296 async_send_request_ex_test2
,
5297 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
5303 async_send_request_ex_resolve_failure_test
,
5304 sizeof(async_send_request_ex_resolve_failure_test
)/sizeof(async_send_request_ex_resolve_failure_test
[0]),
5313 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
5316 HINTERNET ses
, req
, con
;
5318 DWORD size
, written
, error
;
5319 INTERNET_BUFFERSA b
;
5320 static const char *accept
[2] = {"*/*", NULL
};
5323 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
5325 InitializeCriticalSection( ¬ification_cs
);
5327 info
.test
= nd
->test
;
5328 info
.count
= nd
->count
;
5330 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
5331 info
.thread
= GetCurrentThreadId();
5332 info
.is_aborted
= FALSE
;
5334 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5335 ok( ses
!= NULL
, "InternetOpen failed\n" );
5337 pInternetSetStatusCallbackA( ses
, check_notification
);
5339 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
5340 con
= InternetConnectA( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
5341 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
5343 WaitForSingleObject( info
.wait
, 10000 );
5345 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
5346 req
= HttpOpenRequestA( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
5347 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
5349 WaitForSingleObject( info
.wait
, 10000 );
5352 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
5353 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
5354 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
5355 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
5356 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
5359 setup_test( &info
, http_send_request_ex
, __LINE__
,
5360 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
5361 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
5362 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
5364 error
= WaitForSingleObject( info
.wait
, 10000 );
5365 if(error
!= WAIT_OBJECT_0
) {
5366 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
5367 info
.is_aborted
= TRUE
;
5371 size
= sizeof(buffer
);
5372 SetLastError( 0xdeadbeef );
5373 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
5374 error
= GetLastError();
5375 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
5376 if(nd
->expect_conn_failure
) {
5377 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
5380 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
5381 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
5387 size
= strlen( nd
->data
);
5388 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
5389 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
5390 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
5391 ok( written
== size
, "expected %u got %u\n", written
, size
);
5393 WaitForSingleObject( info
.wait
, 10000 );
5395 SetLastError( 0xdeadbeef );
5396 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
5397 error
= GetLastError();
5398 ok( !ret
, "HttpEndRequestA succeeded\n" );
5399 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
5402 SetLastError( 0xdeadbeef );
5403 setup_test( &info
, http_end_request
, __LINE__
,
5404 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
5405 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
5406 error
= GetLastError();
5407 ok( !ret
, "HttpEndRequestA succeeded\n" );
5408 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
5410 WaitForSingleObject( info
.wait
, 10000 );
5412 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
5414 InternetCloseHandle( req
);
5415 InternetCloseHandle( con
);
5416 InternetCloseHandle( ses
);
5418 WaitForSingleObject( info
.wait
, 10000 );
5420 CloseHandle( info
.wait
);
5423 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
5424 static BOOL closetest_closed
;
5426 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
5427 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
5432 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
5434 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
5435 "Unexpected hInternet %p\n", hInternet
);
5436 if(!closetest_closed
)
5440 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
5441 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
5442 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5443 closetest_req
, res
, GetLastError());
5446 static void test_InternetCloseHandle(void)
5451 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5452 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
5454 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
5456 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
5457 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
5458 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
5460 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
5461 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
5463 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
5464 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
5465 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
5467 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
5469 res
= InternetCloseHandle(closetest_session
);
5470 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
5471 closetest_closed
= TRUE
;
5472 trace("Closed session handle\n");
5474 res
= InternetCloseHandle(closetest_conn
);
5475 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
5476 res
, GetLastError());
5478 res
= InternetCloseHandle(closetest_req
);
5479 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
5480 res
, GetLastError());
5482 len
= sizeof(flags
);
5483 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
5484 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
5485 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5486 closetest_req
, res
, GetLastError());
5489 static void test_connection_failure(void)
5491 HINTERNET session
, connect
, request
;
5495 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5496 ok(session
!= NULL
, "failed to get session handle\n");
5498 connect
= InternetConnectA(session
, "localhost", 1, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5499 ok(connect
!= NULL
, "failed to get connection handle\n");
5501 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
5502 ok(request
!= NULL
, "failed to get request handle\n");
5504 SetLastError(0xdeadbeef);
5505 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
5506 error
= GetLastError();
5507 ok(!ret
, "unexpected success\n");
5508 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
5510 InternetCloseHandle(request
);
5511 InternetCloseHandle(connect
);
5512 InternetCloseHandle(session
);
5515 static void test_default_service_port(void)
5517 HINTERNET session
, connect
, request
;
5521 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
5522 ok(session
!= NULL
, "InternetOpen failed\n");
5524 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
5525 INTERNET_SERVICE_HTTP
, 0, 0);
5526 ok(connect
!= NULL
, "InternetConnect failed\n");
5528 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
5529 ok(request
!= NULL
, "HttpOpenRequest failed\n");
5531 SetLastError(0xdeadbeef);
5532 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
5533 error
= GetLastError();
5534 ok(!ret
, "HttpSendRequest succeeded\n");
5535 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
5538 InternetCloseHandle(request
);
5539 InternetCloseHandle(connect
);
5540 InternetCloseHandle(session
);
5543 static void init_status_tests(void)
5545 memset(expect
, 0, sizeof(expect
));
5546 memset(optional
, 0, sizeof(optional
));
5547 memset(wine_allow
, 0, sizeof(wine_allow
));
5548 memset(notified
, 0, sizeof(notified
));
5549 memset(status_string
, 0, sizeof(status_string
));
5551 #define STATUS_STRING(status) status_string[status] = #status
5552 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
5553 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
5554 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5555 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5556 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
5557 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
5558 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
5559 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
5560 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
5561 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
5562 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
5563 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
5564 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
5565 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
5566 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
5567 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
5568 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
5569 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
5570 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
5571 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
5572 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
5573 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
5574 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
5575 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
5576 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
5577 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
5578 #undef STATUS_STRING
5581 static void WINAPI
header_cb( HINTERNET handle
, DWORD_PTR ctx
, DWORD status
, LPVOID info
, DWORD len
)
5583 if (status
== INTERNET_STATUS_REQUEST_COMPLETE
) SetEvent( (HANDLE
)ctx
);
5586 static void test_concurrent_header_access(void)
5588 HINTERNET ses
, con
, req
;
5589 DWORD index
, len
, err
;
5592 HANDLE wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
5594 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5595 ok( ses
!= NULL
, "InternetOpenA failed\n" );
5597 con
= InternetConnectA( ses
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
5598 INTERNET_SERVICE_HTTP
, 0, 0 );
5599 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
5601 req
= HttpOpenRequestA( con
, NULL
, "/", NULL
, NULL
, NULL
, 0, (DWORD_PTR
)wait
);
5602 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
5604 pInternetSetStatusCallbackA( req
, header_cb
);
5606 SetLastError( 0xdeadbeef );
5607 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
5608 err
= GetLastError();
5609 ok( !ret
, "HttpSendRequestA succeeded\n" );
5610 ok( err
== ERROR_IO_PENDING
, "got %u\n", ERROR_IO_PENDING
);
5612 ret
= HttpAddRequestHeadersA( req
, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD
);
5613 ok( ret
, "HttpAddRequestHeadersA failed %u\n", GetLastError() );
5617 ret
= HttpQueryInfoA( req
, HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
5618 buf
, &len
, &index
);
5619 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
5620 ok( strstr( buf
, "winetest: winetest" ) != NULL
, "header missing\n" );
5622 WaitForSingleObject( wait
, 5000 );
5624 InternetCloseHandle( req
);
5625 InternetCloseHandle( con
);
5626 InternetCloseHandle( ses
);
5627 CloseHandle( wait
);
5633 hdll
= GetModuleHandleA("wininet.dll");
5635 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
5636 win_skip("Too old IE (older than 6.0)\n");
5640 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
5641 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
5642 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
5644 init_status_tests();
5645 test_InternetCloseHandle();
5646 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
5647 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
5648 InternetReadFile_test(0, &test_data
[1]);
5649 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
5650 test_security_flags();
5651 InternetReadFile_test(0, &test_data
[2]);
5652 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
5653 test_open_url_async();
5654 test_async_HttpSendRequestEx(¬ification_data
[0]);
5655 test_async_HttpSendRequestEx(¬ification_data
[1]);
5656 test_async_HttpSendRequestEx(¬ification_data
[2]);
5657 test_async_HttpSendRequestEx(¬ification_data
[3]);
5658 InternetOpenRequest_test();
5660 InternetLockRequestFile_test();
5661 InternetOpenUrlA_test();
5663 test_http_connection();
5664 test_secure_connection();
5665 test_user_agent_header();
5666 test_bogus_accept_types_array();
5667 InternetReadFile_chunked_test();
5668 HttpSendRequestEx_test();
5669 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
5670 test_connection_failure();
5671 test_default_service_port();
5672 test_concurrent_header_access();