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
27 #define WIN32_NO_STATUS
38 #include <wine/test.h>
40 /* Undocumented security flags */
41 #define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
42 #define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
43 #define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
44 #define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
46 #define TEST_URL "http://test.winehq.org/tests/hello.html"
48 static BOOL first_connection_to_test_url
= TRUE
;
50 /* Adapted from dlls/urlmon/tests/protocol.c */
52 #define SET_EXPECT2(status, num) \
55 #define SET_EXPECT(status) \
56 SET_EXPECT2(status, 1)
58 #define SET_OPTIONAL2(status, num) \
59 optional[status] = num
61 #define SET_OPTIONAL(status) \
62 SET_OPTIONAL2(status, 1)
64 /* SET_WINE_ALLOW's should be used with an appropriate
65 * todo_wine CHECK_NOTIFIED at a later point in the code */
66 #define SET_WINE_ALLOW2(status, num) \
67 wine_allow[status] = num
69 #define SET_WINE_ALLOW(status) \
70 SET_WINE_ALLOW2(status, 1)
72 #define CHECK_EXPECT(status) \
74 if (!expect[status] && !optional[status] && wine_allow[status]) \
76 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
77 status < MAX_INTERNET_STATUS && status_string[status] ? \
78 status_string[status] : "unknown"); \
79 wine_allow[status]--; \
83 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
84 status < MAX_INTERNET_STATUS && status_string[status] ? \
85 status_string[status] : "unknown"); \
86 if (expect[status]) expect[status]--; \
87 else if(optional[status]) optional[status]--; \
92 /* CLEAR_NOTIFIED used in cases when notification behavior
93 * differs between Windows versions */
94 #define CLEAR_NOTIFIED(status) \
95 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
97 #define CHECK_NOTIFIED2(status, num) \
99 ok(notified[status] + optional[status] == (num), \
100 "expected status %d (%s) %d times, received %d times\n", \
101 status, status < MAX_INTERNET_STATUS && status_string[status] ? \
102 status_string[status] : "unknown", (num), notified[status]); \
103 CLEAR_NOTIFIED(status); \
106 #define CHECK_NOTIFIED(status) \
107 CHECK_NOTIFIED2(status, 1)
109 #define CHECK_NOT_NOTIFIED(status) \
110 CHECK_NOTIFIED2(status, 0)
112 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
113 static int expect
[MAX_INTERNET_STATUS
], optional
[MAX_INTERNET_STATUS
],
114 wine_allow
[MAX_INTERNET_STATUS
], notified
[MAX_INTERNET_STATUS
];
115 static const char *status_string
[MAX_INTERNET_STATUS
];
117 static HANDLE hCompleteEvent
, conn_close_event
;
118 static DWORD req_error
;
120 #define TESTF_REDIRECT 0x01
121 #define TESTF_COMPRESSED 0x02
122 #define TESTF_CHUNKED 0x04
126 const char *redirected_url
;
131 const char *post_data
;
135 static const test_data_t test_data
[] = {
137 "http://test.winehq.org/tests/data.php",
138 "http://test.winehq.org/tests/data.php",
145 "http://test.winehq.org/tests/redirect",
146 "http://test.winehq.org/tests/hello.html",
153 "http://test.winehq.org/tests/gzip.php",
154 "http://test.winehq.org/tests/gzip.php",
157 "Accept-Encoding: gzip, deflate",
161 "http://test.winehq.org/tests/post.php",
162 "http://test.winehq.org/tests/post.php",
165 "Content-Type: application/x-www-form-urlencoded",
172 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackA
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
173 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackW
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
174 static BOOL (WINAPI
*pInternetGetSecurityInfoByURLA
)(LPSTR
,PCCERT_CHAIN_CONTEXT
*,DWORD
*);
176 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
179 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
180 return lstrcmpW(strw
, buf
);
183 static BOOL
proxy_active(void)
185 HKEY internet_settings
;
189 if (RegOpenKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
190 0, KEY_QUERY_VALUE
, &internet_settings
) != ERROR_SUCCESS
)
193 size
= sizeof(DWORD
);
194 if (RegQueryValueExA(internet_settings
, "ProxyEnable", NULL
, NULL
, (LPBYTE
) &proxy_enable
, &size
) != ERROR_SUCCESS
)
197 RegCloseKey(internet_settings
);
199 return proxy_enable
!= 0;
202 #define test_status_code(a,b) _test_status_code(__LINE__,a,b, FALSE)
203 #define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)
204 static void _test_status_code(unsigned line
, HINTERNET req
, DWORD excode
, BOOL is_todo
)
206 DWORD code
, size
, index
;
207 char exbuf
[10], bufa
[10];
213 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, NULL
);
214 ok_(__FILE__
,line
)(res
, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
216 todo_wine
ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
218 ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
219 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
224 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
225 ok_(__FILE__
,line
)(res
, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
227 todo_wine
ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
229 ok_(__FILE__
,line
)(!index
, "index = %d, expected 0\n", code
);
230 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
232 sprintf(exbuf
, "%u", excode
);
235 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, bufa
, &size
, NULL
);
236 ok_(__FILE__
,line
)(res
, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
238 todo_wine
ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
240 ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
241 ok_(__FILE__
,line
)(size
== strlen(exbuf
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
244 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
245 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
246 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
247 ok_(__FILE__
,line
)(size
== strlen(exbuf
)+1, "unexpected size %d for \"%s\"\n", size
, exbuf
);
250 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
251 ok_(__FILE__
,line
)(res
, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
253 todo_wine
ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
255 ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
256 ok_(__FILE__
,line
)(size
== strlen(exbuf
)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
259 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
260 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
261 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
262 ok_(__FILE__
,line
)(size
== (strlen(exbuf
)+1)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
266 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
267 ok(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
268 ok(size
== sizeof(bufw
), "unexpected size %d\n", size
);
274 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
275 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
276 "[7] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
280 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, &code
, &size
, NULL
);
281 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST
,
282 "[8] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
285 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
286 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
287 static void _test_request_flags(unsigned line
, HINTERNET req
, DWORD exflags
, BOOL is_todo
)
293 size
= sizeof(flags
);
294 res
= InternetQueryOptionW(req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &size
);
295 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
297 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
298 flags
&= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED
;
300 ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
302 todo_wine
ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
305 #define test_http_version(a) _test_http_version(__LINE__,a)
306 static void _test_http_version(unsigned line
, HINTERNET req
)
308 HTTP_VERSION_INFO v
= {0xdeadbeef, 0xdeadbeef};
313 res
= InternetQueryOptionW(req
, INTERNET_OPTION_HTTP_VERSION
, &v
, &size
);
314 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
315 ok_(__FILE__
,line
)(v
.dwMajorVersion
== 1, "dwMajorVersion = %d\n", v
.dwMajorVersion
);
316 ok_(__FILE__
,line
)(v
.dwMinorVersion
== 1, "dwMinorVersion = %d\n", v
.dwMinorVersion
);
319 static int close_handle_cnt
;
321 static VOID WINAPI
callback(
324 DWORD dwInternetStatus
,
325 LPVOID lpvStatusInformation
,
326 DWORD dwStatusInformationLength
329 CHECK_EXPECT(dwInternetStatus
);
330 switch (dwInternetStatus
)
332 case INTERNET_STATUS_RESOLVING_NAME
:
333 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
334 GetCurrentThreadId(), hInternet
, dwContext
,
335 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
336 *(LPSTR
)lpvStatusInformation
= '\0';
338 case INTERNET_STATUS_NAME_RESOLVED
:
339 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
340 GetCurrentThreadId(), hInternet
, dwContext
,
341 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
342 *(LPSTR
)lpvStatusInformation
= '\0';
344 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
345 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
346 GetCurrentThreadId(), hInternet
, dwContext
,
347 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
348 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
349 dwStatusInformationLength
);
350 *(LPSTR
)lpvStatusInformation
= '\0';
352 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
353 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
354 GetCurrentThreadId(), hInternet
, dwContext
,
355 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
356 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
357 dwStatusInformationLength
);
358 *(LPSTR
)lpvStatusInformation
= '\0';
360 case INTERNET_STATUS_SENDING_REQUEST
:
361 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
362 GetCurrentThreadId(), hInternet
, dwContext
,
363 lpvStatusInformation
,dwStatusInformationLength
);
365 case INTERNET_STATUS_REQUEST_SENT
:
366 ok(dwStatusInformationLength
== sizeof(DWORD
),
367 "info length should be sizeof(DWORD) instead of %d\n",
368 dwStatusInformationLength
);
369 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
370 GetCurrentThreadId(), hInternet
, dwContext
,
371 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
373 case INTERNET_STATUS_RECEIVING_RESPONSE
:
374 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
375 GetCurrentThreadId(), hInternet
, dwContext
,
376 lpvStatusInformation
,dwStatusInformationLength
);
378 case INTERNET_STATUS_RESPONSE_RECEIVED
:
379 ok(dwStatusInformationLength
== sizeof(DWORD
),
380 "info length should be sizeof(DWORD) instead of %d\n",
381 dwStatusInformationLength
);
382 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
383 GetCurrentThreadId(), hInternet
, dwContext
,
384 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
386 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
387 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
388 GetCurrentThreadId(), hInternet
,dwContext
,
389 lpvStatusInformation
,dwStatusInformationLength
);
391 case INTERNET_STATUS_PREFETCH
:
392 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
393 GetCurrentThreadId(), hInternet
, dwContext
,
394 lpvStatusInformation
,dwStatusInformationLength
);
396 case INTERNET_STATUS_CLOSING_CONNECTION
:
397 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
398 GetCurrentThreadId(), hInternet
, dwContext
,
399 lpvStatusInformation
,dwStatusInformationLength
);
401 case INTERNET_STATUS_CONNECTION_CLOSED
:
402 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
403 GetCurrentThreadId(), hInternet
, dwContext
,
404 lpvStatusInformation
,dwStatusInformationLength
);
406 case INTERNET_STATUS_HANDLE_CREATED
:
407 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
408 "info length should be sizeof(HINTERNET) instead of %d\n",
409 dwStatusInformationLength
);
410 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
411 GetCurrentThreadId(), hInternet
, dwContext
,
412 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
413 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
414 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
416 case INTERNET_STATUS_HANDLE_CLOSING
:
417 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
418 "info length should be sizeof(HINTERNET) instead of %d\n",
419 dwStatusInformationLength
);
420 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
421 GetCurrentThreadId(), hInternet
, dwContext
,
422 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
423 if(!InterlockedDecrement(&close_handle_cnt
))
424 SetEvent(hCompleteEvent
);
426 case INTERNET_STATUS_REQUEST_COMPLETE
:
428 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
429 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
430 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
431 dwStatusInformationLength
);
432 ok(iar
->dwResult
== 1 || iar
->dwResult
== 0, "iar->dwResult = %ld\n", iar
->dwResult
);
433 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
434 GetCurrentThreadId(), hInternet
, dwContext
,
435 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
436 req_error
= iar
->dwError
;
437 if(!close_handle_cnt
)
438 SetEvent(hCompleteEvent
);
441 case INTERNET_STATUS_REDIRECT
:
442 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
443 GetCurrentThreadId(), hInternet
, dwContext
,
444 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
445 *(LPSTR
)lpvStatusInformation
= '\0';
446 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
447 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
449 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
450 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
451 GetCurrentThreadId(), hInternet
, dwContext
,
452 lpvStatusInformation
, dwStatusInformationLength
);
455 trace("%04x:Callback %p 0x%lx %d %p %d\n",
456 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
457 lpvStatusInformation
, dwStatusInformationLength
);
461 static void close_async_handle(HINTERNET handle
, HANDLE complete_event
, int handle_cnt
)
465 close_handle_cnt
= handle_cnt
;
467 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
468 res
= InternetCloseHandle(handle
);
469 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
470 WaitForSingleObject(hCompleteEvent
, INFINITE
);
471 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
474 static void InternetReadFile_test(int flags
, const test_data_t
*test
)
476 char *post_data
= NULL
;
477 BOOL res
, on_async
= TRUE
;
480 DWORD length
, length2
, index
, exlen
= 0, post_len
= 0;
481 const char *types
[2] = { "*", NULL
};
482 HINTERNET hi
, hic
= 0, hor
= 0;
484 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
486 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags
,test
->url
);
488 trace("InternetOpenA <--\n");
489 hi
= InternetOpenA((test
->flags
& TESTF_COMPRESSED
) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
490 INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
491 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
492 trace("InternetOpenA -->\n");
494 if (hi
== 0x0) goto abort
;
496 pInternetSetStatusCallbackA(hi
,&callback
);
498 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
500 trace("InternetConnectA <--\n");
501 hic
=InternetConnectA(hi
, test
->host
, INTERNET_INVALID_PORT_NUMBER
,
502 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
503 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
504 trace("InternetConnectA -->\n");
506 if (hic
== 0x0) goto abort
;
508 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
509 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
511 trace("HttpOpenRequestA <--\n");
512 hor
= HttpOpenRequestA(hic
, test
->post_data
? "POST" : "GET", test
->path
, NULL
, NULL
, types
,
513 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
515 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
517 * If the internet name can't be resolved we are probably behind
518 * a firewall or in some other way not directly connected to the
519 * Internet. Not enough reason to fail the test. Just ignore and
523 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
525 trace("HttpOpenRequestA -->\n");
527 if (hor
== 0x0) goto abort
;
529 test_request_flags(hor
, INTERNET_REQFLAG_NO_HEADERS
);
531 length
= sizeof(buffer
);
532 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
533 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
534 ok(!strcmp(buffer
, test
->url
), "Wrong URL %s, expected %s\n", buffer
, test
->url
);
536 length
= sizeof(buffer
);
537 res
= HttpQueryInfoA(hor
, HTTP_QUERY_RAW_HEADERS
, buffer
, &length
, 0x0);
538 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
539 ok(length
== 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length
);
540 ok(!strcmp(buffer
, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer
);
542 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
543 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
544 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
545 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
,2);
546 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED
,2);
547 if (first_connection_to_test_url
)
549 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
550 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
552 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
553 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
554 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
555 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
556 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
557 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
558 if(test
->flags
& TESTF_REDIRECT
) {
559 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
560 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
562 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
563 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
564 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
565 if (flags
& INTERNET_FLAG_ASYNC
)
566 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
568 if(test
->flags
& TESTF_COMPRESSED
) {
571 res
= InternetSetOptionA(hor
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
572 ok(res
|| broken(!res
&& GetLastError() == ERROR_INTERNET_INVALID_OPTION
),
573 "InternetSetOption failed: %u\n", GetLastError());
578 test_status_code(hor
, 0);
580 trace("HttpSendRequestA -->\n");
581 if(test
->post_data
) {
582 post_len
= strlen(test
->post_data
);
583 post_data
= HeapAlloc(GetProcessHeap(), 0, post_len
);
584 memcpy(post_data
, test
->post_data
, post_len
);
586 SetLastError(0xdeadbeef);
587 res
= HttpSendRequestA(hor
, test
->headers
, -1, post_data
, post_len
);
588 if (flags
& INTERNET_FLAG_ASYNC
)
589 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
590 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
592 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
593 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
594 trace("HttpSendRequestA <--\n");
596 if (flags
& INTERNET_FLAG_ASYNC
) {
597 WaitForSingleObject(hCompleteEvent
, INFINITE
);
598 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
600 HeapFree(GetProcessHeap(), 0, post_data
);
602 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
603 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED
);
604 if (first_connection_to_test_url
)
606 if (! proxy_active())
608 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
609 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
613 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
614 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
619 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
620 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
622 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
623 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
624 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
625 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
626 if(test
->flags
& TESTF_REDIRECT
)
627 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
628 if (flags
& INTERNET_FLAG_ASYNC
)
629 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
630 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
631 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
632 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
634 test_request_flags(hor
, 0);
637 res
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
638 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
640 length
= sizeof(buffer
)-1;
641 memset(buffer
, 0x77, sizeof(buffer
));
642 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
643 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
644 /* show that the function writes data past the length returned */
645 ok(buffer
[length
-2], "Expected any header character, got 0x00\n");
646 ok(!buffer
[length
-1], "Expected 0x00, got %02X\n", buffer
[length
-1]);
647 ok(!buffer
[length
], "Expected 0x00, got %02X\n", buffer
[length
]);
648 ok(buffer
[length
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length
+1]);
651 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
652 ok(!res
, "Expected 0x00, got %d\n", res
);
653 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
654 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
655 /* the in length of the buffer must be +1 but the length returned does not count this */
657 memset(buffer
, 0x77, sizeof(buffer
));
658 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
659 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
660 ok(buffer
[length2
] == 0x00, "Expected 0x00, got %02X\n", buffer
[length2
]);
661 ok(buffer
[length2
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length2
+1]);
662 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
664 length
= sizeof(wbuffer
)-sizeof(WCHAR
);
665 memset(wbuffer
, 0x77, sizeof(wbuffer
));
666 res
= HttpQueryInfoW(hor
, HTTP_QUERY_RAW_HEADERS
, wbuffer
, &length
, 0x0);
667 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
668 ok(length
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length
);
669 length
/= sizeof(WCHAR
);
670 /* show that the function writes data past the length returned */
671 ok(wbuffer
[length
-2], "Expected any header character, got 0x0000\n");
672 ok(!wbuffer
[length
-1], "Expected 0x0000, got %04X\n", wbuffer
[length
-1]);
673 ok(!wbuffer
[length
], "Expected 0x0000, got %04X\n", wbuffer
[length
]);
674 ok(wbuffer
[length
+1] == 0x7777 || broken(wbuffer
[length
+1] != 0x7777),
675 "Expected 0x7777, got %04X\n", wbuffer
[length
+1]);
677 length2
= length
*sizeof(WCHAR
);
678 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
679 ok(!res
, "Expected 0x00, got %d\n", res
);
680 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
681 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
682 length2
/= sizeof(WCHAR
);
683 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
684 /* the in length of the buffer must be +1 but the length returned does not count this */
685 length2
= (length
+1)*sizeof(WCHAR
);
686 memset(wbuffer
, 0x77, sizeof(wbuffer
));
687 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
688 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
689 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
690 length2
/= sizeof(WCHAR
);
691 ok(!wbuffer
[length2
], "Expected 0x0000, got %04X\n", wbuffer
[length2
]);
692 ok(wbuffer
[length2
+1] == 0x7777, "Expected 0x7777, got %04X\n", wbuffer
[length2
+1]);
693 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
695 length
= sizeof(buffer
);
696 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
697 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
698 ok(!strcmp(buffer
, test
->redirected_url
), "Wrong URL %s\n", buffer
);
702 SetLastError(0xdeadbeef);
703 ok(HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,NULL
,&length
,&index
) == FALSE
,"Query worked\n");
704 if(test
->flags
& TESTF_COMPRESSED
)
705 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
706 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
707 ok(index
== 0, "Index was incremented\n");
711 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,&index
);
712 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res
,buffer
,GetLastError());
713 if(test
->flags
& TESTF_COMPRESSED
)
714 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
715 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res
, GetLastError());
716 ok(!res
|| index
== 1, "Index was not incremented although result is %x (index = %u)\n", res
, index
);
719 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
721 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res
,buffer
);
724 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_ENCODING
,buffer
,&length
,0x0);
726 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res
,buffer
);
728 SetLastError(0xdeadbeef);
729 res
= InternetReadFile(NULL
, buffer
, 100, &length
);
730 ok(!res
, "InternetReadFile should have failed\n");
731 ok(GetLastError() == ERROR_INVALID_HANDLE
,
732 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
736 trace("Entering Query loop\n");
740 if (flags
& INTERNET_FLAG_ASYNC
)
741 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
743 /* IE11 calls those in InternetQueryDataAvailable call. */
744 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
745 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
748 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
750 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
752 if (flags
& INTERNET_FLAG_ASYNC
)
756 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
758 ok(length
>= exlen
, "length %u < exlen %u\n", length
, exlen
);
762 else if (GetLastError() == ERROR_IO_PENDING
)
765 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
766 if(!(test
->flags
& TESTF_CHUNKED
))
767 ok(!length
, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length
);
768 WaitForSingleObject(hCompleteEvent
, INFINITE
);
770 ok(exlen
, "length = 0\n");
771 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
772 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
773 ok(req_error
, "req_error = 0\n");
776 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
779 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
781 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
783 trace("LENGTH %d\n", length
);
784 if(test
->flags
& TESTF_CHUNKED
)
785 ok(length
<= 8192, "length = %d, expected <= 8192\n", length
);
789 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
791 res
= InternetReadFile(hor
,buffer
,length
,&length
);
795 trace("ReadFile -> %s %i\n",res
?"TRUE":"FALSE",length
);
798 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
799 HeapFree(GetProcessHeap(),0,buffer
);
801 ok(!on_async
, "Returned zero size in response to request complete\n");
806 if(test
->flags
& TESTF_REDIRECT
) {
807 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
808 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
812 close_async_handle(hi
, hCompleteEvent
, 2);
813 CloseHandle(hCompleteEvent
);
814 first_connection_to_test_url
= FALSE
;
817 static void InternetReadFile_chunked_test(void)
822 const char *types
[2] = { "*", NULL
};
823 HINTERNET hi
, hic
= 0, hor
= 0;
825 trace("Starting InternetReadFile chunked test\n");
827 trace("InternetOpenA <--\n");
828 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
829 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
830 trace("InternetOpenA -->\n");
832 if (hi
== 0x0) goto abort
;
834 trace("InternetConnectA <--\n");
835 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
836 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
837 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
838 trace("InternetConnectA -->\n");
840 if (hic
== 0x0) goto abort
;
842 trace("HttpOpenRequestA <--\n");
843 hor
= HttpOpenRequestA(hic
, "GET", "/tests/chunked", NULL
, NULL
, types
,
844 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
846 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
848 * If the internet name can't be resolved we are probably behind
849 * a firewall or in some other way not directly connected to the
850 * Internet. Not enough reason to fail the test. Just ignore and
854 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
856 trace("HttpOpenRequestA -->\n");
858 if (hor
== 0x0) goto abort
;
860 trace("HttpSendRequestA -->\n");
861 SetLastError(0xdeadbeef);
862 res
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
863 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
864 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
865 trace("HttpSendRequestA <--\n");
867 test_request_flags(hor
, 0);
870 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
872 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
874 SetLastError( 0xdeadbeef );
876 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
878 trace("Option TRANSFER_ENCODING -> %i %s\n",res
,buffer
);
879 ok( res
|| ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
880 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
881 ok( !strcmp( buffer
, "chunked" ) || ( ! res
&& proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
882 "Wrong transfer encoding '%s'\n", buffer
);
884 SetLastError( 0xdeadbeef );
886 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
887 ok( !res
, "Found CONTENT_LENGTH option '%s'\n", buffer
);
888 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Wrong error %u\n", GetLastError() );
891 trace("Entering Query loop\n");
895 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
896 ok(!(!res
&& length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
897 ok(res
, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
898 trace("got %u available\n",length
);
901 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
903 res
= InternetReadFile(hor
,buffer
,length
,&got
);
906 trace("ReadFile -> %i %i\n",res
,got
);
907 ok( length
== got
, "only got %u of %u available\n", got
, length
);
908 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
910 HeapFree(GetProcessHeap(),0,buffer
);
916 res
= InternetReadFile( hor
, buffer
, 1, &got
);
917 ok( res
, "InternetReadFile failed: %u\n", GetLastError() );
918 ok( !got
, "got %u\n", got
);
925 res
= InternetCloseHandle(hor
);
926 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
929 res
= InternetCloseHandle(hi
);
930 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
934 static void InternetReadFileExA_test(int flags
)
938 const char *types
[2] = { "*", NULL
};
939 HINTERNET hi
, hic
= 0, hor
= 0;
940 INTERNET_BUFFERSA inetbuffers
;
942 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
944 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
946 trace("InternetOpenA <--\n");
947 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
948 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
949 trace("InternetOpenA -->\n");
951 if (hi
== 0x0) goto abort
;
953 pInternetSetStatusCallbackA(hi
,&callback
);
955 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
957 trace("InternetConnectA <--\n");
958 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
959 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
960 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
961 trace("InternetConnectA -->\n");
963 if (hic
== 0x0) goto abort
;
965 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
966 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
968 trace("HttpOpenRequestA <--\n");
969 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
970 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
972 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
974 * If the internet name can't be resolved we are probably behind
975 * a firewall or in some other way not directly connected to the
976 * Internet. Not enough reason to fail the test. Just ignore and
980 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
982 trace("HttpOpenRequestA -->\n");
984 if (hor
== 0x0) goto abort
;
986 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
987 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
988 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
989 if (first_connection_to_test_url
)
991 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
992 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
994 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
, 2);
995 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
996 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
997 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
998 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
999 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1000 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1001 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1002 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1003 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
1004 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1005 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1006 if (flags
& INTERNET_FLAG_ASYNC
)
1007 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1009 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1011 trace("HttpSendRequestA -->\n");
1012 SetLastError(0xdeadbeef);
1013 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
1014 if (flags
& INTERNET_FLAG_ASYNC
)
1015 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
1016 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
1018 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
1019 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
1020 trace("HttpSendRequestA <--\n");
1022 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
1023 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1024 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1027 if (first_connection_to_test_url
)
1029 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1030 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1034 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1035 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1037 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1038 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
1039 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1040 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1041 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1042 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1043 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
1044 if (flags
& INTERNET_FLAG_ASYNC
)
1045 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1047 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1048 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
1049 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
1050 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1051 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1053 /* tests invalid dwStructSize */
1054 inetbuffers
.dwStructSize
= sizeof(inetbuffers
)+1;
1055 inetbuffers
.lpcszHeader
= NULL
;
1056 inetbuffers
.dwHeadersLength
= 0;
1057 inetbuffers
.dwBufferLength
= 10;
1058 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
1059 inetbuffers
.dwOffsetHigh
= 1234;
1060 inetbuffers
.dwOffsetLow
= 5678;
1061 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1062 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1063 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1064 rc
? "TRUE" : "FALSE", GetLastError());
1065 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1067 test_request_flags(hor
, 0);
1069 /* tests to see whether lpcszHeader is used - it isn't */
1070 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1071 inetbuffers
.lpcszHeader
= (LPCSTR
)0xdeadbeef;
1072 inetbuffers
.dwHeadersLength
= 255;
1073 inetbuffers
.dwBufferLength
= 0;
1074 inetbuffers
.lpvBuffer
= NULL
;
1075 inetbuffers
.dwOffsetHigh
= 1234;
1076 inetbuffers
.dwOffsetLow
= 5678;
1077 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
1078 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
1079 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1080 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
1081 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1084 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1085 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1088 rc
= InternetReadFileExA(NULL
, &inetbuffers
, 0, 0xdeadcafe);
1089 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
1090 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1091 rc
? "TRUE" : "FALSE", GetLastError());
1094 trace("Entering Query loop\n");
1098 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1099 inetbuffers
.dwBufferLength
= 1024;
1100 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
1101 inetbuffers
.dwOffsetHigh
= 1234;
1102 inetbuffers
.dwOffsetLow
= 5678;
1104 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1105 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1106 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1107 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
1110 if (GetLastError() == ERROR_IO_PENDING
)
1112 trace("InternetReadFileEx -> PENDING\n");
1113 ok(flags
& INTERNET_FLAG_ASYNC
,
1114 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1115 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1116 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1117 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1118 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1119 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1123 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1129 trace("InternetReadFileEx -> SUCCEEDED\n");
1130 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1131 if (inetbuffers
.dwBufferLength
)
1134 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1135 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1140 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1141 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1142 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1146 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1147 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
1149 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
1150 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1151 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
1153 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1155 if (!inetbuffers
.dwBufferLength
)
1158 length
+= inetbuffers
.dwBufferLength
;
1160 ok(length
> 0, "failed to read any of the document\n");
1161 trace("Finished. Read %d bytes\n", length
);
1164 close_async_handle(hi
, hCompleteEvent
, 2);
1165 CloseHandle(hCompleteEvent
);
1166 first_connection_to_test_url
= FALSE
;
1169 static void InternetOpenUrlA_test(void)
1171 HINTERNET myhinternet
, myhttp
;
1173 DWORD size
, readbytes
, totalbytes
=0;
1176 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1177 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
1178 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret
, GetLastError());
1180 myhinternet
= InternetOpenA("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
1181 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
1183 ret
= InternetCanonicalizeUrlA(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1184 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1187 myhttp
= InternetOpenUrlA(myhinternet
, TEST_URL
, 0, 0,
1188 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
1189 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1190 return; /* WinXP returns this when not connected to the net */
1191 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1192 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
1193 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
1194 totalbytes
+= readbytes
;
1195 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
1196 totalbytes
+= readbytes
;
1197 trace("read 0x%08x bytes\n",totalbytes
);
1199 InternetCloseHandle(myhttp
);
1200 InternetCloseHandle(myhinternet
);
1202 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1203 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1206 static void HttpSendRequestEx_test(void)
1212 INTERNET_BUFFERSA BufferIn
;
1213 DWORD dwBytesWritten
, dwBytesRead
, error
;
1218 static char szPostData
[] = "mode=Test";
1219 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
1221 hSession
= InternetOpenA("Wine Regression Test",
1222 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1223 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1224 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1225 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1227 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1228 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1229 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1230 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1232 skip( "Network unreachable, skipping test\n" );
1235 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1237 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1239 BufferIn
.dwStructSize
= sizeof(BufferIn
);
1240 BufferIn
.Next
= (INTERNET_BUFFERSA
*)0xdeadcab;
1241 BufferIn
.lpcszHeader
= szContentType
;
1242 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1243 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1244 BufferIn
.lpvBuffer
= szPostData
;
1245 BufferIn
.dwBufferLength
= 3;
1246 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1247 BufferIn
.dwOffsetLow
= 0;
1248 BufferIn
.dwOffsetHigh
= 0;
1250 SetLastError(0xdeadbeef);
1251 ret
= HttpSendRequestExA(hRequest
, &BufferIn
, NULL
, 0 ,0);
1252 error
= GetLastError();
1253 ok(ret
, "HttpSendRequestEx Failed with error %u\n", error
);
1254 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", error
);
1256 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1258 for (i
= 3; szPostData
[i
]; i
++)
1259 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1260 "InternetWriteFile failed\n");
1262 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1264 ok(HttpEndRequestA(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1266 test_request_flags(hRequest
, 0);
1268 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1269 "Unable to read response\n");
1270 szBuffer
[dwBytesRead
] = 0;
1272 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
1273 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1275 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1277 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1278 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1281 static void InternetOpenRequest_test(void)
1283 HINTERNET session
, connect
, request
;
1284 static const char *types
[] = { "*", "", NULL
};
1285 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1286 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1289 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1290 ok(session
!= NULL
,"Unable to open Internet session\n");
1292 connect
= InternetConnectA(session
, NULL
, 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 NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1297 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1298 INTERNET_SERVICE_HTTP
, 0, 0);
1299 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1300 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1302 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1303 INTERNET_SERVICE_HTTP
, 0, 0);
1304 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1306 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1307 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1309 skip( "Network unreachable, skipping test\n" );
1312 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1314 ret
= HttpSendRequestW(request
, NULL
, 0, NULL
, 0);
1315 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1316 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1318 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1319 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1321 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1322 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1323 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1326 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1327 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1330 static void test_cache_read(void)
1332 HINTERNET session
, connection
, req
;
1333 FILETIME now
, tomorrow
, yesterday
;
1334 BYTE content
[1000], buf
[2000];
1335 char file_path
[MAX_PATH
];
1342 static const char cache_only_url
[] = "http://test.winehq.org/tests/cache-only";
1343 BYTE cache_headers
[] = "HTTP/1.1 200 OK\r\n\r\n";
1345 trace("Testing cache read...\n");
1347 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1349 for(i
= 0; i
< sizeof(content
); i
++)
1350 content
[i
] = '0' + (i
%10);
1352 GetSystemTimeAsFileTime(&now
);
1353 li
.u
.HighPart
= now
.dwHighDateTime
;
1354 li
.u
.LowPart
= now
.dwLowDateTime
;
1355 li
.QuadPart
+= (LONGLONG
)10000000 * 3600 * 24;
1356 tomorrow
.dwHighDateTime
= li
.u
.HighPart
;
1357 tomorrow
.dwLowDateTime
= li
.u
.LowPart
;
1358 li
.QuadPart
-= (LONGLONG
)10000000 * 3600 * 24 * 2;
1359 yesterday
.dwHighDateTime
= li
.u
.HighPart
;
1360 yesterday
.dwLowDateTime
= li
.u
.LowPart
;
1362 res
= CreateUrlCacheEntryA(cache_only_url
, sizeof(content
), "", file_path
, 0);
1363 ok(res
, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1365 file
= CreateFileA(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1366 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
1368 WriteFile(file
, content
, sizeof(content
), &size
, NULL
);
1371 res
= CommitUrlCacheEntryA(cache_only_url
, file_path
, tomorrow
, yesterday
, NORMAL_CACHE_ENTRY
,
1372 cache_headers
, sizeof(cache_headers
)-1, "", 0);
1373 ok(res
, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1375 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
1376 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
1378 pInternetSetStatusCallbackA(session
, callback
);
1380 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1381 connection
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
,
1382 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1383 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
1384 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1386 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1387 req
= HttpOpenRequestA(connection
, "GET", "/tests/cache-only", NULL
, NULL
, NULL
, 0, 0xdeadbead);
1388 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
1389 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1391 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1392 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1393 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST
);
1394 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT
);
1395 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1396 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1397 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1399 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
1401 ok(res
, "HttpSendRequest failed: %u\n", GetLastError());
1405 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
1406 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1407 ok(size
== sizeof(content
), "size = %u\n", size
);
1410 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
1411 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
1412 ok(size
== sizeof(content
), "size = %u\n", size
);
1413 ok(!memcmp(content
, buf
, sizeof(content
)), "unexpected content\n");
1416 close_async_handle(session
, hCompleteEvent
, 2);
1418 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1419 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1420 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
1421 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
1422 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1423 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1424 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1426 res
= DeleteUrlCacheEntryA(cache_only_url
);
1427 ok(res
, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1429 CloseHandle(hCompleteEvent
);
1432 static void test_http_cache(void)
1434 HINTERNET session
, connect
, request
;
1435 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1436 DWORD size
, file_size
;
1440 FILETIME filetime_zero
= {0};
1442 static const char cached_content
[] = "data read from cache";
1443 static const char *types
[] = { "*", "", NULL
};
1445 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1446 ok(session
!= NULL
,"Unable to open Internet session\n");
1448 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1449 INTERNET_SERVICE_HTTP
, 0, 0);
1450 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1452 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1453 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1455 skip( "Network unreachable, skipping test\n" );
1457 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1458 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1462 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1465 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1466 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1467 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1469 size
= sizeof(file_name
);
1470 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1471 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1472 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1473 ok(!size
, "size = %d\n", size
);
1475 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1476 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1478 size
= sizeof(file_name
);
1479 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1480 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1482 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1483 FILE_ATTRIBUTE_NORMAL
, NULL
);
1484 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1485 file_size
= GetFileSize(file
, NULL
);
1486 ok(file_size
== 106, "file size = %u\n", file_size
);
1489 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1490 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1491 ok(size
== 100, "size = %u\n", size
);
1493 file_size
= GetFileSize(file
, NULL
);
1494 ok(file_size
== 106, "file size = %u\n", file_size
);
1497 ret
= DeleteFileA(file_name
);
1498 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1500 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1502 file
= CreateFileA(file_name
, GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1503 FILE_ATTRIBUTE_NORMAL
, NULL
);
1504 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1505 ret
= WriteFile(file
, cached_content
, sizeof(cached_content
), &size
, NULL
);
1506 ok(ret
&& size
, "WriteFile failed: %d, %d\n", ret
, size
);
1507 ret
= CommitUrlCacheEntryA(url
, file_name
, filetime_zero
, filetime_zero
, NORMAL_CACHE_ENTRY
, NULL
, 0, NULL
, 0);
1508 ok(ret
, "CommitUrlCacheEntry failed: %d\n", GetLastError());
1511 /* Send the same request, requiring it to be retrieved from the cache */
1512 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1514 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1515 ok(ret
, "HttpSendRequest failed\n");
1518 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1519 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1520 ok(size
== 100, "size = %u\n", size
);
1522 todo_wine
ok(!strcmp((char*)buf
, cached_content
), "incorrect page data: %s\n", (char*)buf
);
1524 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1526 DeleteUrlCacheEntryA(url
);
1527 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1528 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1529 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
1531 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError() = %d\n", GetLastError());
1532 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1534 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1535 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1537 size
= sizeof(file_name
);
1538 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1539 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1540 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1541 ok(!size
, "size = %d\n", size
);
1543 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1544 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1546 size
= sizeof(file_name
);
1548 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1551 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1552 FILE_ATTRIBUTE_NORMAL
, NULL
);
1553 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1559 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1562 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1563 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1564 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1569 static void InternetLockRequestFile_test(void)
1571 HINTERNET session
, connect
, request
;
1572 char file_name
[MAX_PATH
];
1577 static const char *types
[] = { "*", "", NULL
};
1579 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1580 ok(session
!= NULL
,"Unable to open Internet session\n");
1582 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1583 INTERNET_SERVICE_HTTP
, 0, 0);
1584 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1586 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
|INTERNET_FLAG_RELOAD
, 0);
1587 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1589 skip( "Network unreachable, skipping test\n" );
1591 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1592 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1596 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1598 size
= sizeof(file_name
);
1599 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1600 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1601 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1602 ok(!size
, "size = %d\n", size
);
1605 ret
= InternetLockRequestFile(request
, &lock
);
1606 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1608 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1609 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1611 size
= sizeof(file_name
);
1612 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1613 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1615 ret
= InternetLockRequestFile(request
, &lock
);
1616 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1617 ok(lock
!= NULL
, "lock == NULL\n");
1619 ret
= InternetLockRequestFile(request
, &lock2
);
1620 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1621 ok(lock
== lock2
, "lock != lock2\n");
1623 ret
= InternetUnlockRequestFile(lock2
);
1624 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1626 ret
= DeleteFileA(file_name
);
1627 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1629 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1631 ret
= DeleteFileA(file_name
);
1632 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1634 ret
= InternetUnlockRequestFile(lock
);
1635 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1637 ret
= DeleteFileA(file_name
);
1638 ok(ret
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1641 static void HttpHeaders_test(void)
1653 hSession
= InternetOpenA("Wine Regression Test",
1654 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1655 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1656 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1657 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1659 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1660 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1661 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1662 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1664 skip( "Network unreachable, skipping test\n" );
1667 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1670 len
= sizeof(buffer
);
1671 strcpy(buffer
,"Warning");
1672 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1673 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1675 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1676 "Failed to add new header\n");
1679 len
= sizeof(buffer
);
1680 strcpy(buffer
,"Warning");
1681 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1682 buffer
,&len
,&index
),"Unable to query header\n");
1683 ok(index
== 1, "Index was not incremented\n");
1684 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1685 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1686 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1687 len
= sizeof(buffer
);
1688 strcpy(buffer
,"Warning");
1689 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1690 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1693 len
= 5; /* could store the string but not the NULL terminator */
1694 strcpy(buffer
,"Warning");
1695 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1696 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1697 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1698 ok(index
== 0, "Index was incremented\n");
1699 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1700 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1702 /* a call with NULL will fail but will return the length */
1704 len
= sizeof(buffer
);
1705 SetLastError(0xdeadbeef);
1706 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1707 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1708 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1709 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1710 ok(index
== 0, "Index was incremented\n");
1712 /* even for a len that is too small */
1715 SetLastError(0xdeadbeef);
1716 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1717 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1718 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1719 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1720 ok(index
== 0, "Index was incremented\n");
1724 SetLastError(0xdeadbeef);
1725 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1726 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1727 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1728 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1729 ok(index
== 0, "Index was incremented\n");
1730 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1733 /* a working query */
1735 len
= sizeof(buffer
);
1736 memset(buffer
, 'x', sizeof(buffer
));
1737 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1738 buffer
,&len
,&index
),"Unable to query header\n");
1739 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1740 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1741 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1742 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1743 ok(strncmp(buffer
, "POST /tests/post.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1744 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1745 ok(index
== 0, "Index was incremented\n");
1747 /* Like above two tests, but for W version */
1751 SetLastError(0xdeadbeef);
1752 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1753 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1754 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1755 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1756 ok(index
== 0, "Index was incremented\n");
1757 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1759 /* a working query */
1761 len
= sizeof(wbuffer
);
1762 memset(wbuffer
, 'x', sizeof(wbuffer
));
1763 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1764 wbuffer
,&len
,&index
),"Unable to query header\n");
1765 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1766 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1767 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1768 ok(index
== 0, "Index was incremented\n");
1770 /* end of W version tests */
1772 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1774 len
= sizeof(buffer
);
1775 memset(buffer
, 'x', sizeof(buffer
));
1776 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1777 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1778 ok(len
== 2, "Expected 2, got %d\n", len
);
1779 ok(strcmp(buffer
, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer
);
1780 ok(index
== 0, "Index was incremented\n");
1782 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1783 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1786 len
= sizeof(buffer
);
1787 strcpy(buffer
,"Warning");
1788 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1789 buffer
,&len
,&index
),"Unable to query header\n");
1790 ok(index
== 1, "Index was not incremented\n");
1791 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1792 len
= sizeof(buffer
);
1793 strcpy(buffer
,"Warning");
1794 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1795 buffer
,&len
,&index
),"Failed to get second header\n");
1796 ok(index
== 2, "Index was not incremented\n");
1797 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1798 len
= sizeof(buffer
);
1799 strcpy(buffer
,"Warning");
1800 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1801 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1803 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1806 len
= sizeof(buffer
);
1807 strcpy(buffer
,"Warning");
1808 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1809 buffer
,&len
,&index
),"Unable to query header\n");
1810 ok(index
== 1, "Index was not incremented\n");
1811 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1812 len
= sizeof(buffer
);
1813 strcpy(buffer
,"Warning");
1814 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1815 buffer
,&len
,&index
),"Failed to get second header\n");
1816 ok(index
== 2, "Index was not incremented\n");
1817 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1818 len
= sizeof(buffer
);
1819 strcpy(buffer
,"Warning");
1820 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1821 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1823 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1826 len
= sizeof(buffer
);
1827 strcpy(buffer
,"Warning");
1828 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1829 buffer
,&len
,&index
),"Unable to query header\n");
1830 ok(index
== 1, "Index was not incremented\n");
1831 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1832 len
= sizeof(buffer
);
1833 strcpy(buffer
,"Warning");
1834 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1835 buffer
,&len
,&index
),"Failed to get second header\n");
1836 ok(index
== 2, "Index was not incremented\n");
1837 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1838 len
= sizeof(buffer
);
1839 strcpy(buffer
,"Warning");
1840 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1841 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1843 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1846 len
= sizeof(buffer
);
1847 strcpy(buffer
,"Warning");
1848 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1849 buffer
,&len
,&index
),"Unable to query header\n");
1850 ok(index
== 1, "Index was not incremented\n");
1851 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1852 len
= sizeof(buffer
);
1853 strcpy(buffer
,"Warning");
1854 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1855 ok(index
== 2, "Index was not incremented\n");
1856 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1857 len
= sizeof(buffer
);
1858 strcpy(buffer
,"Warning");
1859 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1861 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1864 len
= sizeof(buffer
);
1865 strcpy(buffer
,"Warning");
1866 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1867 ok(index
== 1, "Index was not incremented\n");
1868 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1869 len
= sizeof(buffer
);
1870 strcpy(buffer
,"Warning");
1871 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1872 ok(index
== 2, "Index was not incremented\n");
1873 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1874 len
= sizeof(buffer
);
1875 strcpy(buffer
,"Warning");
1876 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1878 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1881 len
= sizeof(buffer
);
1882 strcpy(buffer
,"Warning");
1883 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1884 ok(index
== 1, "Index was not incremented\n");
1885 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1886 len
= sizeof(buffer
);
1887 strcpy(buffer
,"Warning");
1888 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1889 ok(index
== 2, "Index was not incremented\n");
1890 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1891 len
= sizeof(buffer
);
1892 strcpy(buffer
,"Warning");
1893 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1895 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");
1898 len
= sizeof(buffer
);
1899 strcpy(buffer
,"Warning");
1900 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1901 ok(index
== 1, "Index was not incremented\n");
1902 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1903 len
= sizeof(buffer
);
1904 strcpy(buffer
,"Warning");
1905 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1906 ok(index
== 2, "Index was not incremented\n");
1907 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1908 len
= sizeof(buffer
);
1909 strcpy(buffer
,"Warning");
1910 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1912 /* Ensure that blank headers are ignored and don't cause a failure */
1913 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");
1916 len
= sizeof(buffer
);
1917 strcpy(buffer
,"BlankTest");
1918 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1919 ok(index
== 1, "Index was not incremented\n");
1920 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1922 /* Ensure that malformed header separators are ignored and don't cause a failure */
1923 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
),
1924 "Failed to add header with malformed entries in list\n");
1927 len
= sizeof(buffer
);
1928 strcpy(buffer
,"MalformedTest");
1929 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1930 ok(index
== 1, "Index was not incremented\n");
1931 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1933 len
= sizeof(buffer
);
1934 strcpy(buffer
,"MalformedTestTwo");
1935 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1936 ok(index
== 1, "Index was not incremented\n");
1937 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
1939 len
= sizeof(buffer
);
1940 strcpy(buffer
,"MalformedTestThree");
1941 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1942 ok(index
== 1, "Index was not incremented\n");
1943 ok(strcmp(buffer
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
1945 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD
);
1946 ok(ret
, "unable to add header %u\n", GetLastError());
1950 len
= sizeof(buffer
);
1951 ret
= HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
);
1952 ok(ret
, "unable to query header %u\n", GetLastError());
1953 ok(index
== 1, "index was not incremented\n");
1954 ok(!strcmp(buffer
, "Basic"), "incorrect string was returned (%s)\n", buffer
);
1956 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE
);
1957 ok(ret
, "unable to remove header %u\n", GetLastError());
1960 len
= sizeof(buffer
);
1961 SetLastError(0xdeadbeef);
1962 ok(!HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
),
1963 "header still present\n");
1964 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "got %u\n", GetLastError());
1966 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1968 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1969 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1972 static const char garbagemsg
[] =
1973 "Garbage: Header\r\n";
1975 static const char contmsg
[] =
1976 "HTTP/1.1 100 Continue\r\n";
1978 static const char expandcontmsg
[] =
1979 "HTTP/1.1 100 Continue\r\n"
1980 "Server: winecontinue\r\n"
1981 "Tag: something witty\r\n"
1984 static const char okmsg
[] =
1985 "HTTP/1.1 200 OK\r\n"
1986 "Server: winetest\r\n"
1989 static const char okmsg2
[] =
1990 "HTTP/1.1 200 OK\r\n"
1991 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1992 "Server: winetest\r\n"
1993 "Content-Length: 0\r\n"
1994 "Set-Cookie: one\r\n"
1995 "Set-Cookie: two\r\n"
1998 static const char okmsg_cookie_path
[] =
1999 "HTTP/1.1 200 OK\r\n"
2000 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
2001 "Server: winetest\r\n"
2002 "Content-Length: 0\r\n"
2003 "Set-Cookie: subcookie2=data; path=/test_cookie_set_path\r\n"
2006 static const char okmsg_cookie
[] =
2007 "HTTP/1.1 200 OK\r\n"
2008 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
2009 "Server: winetest\r\n"
2010 "Content-Length: 0\r\n"
2011 "Set-Cookie: testcookie=testvalue\r\n"
2014 static const char notokmsg
[] =
2015 "HTTP/1.1 400 Bad Request\r\n"
2016 "Server: winetest\r\n"
2019 static const char noauthmsg
[] =
2020 "HTTP/1.1 401 Unauthorized\r\n"
2021 "Server: winetest\r\n"
2022 "Connection: close\r\n"
2023 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
2026 static const char noauthmsg2
[] =
2027 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
2028 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
2030 "Server: winetest\r\n";
2032 static const char proxymsg
[] =
2033 "HTTP/1.1 407 Proxy Authentication Required\r\n"
2034 "Server: winetest\r\n"
2035 "Proxy-Connection: close\r\n"
2036 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
2039 static const char page1
[] =
2041 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
2042 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
2045 static const char ok_with_length
[] =
2046 "HTTP/1.1 200 OK\r\n"
2047 "Connection: Keep-Alive\r\n"
2048 "Content-Length: 18\r\n\r\n"
2049 "HTTP/1.1 211 OK\r\n\r\n";
2051 static const char ok_with_length2
[] =
2052 "HTTP/1.1 210 OK\r\n"
2053 "Connection: Keep-Alive\r\n"
2054 "Content-Length: 19\r\n\r\n"
2055 "HTTP/1.1 211 OK\r\n\r\n";
2057 struct server_info
{
2062 static int test_cache_gzip
;
2063 static const char *send_buffer
;
2065 static DWORD CALLBACK
server_thread(LPVOID param
)
2067 struct server_info
*si
= param
;
2068 int r
, c
= -1, i
, on
, count
= 0;
2070 struct sockaddr_in sa
;
2073 int last_request
= 0;
2074 char host_header
[22];
2075 char host_header_override
[30];
2076 static BOOL test_b
= FALSE
;
2077 static int test_no_cache
= 0;
2079 WSAStartup(MAKEWORD(1,1), &wsaData
);
2081 s
= socket(AF_INET
, SOCK_STREAM
, 0);
2082 if (s
== INVALID_SOCKET
)
2086 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
2088 memset(&sa
, 0, sizeof sa
);
2089 sa
.sin_family
= AF_INET
;
2090 sa
.sin_port
= htons(si
->port
);
2091 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
2093 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
2099 SetEvent(si
->hEvent
);
2101 sprintf(host_header
, "Host: localhost:%d", si
->port
);
2102 sprintf(host_header_override
, "Host: test.local:%d\r\n", si
->port
);
2107 c
= accept(s
, NULL
, NULL
);
2109 memset(buffer
, 0, sizeof buffer
);
2110 for(i
=0; i
<(sizeof buffer
-1); i
++)
2112 r
= recv(c
, &buffer
[i
], 1, 0);
2116 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
2117 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
2120 if (strstr(buffer
, "GET /test1"))
2122 if (!strstr(buffer
, "Content-Length: 0"))
2124 send(c
, okmsg
, sizeof okmsg
-1, 0);
2125 send(c
, page1
, sizeof page1
-1, 0);
2128 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2130 if (strstr(buffer
, "/test2"))
2132 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2134 send(c
, okmsg
, sizeof okmsg
-1, 0);
2135 send(c
, page1
, sizeof page1
-1, 0);
2138 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2140 if (strstr(buffer
, "/test3"))
2142 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2143 send(c
, okmsg
, sizeof okmsg
-1, 0);
2145 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2147 if (strstr(buffer
, "/test4"))
2149 if (strstr(buffer
, "Connection: Close"))
2150 send(c
, okmsg
, sizeof okmsg
-1, 0);
2152 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2154 if (strstr(buffer
, "POST /test5") ||
2155 strstr(buffer
, "RPC_IN_DATA /test5") ||
2156 strstr(buffer
, "RPC_OUT_DATA /test5"))
2158 if (strstr(buffer
, "Content-Length: 0"))
2160 send(c
, okmsg
, sizeof okmsg
-1, 0);
2161 send(c
, page1
, sizeof page1
-1, 0);
2164 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2166 if (strstr(buffer
, "GET /test6"))
2168 send(c
, contmsg
, sizeof contmsg
-1, 0);
2169 send(c
, contmsg
, sizeof contmsg
-1, 0);
2170 send(c
, okmsg
, sizeof okmsg
-1, 0);
2171 send(c
, page1
, sizeof page1
-1, 0);
2173 if (strstr(buffer
, "POST /test7"))
2175 if (strstr(buffer
, "Content-Length: 100"))
2177 send(c
, okmsg
, sizeof okmsg
-1, 0);
2178 send(c
, page1
, sizeof page1
-1, 0);
2181 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2183 if (strstr(buffer
, "/test8"))
2185 if (!strstr(buffer
, "Connection: Close") &&
2186 strstr(buffer
, "Connection: Keep-Alive") &&
2187 !strstr(buffer
, "Cache-Control: no-cache") &&
2188 !strstr(buffer
, "Pragma: no-cache") &&
2189 strstr(buffer
, host_header
))
2190 send(c
, okmsg
, sizeof okmsg
-1, 0);
2192 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2194 if (strstr(buffer
, "/test9"))
2196 if (!strstr(buffer
, "Connection: Close") &&
2197 !strstr(buffer
, "Connection: Keep-Alive") &&
2198 !strstr(buffer
, "Cache-Control: no-cache") &&
2199 !strstr(buffer
, "Pragma: no-cache") &&
2200 strstr(buffer
, host_header
))
2201 send(c
, okmsg
, sizeof okmsg
-1, 0);
2203 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2205 if (strstr(buffer
, "/testA"))
2207 if (!strstr(buffer
, "Connection: Close") &&
2208 !strstr(buffer
, "Connection: Keep-Alive") &&
2209 (strstr(buffer
, "Cache-Control: no-cache") ||
2210 strstr(buffer
, "Pragma: no-cache")) &&
2211 strstr(buffer
, host_header
))
2212 send(c
, okmsg
, sizeof okmsg
-1, 0);
2214 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2216 if (!test_b
&& strstr(buffer
, "/testB HTTP/1.1"))
2219 send(c
, okmsg
, sizeof okmsg
-1, 0);
2220 recvfrom(c
, buffer
, sizeof buffer
, 0, NULL
, NULL
);
2221 send(c
, okmsg
, sizeof okmsg
-1, 0);
2223 if (strstr(buffer
, "/testC"))
2225 if (strstr(buffer
, "cookie=biscuit"))
2226 send(c
, okmsg
, sizeof okmsg
-1, 0);
2228 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2230 if (strstr(buffer
, "/testD"))
2232 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
2234 if (strstr(buffer
, "/testE"))
2236 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
2238 if (strstr(buffer
, "GET /quit"))
2240 send(c
, okmsg
, sizeof okmsg
-1, 0);
2241 send(c
, page1
, sizeof page1
-1, 0);
2244 if (strstr(buffer
, "GET /testF"))
2246 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
2247 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2248 send(c
, contmsg
, sizeof contmsg
-1, 0);
2249 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2250 send(c
, okmsg
, sizeof okmsg
-1, 0);
2251 send(c
, page1
, sizeof page1
-1, 0);
2253 if (strstr(buffer
, "GET /testG"))
2255 send(c
, page1
, sizeof page1
-1, 0);
2258 if (strstr(buffer
, "GET /testJ"))
2263 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2267 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2271 if (strstr(buffer
, "GET /testH"))
2273 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2274 recvfrom(c
, buffer
, sizeof(buffer
), 0, NULL
, NULL
);
2275 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2278 if (strstr(buffer
, "GET /test_no_content"))
2280 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2281 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2283 if (strstr(buffer
, "GET /test_conn_close"))
2285 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2286 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
2287 WaitForSingleObject(conn_close_event
, INFINITE
);
2288 trace("closing connection\n");
2290 if (strstr(buffer
, "GET /test_cache_control_no_cache"))
2292 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2293 if(!test_no_cache
++)
2294 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2296 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2298 if (strstr(buffer
, "GET /test_cache_control_no_store"))
2300 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2301 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2303 if (strstr(buffer
, "GET /test_cache_gzip"))
2305 static const char gzip_response
[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2306 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2307 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2308 if(!test_cache_gzip
++)
2309 send(c
, gzip_response
, sizeof(gzip_response
), 0);
2311 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2313 if (strstr(buffer
, "HEAD /test_head")) {
2314 static const char head_response
[] =
2315 "HTTP/1.1 200 OK\r\n"
2316 "Connection: Keep-Alive\r\n"
2317 "Content-Length: 100\r\n"
2320 send(c
, head_response
, sizeof(head_response
), 0);
2323 if (strstr(buffer
, "GET /send_from_buffer"))
2324 send(c
, send_buffer
, strlen(send_buffer
), 0);
2325 if (strstr(buffer
, "/test_cache_control_verb"))
2327 if (!memcmp(buffer
, "GET ", sizeof("GET ")-1) &&
2328 !strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2329 else if (strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2330 else send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2332 if (strstr(buffer
, "/test_request_content_length"))
2334 static char msg
[] = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\n\r\n";
2335 static int seen_content_length
;
2337 if (!seen_content_length
)
2339 if (strstr(buffer
, "Content-Length: 0"))
2341 seen_content_length
= 1;
2342 send(c
, msg
, sizeof msg
-1, 0);
2344 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2345 WaitForSingleObject(hCompleteEvent
, 5000);
2349 if (strstr(buffer
, "Content-Length: 0")) send(c
, msg
, sizeof msg
-1, 0);
2350 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2351 WaitForSingleObject(hCompleteEvent
, 5000);
2354 if (strstr(buffer
, "GET /test_premature_disconnect"))
2355 trace("closing connection\n");
2356 if (strstr(buffer
, "/test_accept_encoding_http10"))
2358 if (strstr(buffer
, "Accept-Encoding: gzip"))
2359 send(c
, okmsg
, sizeof okmsg
-1, 0);
2361 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2363 if (strstr(buffer
, "HEAD /upload.txt"))
2365 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2366 send(c
, okmsg
, sizeof okmsg
-1, 0);
2368 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2370 if (strstr(buffer
, "PUT /upload2.txt"))
2372 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2373 send(c
, okmsg
, sizeof okmsg
-1, 0);
2375 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2377 if (strstr(buffer
, "/test_cookie_path1"))
2379 if (strstr(buffer
, "subcookie=data"))
2380 send(c
, okmsg
, sizeof okmsg
-1, 0);
2382 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2384 if (strstr(buffer
, "/test_cookie_path2"))
2386 if (strstr(buffer
, "subcookie2=data"))
2387 send(c
, okmsg
, sizeof okmsg
-1, 0);
2389 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2391 if (strstr(buffer
, "/test_cookie_set_path"))
2393 send(c
, okmsg_cookie_path
, sizeof okmsg_cookie_path
-1, 0);
2395 if (strstr(buffer
, "/test_cookie_merge"))
2397 if (strstr(buffer
, "subcookie=data") &&
2398 !strstr(buffer
, "manual_cookie=test"))
2399 send(c
, okmsg
, sizeof okmsg
-1, 0);
2401 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2403 if (strstr(buffer
, "/test_cookie_set_host_override"))
2405 send(c
, okmsg_cookie
, sizeof okmsg_cookie
-1, 0);
2407 if (strstr(buffer
, "/test_cookie_check_host_override"))
2409 if (strstr(buffer
, "Cookie:") && strstr(buffer
, "testcookie=testvalue"))
2410 send(c
, okmsg
, sizeof okmsg
-1, 0);
2412 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2414 if (strstr(buffer
, "/test_cookie_check_different_host"))
2416 if (!strstr(buffer
, "foo") &&
2417 strstr(buffer
, "cookie=biscuit"))
2418 send(c
, okmsg
, sizeof okmsg
-1, 0);
2420 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2422 if (strstr(buffer
, "/test_host_override"))
2424 if (strstr(buffer
, host_header_override
))
2425 send(c
, okmsg
, sizeof okmsg
-1, 0);
2427 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2429 if (strstr(buffer
, "HEAD /test_auth_host1"))
2431 if (strstr(buffer
, "Authorization: Basic dGVzdDE6cGFzcw=="))
2432 send(c
, okmsg
, sizeof okmsg
-1, 0);
2434 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2436 if (strstr(buffer
, "HEAD /test_auth_host2"))
2438 if (strstr(buffer
, "Authorization: Basic dGVzdDE6cGFzczI="))
2439 send(c
, okmsg
, sizeof okmsg
-1, 0);
2441 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2446 } while (!last_request
);
2453 static void test_basic_request(int port
, const char *verb
, const char *url
)
2455 HINTERNET hi
, hc
, hr
;
2456 DWORD r
, count
, error
;
2459 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2460 ok(hi
!= NULL
, "open failed\n");
2462 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2463 ok(hc
!= NULL
, "connect failed\n");
2465 hr
= HttpOpenRequestA(hc
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
2466 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2468 SetLastError(0xdeadbeef);
2469 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2470 error
= GetLastError();
2471 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
2472 ok(r
, "HttpSendRequest failed\n");
2475 memset(buffer
, 0, sizeof buffer
);
2476 SetLastError(0xdeadbeef);
2477 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
2478 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2479 ok(count
== sizeof page1
- 1, "count was wrong\n");
2480 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2482 InternetCloseHandle(hr
);
2483 InternetCloseHandle(hc
);
2484 InternetCloseHandle(hi
);
2487 static void test_proxy_indirect(int port
)
2489 HINTERNET hi
, hc
, hr
;
2493 hi
= InternetOpenA(NULL
, 0, NULL
, NULL
, 0);
2494 ok(hi
!= NULL
, "open failed\n");
2496 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2497 ok(hc
!= NULL
, "connect failed\n");
2499 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2500 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2502 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
2503 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2506 r
= HttpQueryInfoA(hr
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2507 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
2510 skip("missing proxy header, not testing remaining proxy headers\n");
2513 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2515 test_status_code(hr
, 407);
2516 test_request_flags(hr
, 0);
2519 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2520 ok(r
, "HttpQueryInfo failed\n");
2521 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2524 r
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2525 ok(r
, "HttpQueryInfo failed\n");
2526 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2529 r
= HttpQueryInfoA(hr
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2530 ok(r
, "HttpQueryInfo failed\n");
2531 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2534 r
= HttpQueryInfoA(hr
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2535 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2536 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2539 InternetCloseHandle(hr
);
2540 InternetCloseHandle(hc
);
2541 InternetCloseHandle(hi
);
2544 static void test_proxy_direct(int port
)
2546 HINTERNET hi
, hc
, hr
;
2548 char buffer
[0x40], *url
;
2549 WCHAR bufferW
[0x40];
2550 static const char url_fmt
[] = "http://test.winehq.org:%u/test2";
2551 static CHAR username
[] = "mike",
2552 password
[] = "1101",
2553 useragent
[] = "winetest";
2554 static const WCHAR usernameW
[] = {'m','i','k','e',0},
2555 passwordW
[] = {'1','1','0','1',0},
2556 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2558 /* specify proxy type without the proxy and bypass */
2559 SetLastError(0xdeadbeef);
2560 hi
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2561 error
= GetLastError();
2562 ok(error
== ERROR_INVALID_PARAMETER
||
2563 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %u\n", error
);
2564 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2566 sprintf(buffer
, "localhost:%d\n", port
);
2567 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2568 ok(hi
!= NULL
, "open failed\n");
2570 /* try connect without authorization */
2571 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2572 ok(hc
!= NULL
, "connect failed\n");
2574 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2575 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2578 SetLastError(0xdeadbeef);
2579 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
2580 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2581 ok(!r
, "unexpected success\n");
2582 ok(sz
== 1, "got %u\n", sz
);
2585 SetLastError(0xdeadbeef);
2586 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
2587 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2588 ok(!r
, "unexpected success\n");
2589 ok(sz
== 1, "got %u\n", sz
);
2591 sz
= sizeof(buffer
);
2592 SetLastError(0xdeadbeef);
2593 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2594 ok(r
, "unexpected failure %u\n", GetLastError());
2595 ok(!sz
, "got %u\n", sz
);
2597 sz
= sizeof(buffer
);
2598 SetLastError(0xdeadbeef);
2599 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2600 ok(r
, "unexpected failure %u\n", GetLastError());
2601 ok(!sz
, "got %u\n", sz
);
2604 SetLastError(0xdeadbeef);
2605 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
2606 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2607 ok(!r
, "unexpected success\n");
2608 ok(sz
== 1, "got %u\n", sz
);
2611 SetLastError(0xdeadbeef);
2612 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
2613 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2614 ok(!r
, "unexpected success\n");
2615 ok(sz
== 1, "got %u\n", sz
);
2617 sz
= sizeof(buffer
);
2618 SetLastError(0xdeadbeef);
2619 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2620 ok(r
, "unexpected failure %u\n", GetLastError());
2621 ok(!sz
, "got %u\n", sz
);
2623 sz
= sizeof(buffer
);
2624 SetLastError(0xdeadbeef);
2625 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2626 ok(r
, "unexpected failure %u\n", GetLastError());
2627 ok(!sz
, "got %u\n", sz
);
2630 SetLastError(0xdeadbeef);
2631 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
2632 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2633 ok(!r
, "unexpected success\n");
2634 ok(sz
== 34, "got %u\n", sz
);
2636 sz
= sizeof(buffer
);
2637 SetLastError(0xdeadbeef);
2638 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2639 ok(r
, "unexpected failure %u\n", GetLastError());
2640 ok(sz
== 33, "got %u\n", sz
);
2642 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2643 ok(r
|| broken(!r
), "HttpSendRequest failed %u\n", GetLastError());
2646 win_skip("skipping proxy tests on broken wininet\n");
2650 test_status_code(hr
, 407);
2652 /* set the user + password then try again */
2653 r
= InternetSetOptionA(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2654 ok(!r
, "unexpected success\n");
2656 r
= InternetSetOptionA(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2657 ok(r
, "failed to set user\n");
2659 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2660 ok(r
, "failed to set user\n");
2664 SetLastError(0xdeadbeef);
2665 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2666 ok(!r
, "unexpected failure %u\n", GetLastError());
2667 ok(!buffer
[0], "got %s\n", buffer
);
2668 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2672 SetLastError(0xdeadbeef);
2673 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2674 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2675 ok(!r
, "unexpected success\n");
2676 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2680 SetLastError(0xdeadbeef);
2681 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2682 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2683 ok(!r
, "unexpected success\n");
2684 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2687 sz
= sizeof(buffer
);
2688 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2689 ok(r
, "failed to get username\n");
2690 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2691 ok(sz
== strlen(username
), "got %u\n", sz
);
2694 sz
= sizeof(bufferW
);
2695 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2696 ok(r
, "failed to get username\n");
2697 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
2698 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2700 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
2701 ok(r
, "failed to set user\n");
2704 sz
= sizeof(buffer
);
2705 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2706 ok(r
, "failed to get username\n");
2707 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2708 ok(sz
== strlen(username
), "got %u\n", sz
);
2710 r
= InternetSetOptionA(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
2711 ok(r
, "failed to set useragent\n");
2715 SetLastError(0xdeadbeef);
2716 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2717 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2718 ok(!r
, "unexpected success\n");
2719 ok(sz
== strlen(useragent
) + 1, "got %u\n", sz
);
2722 sz
= sizeof(buffer
);
2723 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2724 ok(r
, "failed to get user agent\n");
2725 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
2726 ok(sz
== strlen(useragent
), "got %u\n", sz
);
2730 SetLastError(0xdeadbeef);
2731 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2732 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2733 ok(!r
, "unexpected success\n");
2734 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2737 sz
= sizeof(bufferW
);
2738 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2739 ok(r
, "failed to get user agent\n");
2740 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
2741 ok(sz
== lstrlenW(useragentW
), "got %u\n", sz
);
2743 r
= InternetSetOptionA(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
2744 ok(r
, "failed to set user\n");
2748 SetLastError(0xdeadbeef);
2749 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2750 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2751 ok(!r
, "unexpected success\n");
2752 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2755 sz
= sizeof(buffer
);
2756 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2757 ok(r
, "failed to get user\n");
2758 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2759 ok(sz
== strlen(username
), "got %u\n", sz
);
2763 SetLastError(0xdeadbeef);
2764 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2765 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2766 ok(!r
, "unexpected success\n");
2767 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2770 sz
= sizeof(bufferW
);
2771 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2772 ok(r
, "failed to get user\n");
2773 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
2774 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2776 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
2777 ok(r
, "failed to set password\n");
2781 SetLastError(0xdeadbeef);
2782 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2783 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2784 ok(!r
, "unexpected success\n");
2785 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2788 sz
= sizeof(buffer
);
2789 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2790 ok(r
, "failed to get password\n");
2791 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2792 ok(sz
== strlen(password
), "got %u\n", sz
);
2796 SetLastError(0xdeadbeef);
2797 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2798 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2799 ok(!r
, "unexpected success\n");
2800 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2803 sz
= sizeof(bufferW
);
2804 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2805 ok(r
, "failed to get password\n");
2806 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2807 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2809 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
2810 sprintf(url
, url_fmt
, port
);
2813 SetLastError(0xdeadbeef);
2814 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2815 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2816 ok(!r
, "unexpected success\n");
2817 ok(sz
== strlen(url
) + 1, "got %u\n", sz
);
2820 sz
= sizeof(buffer
);
2821 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2822 ok(r
, "failed to get url\n");
2823 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
2824 ok(sz
== strlen(url
), "got %u\n", sz
);
2828 SetLastError(0xdeadbeef);
2829 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2830 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2831 ok(!r
, "unexpected success\n");
2832 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2835 sz
= sizeof(bufferW
);
2836 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2837 ok(r
, "failed to get url\n");
2838 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
2839 ok(sz
== strlen(url
), "got %u\n", sz
);
2840 HeapFree(GetProcessHeap(), 0, url
);
2842 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2843 ok(r
, "failed to set password\n");
2847 SetLastError(0xdeadbeef);
2848 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2849 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2850 ok(!r
, "unexpected success\n");
2851 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2854 sz
= sizeof(buffer
);
2855 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2856 ok(r
, "failed to get password\n");
2857 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2858 ok(sz
== strlen(password
), "got %u\n", sz
);
2862 SetLastError(0xdeadbeef);
2863 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2864 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2865 ok(!r
, "unexpected success\n");
2866 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2869 sz
= sizeof(bufferW
);
2870 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2871 ok(r
, "failed to get password\n");
2872 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2873 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2875 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2878 win_skip("skipping proxy tests on broken wininet\n");
2881 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2883 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2884 ok(r
, "HttpQueryInfo failed\n");
2885 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2888 InternetCloseHandle(hr
);
2889 InternetCloseHandle(hc
);
2890 InternetCloseHandle(hi
);
2893 static void test_header_handling_order(int port
)
2895 static const char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
2896 static const char connection
[] = "Connection: Close";
2897 static const char *types
[2] = { "*", NULL
};
2899 HINTERNET session
, connect
, request
;
2900 DWORD size
, status
, data_len
;
2903 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2904 ok(session
!= NULL
, "InternetOpen failed\n");
2906 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2907 ok(connect
!= NULL
, "InternetConnect failed\n");
2909 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2910 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2912 ret
= HttpAddRequestHeadersA(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
2913 ok(ret
, "HttpAddRequestHeaders failed\n");
2915 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
2916 ok(ret
, "HttpSendRequest failed\n");
2918 test_status_code(request
, 200);
2919 test_request_flags(request
, 0);
2921 InternetCloseHandle(request
);
2923 request
= HttpOpenRequestA(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2924 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2926 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2927 ok(ret
, "HttpSendRequest failed\n");
2930 size
= sizeof(status
);
2931 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2932 ok(ret
, "HttpQueryInfo failed\n");
2933 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2935 InternetCloseHandle(request
);
2936 InternetCloseHandle(connect
);
2938 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2939 ok(connect
!= NULL
, "InternetConnect failed\n");
2941 request
= HttpOpenRequestA(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2942 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2944 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2945 ok(ret
, "HttpAddRequestHeaders failed\n");
2947 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2948 ok(ret
, "HttpSendRequest failed\n");
2951 size
= sizeof(status
);
2952 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2953 ok(ret
, "HttpQueryInfo failed\n");
2954 ok(status
== 200, "got status %u, expected 200\n", status
);
2956 InternetCloseHandle(request
);
2957 InternetCloseHandle(connect
);
2959 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2960 ok(connect
!= NULL
, "InternetConnect failed\n");
2962 request
= HttpOpenRequestA(connect
, "POST", "/test7b", NULL
, NULL
, types
, 0, 0);
2963 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2965 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2966 ok(ret
, "HttpAddRequestHeaders failed\n");
2968 data_len
= sizeof(data
);
2969 memset(data
, 'a', sizeof(data
));
2970 ret
= HttpSendRequestA(request
, connection
, ~0u, data
, data_len
);
2971 ok(ret
, "HttpSendRequest failed\n");
2974 size
= sizeof(status
);
2975 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2976 ok(ret
, "HttpQueryInfo failed\n");
2977 ok(status
== 200, "got status %u, expected 200\n", status
);
2979 InternetCloseHandle(request
);
2980 InternetCloseHandle(connect
);
2981 InternetCloseHandle(session
);
2984 static void test_connection_header(int port
)
2986 HINTERNET ses
, con
, req
;
2989 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2990 ok(ses
!= NULL
, "InternetOpen failed\n");
2992 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2993 ok(con
!= NULL
, "InternetConnect failed\n");
2995 req
= HttpOpenRequestA(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2996 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2998 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
2999 ok(ret
, "HttpSendRequest failed\n");
3001 test_status_code(req
, 200);
3003 InternetCloseHandle(req
);
3005 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
3006 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3008 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3009 ok(ret
, "HttpSendRequest failed\n");
3011 test_status_code(req
, 200);
3013 InternetCloseHandle(req
);
3015 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3016 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3018 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3019 ok(ret
, "HttpSendRequest failed\n");
3021 test_status_code(req
, 200);
3023 InternetCloseHandle(req
);
3025 req
= HttpOpenRequestA(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3026 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3028 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3029 ok(ret
, "HttpSendRequest failed\n");
3031 test_status_code(req
, 200);
3033 InternetCloseHandle(req
);
3034 InternetCloseHandle(con
);
3035 InternetCloseHandle(ses
);
3038 static void test_header_override(int port
)
3040 char buffer
[128], host_header_override
[30], full_url
[128];
3041 HINTERNET ses
, con
, req
;
3042 DWORD size
, count
, err
;
3045 sprintf(host_header_override
, "Host: test.local:%d\r\n", port
);
3046 sprintf(full_url
, "http://localhost:%d/test_host_override", port
);
3048 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3049 ok(ses
!= NULL
, "InternetOpen failed\n");
3051 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3052 ok(con
!= NULL
, "InternetConnect failed\n");
3054 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3055 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3057 size
= sizeof(buffer
) - 1;
3059 memset(buffer
, 0, sizeof(buffer
));
3060 ret
= HttpQueryInfoA(req
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &count
);
3061 err
= GetLastError();
3062 ok(!ret
, "HttpQueryInfo succeeded\n");
3063 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err
);
3065 size
= sizeof(buffer
) - 1;
3066 memset(buffer
, 0, sizeof(buffer
));
3067 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_URL
, buffer
, &size
);
3068 ok(ret
, "InternetQueryOption failed\n");
3069 ok(!strcmp(full_url
, buffer
), "Expected %s, got %s\n", full_url
, buffer
);
3071 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3072 ok(ret
, "HttpAddRequestHeaders failed\n");
3074 size
= sizeof(buffer
) - 1;
3076 memset(buffer
, 0, sizeof(buffer
));
3077 ret
= HttpQueryInfoA(req
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &count
);
3078 ok(ret
, "HttpQueryInfo failed\n");
3080 size
= sizeof(buffer
) - 1;
3081 memset(buffer
, 0, sizeof(buffer
));
3082 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_URL
, buffer
, &size
);
3083 ok(ret
, "InternetQueryOption failed\n");
3084 ok(!strcmp(full_url
, buffer
), "Expected %s, got %s\n", full_url
, buffer
);
3086 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3087 ok(ret
, "HttpSendRequest failed\n");
3089 test_status_code(req
, 200);
3091 InternetCloseHandle(req
);
3092 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3093 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3095 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3096 ok(ret
, "HttpAddRequestHeaders failed\n");
3098 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3099 ok(ret
, "HttpAddRequestHeaders failed\n");
3101 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3102 ok(ret
, "HttpSendRequest failed\n");
3104 test_status_code(req
, 400);
3106 InternetCloseHandle(req
);
3107 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3108 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3110 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3111 ok(ret
, "HttpAddRequestHeaders failed\n");
3113 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3114 ok(ret
, "HttpSendRequest failed\n");
3116 test_status_code(req
, 200);
3118 InternetCloseHandle(req
);
3119 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3120 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3122 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_REPLACE
);
3123 err
= GetLastError();
3124 ok(!ret
, "HttpAddRequestHeaders succeeded\n");
3125 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err
);
3127 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3128 ok(ret
, "HttpSendRequest failed\n");
3130 test_status_code(req
, 400);
3132 InternetCloseHandle(req
);
3133 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3134 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3135 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3137 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3138 ok(ret
, "HttpAddRequestHeaders failed\n");
3140 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3141 ok(ret
, "HttpSendRequest failed\n");
3143 test_status_code(req
, 200);
3145 InternetCloseHandle(req
);
3146 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_set_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3147 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3149 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3150 ok(ret
, "HttpAddRequestHeaders failed\n");
3152 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3153 ok(ret
, "HttpSendRequest failed\n");
3155 test_status_code(req
, 200);
3157 InternetCloseHandle(req
);
3158 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_check_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3159 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3161 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3162 ok(ret
, "HttpAddRequestHeaders failed\n");
3164 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3165 ok(ret
, "HttpSendRequest failed\n");
3167 test_status_code(req
, 200);
3169 InternetCloseHandle(req
);
3170 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_check_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3171 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3173 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3174 ok(ret
, "HttpSendRequest failed\n");
3176 test_status_code(req
, 200);
3178 InternetCloseHandle(req
);
3179 InternetSetCookieA("http://test.local", "foo", "bar");
3180 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_check_different_host", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3181 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3183 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3184 ok(ret
, "HttpSendRequest failed\n");
3186 test_status_code(req
, 200);
3188 InternetCloseHandle(req
);
3189 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_check_different_host", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3190 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3192 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3193 ok(ret
, "HttpAddRequestHeaders failed\n");
3195 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3196 ok(ret
, "HttpSendRequest failed\n");
3198 test_status_code(req
, 200);
3200 InternetCloseHandle(req
);
3201 InternetCloseHandle(con
);
3202 InternetCloseHandle(ses
);
3204 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3205 ok(ses
!= NULL
, "InternetOpenA failed\n");
3207 con
= InternetConnectA(ses
, "localhost", port
, "test1", "pass", INTERNET_SERVICE_HTTP
, 0, 0);
3208 ok(con
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
3210 req
= HttpOpenRequestA( con
, "HEAD", "/test_auth_host1", NULL
, NULL
, NULL
, 0, 0);
3211 ok(req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
3213 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3214 ok(ret
, "HttpSendRequestA failed %u\n", GetLastError());
3216 test_status_code(req
, 200);
3218 InternetCloseHandle(req
);
3219 InternetCloseHandle(con
);
3220 InternetCloseHandle(ses
);
3222 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3223 ok(ses
!= NULL
, "InternetOpenA failed\n");
3225 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3226 ok(con
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
3228 req
= HttpOpenRequestA(con
, "HEAD", "/test_auth_host1", NULL
, NULL
, NULL
, 0, 0);
3229 ok(req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
3231 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3232 ok(ret
, "HttpAddRequestHeaders failed\n");
3234 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
3235 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
3237 test_status_code(req
, 200);
3239 InternetCloseHandle(req
);
3240 InternetCloseHandle(con
);
3241 InternetCloseHandle(ses
);
3243 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3244 ok(ses
!= NULL
, "InternetOpenA failed\n");
3246 con
= InternetConnectA(ses
, "localhost", port
, "test1", "pass2", INTERNET_SERVICE_HTTP
, 0, 0);
3247 ok(con
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
3249 req
= HttpOpenRequestA(con
, "HEAD", "/test_auth_host2", NULL
, NULL
, NULL
, 0, 0);
3250 ok(req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
3252 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3253 ok(ret
, "HttpAddRequestHeaders failed\n");
3255 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3256 ok(ret
, "HttpSendRequestA failed %u\n", GetLastError());
3258 test_status_code(req
, 200);
3260 InternetCloseHandle(req
);
3261 InternetCloseHandle(con
);
3262 InternetCloseHandle(ses
);
3264 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3265 ok(ses
!= NULL
, "InternetOpenA failed\n");
3267 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3268 ok(con
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
3270 req
= HttpOpenRequestA(con
, "HEAD", "/test_auth_host2", NULL
, NULL
, NULL
, 0, 0);
3271 ok(req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
3273 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3274 ok(ret
, "HttpSendRequestA failed %u\n", GetLastError());
3276 test_status_code(req
, 200);
3278 InternetCloseHandle(req
);
3279 InternetCloseHandle(con
);
3280 InternetCloseHandle(ses
);
3283 static void test_http1_1(int port
)
3285 HINTERNET ses
, con
, req
;
3288 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3289 ok(ses
!= NULL
, "InternetOpen failed\n");
3291 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3292 ok(con
!= NULL
, "InternetConnect failed\n");
3294 req
= HttpOpenRequestA(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3295 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3297 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3300 InternetCloseHandle(req
);
3302 req
= HttpOpenRequestA(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3303 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3305 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3306 ok(ret
, "HttpSendRequest failed\n");
3309 InternetCloseHandle(req
);
3310 InternetCloseHandle(con
);
3311 InternetCloseHandle(ses
);
3314 static void test_connection_closing(int port
)
3316 HINTERNET session
, connection
, req
;
3319 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3321 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3322 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3324 pInternetSetStatusCallbackA(session
, callback
);
3326 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3327 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3328 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3329 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3331 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3332 req
= HttpOpenRequestA(connection
, "GET", "/testJ", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3333 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3334 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3336 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3337 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3338 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3339 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3340 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3341 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3342 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3343 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3344 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3345 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3346 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3348 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3349 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3350 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3351 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3352 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3354 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3355 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3356 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3357 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3358 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3359 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3360 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3361 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3362 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3363 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3364 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3366 test_status_code(req
, 200);
3368 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3369 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3370 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3371 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3372 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3373 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3374 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3375 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3376 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3378 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3379 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3380 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3381 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3382 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3384 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3385 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3386 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3387 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3388 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3389 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3390 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3391 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3392 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3394 test_status_code(req
, 210);
3396 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3397 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3398 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3399 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3400 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3401 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3402 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3403 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3404 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3405 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3406 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3408 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3409 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3410 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3411 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3412 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3414 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3415 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3416 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3417 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3418 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3419 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3420 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3421 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3422 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3423 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3424 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3426 test_status_code(req
, 200);
3428 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3429 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3431 close_async_handle(session
, hCompleteEvent
, 2);
3432 CloseHandle(hCompleteEvent
);
3435 static void test_successive_HttpSendRequest(int port
)
3437 HINTERNET session
, connection
, req
;
3440 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3442 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3443 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3445 pInternetSetStatusCallbackA(session
, callback
);
3447 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3448 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3449 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3450 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3452 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3453 req
= HttpOpenRequestA(connection
, "GET", "/testH", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3454 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3455 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3457 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3458 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3459 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3460 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3461 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3462 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3463 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3464 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3465 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3467 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3468 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3469 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3470 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3471 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3473 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3474 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3475 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3476 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3477 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3478 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3479 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3480 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3481 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3483 test_status_code(req
, 210);
3485 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3486 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3487 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3488 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3489 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3490 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3491 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3492 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3493 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3495 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3496 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3497 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3498 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3499 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3501 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3502 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3503 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3504 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3505 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3506 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3507 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3508 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3509 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3511 test_status_code(req
, 200);
3513 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3514 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3516 close_async_handle(session
, hCompleteEvent
, 2);
3517 CloseHandle(hCompleteEvent
);
3520 static void test_no_content(int port
)
3522 HINTERNET session
, connection
, req
;
3525 trace("Testing 204 no content response...\n");
3527 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3529 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3530 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3532 pInternetSetStatusCallbackA(session
, callback
);
3534 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3535 connection
= InternetConnectA(session
, "localhost", port
,
3536 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3537 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3538 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3540 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3541 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
3542 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3543 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3544 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3546 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3547 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3548 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3549 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3550 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3551 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3552 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3553 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3554 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3555 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3557 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3558 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3559 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3560 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3561 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3563 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3564 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3565 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3566 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3567 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3568 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3569 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3570 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3572 close_async_handle(session
, hCompleteEvent
, 2);
3573 CloseHandle(hCompleteEvent
);
3576 * The connection should be closed before closing handle. This is true for most
3577 * wininet versions (including Wine), but some old win2k versions fail to do that.
3579 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3580 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3583 static void test_conn_close(int port
)
3585 HINTERNET session
, connection
, req
;
3586 DWORD res
, avail
, size
;
3589 trace("Testing connection close connection...\n");
3591 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3592 conn_close_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3594 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3595 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3597 pInternetSetStatusCallbackA(session
, callback
);
3599 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3600 connection
= InternetConnectA(session
, "localhost", port
,
3601 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3602 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3603 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3605 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3606 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
3607 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3608 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3609 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3611 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3612 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3613 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3614 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3615 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3616 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3617 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3618 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3620 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3621 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3622 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3623 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3624 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3626 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3627 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3628 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3629 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3630 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3631 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3632 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3633 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3636 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3637 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3638 ok(avail
!= 0, "avail = 0\n");
3641 res
= InternetReadFile(req
, buf
, avail
, &size
);
3642 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3644 /* IE11 calls those in InternetQueryDataAvailable call. */
3645 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
3646 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
3648 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3649 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3650 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3651 ok(!avail
, "avail = %u, expected 0\n", avail
);
3653 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3655 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3656 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3657 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3658 SetEvent(conn_close_event
);
3659 #ifdef ROSTESTS_73_FIXED
3660 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3661 #else /* ROSTESTS_73_FIXED */
3662 ok(WaitForSingleObject(hCompleteEvent
, 5000) == WAIT_OBJECT_0
, "Wait timed out\n");
3663 #endif /* ROSTESTS_73_FIXED */
3664 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3665 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3666 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3667 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3668 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3670 close_async_handle(session
, hCompleteEvent
, 2);
3671 CloseHandle(hCompleteEvent
);
3674 static void test_no_cache(int port
)
3676 static const char cache_control_no_cache
[] = "/test_cache_control_no_cache";
3677 static const char cache_control_no_store
[] = "/test_cache_control_no_store";
3678 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3680 char cache_url
[256], buf
[256];
3681 HINTERNET ses
, con
, req
;
3685 trace("Testing no-cache header\n");
3687 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3688 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3690 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3691 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3693 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3694 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3696 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_cache
);
3697 DeleteUrlCacheEntryA(cache_url
);
3699 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3700 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3702 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3704 ok(size
== 12, "read %d bytes of data\n", size
);
3705 InternetCloseHandle(req
);
3707 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3708 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3710 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3711 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3713 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3715 ok(size
== 0, "read %d bytes of data\n", size
);
3716 InternetCloseHandle(req
);
3717 DeleteUrlCacheEntryA(cache_url
);
3719 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_store
, NULL
, NULL
, NULL
, 0, 0);
3720 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3722 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_store
);
3723 DeleteUrlCacheEntryA(cache_url
);
3725 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3726 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3728 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3730 ok(size
== 12, "read %d bytes of data\n", size
);
3731 InternetCloseHandle(req
);
3733 ret
= DeleteUrlCacheEntryA(cache_url
);
3734 ok(!ret
&& GetLastError()==ERROR_FILE_NOT_FOUND
, "cache entry should not exist\n");
3736 InternetCloseHandle(con
);
3737 InternetCloseHandle(ses
);
3740 static void test_cache_read_gzipped(int port
)
3742 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3743 static const char get_gzip
[] = "/test_cache_gzip";
3744 static const char content
[] = "gzip test\n";
3745 static const char text_html
[] = "text/html";
3746 static const char raw_header
[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3748 HINTERNET ses
, con
, req
;
3750 char cache_url
[256], buf
[256];
3753 trace("Testing reading compressed content from cache\n");
3755 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3756 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3758 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3759 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3761 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3762 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3765 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3766 if(!ret
&& GetLastError()==ERROR_INTERNET_INVALID_OPTION
) {
3767 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3768 InternetCloseHandle(req
);
3769 InternetCloseHandle(con
);
3770 InternetCloseHandle(ses
);
3773 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3775 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3776 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3778 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-size
, &read
) && read
)
3780 ok(size
== 10, "read %d bytes of data\n", size
);
3782 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3784 size
= sizeof(buf
)-1;
3785 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3786 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3788 ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3790 size
= sizeof(buf
)-1;
3791 ret
= HttpQueryInfoA(req
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &size
, 0);
3792 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3794 ok(!strncmp(raw_header
, buf
, size
), "buf = %s\n", buf
);
3795 InternetCloseHandle(req
);
3797 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3798 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3801 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3802 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3804 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3805 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3807 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3809 todo_wine
ok(size
== 10, "read %d bytes of data\n", size
);
3811 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3814 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3815 ok(!ret
&& GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND
,
3816 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3817 ret
, GetLastError());
3819 size
= sizeof(buf
)-1;
3820 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3821 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3823 todo_wine
ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3824 InternetCloseHandle(req
);
3826 /* Decompression doesn't work while reading from cache */
3827 test_cache_gzip
= 0;
3828 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3829 DeleteUrlCacheEntryA(cache_url
);
3831 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3832 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3834 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3835 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3837 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3839 ok(size
== 31, "read %d bytes of data\n", size
);
3840 InternetCloseHandle(req
);
3842 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3843 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3846 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3847 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3849 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3850 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3852 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3854 todo_wine
ok(size
== 31, "read %d bytes of data\n", size
);
3857 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3858 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3859 InternetCloseHandle(req
);
3861 InternetCloseHandle(con
);
3862 InternetCloseHandle(ses
);
3864 DeleteUrlCacheEntryA(cache_url
);
3867 static void test_HttpSendRequestW(int port
)
3869 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3870 HINTERNET ses
, con
, req
;
3874 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3875 ok(ses
!= NULL
, "InternetOpen failed\n");
3877 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3878 ok(con
!= NULL
, "InternetConnect failed\n");
3880 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3881 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3883 SetLastError(0xdeadbeef);
3884 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
3885 error
= GetLastError();
3886 ok(!ret
, "HttpSendRequestW succeeded\n");
3887 ok(error
== ERROR_IO_PENDING
||
3888 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
3889 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
3890 "got %u expected ERROR_IO_PENDING\n", error
);
3892 InternetCloseHandle(req
);
3893 InternetCloseHandle(con
);
3894 InternetCloseHandle(ses
);
3897 static void test_cookie_header(int port
)
3899 HINTERNET ses
, con
, req
;
3904 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3905 ok(ses
!= NULL
, "InternetOpen failed\n");
3907 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3908 ok(con
!= NULL
, "InternetConnect failed\n");
3910 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3912 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3913 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3916 size
= sizeof(buffer
);
3917 SetLastError(0xdeadbeef);
3918 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3919 error
= GetLastError();
3920 ok(!ret
, "HttpQueryInfo succeeded\n");
3921 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3923 ret
= HttpAddRequestHeadersA(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
3924 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3927 size
= sizeof(buffer
);
3928 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3929 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3930 ok(!!strstr(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
3932 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3933 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3935 test_status_code(req
, 200);
3938 size
= sizeof(buffer
);
3939 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3940 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3941 ok(!strstr(buffer
, "cookie=not biscuit"), "'%s' should not contain \'cookie=not biscuit\'\n", buffer
);
3942 ok(!!strstr(buffer
, "cookie=biscuit"), "'%s' should contain \'cookie=biscuit\'\n", buffer
);
3944 InternetCloseHandle(req
);
3946 InternetSetCookieA("http://localhost/testCCCC", "subcookie", "data");
3948 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_path1", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3949 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3951 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3952 ok(ret
, "HttpSendRequest failed\n");
3954 test_status_code(req
, 200);
3955 InternetCloseHandle(req
);
3957 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_path1/abc", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3958 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3960 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3961 ok(ret
, "HttpSendRequest failed\n");
3963 test_status_code(req
, 200);
3964 InternetCloseHandle(req
);
3966 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_set_path", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3967 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3969 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3970 ok(ret
, "HttpSendRequest failed\n");
3972 test_status_code(req
, 200);
3973 InternetCloseHandle(req
);
3975 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_path2", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3976 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3978 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3979 ok(ret
, "HttpSendRequest failed\n");
3981 test_status_code(req
, 400);
3982 InternetCloseHandle(req
);
3984 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_merge", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3985 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3987 ret
= HttpAddRequestHeadersA(req
, "Cookie: manual_cookie=test\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
3988 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3990 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3991 ok(ret
, "HttpSendRequest failed\n");
3993 test_status_code(req
, 200);
3994 InternetCloseHandle(req
);
3996 InternetCloseHandle(con
);
3997 InternetCloseHandle(ses
);
4000 static void test_basic_authentication(int port
)
4002 HINTERNET session
, connect
, request
;
4005 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4006 ok(session
!= NULL
, "InternetOpen failed\n");
4008 connect
= InternetConnectA(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
4009 ok(connect
!= NULL
, "InternetConnect failed\n");
4011 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
4012 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4014 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4015 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4017 test_status_code(request
, 200);
4018 test_request_flags(request
, 0);
4020 InternetCloseHandle(request
);
4021 InternetCloseHandle(connect
);
4022 InternetCloseHandle(session
);
4025 static void test_premature_disconnect(int port
)
4027 HINTERNET session
, connect
, request
;
4031 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4032 ok(session
!= NULL
, "InternetOpen failed\n");
4034 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4035 ok(connect
!= NULL
, "InternetConnect failed\n");
4037 request
= HttpOpenRequestA(connect
, NULL
, "/premature_disconnect", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
4038 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4040 SetLastError(0xdeadbeef);
4041 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4042 err
= GetLastError();
4043 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
4044 todo_wine
ok(err
== ERROR_HTTP_INVALID_SERVER_RESPONSE
, "got %u\n", err
);
4046 InternetCloseHandle(request
);
4047 InternetCloseHandle(connect
);
4048 InternetCloseHandle(session
);
4051 static void test_invalid_response_headers(int port
)
4053 HINTERNET session
, connect
, request
;
4058 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4059 ok(session
!= NULL
, "InternetOpen failed\n");
4061 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4062 ok(connect
!= NULL
, "InternetConnect failed\n");
4064 request
= HttpOpenRequestA(connect
, NULL
, "/testE", NULL
, NULL
, NULL
, 0, 0);
4065 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4067 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4068 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4070 test_status_code(request
, 401);
4071 test_request_flags(request
, 0);
4074 size
= sizeof(buffer
);
4075 ret
= HttpQueryInfoA( request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
4076 ok(ret
, "HttpQueryInfo failed\n");
4077 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
4078 "headers wrong \"%s\"\n", buffer
);
4081 size
= sizeof(buffer
);
4082 ret
= HttpQueryInfoA( request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
4083 ok(ret
, "HttpQueryInfo failed\n");
4084 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
4086 InternetCloseHandle(request
);
4087 InternetCloseHandle(connect
);
4088 InternetCloseHandle(session
);
4091 static void test_response_without_headers(int port
)
4093 HINTERNET hi
, hc
, hr
;
4094 DWORD r
, count
, size
;
4097 SetLastError(0xdeadbeef);
4098 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4099 ok(hi
!= NULL
, "open failed %u\n", GetLastError());
4101 SetLastError(0xdeadbeef);
4102 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4103 ok(hc
!= NULL
, "connect failed %u\n", GetLastError());
4105 SetLastError(0xdeadbeef);
4106 hr
= HttpOpenRequestA(hc
, NULL
, "/testG", NULL
, NULL
, NULL
, 0, 0);
4107 ok(hr
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError());
4109 test_request_flags(hr
, INTERNET_REQFLAG_NO_HEADERS
);
4111 SetLastError(0xdeadbeef);
4112 r
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
4113 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
4115 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
4118 memset(buffer
, 0, sizeof buffer
);
4119 SetLastError(0xdeadbeef);
4120 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
4121 ok(r
, "InternetReadFile failed %u\n", GetLastError());
4122 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
4123 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
4125 test_status_code(hr
, 200);
4126 test_request_flags_todo(hr
, INTERNET_REQFLAG_NO_HEADERS
);
4129 size
= sizeof(buffer
);
4130 SetLastError(0xdeadbeef);
4131 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
4132 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
4133 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
4136 size
= sizeof(buffer
);
4137 SetLastError(0xdeadbeef);
4138 r
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
4139 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
4140 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
4143 size
= sizeof(buffer
);
4144 SetLastError(0xdeadbeef);
4145 r
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
4146 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
4147 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
4149 InternetCloseHandle(hr
);
4150 InternetCloseHandle(hc
);
4151 InternetCloseHandle(hi
);
4154 static void test_head_request(int port
)
4156 DWORD len
, content_length
;
4157 HINTERNET ses
, con
, req
;
4161 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4162 ok(ses
!= NULL
, "InternetOpen failed\n");
4164 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4165 ok(con
!= NULL
, "InternetConnect failed\n");
4167 req
= HttpOpenRequestA(con
, "HEAD", "/test_head", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
4168 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4170 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4171 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
4173 len
= sizeof(content_length
);
4174 content_length
= -1;
4175 ret
= HttpQueryInfoA(req
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
, &content_length
, &len
, 0);
4176 ok(ret
, "HttpQueryInfo dailed: %u\n", GetLastError());
4177 ok(len
== sizeof(DWORD
), "len = %u\n", len
);
4178 ok(content_length
== 100, "content_length = %u\n", content_length
);
4181 ret
= InternetReadFile(req
, buf
, sizeof(buf
), &len
);
4182 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
4185 ret
= InternetReadFile(req
, buf
, sizeof(buf
), &len
);
4186 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
4188 InternetCloseHandle(req
);
4189 InternetCloseHandle(con
);
4190 InternetCloseHandle(ses
);
4193 static void test_HttpQueryInfo(int port
)
4195 HINTERNET hi
, hc
, hr
;
4196 DWORD size
, index
, error
;
4200 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4201 ok(hi
!= NULL
, "InternetOpen failed\n");
4203 hc
= InternetConnectA(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4204 ok(hc
!= NULL
, "InternetConnect failed\n");
4206 hr
= HttpOpenRequestA(hc
, NULL
, "/testD", NULL
, NULL
, NULL
, 0, 0);
4207 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
4209 size
= sizeof(buffer
);
4210 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
4211 error
= GetLastError();
4212 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
4213 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
4215 ret
= HttpSendRequestA(hr
, NULL
, 0, NULL
, 0);
4216 ok(ret
, "HttpSendRequest failed\n");
4219 size
= sizeof(buffer
);
4220 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
4221 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4222 ok(index
== 1, "expected 1 got %u\n", index
);
4225 size
= sizeof(buffer
);
4226 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
4227 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4228 ok(index
== 1, "expected 1 got %u\n", index
);
4231 size
= sizeof(buffer
);
4232 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4233 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4234 ok(index
== 0, "expected 0 got %u\n", index
);
4236 size
= sizeof(buffer
);
4237 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4238 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4239 ok(index
== 0, "expected 0 got %u\n", index
);
4241 index
= 0xdeadbeef; /* invalid start index */
4242 size
= sizeof(buffer
);
4243 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4244 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
4245 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
4246 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
4249 size
= sizeof(buffer
);
4250 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
4251 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4252 ok(index
== 0, "expected 0 got %u\n", index
);
4254 size
= sizeof(buffer
);
4255 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
4256 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4257 ok(index
== 0, "expected 0 got %u\n", index
);
4259 size
= sizeof(buffer
);
4260 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
4261 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4262 ok(index
== 0, "expected 0 got %u\n", index
);
4264 test_status_code(hr
, 200);
4267 size
= sizeof(buffer
);
4268 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
4269 ok(!ret
, "HttpQueryInfo succeeded\n");
4270 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
4273 size
= sizeof(buffer
);
4274 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
4275 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4276 ok(index
== 1, "expected 1 got %u\n", index
);
4279 size
= sizeof(buffer
);
4280 strcpy(buffer
, "Server");
4281 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
4282 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4283 ok(index
== 1, "expected 1 got %u\n", index
);
4286 size
= sizeof(buffer
);
4287 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
4288 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4289 ok(index
== 1, "expected 1 got %u\n", index
);
4291 size
= sizeof(buffer
);
4292 ret
= HttpQueryInfoA(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
4293 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4294 ok(index
== 2, "expected 2 got %u\n", index
);
4296 InternetCloseHandle(hr
);
4297 InternetCloseHandle(hc
);
4298 InternetCloseHandle(hi
);
4301 static void test_options(int port
)
4303 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi
;
4304 HINTERNET ses
, con
, req
;
4309 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4310 ok(ses
!= NULL
, "InternetOpen failed\n");
4312 SetLastError(0xdeadbeef);
4313 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
4314 error
= GetLastError();
4315 ok(!ret
, "InternetSetOption succeeded\n");
4316 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4318 SetLastError(0xdeadbeef);
4319 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
4320 ok(!ret
, "InternetSetOption succeeded\n");
4321 error
= GetLastError();
4322 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4324 SetLastError(0xdeadbeef);
4325 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
4326 ok(!ret
, "InternetSetOption succeeded\n");
4327 error
= GetLastError();
4328 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4331 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4332 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4334 SetLastError(0xdeadbeef);
4335 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
4336 error
= GetLastError();
4337 ok(!ret
, "InternetQueryOption succeeded\n");
4338 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4340 SetLastError(0xdeadbeef);
4341 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
4342 error
= GetLastError();
4343 ok(!ret
, "InternetQueryOption succeeded\n");
4344 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4347 SetLastError(0xdeadbeef);
4348 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
4349 error
= GetLastError();
4350 ok(!ret
, "InternetQueryOption succeeded\n");
4351 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
4354 SetLastError(0xdeadbeef);
4355 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4356 error
= GetLastError();
4357 ok(!ret
, "InternetQueryOption succeeded\n");
4358 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
4362 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4363 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4364 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
4366 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4367 ok(con
!= NULL
, "InternetConnect failed\n");
4371 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4372 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4373 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
4376 ret
= InternetSetOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4377 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4381 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4382 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4383 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
4385 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
4386 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4390 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4391 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4392 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
4395 ret
= InternetSetOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4396 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4400 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4401 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4402 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
4404 size
= sizeof(idsi
);
4405 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO
, &idsi
, &size
);
4406 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4409 SetLastError(0xdeadbeef);
4410 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
4411 error
= GetLastError();
4412 ok(!ret
, "InternetQueryOption succeeded\n");
4413 ok(error
== ERROR_INTERNET_INVALID_OPERATION
, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error
);
4415 /* INTERNET_OPTION_PROXY */
4416 SetLastError(0xdeadbeef);
4417 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
4418 error
= GetLastError();
4419 ok(!ret
, "InternetQueryOption succeeded\n");
4420 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4422 SetLastError(0xdeadbeef);
4423 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
4424 error
= GetLastError();
4425 ok(!ret
, "InternetQueryOption succeeded\n");
4426 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4429 SetLastError(0xdeadbeef);
4430 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
4431 error
= GetLastError();
4432 ok(!ret
, "InternetQueryOption succeeded\n");
4433 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
4434 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
4436 InternetCloseHandle(req
);
4437 InternetCloseHandle(con
);
4438 InternetCloseHandle(ses
);
4442 const char *response_text
;
4444 const char *status_text
;
4445 const char *raw_headers
;
4446 } http_status_test_t
;
4448 static const http_status_test_t http_status_tests
[] = {
4450 "HTTP/1.1 200 OK\r\n"
4451 "Content-Length: 1\r\n"
4457 "HTTP/1.1 404 Fail\r\n"
4458 "Content-Length: 1\r\n"
4465 "Content-Length: 1\r\n"
4472 "Content-Length: 1\r\n"
4479 static void test_http_status(int port
)
4481 HINTERNET ses
, con
, req
;
4486 for(i
=0; i
< sizeof(http_status_tests
)/sizeof(*http_status_tests
); i
++) {
4487 send_buffer
= http_status_tests
[i
].response_text
;
4489 ses
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4490 ok(ses
!= NULL
, "InternetOpen failed\n");
4492 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4493 ok(con
!= NULL
, "InternetConnect failed\n");
4495 req
= HttpOpenRequestA(con
, NULL
, "/send_from_buffer", NULL
, NULL
, NULL
, 0, 0);
4496 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4498 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4499 ok(res
, "HttpSendRequest failed\n");
4501 test_status_code(req
, http_status_tests
[i
].status_code
);
4504 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_TEXT
, buf
, &size
, NULL
);
4505 ok(res
, "HttpQueryInfo failed: %u\n", GetLastError());
4506 ok(!strcmp(buf
, http_status_tests
[i
].status_text
), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
4507 i
, buf
, http_status_tests
[i
].status_text
);
4509 InternetCloseHandle(req
);
4510 InternetCloseHandle(con
);
4511 InternetCloseHandle(ses
);
4515 static void test_cache_control_verb(int port
)
4517 HINTERNET session
, connect
, request
;
4520 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4521 ok(session
!= NULL
, "InternetOpen failed\n");
4523 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4524 ok(connect
!= NULL
, "InternetConnect failed\n");
4526 request
= HttpOpenRequestA(connect
, "RPC_OUT_DATA", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4527 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4528 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4529 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4530 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4531 test_status_code(request
, 200);
4532 InternetCloseHandle(request
);
4534 request
= HttpOpenRequestA(connect
, "POST", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4535 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4536 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4537 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4538 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4539 test_status_code(request
, 200);
4540 InternetCloseHandle(request
);
4542 request
= HttpOpenRequestA(connect
, "HEAD", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4543 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4544 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4545 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4546 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4547 test_status_code(request
, 200);
4548 InternetCloseHandle(request
);
4550 request
= HttpOpenRequestA(connect
, "GET", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4551 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4552 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4553 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4554 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4555 test_status_code(request
, 200);
4556 InternetCloseHandle(request
);
4558 InternetCloseHandle(connect
);
4559 InternetCloseHandle(session
);
4562 static void test_request_content_length(int port
)
4564 char data
[] = {'t','e','s','t'};
4565 HINTERNET ses
, con
, req
;
4568 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4570 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4571 ok(ses
!= NULL
, "InternetOpen failed\n");
4573 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4574 ok(con
!= NULL
, "InternetConnect failed\n");
4576 /* On XP there is a weird bug that the following tests fail if certain cookies
4577 * are set. We workaround this problem by passing INTERNET_FLAG_NO_COOKIES as flag. */
4578 req
= HttpOpenRequestA(con
, "POST", "/test_request_content_length", NULL
, NULL
, NULL
,
4579 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_NO_COOKIES
, 0);
4580 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4582 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4583 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4584 test_status_code(req
, 200);
4586 SetEvent(hCompleteEvent
);
4588 ret
= HttpSendRequestA(req
, NULL
, 0, data
, sizeof(data
));
4589 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4590 test_status_code(req
, 200);
4592 SetEvent(hCompleteEvent
);
4594 InternetCloseHandle(req
);
4595 InternetCloseHandle(con
);
4596 InternetCloseHandle(ses
);
4597 CloseHandle(hCompleteEvent
);
4600 static void test_accept_encoding(int port
)
4602 HINTERNET ses
, con
, req
;
4605 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
4606 ok(ses
!= NULL
, "InternetOpen failed\n");
4608 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4609 ok(con
!= NULL
, "InternetConnect failed\n");
4611 req
= HttpOpenRequestA(con
, "GET", "/test_accept_encoding_http10", "HTTP/1.0", NULL
, NULL
, 0, 0);
4612 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4614 ret
= HttpAddRequestHeadersA(req
, "Accept-Encoding: gzip\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDREQ_FLAG_ADD
);
4615 ok(ret
, "HttpAddRequestHeaders failed\n");
4617 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4618 ok(ret
, "HttpSendRequestA failed\n");
4620 test_status_code(req
, 200);
4622 InternetCloseHandle(req
);
4624 req
= HttpOpenRequestA(con
, "GET", "/test_accept_encoding_http10", "HTTP/1.0", NULL
, NULL
, 0, 0);
4625 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4627 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", ~0u, NULL
, 0);
4628 ok(ret
, "HttpSendRequestA failed\n");
4630 test_status_code(req
, 200);
4632 InternetCloseHandle(req
);
4633 InternetCloseHandle(con
);
4634 InternetCloseHandle(ses
);
4637 static void test_basic_auth_credentials_reuse(int port
)
4639 HINTERNET ses
, con
, req
;
4643 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, 0 );
4644 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4646 con
= InternetConnectA( ses
, "localhost", port
, "user", "pwd",
4647 INTERNET_SERVICE_HTTP
, 0, 0 );
4648 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4650 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
4651 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4653 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4654 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4656 status
= 0xdeadbeef;
4657 size
= sizeof(status
);
4658 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4659 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4660 ok( status
== 200, "got %u\n", status
);
4662 InternetCloseHandle( req
);
4663 InternetCloseHandle( con
);
4664 InternetCloseHandle( ses
);
4666 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, 0 );
4667 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4669 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
,
4670 INTERNET_SERVICE_HTTP
, 0, 0 );
4671 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4673 req
= HttpOpenRequestA( con
, "PUT", "/upload2.txt", NULL
, NULL
, NULL
, 0, 0 );
4674 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4676 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4677 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4679 status
= 0xdeadbeef;
4680 size
= sizeof(status
);
4681 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4682 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4683 ok( status
== 200, "got %u\n", status
);
4685 InternetCloseHandle( req
);
4686 InternetCloseHandle( con
);
4687 InternetCloseHandle( ses
);
4690 static void test_http_connection(void)
4692 struct server_info si
;
4696 si
.hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
4699 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
4700 ok( hThread
!= NULL
, "create thread failed\n");
4702 r
= WaitForSingleObject(si
.hEvent
, 10000);
4703 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
4704 if (r
!= WAIT_OBJECT_0
)
4707 test_basic_request(si
.port
, "GET", "/test1");
4708 test_proxy_indirect(si
.port
);
4709 test_proxy_direct(si
.port
);
4710 test_header_handling_order(si
.port
);
4711 test_basic_request(si
.port
, "POST", "/test5");
4712 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
4713 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
4714 test_basic_request(si
.port
, "GET", "/test6");
4715 test_basic_request(si
.port
, "GET", "/testF");
4716 test_connection_header(si
.port
);
4717 test_header_override(si
.port
);
4718 test_http1_1(si
.port
);
4719 test_cookie_header(si
.port
);
4720 test_basic_authentication(si
.port
);
4721 test_invalid_response_headers(si
.port
);
4722 test_response_without_headers(si
.port
);
4723 test_HttpQueryInfo(si
.port
);
4724 test_HttpSendRequestW(si
.port
);
4725 test_options(si
.port
);
4726 test_no_content(si
.port
);
4727 test_conn_close(si
.port
);
4728 test_no_cache(si
.port
);
4729 test_cache_read_gzipped(si
.port
);
4730 test_http_status(si
.port
);
4731 test_premature_disconnect(si
.port
);
4732 test_connection_closing(si
.port
);
4733 test_cache_control_verb(si
.port
);
4734 test_successive_HttpSendRequest(si
.port
);
4735 test_head_request(si
.port
);
4736 test_request_content_length(si
.port
);
4737 test_accept_encoding(si
.port
);
4738 test_basic_auth_credentials_reuse(si
.port
);
4740 /* send the basic request again to shutdown the server thread */
4741 test_basic_request(si
.port
, "GET", "/quit");
4743 r
= WaitForSingleObject(hThread
, 3000);
4744 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
4745 CloseHandle(hThread
);
4748 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
4750 LocalFree(info
->lpszSubjectInfo
);
4751 LocalFree(info
->lpszIssuerInfo
);
4752 LocalFree(info
->lpszProtocolName
);
4753 LocalFree(info
->lpszSignatureAlgName
);
4754 LocalFree(info
->lpszEncryptionAlgName
);
4758 const char *ex_subject
;
4759 const char *ex_issuer
;
4760 } cert_struct_test_t
;
4762 static const cert_struct_test_t test_winehq_org_cert
= {
4764 "See www.rapidssl.com/resources/cps (c)14\r\n"
4765 "Domain Control Validated - RapidSSL(R)\r\n"
4770 "RapidSSL SHA256 CA - G3"
4773 static const cert_struct_test_t test_winehq_com_cert
= {
4778 "test.winehq.com\r\n"
4779 "webmaster@winehq.org",
4784 "test.winehq.com\r\n"
4785 "webmaster@winehq.org"
4788 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
4790 INTERNET_CERTIFICATE_INFOA info
;
4794 memset(&info
, 0x5, sizeof(info
));
4796 size
= sizeof(info
);
4797 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
4798 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
4799 ok(size
== sizeof(info
), "size = %u\n", size
);
4801 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
4802 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
4803 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
4804 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
4805 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
4806 ok(info
.dwKeySize
>= 128 && info
.dwKeySize
<= 256, "dwKeySize = %u\n", info
.dwKeySize
);
4808 release_cert_info(&info
);
4811 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
4812 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
4814 char url
[INTERNET_MAX_URL_LENGTH
];
4815 const CERT_CHAIN_CONTEXT
*chain
;
4819 if(!pInternetGetSecurityInfoByURLA
) {
4820 win_skip("pInternetGetSecurityInfoByURLA not available\n");
4825 chain
= (void*)0xdeadbeef;
4827 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
4828 if(error
== ERROR_SUCCESS
) {
4829 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
4830 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
4831 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
4832 CertFreeCertificateChain(chain
);
4834 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
4835 "InternetGetSecurityInfoByURLA returned: %x(%u), exected %u\n", res
, GetLastError(), error
);
4839 #define test_secflags_option(a,b,c) _test_secflags_option(__LINE__,a,b,c)
4840 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
, DWORD opt_flags
)
4846 size
= sizeof(flags
);
4847 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
4848 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4849 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n",
4852 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
4854 size
= sizeof(flags
);
4855 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4856 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
4857 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n",
4861 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
4862 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
4866 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
4867 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
4870 static void test_security_flags(void)
4872 INTERNET_CERTIFICATE_INFOA
*cert
;
4873 HINTERNET ses
, conn
, req
;
4878 trace("Testing security flags...\n");
4880 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4882 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4883 ok(ses
!= NULL
, "InternetOpen failed\n");
4885 pInternetSetStatusCallbackA(ses
, &callback
);
4887 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4888 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
4889 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
4890 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
4891 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4893 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4894 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4895 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4897 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4898 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4901 size
= sizeof(flags
);
4902 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
4903 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
4904 win_skip("Incomplete security flags support, skipping\n");
4906 close_async_handle(ses
, hCompleteEvent
, 2);
4907 CloseHandle(hCompleteEvent
);
4911 test_secflags_option(req
, 0, 0);
4912 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
4914 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
4915 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
, 0);
4917 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
4918 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
4920 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
4921 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
4923 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
4924 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
4925 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
4927 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
4928 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
4929 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4930 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4931 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
4932 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
4933 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
4934 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
4935 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4936 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4937 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
4938 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
4939 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4940 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4941 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4943 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4944 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
4946 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4947 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
4949 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
4950 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
4951 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
4952 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
4953 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
4954 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
4955 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4956 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4957 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
4958 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
4959 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4960 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4961 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4963 test_request_flags(req
, 0);
4964 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
4965 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
, 0);
4967 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
4968 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
4969 ok(size
, "size = 0\n");
4971 /* Collect all existing persistent connections */
4972 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
4973 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
4975 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4976 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
4977 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
4979 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4980 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4982 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
4983 res
= InternetSetOptionA(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
4984 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
4986 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4987 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4988 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
4989 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
4990 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
4991 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
4992 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
4993 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
4994 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4995 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4996 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4998 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4999 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5001 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5002 ok(req_error
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| broken(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
),
5003 "req_error = %d\n", req_error
);
5006 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
5007 ok(res
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5008 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %u\n", size
);
5009 cert
= HeapAlloc(GetProcessHeap(), 0, size
);
5010 cert
->lpszSubjectInfo
= NULL
;
5011 cert
->lpszIssuerInfo
= NULL
;
5012 cert
->lpszSignatureAlgName
= (char *)0xdeadbeef;
5013 cert
->lpszEncryptionAlgName
= (char *)0xdeadbeef;
5014 cert
->lpszProtocolName
= (char *)0xdeadbeef;
5015 cert
->dwKeySize
= 0xdeadbeef;
5016 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, cert
, &size
);
5017 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
5020 ok(cert
->lpszSubjectInfo
&& strlen(cert
->lpszSubjectInfo
) > 1, "expected a non-empty subject name\n");
5021 ok(cert
->lpszIssuerInfo
&& strlen(cert
->lpszIssuerInfo
) > 1, "expected a non-empty issuer name\n");
5022 ok(!cert
->lpszSignatureAlgName
, "unexpected signature algorithm name\n");
5023 ok(!cert
->lpszEncryptionAlgName
, "unexpected encryption algorithm name\n");
5024 ok(!cert
->lpszProtocolName
, "unexpected protocol name\n");
5025 ok(cert
->dwKeySize
!= 0xdeadbeef, "unexpected key size\n");
5027 HeapFree(GetProcessHeap(), 0, cert
);
5029 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5030 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5031 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
5032 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
5033 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5034 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5035 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5037 if(req_error
!= ERROR_INTERNET_SEC_CERT_REV_FAILED
) {
5038 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error
);
5040 close_async_handle(ses
, hCompleteEvent
, 3);
5041 CloseHandle(hCompleteEvent
);
5046 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
5047 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
5049 test_request_flags(req
, 8);
5050 /* IE11 finds both rev failure and invalid CA. Previous versions required rev failure
5051 to be ignored before invalid CA was reported. */
5052 test_secflags_option(req
, _SECURITY_FLAG_CERT_REV_FAILED
, _SECURITY_FLAG_CERT_INVALID_CA
);
5054 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
5055 test_secflags_option(req
, _SECURITY_FLAG_CERT_REV_FAILED
|SECURITY_FLAG_IGNORE_REVOCATION
, _SECURITY_FLAG_CERT_INVALID_CA
);
5057 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5058 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5059 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5060 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5061 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5062 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5063 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5065 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5066 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5068 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5069 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
5071 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5072 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5073 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5074 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5075 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5076 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5077 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5079 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
5080 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5081 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5083 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
5084 test_secflags_option(req
, _SECURITY_FLAG_CERT_INVALID_CA
|_SECURITY_FLAG_CERT_REV_FAILED
5085 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
, 0);
5086 test_http_version(req
);
5088 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5089 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5090 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5091 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5092 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5093 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5094 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5095 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5096 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5097 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5098 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5099 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5100 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5102 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5103 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5105 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5106 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5108 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5109 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5110 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5111 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5112 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5113 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5114 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5115 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5116 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5117 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5118 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5120 test_request_flags(req
, 0);
5121 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
5122 |SECURITY_FLAG_STRENGTH_STRONG
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5124 test_cert_struct(req
, &test_winehq_com_cert
);
5125 test_security_info("https://test.winehq.com/data/some_file.html?q", 0,
5126 _SECURITY_FLAG_CERT_INVALID_CA
|_SECURITY_FLAG_CERT_REV_FAILED
);
5128 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5129 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5130 ok(size
, "size = 0\n");
5132 close_async_handle(ses
, hCompleteEvent
, 3);
5134 /* Collect all existing persistent connections */
5135 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5136 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5138 /* Make another request, without setting security flags */
5140 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5141 ok(ses
!= NULL
, "InternetOpen failed\n");
5143 pInternetSetStatusCallbackA(ses
, &callback
);
5145 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5146 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
5147 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
5148 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
5149 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5151 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5152 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5153 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5155 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5156 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5158 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
5159 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5160 test_http_version(req
);
5162 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5163 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5164 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5165 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5166 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5167 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5168 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5169 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5170 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5171 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5172 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5173 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5175 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5176 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5178 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5179 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5181 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5182 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5183 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5184 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5185 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5186 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5187 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5188 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5189 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5190 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5192 test_request_flags(req
, 0);
5193 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
5194 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5196 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5197 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5198 ok(size
, "size = 0\n");
5200 close_async_handle(ses
, hCompleteEvent
, 2);
5202 CloseHandle(hCompleteEvent
);
5204 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5205 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5206 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5209 static void test_secure_connection(void)
5211 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
5212 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
5213 static const WCHAR get
[] = {'G','E','T',0};
5214 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
5215 HINTERNET ses
, con
, req
;
5217 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
5218 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
5221 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5222 ok(ses
!= NULL
, "InternetOpen failed\n");
5224 con
= InternetConnectA(ses
, "test.winehq.org",
5225 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
5226 INTERNET_SERVICE_HTTP
, 0, 0);
5227 ok(con
!= NULL
, "InternetConnect failed\n");
5229 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5230 INTERNET_FLAG_SECURE
, 0);
5231 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5233 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5234 ok(ret
|| broken(GetLastError() == ERROR_INTERNET_CANNOT_CONNECT
),
5235 "HttpSendRequest failed: %d\n", GetLastError());
5238 win_skip("Cannot connect to https.\n");
5242 size
= sizeof(flags
);
5243 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
5244 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5245 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
5247 test_cert_struct(req
, &test_winehq_org_cert
);
5249 /* Querying the same option through InternetQueryOptionW still results in
5250 * ASCII strings being returned.
5253 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5255 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5256 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
5257 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
5258 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5259 certificate_structW
, &size
);
5260 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
5261 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5264 ok(certificate_structA
->lpszSubjectInfo
&&
5265 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
5266 "expected a non-empty subject name\n");
5267 ok(certificate_structA
->lpszIssuerInfo
&&
5268 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
5269 "expected a non-empty issuer name\n");
5270 ok(!certificate_structA
->lpszSignatureAlgName
,
5271 "unexpected signature algorithm name\n");
5272 ok(!certificate_structA
->lpszEncryptionAlgName
,
5273 "unexpected encryption algorithm name\n");
5274 ok(!certificate_structA
->lpszProtocolName
,
5275 "unexpected protocol name\n");
5276 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
5277 release_cert_info(certificate_structA
);
5279 HeapFree(GetProcessHeap(), 0, certificate_structW
);
5281 InternetCloseHandle(req
);
5282 InternetCloseHandle(con
);
5283 InternetCloseHandle(ses
);
5285 /* Repeating the tests with the W functions has the same result: */
5286 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5287 ok(ses
!= NULL
, "InternetOpen failed\n");
5289 con
= InternetConnectW(ses
, testsite
,
5290 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
5291 INTERNET_SERVICE_HTTP
, 0, 0);
5292 ok(con
!= NULL
, "InternetConnect failed\n");
5294 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
5295 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
5296 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5298 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5299 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
5301 size
= sizeof(flags
);
5302 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
5303 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5304 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %x\n", flags
);
5306 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5308 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5309 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
5310 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
5311 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5312 certificate_structA
, &size
);
5313 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5316 ok(certificate_structA
->lpszSubjectInfo
&&
5317 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
5318 "expected a non-empty subject name\n");
5319 ok(certificate_structA
->lpszIssuerInfo
&&
5320 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
5321 "expected a non-empty issuer name\n");
5322 ok(!certificate_structA
->lpszSignatureAlgName
,
5323 "unexpected signature algorithm name\n");
5324 ok(!certificate_structA
->lpszEncryptionAlgName
,
5325 "unexpected encryption algorithm name\n");
5326 ok(!certificate_structA
->lpszProtocolName
,
5327 "unexpected protocol name\n");
5328 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
5329 release_cert_info(certificate_structA
);
5331 HeapFree(GetProcessHeap(), 0, certificate_structA
);
5333 /* Again, querying the same option through InternetQueryOptionW still
5334 * results in ASCII strings being returned.
5337 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5339 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5340 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
5341 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
5342 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5343 certificate_structW
, &size
);
5344 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
5345 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5348 ok(certificate_structA
->lpszSubjectInfo
&&
5349 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
5350 "expected a non-empty subject name\n");
5351 ok(certificate_structA
->lpszIssuerInfo
&&
5352 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
5353 "expected a non-empty issuer name\n");
5354 ok(!certificate_structA
->lpszSignatureAlgName
,
5355 "unexpected signature algorithm name\n");
5356 ok(!certificate_structA
->lpszEncryptionAlgName
,
5357 "unexpected encryption algorithm name\n");
5358 ok(!certificate_structA
->lpszProtocolName
,
5359 "unexpected protocol name\n");
5360 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
5361 release_cert_info(certificate_structA
);
5363 HeapFree(GetProcessHeap(), 0, certificate_structW
);
5366 InternetCloseHandle(req
);
5367 InternetCloseHandle(con
);
5368 InternetCloseHandle(ses
);
5371 static void test_user_agent_header(void)
5373 HINTERNET ses
, con
, req
;
5378 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5379 ok(ses
!= NULL
, "InternetOpen failed\n");
5381 con
= InternetConnectA(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5382 ok(con
!= NULL
, "InternetConnect failed\n");
5384 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
5385 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5387 size
= sizeof(buffer
);
5388 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5389 err
= GetLastError();
5390 ok(!ret
, "HttpQueryInfo succeeded\n");
5391 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
5393 ret
= HttpAddRequestHeadersA(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
5394 ok(ret
, "HttpAddRequestHeaders succeeded\n");
5396 size
= sizeof(buffer
);
5397 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5398 err
= GetLastError();
5399 ok(ret
, "HttpQueryInfo failed\n");
5401 InternetCloseHandle(req
);
5403 req
= HttpOpenRequestA(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
5404 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5406 size
= sizeof(buffer
);
5407 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5408 err
= GetLastError();
5409 ok(!ret
, "HttpQueryInfo succeeded\n");
5410 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
5412 ret
= HttpAddRequestHeadersA(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
5413 ok(ret
, "HttpAddRequestHeaders failed\n");
5416 size
= sizeof(buffer
);
5417 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5418 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
5419 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
5421 InternetCloseHandle(req
);
5422 InternetCloseHandle(con
);
5423 InternetCloseHandle(ses
);
5426 static void test_bogus_accept_types_array(void)
5428 HINTERNET ses
, con
, req
;
5429 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
5434 ses
= InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
5435 con
= InternetConnectA(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5436 req
= HttpOpenRequestA(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
5438 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
5441 size
= sizeof(buffer
);
5442 SetLastError(0xdeadbeef);
5443 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5444 error
= GetLastError();
5445 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
5446 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
5447 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
5448 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
5449 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
5451 InternetCloseHandle(req
);
5452 InternetCloseHandle(con
);
5453 InternetCloseHandle(ses
);
5462 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
5464 INTERNET_ASYNC_RESULT
*result
= info
;
5465 struct context
*ctx
= (struct context
*)context
;
5467 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
5470 case INTERNET_STATUS_REQUEST_COMPLETE
:
5471 trace("request handle: 0x%08lx\n", result
->dwResult
);
5472 ctx
->req
= (HINTERNET
)result
->dwResult
;
5473 SetEvent(ctx
->event
);
5475 case INTERNET_STATUS_HANDLE_CLOSING
: {
5476 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
5478 if (InternetQueryOptionA(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
5479 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
5480 SetEvent(ctx
->event
);
5483 case INTERNET_STATUS_NAME_RESOLVED
:
5484 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
5485 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
5487 ok(str
[0] && str
[1], "Got string: %s\n", str
);
5488 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
5493 static void test_open_url_async(void)
5501 /* Collect all existing persistent connections */
5502 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5503 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5506 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
5507 * other versions never do. They also hang of following tests. We disable it for everything older
5510 if(!pInternetGetSecurityInfoByURLA
) {
5511 win_skip("Skipping async open on too old wininet version.\n");
5516 ctx
.event
= CreateEventA(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
5518 ses
= InternetOpenA("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5519 ok(ses
!= NULL
, "InternetOpen failed\n");
5521 SetLastError(0xdeadbeef);
5522 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
5523 error
= GetLastError();
5524 ok(!ret
, "InternetSetOptionA succeeded\n");
5525 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
5527 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
5528 error
= GetLastError();
5529 ok(!ret
, "InternetSetOptionA failed\n");
5530 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
5532 pInternetSetStatusCallbackW(ses
, cb
);
5533 ResetEvent(ctx
.event
);
5535 req
= InternetOpenUrlA(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
5536 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
5538 WaitForSingleObject(ctx
.event
, INFINITE
);
5541 size
= sizeof(type
);
5542 ret
= InternetQueryOptionA(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
5543 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
5544 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
5545 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
5548 ret
= HttpQueryInfoA(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
5549 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
5550 ok(size
> 0, "expected size > 0\n");
5552 ResetEvent(ctx
.event
);
5553 InternetCloseHandle(ctx
.req
);
5554 WaitForSingleObject(ctx
.event
, INFINITE
);
5556 InternetCloseHandle(ses
);
5557 CloseHandle(ctx
.event
);
5562 internet_connect
= 1,
5564 http_send_request_ex
,
5567 internet_close_handle
5572 enum api function
; /* api responsible for notification */
5573 unsigned int status
; /* status received */
5574 BOOL async
; /* delivered from another thread? */
5582 const struct notification
*test
;
5588 DWORD expect_result
;
5592 static CRITICAL_SECTION notification_cs
;
5594 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
5596 BOOL status_ok
, function_ok
;
5597 struct info
*info
= (struct info
*)context
;
5600 EnterCriticalSection( ¬ification_cs
);
5602 if(info
->is_aborted
) {
5603 LeaveCriticalSection(¬ification_cs
);
5607 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
5609 DWORD size
= sizeof(struct info
*);
5610 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
5611 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
5612 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
5614 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
5615 if(info
->expect_result
== ERROR_SUCCESS
) {
5616 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
5618 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
5619 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
5624 if (i
>= info
->count
)
5626 LeaveCriticalSection( ¬ification_cs
);
5630 while (info
->test
[i
].status
!= status
&&
5631 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
5632 i
< info
->count
- 1 &&
5633 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
5638 status_ok
= (info
->test
[i
].status
== status
);
5639 function_ok
= (info
->test
[i
].function
== info
->function
);
5641 if (!info
->test
[i
].todo
)
5643 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
5644 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
5646 if (info
->test
[i
].async
)
5647 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
5648 info
->line
, info
->thread
, GetCurrentThreadId());
5652 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
5654 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
5656 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
5659 LeaveCriticalSection( ¬ification_cs
);
5662 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
5664 info
->function
= function
;
5666 info
->expect_result
= expect_result
;
5669 struct notification_data
5671 const struct notification
*test
;
5672 const unsigned int count
;
5677 BOOL expect_conn_failure
;
5680 static const struct notification async_send_request_ex_test
[] =
5682 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5683 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5684 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5685 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
5686 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
5687 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
5688 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
5689 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
5690 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
5691 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
5692 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5693 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, FALSE
},
5694 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, FALSE
},
5695 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
5696 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
5697 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5698 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
5699 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
5700 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
5701 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
5704 static const struct notification async_send_request_ex_test2
[] =
5706 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5707 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5708 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5709 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
5710 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
5711 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
5712 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
, TRUE
},
5713 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
, TRUE
},
5714 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
5715 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
5716 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5717 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
5718 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
5719 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5720 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
5721 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
5722 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
5723 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
5726 static const struct notification async_send_request_ex_resolve_failure_test
[] =
5728 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5729 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
5730 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5731 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
},
5732 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5733 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5734 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5735 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
5736 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
5737 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
5738 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
5741 static const struct notification async_send_request_ex_chunked_test
[] =
5743 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
},
5744 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
},
5745 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
5746 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
5747 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
5748 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
5749 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
5750 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
5751 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
5752 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
5753 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5754 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
5755 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
5756 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
5757 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
},
5758 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
},
5759 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
},
5760 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
}
5763 static const struct notification_data notification_data
[] = {
5765 async_send_request_ex_chunked_test
,
5766 sizeof(async_send_request_ex_chunked_test
)/sizeof(async_send_request_ex_chunked_test
[0]),
5772 async_send_request_ex_test
,
5773 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
5777 "Public ID=codeweavers"
5780 async_send_request_ex_test2
,
5781 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
5787 async_send_request_ex_resolve_failure_test
,
5788 sizeof(async_send_request_ex_resolve_failure_test
)/sizeof(async_send_request_ex_resolve_failure_test
[0]),
5797 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
5800 HINTERNET ses
, req
, con
;
5802 DWORD size
, written
, error
;
5803 INTERNET_BUFFERSA b
;
5804 static const char *accept
[2] = {"*/*", NULL
};
5807 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
5809 InitializeCriticalSection( ¬ification_cs
);
5811 info
.test
= nd
->test
;
5812 info
.count
= nd
->count
;
5814 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
5815 info
.thread
= GetCurrentThreadId();
5816 info
.is_aborted
= FALSE
;
5818 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5819 ok( ses
!= NULL
, "InternetOpen failed\n" );
5821 pInternetSetStatusCallbackA( ses
, check_notification
);
5823 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
5824 con
= InternetConnectA( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
5825 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
5827 WaitForSingleObject( info
.wait
, 10000 );
5829 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
5830 req
= HttpOpenRequestA( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
5831 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
5833 WaitForSingleObject( info
.wait
, 10000 );
5836 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
5837 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
5838 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
5839 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
5840 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
5843 setup_test( &info
, http_send_request_ex
, __LINE__
,
5844 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
5845 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
5846 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
5848 error
= WaitForSingleObject( info
.wait
, 10000 );
5849 if(error
!= WAIT_OBJECT_0
) {
5850 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
5851 info
.is_aborted
= TRUE
;
5855 size
= sizeof(buffer
);
5856 SetLastError( 0xdeadbeef );
5857 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
5858 error
= GetLastError();
5859 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
5860 if(nd
->expect_conn_failure
) {
5861 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
5864 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
5865 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
5871 size
= strlen( nd
->data
);
5872 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
5873 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
5874 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
5875 ok( written
== size
, "expected %u got %u\n", written
, size
);
5877 WaitForSingleObject( info
.wait
, 10000 );
5879 SetLastError( 0xdeadbeef );
5880 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
5881 error
= GetLastError();
5882 ok( !ret
, "HttpEndRequestA succeeded\n" );
5883 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
5886 SetLastError( 0xdeadbeef );
5887 setup_test( &info
, http_end_request
, __LINE__
,
5888 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
5889 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
5890 error
= GetLastError();
5891 ok( !ret
, "HttpEndRequestA succeeded\n" );
5892 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
5894 WaitForSingleObject( info
.wait
, 10000 );
5896 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
5898 InternetCloseHandle( req
);
5899 InternetCloseHandle( con
);
5900 InternetCloseHandle( ses
);
5902 WaitForSingleObject( info
.wait
, 10000 );
5904 CloseHandle( info
.wait
);
5907 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
5908 static BOOL closetest_closed
;
5910 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
5911 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
5916 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
5918 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
5919 "Unexpected hInternet %p\n", hInternet
);
5920 if(!closetest_closed
)
5924 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
5925 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
5926 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5927 closetest_req
, res
, GetLastError());
5930 static void test_InternetCloseHandle(void)
5935 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5936 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
5938 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
5940 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
5941 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
5942 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
5944 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
5945 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
5947 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
5948 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
5949 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
5951 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
5953 res
= InternetCloseHandle(closetest_session
);
5954 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
5955 closetest_closed
= TRUE
;
5956 trace("Closed session handle\n");
5958 res
= InternetCloseHandle(closetest_conn
);
5959 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
5960 res
, GetLastError());
5962 res
= InternetCloseHandle(closetest_req
);
5963 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
5964 res
, GetLastError());
5966 len
= sizeof(flags
);
5967 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
5968 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
5969 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
5970 closetest_req
, res
, GetLastError());
5973 static void test_connection_failure(void)
5975 HINTERNET session
, connect
, request
;
5979 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5980 ok(session
!= NULL
, "failed to get session handle\n");
5982 connect
= InternetConnectA(session
, "localhost", 1, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5983 ok(connect
!= NULL
, "failed to get connection handle\n");
5985 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
5986 ok(request
!= NULL
, "failed to get request handle\n");
5988 SetLastError(0xdeadbeef);
5989 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
5990 error
= GetLastError();
5991 ok(!ret
, "unexpected success\n");
5992 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
5994 InternetCloseHandle(request
);
5995 InternetCloseHandle(connect
);
5996 InternetCloseHandle(session
);
5999 static void test_default_service_port(void)
6001 HINTERNET session
, connect
, request
;
6005 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
6006 ok(session
!= NULL
, "InternetOpen failed\n");
6008 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6009 INTERNET_SERVICE_HTTP
, 0, 0);
6010 ok(connect
!= NULL
, "InternetConnect failed\n");
6012 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
6013 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6015 SetLastError(0xdeadbeef);
6016 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6017 error
= GetLastError();
6018 ok(!ret
, "HttpSendRequest succeeded\n");
6019 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
6022 InternetCloseHandle(request
);
6023 InternetCloseHandle(connect
);
6024 InternetCloseHandle(session
);
6027 static void init_status_tests(void)
6029 memset(expect
, 0, sizeof(expect
));
6030 memset(optional
, 0, sizeof(optional
));
6031 memset(wine_allow
, 0, sizeof(wine_allow
));
6032 memset(notified
, 0, sizeof(notified
));
6033 memset(status_string
, 0, sizeof(status_string
));
6035 #define STATUS_STRING(status) status_string[status] = #status
6036 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
6037 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
6038 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6039 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6040 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
6041 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
6042 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
6043 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
6044 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
6045 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
6046 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
6047 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
6048 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
6049 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
6050 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
6051 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
6052 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
6053 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
6054 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
6055 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
6056 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
6057 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
6058 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
6059 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
6060 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
6061 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
6062 #undef STATUS_STRING
6065 static void WINAPI
header_cb( HINTERNET handle
, DWORD_PTR ctx
, DWORD status
, LPVOID info
, DWORD len
)
6067 if (status
== INTERNET_STATUS_REQUEST_COMPLETE
) SetEvent( (HANDLE
)ctx
);
6070 static void test_concurrent_header_access(void)
6072 HINTERNET ses
, con
, req
;
6073 DWORD index
, len
, err
;
6076 HANDLE wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
6078 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6079 ok( ses
!= NULL
, "InternetOpenA failed\n" );
6081 con
= InternetConnectA( ses
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
6082 INTERNET_SERVICE_HTTP
, 0, 0 );
6083 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
6085 req
= HttpOpenRequestA( con
, NULL
, "/", NULL
, NULL
, NULL
, 0, (DWORD_PTR
)wait
);
6086 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
6088 pInternetSetStatusCallbackA( req
, header_cb
);
6090 SetLastError( 0xdeadbeef );
6091 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
6092 err
= GetLastError();
6093 ok( !ret
, "HttpSendRequestA succeeded\n" );
6094 ok( err
== ERROR_IO_PENDING
, "got %u\n", ERROR_IO_PENDING
);
6096 ret
= HttpAddRequestHeadersA( req
, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD
);
6097 ok( ret
, "HttpAddRequestHeadersA failed %u\n", GetLastError() );
6101 ret
= HttpQueryInfoA( req
, HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
6102 buf
, &len
, &index
);
6103 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
6104 ok( strstr( buf
, "winetest: winetest" ) != NULL
, "header missing\n" );
6106 WaitForSingleObject( wait
, 5000 );
6108 InternetCloseHandle( req
);
6109 InternetCloseHandle( con
);
6110 InternetCloseHandle( ses
);
6111 CloseHandle( wait
);
6117 hdll
= GetModuleHandleA("wininet.dll");
6119 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
6120 win_skip("Too old IE (older than 6.0)\n");
6124 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
6125 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
6126 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
6128 init_status_tests();
6129 test_InternetCloseHandle();
6130 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
6131 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
6132 InternetReadFile_test(0, &test_data
[1]);
6133 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
6134 test_security_flags();
6135 InternetReadFile_test(0, &test_data
[2]);
6136 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
6137 test_open_url_async();
6138 test_async_HttpSendRequestEx(¬ification_data
[0]);
6139 test_async_HttpSendRequestEx(¬ification_data
[1]);
6140 test_async_HttpSendRequestEx(¬ification_data
[2]);
6141 test_async_HttpSendRequestEx(¬ification_data
[3]);
6142 InternetOpenRequest_test();
6144 InternetLockRequestFile_test();
6145 InternetOpenUrlA_test();
6147 test_http_connection();
6148 test_secure_connection();
6149 test_user_agent_header();
6150 test_bogus_accept_types_array();
6151 InternetReadFile_chunked_test();
6152 HttpSendRequestEx_test();
6153 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
6154 test_connection_failure();
6155 test_default_service_port();
6156 test_concurrent_header_access();