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
, conn_wait_event
, server_req_rec_event
;
118 static DWORD req_error
;
119 static BOOL is_ie7plus
= TRUE
;
121 #define TESTF_REDIRECT 0x01
122 #define TESTF_COMPRESSED 0x02
123 #define TESTF_CHUNKED 0x04
127 const char *redirected_url
;
132 const char *post_data
;
136 static const test_data_t test_data
[] = {
138 "http://test.winehq.org/tests/data.php",
139 "http://test.winehq.org/tests/data.php",
146 "http://test.winehq.org/tests/redirect",
147 "http://test.winehq.org/tests/hello.html",
154 "http://test.winehq.org/tests/gzip.php",
155 "http://test.winehq.org/tests/gzip.php",
158 "Accept-Encoding: gzip, deflate",
162 "http://test.winehq.org/tests/post.php",
163 "http://test.winehq.org/tests/post.php",
166 "Content-Type: application/x-www-form-urlencoded",
173 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackA
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
174 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackW
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
175 static BOOL (WINAPI
*pInternetGetSecurityInfoByURLA
)(LPSTR
,PCCERT_CHAIN_CONTEXT
*,DWORD
*);
177 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
180 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
181 return lstrcmpW(strw
, buf
);
184 static BOOL
proxy_active(void)
186 HKEY internet_settings
;
190 if (RegOpenKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
191 0, KEY_QUERY_VALUE
, &internet_settings
) != ERROR_SUCCESS
)
194 size
= sizeof(DWORD
);
195 if (RegQueryValueExA(internet_settings
, "ProxyEnable", NULL
, NULL
, (LPBYTE
) &proxy_enable
, &size
) != ERROR_SUCCESS
)
198 RegCloseKey(internet_settings
);
200 return proxy_enable
!= 0;
203 #define test_status_code(a,b) _test_status_code(__LINE__,a,b, FALSE)
204 #define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)
205 static void _test_status_code(unsigned line
, HINTERNET req
, DWORD excode
, BOOL is_todo
)
207 DWORD code
, size
, index
;
208 char exbuf
[12], bufa
[10];
214 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, NULL
);
215 ok_(__FILE__
,line
)(res
, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
216 todo_wine_if (is_todo
)
217 ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
218 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
223 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
224 ok_(__FILE__
,line
)(res
, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
225 ok_(__FILE__
,line
)(!index
, "index = %d, expected 0\n", index
);
226 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
228 sprintf(exbuf
, "%u", excode
);
231 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, bufa
, &size
, NULL
);
232 ok_(__FILE__
,line
)(res
, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
233 todo_wine_if (is_todo
)
234 ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
235 ok_(__FILE__
,line
)(size
== strlen(exbuf
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
238 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
239 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
240 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
241 ok_(__FILE__
,line
)(size
== strlen(exbuf
)+1, "unexpected size %d for \"%s\"\n", size
, exbuf
);
244 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
245 ok_(__FILE__
,line
)(res
, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
246 todo_wine_if (is_todo
)
247 ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
248 ok_(__FILE__
,line
)(size
== strlen(exbuf
)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
251 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
252 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
253 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
254 ok_(__FILE__
,line
)(size
== (strlen(exbuf
)+1)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
258 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
259 ok(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
260 ok(size
== sizeof(bufw
), "unexpected size %d\n", size
);
266 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
267 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
268 "[7] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
272 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, &code
, &size
, NULL
);
273 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST
,
274 "[8] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
277 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
278 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
279 static void _test_request_flags(unsigned line
, HINTERNET req
, DWORD exflags
, BOOL is_todo
)
285 size
= sizeof(flags
);
286 res
= InternetQueryOptionW(req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &size
);
287 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
289 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
290 flags
&= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED
;
291 todo_wine_if (is_todo
)
292 ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
295 #define test_http_version(a) _test_http_version(__LINE__,a)
296 static void _test_http_version(unsigned line
, HINTERNET req
)
298 HTTP_VERSION_INFO v
= {0xdeadbeef, 0xdeadbeef};
303 res
= InternetQueryOptionW(req
, INTERNET_OPTION_HTTP_VERSION
, &v
, &size
);
304 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
305 ok_(__FILE__
,line
)(v
.dwMajorVersion
== 1, "dwMajorVersion = %d\n", v
.dwMajorVersion
);
306 ok_(__FILE__
,line
)(v
.dwMinorVersion
== 1, "dwMinorVersion = %d\n", v
.dwMinorVersion
);
309 static int close_handle_cnt
;
311 static VOID WINAPI
callback(
314 DWORD dwInternetStatus
,
315 LPVOID lpvStatusInformation
,
316 DWORD dwStatusInformationLength
319 CHECK_EXPECT(dwInternetStatus
);
320 switch (dwInternetStatus
)
322 case INTERNET_STATUS_RESOLVING_NAME
:
323 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
324 GetCurrentThreadId(), hInternet
, dwContext
,
325 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
326 *(LPSTR
)lpvStatusInformation
= '\0';
328 case INTERNET_STATUS_NAME_RESOLVED
:
329 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
330 GetCurrentThreadId(), hInternet
, dwContext
,
331 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
332 *(LPSTR
)lpvStatusInformation
= '\0';
334 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
335 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
336 GetCurrentThreadId(), hInternet
, dwContext
,
337 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
338 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
339 dwStatusInformationLength
);
340 *(LPSTR
)lpvStatusInformation
= '\0';
342 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
343 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
344 GetCurrentThreadId(), hInternet
, dwContext
,
345 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
346 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
347 dwStatusInformationLength
);
348 *(LPSTR
)lpvStatusInformation
= '\0';
350 case INTERNET_STATUS_SENDING_REQUEST
:
351 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
352 GetCurrentThreadId(), hInternet
, dwContext
,
353 lpvStatusInformation
,dwStatusInformationLength
);
355 case INTERNET_STATUS_REQUEST_SENT
:
356 ok(dwStatusInformationLength
== sizeof(DWORD
),
357 "info length should be sizeof(DWORD) instead of %d\n",
358 dwStatusInformationLength
);
359 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
360 GetCurrentThreadId(), hInternet
, dwContext
,
361 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
363 case INTERNET_STATUS_RECEIVING_RESPONSE
:
364 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
365 GetCurrentThreadId(), hInternet
, dwContext
,
366 lpvStatusInformation
,dwStatusInformationLength
);
368 case INTERNET_STATUS_RESPONSE_RECEIVED
:
369 ok(dwStatusInformationLength
== sizeof(DWORD
),
370 "info length should be sizeof(DWORD) instead of %d\n",
371 dwStatusInformationLength
);
372 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
373 GetCurrentThreadId(), hInternet
, dwContext
,
374 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
376 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
377 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
378 GetCurrentThreadId(), hInternet
,dwContext
,
379 lpvStatusInformation
,dwStatusInformationLength
);
381 case INTERNET_STATUS_PREFETCH
:
382 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
383 GetCurrentThreadId(), hInternet
, dwContext
,
384 lpvStatusInformation
,dwStatusInformationLength
);
386 case INTERNET_STATUS_CLOSING_CONNECTION
:
387 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
388 GetCurrentThreadId(), hInternet
, dwContext
,
389 lpvStatusInformation
,dwStatusInformationLength
);
391 case INTERNET_STATUS_CONNECTION_CLOSED
:
392 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
393 GetCurrentThreadId(), hInternet
, dwContext
,
394 lpvStatusInformation
,dwStatusInformationLength
);
396 case INTERNET_STATUS_HANDLE_CREATED
:
397 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
398 "info length should be sizeof(HINTERNET) instead of %d\n",
399 dwStatusInformationLength
);
400 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
401 GetCurrentThreadId(), hInternet
, dwContext
,
402 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
403 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
404 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
406 case INTERNET_STATUS_HANDLE_CLOSING
:
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_CLOSING %p %d\n",
411 GetCurrentThreadId(), hInternet
, dwContext
,
412 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
413 if(!InterlockedDecrement(&close_handle_cnt
))
414 SetEvent(hCompleteEvent
);
416 case INTERNET_STATUS_REQUEST_COMPLETE
:
418 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
419 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
420 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
421 dwStatusInformationLength
);
422 ok(iar
->dwResult
== 1 || iar
->dwResult
== 0, "iar->dwResult = %ld\n", iar
->dwResult
);
423 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
424 GetCurrentThreadId(), hInternet
, dwContext
,
425 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
426 req_error
= iar
->dwError
;
427 if(!close_handle_cnt
)
428 SetEvent(hCompleteEvent
);
431 case INTERNET_STATUS_REDIRECT
:
432 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
433 GetCurrentThreadId(), hInternet
, dwContext
,
434 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
435 *(LPSTR
)lpvStatusInformation
= '\0';
436 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
437 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
439 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
440 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
441 GetCurrentThreadId(), hInternet
, dwContext
,
442 lpvStatusInformation
, dwStatusInformationLength
);
445 trace("%04x:Callback %p 0x%lx %d %p %d\n",
446 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
447 lpvStatusInformation
, dwStatusInformationLength
);
453 HINTERNET connection
;
457 #define open_simple_request(a,b,c,d,e) _open_simple_request(__LINE__,a,b,c,d,e)
458 static void _open_simple_request(unsigned line
, test_request_t
*req
, const char *host
,
459 int port
, const char *verb
, const char *url
)
461 req
->session
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
462 ok_(__FILE__
,line
)(req
->session
!= NULL
, "InternetOpenA failed: %u\n", GetLastError());
464 req
->connection
= InternetConnectA(req
->session
, host
, port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
465 ok_(__FILE__
,line
)(req
->connection
!= NULL
, "InternetConnectA failed: %u\n", GetLastError());
467 req
->request
= HttpOpenRequestA(req
->connection
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
468 ok_(__FILE__
,line
)(req
->request
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
471 #define close_request(a) _close_request(__LINE__,a)
472 static void _close_request(unsigned line
, test_request_t
*req
)
476 ret
= InternetCloseHandle(req
->request
);
477 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(request) failed: %u\n", GetLastError());
478 ret
= InternetCloseHandle(req
->connection
);
479 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(connection) failed: %u\n", GetLastError());
480 ret
= InternetCloseHandle(req
->session
);
481 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(session) failed: %u\n", GetLastError());
484 #define receive_simple_request(a,b,c) _receive_simple_request(__LINE__,a,b,c)
485 static DWORD
_receive_simple_request(unsigned line
, HINTERNET req
, char *buf
, size_t buf_size
)
490 ret
= InternetReadFile(req
, buf
, buf_size
, &read
);
491 ok_(__FILE__
,line
)(ret
, "InternetReadFile failed: %u\n", GetLastError());
496 static void close_async_handle(HINTERNET handle
, HANDLE complete_event
, int handle_cnt
)
500 close_handle_cnt
= handle_cnt
;
502 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
503 res
= InternetCloseHandle(handle
);
504 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
505 WaitForSingleObject(hCompleteEvent
, INFINITE
);
506 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
509 static void InternetReadFile_test(int flags
, const test_data_t
*test
)
511 char *post_data
= NULL
;
512 BOOL res
, on_async
= TRUE
;
515 DWORD length
, length2
, index
, exlen
= 0, post_len
= 0;
516 const char *types
[2] = { "*", NULL
};
517 HINTERNET hi
, hic
= 0, hor
= 0;
519 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
521 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags
,test
->url
);
523 trace("InternetOpenA <--\n");
524 hi
= InternetOpenA((test
->flags
& TESTF_COMPRESSED
) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
525 INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
526 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
527 trace("InternetOpenA -->\n");
529 if (hi
== 0x0) goto abort
;
531 pInternetSetStatusCallbackA(hi
,&callback
);
533 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
535 trace("InternetConnectA <--\n");
536 hic
=InternetConnectA(hi
, test
->host
, INTERNET_INVALID_PORT_NUMBER
,
537 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
538 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
539 trace("InternetConnectA -->\n");
541 if (hic
== 0x0) goto abort
;
543 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
544 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
546 trace("HttpOpenRequestA <--\n");
547 hor
= HttpOpenRequestA(hic
, test
->post_data
? "POST" : "GET", test
->path
, NULL
, NULL
, types
,
548 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
550 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
552 * If the internet name can't be resolved we are probably behind
553 * a firewall or in some other way not directly connected to the
554 * Internet. Not enough reason to fail the test. Just ignore and
558 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
560 trace("HttpOpenRequestA -->\n");
562 if (hor
== 0x0) goto abort
;
564 test_request_flags(hor
, INTERNET_REQFLAG_NO_HEADERS
);
566 length
= sizeof(buffer
);
567 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
568 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
569 ok(!strcmp(buffer
, test
->url
), "Wrong URL %s, expected %s\n", buffer
, test
->url
);
571 length
= sizeof(buffer
);
572 res
= HttpQueryInfoA(hor
, HTTP_QUERY_RAW_HEADERS
, buffer
, &length
, 0x0);
573 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
574 ok(length
== 0 || (length
== 1 && !*buffer
) /* win10 */, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length
);
575 ok(!strcmp(buffer
, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer
);
577 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
578 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
579 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
580 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
,2);
581 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED
,2);
582 if (first_connection_to_test_url
)
584 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
585 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
587 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
588 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
589 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
590 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
591 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
592 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
593 if(test
->flags
& TESTF_REDIRECT
) {
594 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
595 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
597 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
598 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
599 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
600 if (flags
& INTERNET_FLAG_ASYNC
)
601 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
603 if(test
->flags
& TESTF_COMPRESSED
) {
606 res
= InternetSetOptionA(hor
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
607 ok(res
|| broken(!res
&& GetLastError() == ERROR_INTERNET_INVALID_OPTION
),
608 "InternetSetOption failed: %u\n", GetLastError());
613 test_status_code(hor
, 0);
615 trace("HttpSendRequestA -->\n");
616 if(test
->post_data
) {
617 post_len
= strlen(test
->post_data
);
618 post_data
= HeapAlloc(GetProcessHeap(), 0, post_len
);
619 memcpy(post_data
, test
->post_data
, post_len
);
621 SetLastError(0xdeadbeef);
622 res
= HttpSendRequestA(hor
, test
->headers
, -1, post_data
, post_len
);
623 if (flags
& INTERNET_FLAG_ASYNC
)
624 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
625 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
627 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
628 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
629 trace("HttpSendRequestA <--\n");
631 if (flags
& INTERNET_FLAG_ASYNC
) {
632 WaitForSingleObject(hCompleteEvent
, INFINITE
);
633 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
635 HeapFree(GetProcessHeap(), 0, post_data
);
637 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
638 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED
);
639 if (first_connection_to_test_url
)
641 if (! proxy_active())
643 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
644 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
648 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
649 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
654 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
655 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
657 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
658 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
659 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
660 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
661 if(test
->flags
& TESTF_REDIRECT
)
662 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
663 if (flags
& INTERNET_FLAG_ASYNC
)
664 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
665 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
666 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
667 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
669 test_request_flags(hor
, 0);
672 res
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
673 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
675 length
= sizeof(buffer
)-1;
676 memset(buffer
, 0x77, sizeof(buffer
));
677 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
678 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
679 /* show that the function writes data past the length returned */
680 ok(buffer
[length
-2], "Expected any header character, got 0x00\n");
681 ok(!buffer
[length
-1], "Expected 0x00, got %02X\n", buffer
[length
-1]);
682 ok(!buffer
[length
], "Expected 0x00, got %02X\n", buffer
[length
]);
683 ok(buffer
[length
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length
+1]);
686 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
687 ok(!res
, "Expected 0x00, got %d\n", res
);
688 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
689 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
690 /* the in length of the buffer must be +1 but the length returned does not count this */
692 memset(buffer
, 0x77, sizeof(buffer
));
693 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
694 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
695 ok(buffer
[length2
] == 0x00, "Expected 0x00, got %02X\n", buffer
[length2
]);
696 ok(buffer
[length2
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length2
+1]);
697 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
699 length
= sizeof(wbuffer
)-sizeof(WCHAR
);
700 memset(wbuffer
, 0x77, sizeof(wbuffer
));
701 res
= HttpQueryInfoW(hor
, HTTP_QUERY_RAW_HEADERS
, wbuffer
, &length
, 0x0);
702 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
703 ok(length
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length
);
704 length
/= sizeof(WCHAR
);
705 /* show that the function writes data past the length returned */
706 ok(wbuffer
[length
-2], "Expected any header character, got 0x0000\n");
707 ok(!wbuffer
[length
-1], "Expected 0x0000, got %04X\n", wbuffer
[length
-1]);
708 ok(!wbuffer
[length
], "Expected 0x0000, got %04X\n", wbuffer
[length
]);
709 ok(wbuffer
[length
+1] == 0x7777 || broken(wbuffer
[length
+1] != 0x7777),
710 "Expected 0x7777, got %04X\n", wbuffer
[length
+1]);
712 length2
= length
*sizeof(WCHAR
);
713 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
714 ok(!res
, "Expected 0x00, got %d\n", res
);
715 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
716 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
717 length2
/= sizeof(WCHAR
);
718 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
719 /* the in length of the buffer must be +1 but the length returned does not count this */
720 length2
= (length
+1)*sizeof(WCHAR
);
721 memset(wbuffer
, 0x77, sizeof(wbuffer
));
722 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
723 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
724 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
725 length2
/= sizeof(WCHAR
);
726 ok(!wbuffer
[length2
], "Expected 0x0000, got %04X\n", wbuffer
[length2
]);
727 ok(wbuffer
[length2
+1] == 0x7777, "Expected 0x7777, got %04X\n", wbuffer
[length2
+1]);
728 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
730 length
= sizeof(buffer
);
731 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
732 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
733 ok(!strcmp(buffer
, test
->redirected_url
), "Wrong URL %s\n", buffer
);
737 SetLastError(0xdeadbeef);
738 ok(HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,NULL
,&length
,&index
) == FALSE
,"Query worked\n");
739 if(test
->flags
& TESTF_COMPRESSED
)
740 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
741 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
742 ok(index
== 0, "Index was incremented\n");
746 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,&index
);
747 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res
,buffer
,GetLastError());
748 if(test
->flags
& TESTF_COMPRESSED
)
749 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
750 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res
, GetLastError());
751 ok(!res
|| index
== 1, "Index was not incremented although result is %x (index = %u)\n", res
, index
);
754 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
756 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res
,buffer
);
759 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_ENCODING
,buffer
,&length
,0x0);
761 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res
,buffer
);
763 SetLastError(0xdeadbeef);
764 res
= InternetReadFile(NULL
, buffer
, 100, &length
);
765 ok(!res
, "InternetReadFile should have failed\n");
766 ok(GetLastError() == ERROR_INVALID_HANDLE
,
767 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
771 trace("Entering Query loop\n");
775 if (flags
& INTERNET_FLAG_ASYNC
)
776 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
778 /* IE11 calls those in InternetQueryDataAvailable call. */
779 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
780 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
783 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
785 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
787 if (flags
& INTERNET_FLAG_ASYNC
)
791 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
793 ok(length
>= exlen
, "length %u < exlen %u\n", length
, exlen
);
797 else if (GetLastError() == ERROR_IO_PENDING
)
800 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
801 if(!(test
->flags
& TESTF_CHUNKED
))
802 ok(!length
, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length
);
803 WaitForSingleObject(hCompleteEvent
, INFINITE
);
805 ok(exlen
, "length = 0\n");
806 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
807 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
808 ok(req_error
, "req_error = 0\n");
811 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
814 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
816 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
818 trace("LENGTH %d\n", length
);
819 if(test
->flags
& TESTF_CHUNKED
)
820 ok(length
<= 8192, "length = %d, expected <= 8192\n", length
);
824 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
826 res
= InternetReadFile(hor
,buffer
,length
,&length
);
830 trace("ReadFile -> %s %i\n",res
?"TRUE":"FALSE",length
);
833 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
834 HeapFree(GetProcessHeap(),0,buffer
);
836 ok(!on_async
, "Returned zero size in response to request complete\n");
841 if(test
->flags
& TESTF_REDIRECT
) {
842 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
843 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
847 close_async_handle(hi
, hCompleteEvent
, 2);
848 CloseHandle(hCompleteEvent
);
849 first_connection_to_test_url
= FALSE
;
852 static void InternetReadFile_chunked_test(void)
857 const char *types
[2] = { "*", NULL
};
858 HINTERNET hi
, hic
= 0, hor
= 0;
860 trace("Starting InternetReadFile chunked test\n");
862 trace("InternetOpenA <--\n");
863 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
864 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
865 trace("InternetOpenA -->\n");
867 if (hi
== 0x0) goto abort
;
869 trace("InternetConnectA <--\n");
870 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
871 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
872 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
873 trace("InternetConnectA -->\n");
875 if (hic
== 0x0) goto abort
;
877 trace("HttpOpenRequestA <--\n");
878 hor
= HttpOpenRequestA(hic
, "GET", "/tests/chunked", NULL
, NULL
, types
,
879 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
881 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
883 * If the internet name can't be resolved we are probably behind
884 * a firewall or in some other way not directly connected to the
885 * Internet. Not enough reason to fail the test. Just ignore and
889 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
891 trace("HttpOpenRequestA -->\n");
893 if (hor
== 0x0) goto abort
;
895 trace("HttpSendRequestA -->\n");
896 SetLastError(0xdeadbeef);
897 res
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
898 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
899 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
900 trace("HttpSendRequestA <--\n");
902 test_request_flags(hor
, 0);
905 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
907 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
909 SetLastError( 0xdeadbeef );
911 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
913 trace("Option TRANSFER_ENCODING -> %i %s\n",res
,buffer
);
914 ok( res
|| ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
915 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
916 ok( !strcmp( buffer
, "chunked" ) || ( ! res
&& proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
917 "Wrong transfer encoding '%s'\n", buffer
);
919 SetLastError( 0xdeadbeef );
921 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
922 ok( !res
, "Found CONTENT_LENGTH option '%s'\n", buffer
);
923 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Wrong error %u\n", GetLastError() );
926 trace("Entering Query loop\n");
930 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
931 ok(!(!res
&& length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
932 ok(res
, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
933 trace("got %u available\n",length
);
936 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
938 res
= InternetReadFile(hor
,buffer
,length
,&got
);
941 trace("ReadFile -> %i %i\n",res
,got
);
942 ok( length
== got
, "only got %u of %u available\n", got
, length
);
943 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
945 HeapFree(GetProcessHeap(),0,buffer
);
951 res
= InternetReadFile( hor
, buffer
, 1, &got
);
952 ok( res
, "InternetReadFile failed: %u\n", GetLastError() );
953 ok( !got
, "got %u\n", got
);
960 res
= InternetCloseHandle(hor
);
961 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
964 res
= InternetCloseHandle(hi
);
965 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
969 static void InternetReadFileExA_test(int flags
)
973 const char *types
[2] = { "*", NULL
};
974 HINTERNET hi
, hic
= 0, hor
= 0;
975 INTERNET_BUFFERSA inetbuffers
;
977 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
979 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
981 trace("InternetOpenA <--\n");
982 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
983 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
984 trace("InternetOpenA -->\n");
986 if (hi
== 0x0) goto abort
;
988 pInternetSetStatusCallbackA(hi
,&callback
);
990 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
992 trace("InternetConnectA <--\n");
993 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
994 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
995 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
996 trace("InternetConnectA -->\n");
998 if (hic
== 0x0) goto abort
;
1000 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1001 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1003 trace("HttpOpenRequestA <--\n");
1004 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
1005 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
1007 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
1009 * If the internet name can't be resolved we are probably behind
1010 * a firewall or in some other way not directly connected to the
1011 * Internet. Not enough reason to fail the test. Just ignore and
1015 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
1017 trace("HttpOpenRequestA -->\n");
1019 if (hor
== 0x0) goto abort
;
1021 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1022 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1023 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1024 if (first_connection_to_test_url
)
1026 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
1027 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
1029 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
, 2);
1030 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1031 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1032 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1033 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
1034 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1035 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1036 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1037 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1038 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
1039 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1040 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1041 if (flags
& INTERNET_FLAG_ASYNC
)
1042 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1044 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1046 trace("HttpSendRequestA -->\n");
1047 SetLastError(0xdeadbeef);
1048 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
1049 if (flags
& INTERNET_FLAG_ASYNC
)
1050 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
1051 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
1053 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
1054 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
1055 trace("HttpSendRequestA <--\n");
1057 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
1058 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1059 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1062 if (first_connection_to_test_url
)
1064 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1065 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1069 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1070 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1072 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1073 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
1074 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1075 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1076 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1077 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1078 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
1079 if (flags
& INTERNET_FLAG_ASYNC
)
1080 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1082 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1083 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
1084 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
1085 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1086 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1089 rc
= InternetReadFileExW(hor
, NULL
, 0, 0xdeadcafe);
1090 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1091 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1092 rc
? "TRUE" : "FALSE", GetLastError());
1095 /* tests invalid dwStructSize */
1096 inetbuffers
.dwStructSize
= sizeof(inetbuffers
)+1;
1097 inetbuffers
.lpcszHeader
= NULL
;
1098 inetbuffers
.dwHeadersLength
= 0;
1099 inetbuffers
.dwBufferLength
= 10;
1100 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
1101 inetbuffers
.dwOffsetHigh
= 1234;
1102 inetbuffers
.dwOffsetLow
= 5678;
1103 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1104 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1105 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1106 rc
? "TRUE" : "FALSE", GetLastError());
1107 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1109 test_request_flags(hor
, 0);
1111 /* tests to see whether lpcszHeader is used - it isn't */
1112 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1113 inetbuffers
.lpcszHeader
= (LPCSTR
)0xdeadbeef;
1114 inetbuffers
.dwHeadersLength
= 255;
1115 inetbuffers
.dwBufferLength
= 0;
1116 inetbuffers
.lpvBuffer
= NULL
;
1117 inetbuffers
.dwOffsetHigh
= 1234;
1118 inetbuffers
.dwOffsetLow
= 5678;
1119 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
1120 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
1121 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1122 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
1123 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1126 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1127 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1130 rc
= InternetReadFileExA(NULL
, &inetbuffers
, 0, 0xdeadcafe);
1131 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
1132 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1133 rc
? "TRUE" : "FALSE", GetLastError());
1136 trace("Entering Query loop\n");
1140 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1141 inetbuffers
.dwBufferLength
= 1024;
1142 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
1143 inetbuffers
.dwOffsetHigh
= 1234;
1144 inetbuffers
.dwOffsetLow
= 5678;
1146 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1147 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1148 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1149 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
1152 if (GetLastError() == ERROR_IO_PENDING
)
1154 trace("InternetReadFileEx -> PENDING\n");
1155 ok(flags
& INTERNET_FLAG_ASYNC
,
1156 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1157 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1158 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1159 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1160 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1161 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1165 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1171 trace("InternetReadFileEx -> SUCCEEDED\n");
1172 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1173 if (inetbuffers
.dwBufferLength
)
1176 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1177 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1182 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1183 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1184 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1188 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1189 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
1191 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
1192 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1193 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
1195 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1197 if (!inetbuffers
.dwBufferLength
)
1200 length
+= inetbuffers
.dwBufferLength
;
1202 ok(length
> 0, "failed to read any of the document\n");
1203 trace("Finished. Read %d bytes\n", length
);
1206 close_async_handle(hi
, hCompleteEvent
, 2);
1207 CloseHandle(hCompleteEvent
);
1208 first_connection_to_test_url
= FALSE
;
1211 static void InternetOpenUrlA_test(void)
1213 HINTERNET myhinternet
, myhttp
;
1215 DWORD size
, readbytes
, totalbytes
=0;
1218 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1219 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
1220 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret
, GetLastError());
1222 myhinternet
= InternetOpenA("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
1223 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
1225 ret
= InternetCanonicalizeUrlA(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1226 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1229 myhttp
= InternetOpenUrlA(myhinternet
, TEST_URL
, 0, 0,
1230 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
1231 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1232 return; /* WinXP returns this when not connected to the net */
1233 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1234 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
1235 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
1236 totalbytes
+= readbytes
;
1237 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
1238 totalbytes
+= readbytes
;
1239 trace("read 0x%08x bytes\n",totalbytes
);
1241 InternetCloseHandle(myhttp
);
1242 InternetCloseHandle(myhinternet
);
1244 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1245 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1248 static void HttpSendRequestEx_test(void)
1254 INTERNET_BUFFERSA BufferIn
;
1255 DWORD dwBytesWritten
, dwBytesRead
, error
;
1260 static char szPostData
[] = "mode=Test";
1261 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
1263 hSession
= InternetOpenA("Wine Regression Test",
1264 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1265 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1266 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1267 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1269 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1270 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1271 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1272 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1274 skip( "Network unreachable, skipping test\n" );
1277 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1279 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1281 BufferIn
.dwStructSize
= sizeof(BufferIn
);
1282 BufferIn
.Next
= (INTERNET_BUFFERSA
*)0xdeadcab;
1283 BufferIn
.lpcszHeader
= szContentType
;
1284 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1285 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1286 BufferIn
.lpvBuffer
= szPostData
;
1287 BufferIn
.dwBufferLength
= 3;
1288 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1289 BufferIn
.dwOffsetLow
= 0;
1290 BufferIn
.dwOffsetHigh
= 0;
1292 SetLastError(0xdeadbeef);
1293 ret
= HttpSendRequestExA(hRequest
, &BufferIn
, NULL
, 0 ,0);
1294 error
= GetLastError();
1295 ok(ret
, "HttpSendRequestEx Failed with error %u\n", error
);
1296 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", error
);
1298 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1300 for (i
= 3; szPostData
[i
]; i
++)
1301 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1302 "InternetWriteFile failed\n");
1304 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1306 ok(HttpEndRequestA(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1308 test_request_flags(hRequest
, 0);
1310 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1311 "Unable to read response\n");
1312 szBuffer
[dwBytesRead
] = 0;
1314 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
1315 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1317 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1319 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1320 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1323 static void InternetOpenRequest_test(void)
1325 HINTERNET session
, connect
, request
;
1326 static const char *types
[] = { "*", "", NULL
};
1327 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1328 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1331 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1332 ok(session
!= NULL
,"Unable to open Internet session\n");
1334 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1335 INTERNET_SERVICE_HTTP
, 0, 0);
1336 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1337 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1339 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1340 INTERNET_SERVICE_HTTP
, 0, 0);
1341 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1342 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1344 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1345 INTERNET_SERVICE_HTTP
, 0, 0);
1346 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1348 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1349 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1351 skip( "Network unreachable, skipping test\n" );
1354 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1356 ret
= HttpSendRequestW(request
, NULL
, 0, NULL
, 0);
1357 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1358 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1360 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1361 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1363 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1364 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1365 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1368 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1369 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1372 static void test_cache_read(void)
1374 HINTERNET session
, connection
, req
;
1375 FILETIME now
, tomorrow
, yesterday
;
1376 BYTE content
[1000], buf
[2000];
1377 char file_path
[MAX_PATH
];
1384 static const char cache_only_url
[] = "http://test.winehq.org/tests/cache-only";
1385 BYTE cache_headers
[] = "HTTP/1.1 200 OK\r\n\r\n";
1387 trace("Testing cache read...\n");
1389 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1391 for(i
= 0; i
< sizeof(content
); i
++)
1392 content
[i
] = '0' + (i
%10);
1394 GetSystemTimeAsFileTime(&now
);
1395 li
.u
.HighPart
= now
.dwHighDateTime
;
1396 li
.u
.LowPart
= now
.dwLowDateTime
;
1397 li
.QuadPart
+= (LONGLONG
)10000000 * 3600 * 24;
1398 tomorrow
.dwHighDateTime
= li
.u
.HighPart
;
1399 tomorrow
.dwLowDateTime
= li
.u
.LowPart
;
1400 li
.QuadPart
-= (LONGLONG
)10000000 * 3600 * 24 * 2;
1401 yesterday
.dwHighDateTime
= li
.u
.HighPart
;
1402 yesterday
.dwLowDateTime
= li
.u
.LowPart
;
1404 res
= CreateUrlCacheEntryA(cache_only_url
, sizeof(content
), "", file_path
, 0);
1405 ok(res
, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1407 file
= CreateFileA(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1408 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
1410 WriteFile(file
, content
, sizeof(content
), &size
, NULL
);
1413 res
= CommitUrlCacheEntryA(cache_only_url
, file_path
, tomorrow
, yesterday
, NORMAL_CACHE_ENTRY
,
1414 cache_headers
, sizeof(cache_headers
)-1, "", 0);
1415 ok(res
, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1417 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
1418 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
1420 pInternetSetStatusCallbackA(session
, callback
);
1422 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1423 connection
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
,
1424 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1425 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
1426 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1428 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1429 req
= HttpOpenRequestA(connection
, "GET", "/tests/cache-only", NULL
, NULL
, NULL
, 0, 0xdeadbead);
1430 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
1431 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1433 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1434 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1435 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST
);
1436 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT
);
1437 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1438 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1439 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1441 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
1443 ok(res
, "HttpSendRequest failed: %u\n", GetLastError());
1447 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
1448 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1449 ok(size
== sizeof(content
), "size = %u\n", size
);
1452 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
1453 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
1454 ok(size
== sizeof(content
), "size = %u\n", size
);
1455 ok(!memcmp(content
, buf
, sizeof(content
)), "unexpected content\n");
1458 close_async_handle(session
, hCompleteEvent
, 2);
1460 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1461 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1462 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
1463 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
1464 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1465 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1466 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1468 res
= DeleteUrlCacheEntryA(cache_only_url
);
1469 ok(res
, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1471 CloseHandle(hCompleteEvent
);
1474 static void test_http_cache(void)
1476 HINTERNET session
, connect
, request
;
1477 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1478 DWORD size
, file_size
;
1482 FILETIME filetime_zero
= {0};
1484 static const char cached_content
[] = "data read from cache";
1485 static const char *types
[] = { "*", "", NULL
};
1487 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1488 ok(session
!= NULL
,"Unable to open Internet session\n");
1490 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1491 INTERNET_SERVICE_HTTP
, 0, 0);
1492 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1494 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1495 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1497 skip( "Network unreachable, skipping test\n" );
1499 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1500 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1504 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1507 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1508 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1509 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1511 size
= sizeof(file_name
);
1512 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1513 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1514 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1515 ok(!size
, "size = %d\n", size
);
1517 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1518 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1520 size
= sizeof(file_name
);
1521 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1522 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1524 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1525 FILE_ATTRIBUTE_NORMAL
, NULL
);
1526 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1527 file_size
= GetFileSize(file
, NULL
);
1528 ok(file_size
== 106, "file size = %u\n", file_size
);
1531 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1532 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1533 ok(size
== 100, "size = %u\n", size
);
1535 file_size
= GetFileSize(file
, NULL
);
1536 ok(file_size
== 106, "file size = %u\n", file_size
);
1539 ret
= DeleteFileA(file_name
);
1540 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1542 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1544 file
= CreateFileA(file_name
, GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1545 FILE_ATTRIBUTE_NORMAL
, NULL
);
1546 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1547 ret
= WriteFile(file
, cached_content
, sizeof(cached_content
), &size
, NULL
);
1548 ok(ret
&& size
, "WriteFile failed: %d, %d\n", ret
, size
);
1549 ret
= CommitUrlCacheEntryA(url
, file_name
, filetime_zero
, filetime_zero
, NORMAL_CACHE_ENTRY
, NULL
, 0, NULL
, 0);
1550 ok(ret
, "CommitUrlCacheEntry failed: %d\n", GetLastError());
1553 /* Send the same request, requiring it to be retrieved from the cache */
1554 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1556 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1557 ok(ret
, "HttpSendRequest failed\n");
1560 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1561 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1562 ok(size
== 100, "size = %u\n", size
);
1564 todo_wine
ok(!strcmp((char*)buf
, cached_content
), "incorrect page data: %s\n", (char*)buf
);
1566 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1568 DeleteUrlCacheEntryA(url
);
1569 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1570 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1571 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
1573 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError() = %d\n", GetLastError());
1574 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1576 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1577 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1579 size
= sizeof(file_name
);
1580 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1581 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1582 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1583 ok(!size
, "size = %d\n", size
);
1585 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1586 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1588 size
= sizeof(file_name
);
1590 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1593 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1594 FILE_ATTRIBUTE_NORMAL
, NULL
);
1595 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1601 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1604 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1605 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1606 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1611 static void InternetLockRequestFile_test(void)
1613 char file_name
[MAX_PATH
];
1619 open_simple_request(&req
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, "/tests/hello.html");
1621 size
= sizeof(file_name
);
1622 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1623 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1624 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1625 ok(!size
, "size = %d\n", size
);
1628 ret
= InternetLockRequestFile(req
.request
, &lock
);
1629 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1631 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
1632 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1634 size
= sizeof(file_name
);
1635 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1636 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1638 ret
= InternetLockRequestFile(req
.request
, &lock
);
1639 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1640 ok(lock
!= NULL
, "lock == NULL\n");
1642 ret
= InternetLockRequestFile(req
.request
, &lock2
);
1643 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1644 ok(lock
== lock2
, "lock != lock2\n");
1646 ret
= InternetUnlockRequestFile(lock2
);
1647 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1649 ret
= DeleteFileA(file_name
);
1650 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1652 ok(InternetCloseHandle(req
.request
), "Close request handle failed\n");
1654 ret
= DeleteFileA(file_name
);
1655 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1657 ret
= InternetUnlockRequestFile(lock
);
1658 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1660 ret
= DeleteFileA(file_name
);
1661 ok(ret
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1664 static void HttpHeaders_test(void)
1676 hSession
= InternetOpenA("Wine Regression Test",
1677 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1678 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1679 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1680 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1682 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1683 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1684 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1685 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1687 skip( "Network unreachable, skipping test\n" );
1690 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1693 len
= sizeof(buffer
);
1694 strcpy(buffer
,"Warning");
1695 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1696 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1698 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1699 "Failed to add new header\n");
1702 len
= sizeof(buffer
);
1703 strcpy(buffer
,"Warning");
1704 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1705 buffer
,&len
,&index
),"Unable to query header\n");
1706 ok(index
== 1, "Index was not incremented\n");
1707 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1708 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1709 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1710 len
= sizeof(buffer
);
1711 strcpy(buffer
,"Warning");
1712 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1713 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1716 len
= 5; /* could store the string but not the NULL terminator */
1717 strcpy(buffer
,"Warning");
1718 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1719 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1720 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1721 ok(index
== 0, "Index was incremented\n");
1722 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1723 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1725 /* a call with NULL will fail but will return the length */
1727 len
= sizeof(buffer
);
1728 SetLastError(0xdeadbeef);
1729 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1730 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1731 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1732 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1733 ok(index
== 0, "Index was incremented\n");
1735 /* even for a len that is too small */
1738 SetLastError(0xdeadbeef);
1739 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1740 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1741 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1742 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1743 ok(index
== 0, "Index was incremented\n");
1747 SetLastError(0xdeadbeef);
1748 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1749 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1750 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1751 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1752 ok(index
== 0, "Index was incremented\n");
1753 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1756 /* a working query */
1758 len
= sizeof(buffer
);
1759 memset(buffer
, 'x', sizeof(buffer
));
1760 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1761 buffer
,&len
,&index
),"Unable to query header\n");
1762 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1763 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1764 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1765 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1766 ok(strncmp(buffer
, "POST /tests/post.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1767 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1768 ok(index
== 0, "Index was incremented\n");
1770 /* Like above two tests, but for W version */
1774 SetLastError(0xdeadbeef);
1775 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1776 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1777 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1778 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1779 ok(index
== 0, "Index was incremented\n");
1780 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1782 /* a working query */
1784 len
= sizeof(wbuffer
);
1785 memset(wbuffer
, 'x', sizeof(wbuffer
));
1786 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1787 wbuffer
,&len
,&index
),"Unable to query header\n");
1788 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1789 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1790 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1791 ok(index
== 0, "Index was incremented\n");
1793 /* end of W version tests */
1795 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1797 len
= sizeof(buffer
);
1798 memset(buffer
, 'x', sizeof(buffer
));
1799 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1800 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1801 ok(len
== 2 || len
== 4 /* win10 */, "Expected 2 or 4, got %d\n", len
);
1802 ok(memcmp(buffer
, "\r\n\r\n", len
) == 0, "Expected CRLF, got '%s'\n", buffer
);
1803 ok(index
== 0, "Index was incremented\n");
1805 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1806 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1809 len
= sizeof(buffer
);
1810 strcpy(buffer
,"Warning");
1811 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1812 buffer
,&len
,&index
),"Unable to query header\n");
1813 ok(index
== 1, "Index was not incremented\n");
1814 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1815 len
= sizeof(buffer
);
1816 strcpy(buffer
,"Warning");
1817 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1818 buffer
,&len
,&index
),"Failed to get second header\n");
1819 ok(index
== 2, "Index was not incremented\n");
1820 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1821 len
= sizeof(buffer
);
1822 strcpy(buffer
,"Warning");
1823 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1824 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1826 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1829 len
= sizeof(buffer
);
1830 strcpy(buffer
,"Warning");
1831 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1832 buffer
,&len
,&index
),"Unable to query header\n");
1833 ok(index
== 1, "Index was not incremented\n");
1834 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1835 len
= sizeof(buffer
);
1836 strcpy(buffer
,"Warning");
1837 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1838 buffer
,&len
,&index
),"Failed to get second header\n");
1839 ok(index
== 2, "Index was not incremented\n");
1840 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1841 len
= sizeof(buffer
);
1842 strcpy(buffer
,"Warning");
1843 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1844 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1846 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1849 len
= sizeof(buffer
);
1850 strcpy(buffer
,"Warning");
1851 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1852 buffer
,&len
,&index
),"Unable to query header\n");
1853 ok(index
== 1, "Index was not incremented\n");
1854 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1855 len
= sizeof(buffer
);
1856 strcpy(buffer
,"Warning");
1857 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1858 buffer
,&len
,&index
),"Failed to get second header\n");
1859 ok(index
== 2, "Index was not incremented\n");
1860 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1861 len
= sizeof(buffer
);
1862 strcpy(buffer
,"Warning");
1863 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1864 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1866 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1869 len
= sizeof(buffer
);
1870 strcpy(buffer
,"Warning");
1871 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1872 buffer
,&len
,&index
),"Unable to query header\n");
1873 ok(index
== 1, "Index was not incremented\n");
1874 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1875 len
= sizeof(buffer
);
1876 strcpy(buffer
,"Warning");
1877 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1878 ok(index
== 2, "Index was not incremented\n");
1879 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1880 len
= sizeof(buffer
);
1881 strcpy(buffer
,"Warning");
1882 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1884 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1887 len
= sizeof(buffer
);
1888 strcpy(buffer
,"Warning");
1889 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1890 ok(index
== 1, "Index was not incremented\n");
1891 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1892 len
= sizeof(buffer
);
1893 strcpy(buffer
,"Warning");
1894 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1895 ok(index
== 2, "Index was not incremented\n");
1896 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1897 len
= sizeof(buffer
);
1898 strcpy(buffer
,"Warning");
1899 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1901 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1904 len
= sizeof(buffer
);
1905 strcpy(buffer
,"Warning");
1906 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1907 ok(index
== 1, "Index was not incremented\n");
1908 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1909 len
= sizeof(buffer
);
1910 strcpy(buffer
,"Warning");
1911 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1912 ok(index
== 2, "Index was not incremented\n");
1913 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1914 len
= sizeof(buffer
);
1915 strcpy(buffer
,"Warning");
1916 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1918 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");
1921 len
= sizeof(buffer
);
1922 strcpy(buffer
,"Warning");
1923 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1924 ok(index
== 1, "Index was not incremented\n");
1925 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1926 len
= sizeof(buffer
);
1927 strcpy(buffer
,"Warning");
1928 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1929 ok(index
== 2, "Index was not incremented\n");
1930 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1931 len
= sizeof(buffer
);
1932 strcpy(buffer
,"Warning");
1933 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1935 /* Ensure that blank headers are ignored and don't cause a failure */
1936 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");
1939 len
= sizeof(buffer
);
1940 strcpy(buffer
,"BlankTest");
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
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1945 /* Ensure that malformed header separators are ignored and don't cause a failure */
1946 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
),
1947 "Failed to add header with malformed entries in list\n");
1950 len
= sizeof(buffer
);
1951 strcpy(buffer
,"MalformedTest");
1952 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1953 ok(index
== 1, "Index was not incremented\n");
1954 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1956 len
= sizeof(buffer
);
1957 strcpy(buffer
,"MalformedTestTwo");
1958 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1959 ok(index
== 1, "Index was not incremented\n");
1960 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
1962 len
= sizeof(buffer
);
1963 strcpy(buffer
,"MalformedTestThree");
1964 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1965 ok(index
== 1, "Index was not incremented\n");
1966 ok(strcmp(buffer
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
1968 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD
);
1969 ok(ret
, "unable to add header %u\n", GetLastError());
1973 len
= sizeof(buffer
);
1974 ret
= HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
);
1975 ok(ret
, "unable to query header %u\n", GetLastError());
1976 ok(index
== 1, "index was not incremented\n");
1977 ok(!strcmp(buffer
, "Basic"), "incorrect string was returned (%s)\n", buffer
);
1979 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE
);
1980 ok(ret
, "unable to remove header %u\n", GetLastError());
1983 len
= sizeof(buffer
);
1984 SetLastError(0xdeadbeef);
1985 ok(!HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
),
1986 "header still present\n");
1987 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "got %u\n", GetLastError());
1989 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1991 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1992 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1995 static const char garbagemsg
[] =
1996 "Garbage: Header\r\n";
1998 static const char contmsg
[] =
1999 "HTTP/1.1 100 Continue\r\n";
2001 static const char expandcontmsg
[] =
2002 "HTTP/1.1 100 Continue\r\n"
2003 "Server: winecontinue\r\n"
2004 "Tag: something witty\r\n";
2006 static const char okmsg
[] =
2007 "HTTP/1.1 200 OK\r\n"
2008 "Server: winetest\r\n"
2011 static const char okmsg2
[] =
2012 "HTTP/1.1 200 OK\r\n"
2013 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
2014 "Server: winetest\r\n"
2015 "Content-Length: 0\r\n"
2016 "Set-Cookie: one\r\n"
2017 "Set-Cookie: two\r\n"
2020 static const char okmsg_cookie_path
[] =
2021 "HTTP/1.1 200 OK\r\n"
2022 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
2023 "Server: winetest\r\n"
2024 "Content-Length: 0\r\n"
2025 "Set-Cookie: subcookie2=data; path=/test_cookie_set_path\r\n"
2028 static const char okmsg_cookie
[] =
2029 "HTTP/1.1 200 OK\r\n"
2030 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
2031 "Server: winetest\r\n"
2032 "Content-Length: 0\r\n"
2033 "Set-Cookie: testcookie=testvalue\r\n"
2036 static const char notokmsg
[] =
2037 "HTTP/1.1 400 Bad Request\r\n"
2038 "Server: winetest\r\n"
2041 static const char noauthmsg
[] =
2042 "HTTP/1.1 401 Unauthorized\r\n"
2043 "Server: winetest\r\n"
2044 "Connection: close\r\n"
2045 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
2048 static const char noauthmsg2
[] =
2049 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
2050 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
2052 "Server: winetest\r\n";
2054 static const char proxymsg
[] =
2055 "HTTP/1.1 407 Proxy Authentication Required\r\n"
2056 "Server: winetest\r\n"
2057 "Proxy-Connection: close\r\n"
2058 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
2061 static const char page1
[] =
2063 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
2064 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
2067 static const char ok_with_length
[] =
2068 "HTTP/1.1 200 OK\r\n"
2069 "Connection: Keep-Alive\r\n"
2070 "Content-Length: 18\r\n\r\n"
2071 "HTTP/1.1 211 OK\r\n\r\n";
2073 static const char ok_with_length2
[] =
2074 "HTTP/1.1 210 OK\r\n"
2075 "Connection: Keep-Alive\r\n"
2076 "Content-Length: 19\r\n\r\n"
2077 "HTTP/1.1 211 OK\r\n\r\n";
2079 struct server_info
{
2084 static int test_cache_gzip
;
2085 static const char *send_buffer
;
2086 static int server_socket
;
2088 static DWORD CALLBACK
server_thread(LPVOID param
)
2090 struct server_info
*si
= param
;
2091 int r
, c
= -1, i
, on
, count
= 0;
2093 struct sockaddr_in sa
;
2097 int last_request
= 0;
2098 char host_header
[22];
2099 char host_header_override
[30];
2100 static int test_no_cache
= 0;
2102 WSAStartup(MAKEWORD(1,1), &wsaData
);
2104 s
= socket(AF_INET
, SOCK_STREAM
, 0);
2105 if (s
== INVALID_SOCKET
)
2109 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
2111 memset(&sa
, 0, sizeof sa
);
2112 sa
.sin_family
= AF_INET
;
2113 sa
.sin_port
= htons(si
->port
);
2114 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
2116 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
2122 SetEvent(si
->hEvent
);
2124 sprintf(host_header
, "Host: localhost:%d", si
->port
);
2125 sprintf(host_header_override
, "Host: test.local:%d\r\n", si
->port
);
2126 buffer
= HeapAlloc(GetProcessHeap(), 0, buffer_size
= 1000);
2131 c
= accept(s
, NULL
, NULL
);
2133 memset(buffer
, 0, buffer_size
);
2136 if(i
== buffer_size
)
2137 buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, buffer_size
*= 2);
2139 r
= recv(c
, buffer
+i
, 1, 0);
2143 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
2144 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
2147 if (strstr(buffer
, "GET /test1"))
2149 if (!strstr(buffer
, "Content-Length: 0"))
2151 send(c
, okmsg
, sizeof okmsg
-1, 0);
2152 send(c
, page1
, sizeof page1
-1, 0);
2155 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2157 if (strstr(buffer
, "CONNECT "))
2159 if (!strstr(buffer
, "Content-Length: 0"))
2160 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2162 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2164 if (strstr(buffer
, "/test2"))
2166 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2168 send(c
, okmsg
, sizeof okmsg
-1, 0);
2169 send(c
, page1
, sizeof page1
-1, 0);
2172 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2174 if (strstr(buffer
, "/test3"))
2176 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2177 send(c
, okmsg
, sizeof okmsg
-1, 0);
2179 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2181 if (strstr(buffer
, "/test4"))
2183 if (strstr(buffer
, "Connection: Close"))
2184 send(c
, okmsg
, sizeof okmsg
-1, 0);
2186 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2188 if (strstr(buffer
, "POST /test5") ||
2189 strstr(buffer
, "RPC_IN_DATA /test5") ||
2190 strstr(buffer
, "RPC_OUT_DATA /test5"))
2192 if (strstr(buffer
, "Content-Length: 0"))
2194 send(c
, okmsg
, sizeof okmsg
-1, 0);
2195 send(c
, page1
, sizeof page1
-1, 0);
2198 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2200 if (strstr(buffer
, "GET /test6"))
2202 send(c
, contmsg
, sizeof contmsg
-1, 0);
2203 send(c
, contmsg
, sizeof contmsg
-1, 0);
2204 send(c
, okmsg
, sizeof okmsg
-1, 0);
2205 send(c
, page1
, sizeof page1
-1, 0);
2207 if (strstr(buffer
, "POST /test7"))
2209 if (strstr(buffer
, "Content-Length: 100"))
2211 if (strstr(buffer
, "POST /test7b"))
2212 recvfrom(c
, buffer
, buffer_size
, 0, NULL
, NULL
);
2213 send(c
, okmsg
, sizeof okmsg
-1, 0);
2214 send(c
, page1
, sizeof page1
-1, 0);
2217 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2219 if (strstr(buffer
, "/test8"))
2221 if (!strstr(buffer
, "Connection: Close") &&
2222 strstr(buffer
, "Connection: Keep-Alive") &&
2223 !strstr(buffer
, "Cache-Control: no-cache") &&
2224 !strstr(buffer
, "Pragma: no-cache") &&
2225 strstr(buffer
, host_header
))
2226 send(c
, okmsg
, sizeof okmsg
-1, 0);
2228 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2230 if (strstr(buffer
, "/test9"))
2232 if (!strstr(buffer
, "Connection: Close") &&
2233 !strstr(buffer
, "Connection: Keep-Alive") &&
2234 !strstr(buffer
, "Cache-Control: no-cache") &&
2235 !strstr(buffer
, "Pragma: no-cache") &&
2236 strstr(buffer
, host_header
))
2237 send(c
, okmsg
, sizeof okmsg
-1, 0);
2239 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2241 if (strstr(buffer
, "/testA"))
2243 if (!strstr(buffer
, "Connection: Close") &&
2244 !strstr(buffer
, "Connection: Keep-Alive") &&
2245 (strstr(buffer
, "Cache-Control: no-cache") ||
2246 strstr(buffer
, "Pragma: no-cache")) &&
2247 strstr(buffer
, host_header
))
2248 send(c
, okmsg
, sizeof okmsg
-1, 0);
2250 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2252 if (strstr(buffer
, "/testC"))
2254 if (strstr(buffer
, "cookie=biscuit"))
2255 send(c
, okmsg
, sizeof okmsg
-1, 0);
2257 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2259 if (strstr(buffer
, "/testD"))
2261 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
2263 if (strstr(buffer
, "/testE"))
2265 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
2267 if (strstr(buffer
, "GET /quit"))
2269 send(c
, okmsg
, sizeof okmsg
-1, 0);
2270 send(c
, page1
, sizeof page1
-1, 0);
2273 if (strstr(buffer
, "GET /testF"))
2275 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
2276 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2277 send(c
, contmsg
, sizeof contmsg
-1, 0);
2278 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2279 send(c
, okmsg
, sizeof okmsg
-1, 0);
2280 send(c
, page1
, sizeof page1
-1, 0);
2282 if (strstr(buffer
, "GET /testG"))
2284 send(c
, page1
, sizeof page1
-1, 0);
2287 if (strstr(buffer
, "GET /testJ"))
2292 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2296 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2300 if (strstr(buffer
, "GET /testH"))
2302 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2303 recvfrom(c
, buffer
, buffer_size
, 0, NULL
, NULL
);
2304 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2307 if (strstr(buffer
, "GET /test_no_content"))
2309 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2310 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2312 if (strstr(buffer
, "GET /test_conn_close"))
2314 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2315 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
2316 WaitForSingleObject(conn_close_event
, INFINITE
);
2317 trace("closing connection\n");
2319 if (strstr(buffer
, "GET /test_cache_control_no_cache"))
2321 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2322 if(!test_no_cache
++)
2323 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2325 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2327 if (strstr(buffer
, "GET /test_cache_control_no_store"))
2329 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2330 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2332 if (strstr(buffer
, "GET /test_cache_gzip"))
2334 static const char gzip_response
[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2335 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2336 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2337 if(!test_cache_gzip
++)
2338 send(c
, gzip_response
, sizeof(gzip_response
), 0);
2340 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2342 if (strstr(buffer
, "HEAD /test_head")) {
2343 static const char head_response
[] =
2344 "HTTP/1.1 200 OK\r\n"
2345 "Connection: Keep-Alive\r\n"
2346 "Content-Length: 100\r\n"
2349 send(c
, head_response
, sizeof(head_response
), 0);
2352 if (strstr(buffer
, "GET /send_from_buffer"))
2353 send(c
, send_buffer
, strlen(send_buffer
), 0);
2354 if (strstr(buffer
, "/test_cache_control_verb"))
2356 if (!memcmp(buffer
, "GET ", sizeof("GET ")-1) &&
2357 !strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2358 else if (strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2359 else send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2361 if (strstr(buffer
, "/test_request_content_length"))
2363 static char msg
[] = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\n\r\n";
2364 static int seen_content_length
;
2366 if (!seen_content_length
)
2368 if (strstr(buffer
, "Content-Length: 0"))
2370 seen_content_length
= 1;
2371 send(c
, msg
, sizeof msg
-1, 0);
2373 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2374 WaitForSingleObject(hCompleteEvent
, 5000);
2378 if (strstr(buffer
, "Content-Length: 0")) send(c
, msg
, sizeof msg
-1, 0);
2379 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2380 WaitForSingleObject(hCompleteEvent
, 5000);
2383 if (strstr(buffer
, "GET /test_premature_disconnect"))
2384 trace("closing connection\n");
2385 if (strstr(buffer
, "HEAD /upload.txt"))
2387 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2388 send(c
, okmsg
, sizeof okmsg
-1, 0);
2390 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2392 if (strstr(buffer
, "PUT /upload2.txt"))
2394 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2395 send(c
, okmsg
, sizeof okmsg
-1, 0);
2397 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2399 if (strstr(buffer
, "/test_cookie_path1"))
2401 if (strstr(buffer
, "subcookie=data"))
2402 send(c
, okmsg
, sizeof okmsg
-1, 0);
2404 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2406 if (strstr(buffer
, "/test_cookie_path2"))
2408 if (strstr(buffer
, "subcookie2=data"))
2409 send(c
, okmsg
, sizeof okmsg
-1, 0);
2411 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2413 if (strstr(buffer
, "/test_cookie_set_path"))
2415 send(c
, okmsg_cookie_path
, sizeof okmsg_cookie_path
-1, 0);
2417 if (strstr(buffer
, "/test_cookie_merge"))
2419 if (strstr(buffer
, "subcookie=data") &&
2420 !strstr(buffer
, "manual_cookie=test"))
2421 send(c
, okmsg
, sizeof okmsg
-1, 0);
2423 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2425 if (strstr(buffer
, "/test_cookie_set_host_override"))
2427 send(c
, okmsg_cookie
, sizeof okmsg_cookie
-1, 0);
2429 if (strstr(buffer
, "/test_cookie_check_host_override"))
2431 if (strstr(buffer
, "Cookie:") && strstr(buffer
, "testcookie=testvalue"))
2432 send(c
, okmsg
, sizeof okmsg
-1, 0);
2434 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2436 if (strstr(buffer
, "/test_cookie_check_different_host"))
2438 if (!strstr(buffer
, "foo") &&
2439 strstr(buffer
, "cookie=biscuit"))
2440 send(c
, okmsg
, sizeof okmsg
-1, 0);
2442 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2444 if (strstr(buffer
, "/test_host_override"))
2446 if (strstr(buffer
, host_header_override
))
2447 send(c
, okmsg
, sizeof okmsg
-1, 0);
2449 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2451 if (strstr(buffer
, "/async_read"))
2453 const char *page1_mid
= page1
+ (sizeof page1
- 1)/2;
2454 const char *page1_end
= page1
+ sizeof page1
- 1;
2455 send(c
, okmsg
, sizeof okmsg
-1, 0);
2456 send(c
, page1
, page1_mid
- page1
, 0);
2457 WaitForSingleObject(conn_wait_event
, INFINITE
);
2458 send(c
, page1_mid
, page1_end
- page1_mid
, 0);
2460 if (strstr(buffer
, "/socket"))
2463 SetEvent(server_req_rec_event
);
2464 WaitForSingleObject(conn_wait_event
, INFINITE
);
2466 if (strstr(buffer
, "/echo_request"))
2468 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2469 send(c
, buffer
, strlen(buffer
), 0);
2471 if (strstr(buffer
, "GET /test_remove_dot_segments"))
2473 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2475 if (strstr(buffer
, "HEAD /test_auth_host1"))
2477 if (strstr(buffer
, "Authorization: Basic dGVzdDE6cGFzcw=="))
2478 send(c
, okmsg
, sizeof okmsg
-1, 0);
2480 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2482 if (strstr(buffer
, "HEAD /test_auth_host2"))
2484 if (strstr(buffer
, "Authorization: Basic dGVzdDE6cGFzczI="))
2485 send(c
, okmsg
, sizeof okmsg
-1, 0);
2487 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2492 } while (!last_request
);
2495 HeapFree(GetProcessHeap(), 0, buffer
);
2500 static void test_basic_request(int port
, const char *verb
, const char *url
)
2503 DWORD r
, count
, error
;
2506 trace("basic request %s %s\n", verb
, url
);
2508 open_simple_request(&req
, "localhost", port
, verb
, url
);
2510 SetLastError(0xdeadbeef);
2511 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
2512 error
= GetLastError();
2513 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
2514 ok(r
, "HttpSendRequest failed: %u\n", GetLastError());
2517 memset(buffer
, 0, sizeof buffer
);
2518 SetLastError(0xdeadbeef);
2519 r
= InternetReadFile(req
.request
, buffer
, sizeof buffer
, &count
);
2520 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2521 ok(count
== sizeof page1
- 1, "count was wrong\n");
2522 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2524 close_request(&req
);
2527 static void test_proxy_indirect(int port
)
2533 open_simple_request(&req
, "localhost", port
, NULL
, "/test2");
2535 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
2536 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2539 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2540 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
2543 skip("missing proxy header, not testing remaining proxy headers\n");
2546 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2548 test_status_code(req
.request
, 407);
2549 test_request_flags(req
.request
, 0);
2552 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2553 ok(r
, "HttpQueryInfo failed\n");
2554 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2557 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2558 ok(r
, "HttpQueryInfo failed\n");
2559 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2562 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2563 ok(r
, "HttpQueryInfo failed\n");
2564 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2567 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2568 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2569 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2572 close_request(&req
);
2575 static void test_proxy_direct(int port
)
2577 HINTERNET hi
, hc
, hr
;
2579 char buffer
[0x40], *url
;
2580 WCHAR bufferW
[0x40];
2581 static const char url_fmt
[] = "http://test.winehq.org:%u/test2";
2582 static CHAR username
[] = "mike",
2583 password
[] = "1101",
2584 useragent
[] = "winetest";
2585 static const WCHAR usernameW
[] = {'m','i','k','e',0},
2586 passwordW
[] = {'1','1','0','1',0},
2587 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2589 /* specify proxy type without the proxy and bypass */
2590 SetLastError(0xdeadbeef);
2591 hi
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2592 error
= GetLastError();
2593 ok(error
== ERROR_INVALID_PARAMETER
||
2594 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %u\n", error
);
2595 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2597 sprintf(buffer
, "localhost:%d\n", port
);
2598 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2599 ok(hi
!= NULL
, "open failed\n");
2601 /* try connect without authorization */
2602 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2603 ok(hc
!= NULL
, "connect failed\n");
2605 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2606 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2609 SetLastError(0xdeadbeef);
2610 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
2611 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2612 ok(!r
, "unexpected success\n");
2613 ok(sz
== 1, "got %u\n", sz
);
2616 SetLastError(0xdeadbeef);
2617 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
2618 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2619 ok(!r
, "unexpected success\n");
2620 ok(sz
== 1, "got %u\n", sz
);
2622 sz
= sizeof(buffer
);
2623 SetLastError(0xdeadbeef);
2624 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2625 ok(r
, "unexpected failure %u\n", GetLastError());
2626 ok(!sz
, "got %u\n", sz
);
2628 sz
= sizeof(buffer
);
2629 SetLastError(0xdeadbeef);
2630 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2631 ok(r
, "unexpected failure %u\n", GetLastError());
2632 ok(!sz
, "got %u\n", sz
);
2635 SetLastError(0xdeadbeef);
2636 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
2637 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2638 ok(!r
, "unexpected success\n");
2639 ok(sz
== 1, "got %u\n", sz
);
2642 SetLastError(0xdeadbeef);
2643 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
2644 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2645 ok(!r
, "unexpected success\n");
2646 ok(sz
== 1, "got %u\n", sz
);
2648 sz
= sizeof(buffer
);
2649 SetLastError(0xdeadbeef);
2650 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2651 ok(r
, "unexpected failure %u\n", GetLastError());
2652 ok(!sz
, "got %u\n", sz
);
2654 sz
= sizeof(buffer
);
2655 SetLastError(0xdeadbeef);
2656 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2657 ok(r
, "unexpected failure %u\n", GetLastError());
2658 ok(!sz
, "got %u\n", sz
);
2661 SetLastError(0xdeadbeef);
2662 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
2663 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2664 ok(!r
, "unexpected success\n");
2665 ok(sz
== 34, "got %u\n", sz
);
2667 sz
= sizeof(buffer
);
2668 SetLastError(0xdeadbeef);
2669 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2670 ok(r
, "unexpected failure %u\n", GetLastError());
2671 ok(sz
== 33, "got %u\n", sz
);
2673 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2674 ok(r
|| broken(!r
), "HttpSendRequest failed %u\n", GetLastError());
2677 win_skip("skipping proxy tests on broken wininet\n");
2681 test_status_code(hr
, 407);
2683 /* set the user + password then try again */
2684 r
= InternetSetOptionA(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2685 ok(!r
, "unexpected success\n");
2687 r
= InternetSetOptionA(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2688 ok(r
, "failed to set user\n");
2690 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2691 ok(r
, "failed to set user\n");
2695 SetLastError(0xdeadbeef);
2696 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2697 ok(!r
, "unexpected failure %u\n", GetLastError());
2698 ok(!buffer
[0], "got %s\n", buffer
);
2699 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2703 SetLastError(0xdeadbeef);
2704 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2705 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2706 ok(!r
, "unexpected success\n");
2707 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2711 SetLastError(0xdeadbeef);
2712 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2713 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2714 ok(!r
, "unexpected success\n");
2715 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2718 sz
= sizeof(buffer
);
2719 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2720 ok(r
, "failed to get username\n");
2721 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2722 ok(sz
== strlen(username
), "got %u\n", sz
);
2725 sz
= sizeof(bufferW
);
2726 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2727 ok(r
, "failed to get username\n");
2728 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
2729 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2731 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
2732 ok(r
, "failed to set user\n");
2735 sz
= sizeof(buffer
);
2736 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2737 ok(r
, "failed to get username\n");
2738 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2739 ok(sz
== strlen(username
), "got %u\n", sz
);
2741 r
= InternetSetOptionA(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
2742 ok(r
, "failed to set useragent\n");
2746 SetLastError(0xdeadbeef);
2747 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2748 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2749 ok(!r
, "unexpected success\n");
2750 ok(sz
== strlen(useragent
) + 1, "got %u\n", sz
);
2753 sz
= sizeof(buffer
);
2754 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2755 ok(r
, "failed to get user agent\n");
2756 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
2757 ok(sz
== strlen(useragent
), "got %u\n", sz
);
2761 SetLastError(0xdeadbeef);
2762 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2763 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2764 ok(!r
, "unexpected success\n");
2765 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2768 sz
= sizeof(bufferW
);
2769 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2770 ok(r
, "failed to get user agent\n");
2771 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
2772 ok(sz
== lstrlenW(useragentW
), "got %u\n", sz
);
2774 r
= InternetSetOptionA(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
2775 ok(r
, "failed to set user\n");
2779 SetLastError(0xdeadbeef);
2780 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2781 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2782 ok(!r
, "unexpected success\n");
2783 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2786 sz
= sizeof(buffer
);
2787 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2788 ok(r
, "failed to get user\n");
2789 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2790 ok(sz
== strlen(username
), "got %u\n", sz
);
2794 SetLastError(0xdeadbeef);
2795 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2796 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2797 ok(!r
, "unexpected success\n");
2798 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2801 sz
= sizeof(bufferW
);
2802 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2803 ok(r
, "failed to get user\n");
2804 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
2805 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2807 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
2808 ok(r
, "failed to set password\n");
2812 SetLastError(0xdeadbeef);
2813 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2814 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2815 ok(!r
, "unexpected success\n");
2816 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2819 sz
= sizeof(buffer
);
2820 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2821 ok(r
, "failed to get password\n");
2822 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2823 ok(sz
== strlen(password
), "got %u\n", sz
);
2827 SetLastError(0xdeadbeef);
2828 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2829 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2830 ok(!r
, "unexpected success\n");
2831 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2834 sz
= sizeof(bufferW
);
2835 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2836 ok(r
, "failed to get password\n");
2837 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2838 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2840 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
2841 sprintf(url
, url_fmt
, port
);
2844 SetLastError(0xdeadbeef);
2845 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2846 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2847 ok(!r
, "unexpected success\n");
2848 ok(sz
== strlen(url
) + 1, "got %u\n", sz
);
2851 sz
= sizeof(buffer
);
2852 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2853 ok(r
, "failed to get url\n");
2854 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
2855 ok(sz
== strlen(url
), "got %u\n", sz
);
2859 SetLastError(0xdeadbeef);
2860 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2861 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2862 ok(!r
, "unexpected success\n");
2863 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2866 sz
= sizeof(bufferW
);
2867 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2868 ok(r
, "failed to get url\n");
2869 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
2870 ok(sz
== strlen(url
), "got %u\n", sz
);
2871 HeapFree(GetProcessHeap(), 0, url
);
2873 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2874 ok(r
, "failed to set password\n");
2878 SetLastError(0xdeadbeef);
2879 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2880 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2881 ok(!r
, "unexpected success\n");
2882 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2885 sz
= sizeof(buffer
);
2886 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2887 ok(r
, "failed to get password\n");
2888 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2889 ok(sz
== strlen(password
), "got %u\n", sz
);
2893 SetLastError(0xdeadbeef);
2894 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2895 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2896 ok(!r
, "unexpected success\n");
2897 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2900 sz
= sizeof(bufferW
);
2901 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2902 ok(r
, "failed to get password\n");
2903 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2904 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2906 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2909 win_skip("skipping proxy tests on broken wininet\n");
2912 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2914 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2915 ok(r
, "HttpQueryInfo failed\n");
2916 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2918 InternetCloseHandle(hr
);
2919 InternetCloseHandle(hc
);
2920 InternetCloseHandle(hi
);
2922 sprintf(buffer
, "localhost:%d\n", port
);
2923 hi
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2924 ok(hi
!= NULL
, "InternetOpen failed\n");
2926 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2927 ok(hc
!= NULL
, "InternetConnect failed\n");
2929 hr
= HttpOpenRequestA(hc
, "POST", "/test2", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
2930 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2932 r
= HttpSendRequestA(hr
, NULL
, 0, (char *)"data", sizeof("data"));
2933 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2935 test_status_code(hr
, 407);
2938 InternetCloseHandle(hr
);
2939 InternetCloseHandle(hc
);
2940 InternetCloseHandle(hi
);
2943 static void test_header_handling_order(int port
)
2945 static const char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
2946 static const char connection
[] = "Connection: Close";
2947 static const char *types
[2] = { "*", NULL
};
2949 HINTERNET session
, connect
, request
;
2950 DWORD size
, status
, data_len
;
2953 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2954 ok(session
!= NULL
, "InternetOpen failed\n");
2956 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2957 ok(connect
!= NULL
, "InternetConnect failed\n");
2959 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2960 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2962 ret
= HttpAddRequestHeadersA(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
2963 ok(ret
, "HttpAddRequestHeaders failed\n");
2965 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
2966 ok(ret
, "HttpSendRequest failed\n");
2968 test_status_code(request
, 200);
2969 test_request_flags(request
, 0);
2971 InternetCloseHandle(request
);
2973 request
= HttpOpenRequestA(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2974 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2976 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2977 ok(ret
, "HttpSendRequest failed\n");
2980 size
= sizeof(status
);
2981 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2982 ok(ret
, "HttpQueryInfo failed\n");
2983 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2985 InternetCloseHandle(request
);
2986 InternetCloseHandle(connect
);
2988 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2989 ok(connect
!= NULL
, "InternetConnect failed\n");
2991 request
= HttpOpenRequestA(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2992 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2994 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2995 ok(ret
, "HttpAddRequestHeaders failed\n");
2997 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2998 ok(ret
, "HttpSendRequest failed\n");
3001 size
= sizeof(status
);
3002 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
3003 ok(ret
, "HttpQueryInfo failed\n");
3004 ok(status
== 200, "got status %u, expected 200\n", status
);
3006 InternetCloseHandle(request
);
3007 InternetCloseHandle(connect
);
3009 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3010 ok(connect
!= NULL
, "InternetConnect failed\n");
3012 request
= HttpOpenRequestA(connect
, "POST", "/test7b", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3013 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3015 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
3016 ok(ret
, "HttpAddRequestHeaders failed\n");
3018 data_len
= sizeof(data
);
3019 memset(data
, 'a', sizeof(data
));
3020 ret
= HttpSendRequestA(request
, NULL
, 0, data
, data_len
);
3021 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3024 size
= sizeof(status
);
3025 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
3026 ok(ret
, "HttpQueryInfo failed\n");
3027 ok(status
== 200, "got status %u, expected 200\n", status
);
3029 InternetCloseHandle(request
);
3030 InternetCloseHandle(connect
);
3031 InternetCloseHandle(session
);
3034 static void test_connection_header(int port
)
3036 HINTERNET ses
, con
, req
;
3039 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3040 ok(ses
!= NULL
, "InternetOpen failed\n");
3042 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3043 ok(con
!= NULL
, "InternetConnect failed\n");
3045 req
= HttpOpenRequestA(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3046 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3048 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3049 ok(ret
, "HttpSendRequest failed\n");
3051 test_status_code(req
, 200);
3053 InternetCloseHandle(req
);
3055 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
3056 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3058 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3059 ok(ret
, "HttpSendRequest failed\n");
3061 test_status_code(req
, 200);
3063 InternetCloseHandle(req
);
3065 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3066 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3068 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3069 ok(ret
, "HttpSendRequest failed\n");
3071 test_status_code(req
, 200);
3073 InternetCloseHandle(req
);
3075 req
= HttpOpenRequestA(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3076 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3078 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3079 ok(ret
, "HttpSendRequest failed\n");
3081 test_status_code(req
, 200);
3083 InternetCloseHandle(req
);
3084 InternetCloseHandle(con
);
3085 InternetCloseHandle(ses
);
3088 static void test_header_override(int port
)
3090 char buffer
[128], host_header_override
[30], full_url
[128];
3091 HINTERNET ses
, con
, req
;
3092 DWORD size
, count
, err
;
3095 sprintf(host_header_override
, "Host: test.local:%d\r\n", port
);
3096 sprintf(full_url
, "http://localhost:%d/test_host_override", port
);
3098 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3099 ok(ses
!= NULL
, "InternetOpen failed\n");
3101 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3102 ok(con
!= NULL
, "InternetConnect failed\n");
3104 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3105 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3107 size
= sizeof(buffer
) - 1;
3109 memset(buffer
, 0, sizeof(buffer
));
3110 ret
= HttpQueryInfoA(req
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &count
);
3111 err
= GetLastError();
3112 ok(!ret
, "HttpQueryInfo succeeded\n");
3113 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err
);
3115 size
= sizeof(buffer
) - 1;
3116 memset(buffer
, 0, sizeof(buffer
));
3117 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_URL
, buffer
, &size
);
3118 ok(ret
, "InternetQueryOption failed\n");
3119 ok(!strcmp(full_url
, buffer
), "Expected %s, got %s\n", full_url
, buffer
);
3121 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3122 ok(ret
, "HttpAddRequestHeaders failed\n");
3124 size
= sizeof(buffer
) - 1;
3126 memset(buffer
, 0, sizeof(buffer
));
3127 ret
= HttpQueryInfoA(req
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &count
);
3128 ok(ret
, "HttpQueryInfo failed\n");
3130 size
= sizeof(buffer
) - 1;
3131 memset(buffer
, 0, sizeof(buffer
));
3132 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_URL
, buffer
, &size
);
3133 ok(ret
, "InternetQueryOption failed\n");
3134 ok(!strcmp(full_url
, buffer
), "Expected %s, got %s\n", full_url
, buffer
);
3136 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3137 ok(ret
, "HttpSendRequest failed\n");
3139 test_status_code(req
, 200);
3141 InternetCloseHandle(req
);
3142 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3143 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3145 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3146 ok(ret
, "HttpAddRequestHeaders failed\n");
3148 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3149 ok(ret
, "HttpAddRequestHeaders failed\n");
3151 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3152 ok(ret
, "HttpSendRequest failed\n");
3154 test_status_code(req
, 400);
3156 InternetCloseHandle(req
);
3157 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3158 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3160 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3161 ok(ret
, "HttpAddRequestHeaders failed\n");
3163 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3164 ok(ret
, "HttpSendRequest failed\n");
3166 test_status_code(req
, 200);
3168 InternetCloseHandle(req
);
3169 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3170 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3172 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_REPLACE
);
3173 if(ret
) { /* win10 returns success */
3174 trace("replacing host header is supported.\n");
3176 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3177 ok(ret
, "HttpSendRequest failed\n");
3179 test_status_code(req
, 200);
3181 trace("replacing host header is not supported.\n");
3183 err
= GetLastError();
3184 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err
);
3186 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3187 ok(ret
, "HttpSendRequest failed\n");
3189 test_status_code(req
, 400);
3192 InternetCloseHandle(req
);
3193 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3194 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3195 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3197 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3198 ok(ret
, "HttpAddRequestHeaders failed\n");
3200 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3201 ok(ret
, "HttpSendRequest failed\n");
3203 test_status_code(req
, 200);
3205 InternetCloseHandle(req
);
3206 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_set_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3207 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3209 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3210 ok(ret
, "HttpAddRequestHeaders failed\n");
3212 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3213 ok(ret
, "HttpSendRequest failed\n");
3215 test_status_code(req
, 200);
3217 InternetCloseHandle(req
);
3218 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_check_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3219 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3221 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3222 ok(ret
, "HttpAddRequestHeaders failed\n");
3224 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3225 ok(ret
, "HttpSendRequest failed\n");
3227 test_status_code(req
, 200);
3229 InternetCloseHandle(req
);
3230 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_check_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3231 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3233 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3234 ok(ret
, "HttpSendRequest failed\n");
3236 test_status_code(req
, 200);
3238 InternetCloseHandle(req
);
3239 InternetSetCookieA("http://test.local", "foo", "bar");
3240 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_check_different_host", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3241 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3243 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3244 ok(ret
, "HttpSendRequest failed\n");
3246 test_status_code(req
, 200);
3248 InternetCloseHandle(req
);
3249 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_check_different_host", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3250 ok(req
!= NULL
, "HttpOpenRequest failed\n");
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
, "HttpSendRequest failed\n");
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
, "test1", "pass", INTERNET_SERVICE_HTTP
, 0, 0);
3268 ok(con
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
3270 req
= HttpOpenRequestA( con
, "HEAD", "/test_auth_host1", 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
);
3282 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3283 ok(ses
!= NULL
, "InternetOpenA failed\n");
3285 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3286 ok(con
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
3288 req
= HttpOpenRequestA(con
, "HEAD", "/test_auth_host1", NULL
, NULL
, NULL
, 0, 0);
3289 ok(req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
3291 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3292 ok(ret
, "HttpAddRequestHeaders failed\n");
3294 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
3295 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
3297 test_status_code(req
, 200);
3299 InternetCloseHandle(req
);
3300 InternetCloseHandle(con
);
3301 InternetCloseHandle(ses
);
3303 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3304 ok(ses
!= NULL
, "InternetOpenA failed\n");
3306 con
= InternetConnectA(ses
, "localhost", port
, "test1", "pass2", INTERNET_SERVICE_HTTP
, 0, 0);
3307 ok(con
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
3309 req
= HttpOpenRequestA(con
, "HEAD", "/test_auth_host2", NULL
, NULL
, NULL
, 0, 0);
3310 ok(req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
3312 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3313 ok(ret
, "HttpAddRequestHeaders failed\n");
3315 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3316 ok(ret
, "HttpSendRequestA failed %u\n", GetLastError());
3318 test_status_code(req
, 200);
3320 InternetCloseHandle(req
);
3321 InternetCloseHandle(con
);
3322 InternetCloseHandle(ses
);
3324 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3325 ok(ses
!= NULL
, "InternetOpenA failed\n");
3327 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3328 ok(con
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
3330 req
= HttpOpenRequestA(con
, "HEAD", "/test_auth_host2", NULL
, NULL
, NULL
, 0, 0);
3331 ok(req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
3333 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3334 ok(ret
, "HttpSendRequestA failed %u\n", GetLastError());
3336 test_status_code(req
, 200);
3338 InternetCloseHandle(req
);
3339 InternetCloseHandle(con
);
3340 InternetCloseHandle(ses
);
3343 static void test_connection_closing(int port
)
3345 HINTERNET session
, connection
, req
;
3348 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3350 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3351 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3353 pInternetSetStatusCallbackA(session
, callback
);
3355 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3356 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3357 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3358 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3360 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3361 req
= HttpOpenRequestA(connection
, "GET", "/testJ", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3362 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3363 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3365 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3366 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3367 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3368 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3369 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3370 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3371 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3372 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3373 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3374 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3375 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3377 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3378 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3379 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3380 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3381 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3383 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3384 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3385 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3386 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3387 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3388 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3389 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3390 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3391 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3392 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3393 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3395 test_status_code(req
, 200);
3397 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3398 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3399 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3400 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3401 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3402 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3403 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3404 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3405 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3407 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3408 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3409 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3410 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3411 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3413 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3414 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3415 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3416 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3417 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3418 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3419 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3420 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3421 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3423 test_status_code(req
, 210);
3425 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3426 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3427 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3428 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3429 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3430 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3431 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3432 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3433 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3434 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3435 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3437 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3438 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3439 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3440 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3441 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3443 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3444 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3445 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3446 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3447 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3448 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3449 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3450 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3451 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3452 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3453 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3455 test_status_code(req
, 200);
3457 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3458 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3460 close_async_handle(session
, hCompleteEvent
, 2);
3461 CloseHandle(hCompleteEvent
);
3464 static void test_successive_HttpSendRequest(int port
)
3466 HINTERNET session
, connection
, req
;
3469 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3471 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3472 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3474 pInternetSetStatusCallbackA(session
, callback
);
3476 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3477 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3478 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3479 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3481 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3482 req
= HttpOpenRequestA(connection
, "GET", "/testH", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3483 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3484 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3486 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3487 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3488 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3489 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3490 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3491 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3492 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3493 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3494 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3496 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3497 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3498 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3499 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3500 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3502 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3503 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3504 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3505 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3506 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3507 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3508 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3509 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3510 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3512 test_status_code(req
, 210);
3514 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3515 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3516 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3517 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3518 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3519 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3520 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3521 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3522 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3524 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3525 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3526 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3527 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3528 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3530 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3531 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3532 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3533 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3534 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3535 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3536 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3537 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3538 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3540 test_status_code(req
, 200);
3542 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3543 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3545 close_async_handle(session
, hCompleteEvent
, 2);
3546 CloseHandle(hCompleteEvent
);
3549 static void test_no_content(int port
)
3551 HINTERNET session
, connection
, req
;
3554 trace("Testing 204 no content response...\n");
3556 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3558 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3559 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3561 pInternetSetStatusCallbackA(session
, callback
);
3563 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3564 connection
= InternetConnectA(session
, "localhost", port
,
3565 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3566 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3567 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3569 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3570 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
3571 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3572 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3573 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3575 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3576 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3577 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3578 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3579 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3580 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3581 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3582 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3583 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3584 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3586 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3587 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3588 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3589 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3590 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3592 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3593 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3594 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3595 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3596 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3597 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3598 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3599 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3601 close_async_handle(session
, hCompleteEvent
, 2);
3602 CloseHandle(hCompleteEvent
);
3605 * The connection should be closed before closing handle. This is true for most
3606 * wininet versions (including Wine), but some old win2k versions fail to do that.
3608 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3609 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3612 static void test_conn_close(int port
)
3614 HINTERNET session
, connection
, req
;
3615 DWORD res
, avail
, size
;
3618 trace("Testing connection close connection...\n");
3620 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3621 conn_close_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3623 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3624 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3626 pInternetSetStatusCallbackA(session
, callback
);
3628 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3629 connection
= InternetConnectA(session
, "localhost", port
,
3630 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3631 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3632 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3634 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3635 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
3636 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3637 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3638 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3640 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3641 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3642 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3643 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3644 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3645 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3646 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3647 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3649 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3650 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3651 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3652 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3653 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3655 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3656 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3657 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3658 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3659 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3660 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3661 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3662 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3665 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3666 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3667 ok(avail
!= 0, "avail = 0\n");
3670 res
= InternetReadFile(req
, buf
, avail
, &size
);
3671 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3673 /* IE11 calls those in InternetQueryDataAvailable call. */
3674 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
3675 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
3677 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3678 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3679 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3680 ok(!avail
, "avail = %u, expected 0\n", avail
);
3682 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3684 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3685 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3686 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3687 SetEvent(conn_close_event
);
3688 #ifdef ROSTESTS_73_FIXED
3689 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3690 #else /* ROSTESTS_73_FIXED */
3691 ok(WaitForSingleObject(hCompleteEvent
, 5000) == WAIT_OBJECT_0
, "Wait timed out\n");
3692 #endif /* ROSTESTS_73_FIXED */
3693 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3694 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3695 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3696 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3697 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3699 close_async_handle(session
, hCompleteEvent
, 2);
3700 CloseHandle(hCompleteEvent
);
3703 static void test_no_cache(int port
)
3705 static const char cache_control_no_cache
[] = "/test_cache_control_no_cache";
3706 static const char cache_control_no_store
[] = "/test_cache_control_no_store";
3707 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3709 char cache_url
[256], buf
[256];
3710 HINTERNET ses
, con
, req
;
3714 trace("Testing no-cache header\n");
3716 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3717 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3719 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3720 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3722 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3723 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3725 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_cache
);
3726 DeleteUrlCacheEntryA(cache_url
);
3728 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3729 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3731 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3733 ok(size
== 12, "read %d bytes of data\n", size
);
3734 InternetCloseHandle(req
);
3736 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3737 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3739 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3740 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3742 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3744 ok(size
== 0, "read %d bytes of data\n", size
);
3745 InternetCloseHandle(req
);
3746 DeleteUrlCacheEntryA(cache_url
);
3748 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_store
, NULL
, NULL
, NULL
, 0, 0);
3749 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3751 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_store
);
3752 DeleteUrlCacheEntryA(cache_url
);
3754 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3755 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3757 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3759 ok(size
== 12, "read %d bytes of data\n", size
);
3760 InternetCloseHandle(req
);
3762 ret
= DeleteUrlCacheEntryA(cache_url
);
3763 ok(!ret
&& GetLastError()==ERROR_FILE_NOT_FOUND
, "cache entry should not exist\n");
3765 InternetCloseHandle(con
);
3766 InternetCloseHandle(ses
);
3769 static void test_cache_read_gzipped(int port
)
3771 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3772 static const char get_gzip
[] = "/test_cache_gzip";
3773 static const char content
[] = "gzip test\n";
3774 static const char text_html
[] = "text/html";
3775 static const char raw_header
[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3777 HINTERNET ses
, con
, req
;
3779 char cache_url
[256], buf
[256];
3782 trace("Testing reading compressed content from cache\n");
3784 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3785 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3787 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3788 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3790 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3791 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3794 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3795 if(!ret
&& GetLastError()==ERROR_INTERNET_INVALID_OPTION
) {
3796 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3797 InternetCloseHandle(req
);
3798 InternetCloseHandle(con
);
3799 InternetCloseHandle(ses
);
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
)-size
, &read
) && read
)
3809 ok(size
== 10, "read %d bytes of data\n", size
);
3811 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3813 size
= sizeof(buf
)-1;
3814 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3815 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3817 ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3819 size
= sizeof(buf
)-1;
3820 ret
= HttpQueryInfoA(req
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &size
, 0);
3821 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3823 ok(!strncmp(raw_header
, buf
, size
), "buf = %s\n", buf
);
3824 InternetCloseHandle(req
);
3826 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3827 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3830 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3831 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3833 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3834 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3836 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3838 todo_wine
ok(size
== 10, "read %d bytes of data\n", size
);
3840 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3843 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3844 ok(!ret
&& GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND
,
3845 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3846 ret
, GetLastError());
3848 size
= sizeof(buf
)-1;
3849 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3850 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3852 todo_wine
ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3853 InternetCloseHandle(req
);
3855 /* Decompression doesn't work while reading from cache */
3856 test_cache_gzip
= 0;
3857 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3858 DeleteUrlCacheEntryA(cache_url
);
3860 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3861 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3863 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3864 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3866 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3868 ok(size
== 31, "read %d bytes of data\n", size
);
3869 InternetCloseHandle(req
);
3871 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3872 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3875 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3876 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3878 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3879 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3881 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3883 todo_wine
ok(size
== 31, "read %d bytes of data\n", size
);
3886 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3887 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3888 InternetCloseHandle(req
);
3890 InternetCloseHandle(con
);
3891 InternetCloseHandle(ses
);
3893 DeleteUrlCacheEntryA(cache_url
);
3896 static void test_HttpSendRequestW(int port
)
3898 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3899 HINTERNET ses
, con
, req
;
3903 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3904 ok(ses
!= NULL
, "InternetOpen failed\n");
3906 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3907 ok(con
!= NULL
, "InternetConnect failed\n");
3909 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3910 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3912 SetLastError(0xdeadbeef);
3913 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
3914 error
= GetLastError();
3915 ok(!ret
, "HttpSendRequestW succeeded\n");
3916 ok(error
== ERROR_IO_PENDING
||
3917 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
3918 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
3919 "got %u expected ERROR_IO_PENDING\n", error
);
3921 InternetCloseHandle(req
);
3922 InternetCloseHandle(con
);
3923 InternetCloseHandle(ses
);
3926 static void test_cookie_header(int port
)
3928 HINTERNET ses
, con
, req
;
3933 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3934 ok(ses
!= NULL
, "InternetOpen failed\n");
3936 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3937 ok(con
!= NULL
, "InternetConnect failed\n");
3939 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3941 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3942 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3945 size
= sizeof(buffer
);
3946 SetLastError(0xdeadbeef);
3947 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3948 error
= GetLastError();
3949 ok(!ret
, "HttpQueryInfo succeeded\n");
3950 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3952 ret
= HttpAddRequestHeadersA(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
3953 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3956 size
= sizeof(buffer
);
3957 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3958 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3959 ok(!!strstr(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
3961 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3962 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3964 test_status_code(req
, 200);
3967 size
= sizeof(buffer
);
3968 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3969 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3970 ok(!strstr(buffer
, "cookie=not biscuit"), "'%s' should not contain \'cookie=not biscuit\'\n", buffer
);
3971 ok(!!strstr(buffer
, "cookie=biscuit"), "'%s' should contain \'cookie=biscuit\'\n", buffer
);
3973 InternetCloseHandle(req
);
3975 InternetSetCookieA("http://localhost/testCCCC", "subcookie", "data");
3977 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_path1", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3978 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3980 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3981 ok(ret
, "HttpSendRequest failed\n");
3983 test_status_code(req
, 200);
3984 InternetCloseHandle(req
);
3986 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_path1/abc", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3987 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3989 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3990 ok(ret
, "HttpSendRequest failed\n");
3992 test_status_code(req
, 200);
3993 InternetCloseHandle(req
);
3995 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_set_path", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3996 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3998 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3999 ok(ret
, "HttpSendRequest failed\n");
4001 test_status_code(req
, 200);
4002 InternetCloseHandle(req
);
4004 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_path2", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
4005 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4007 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4008 ok(ret
, "HttpSendRequest failed\n");
4010 test_status_code(req
, 400);
4011 InternetCloseHandle(req
);
4013 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_merge", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
4014 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4016 ret
= HttpAddRequestHeadersA(req
, "Cookie: manual_cookie=test\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
4017 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
4019 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4020 ok(ret
, "HttpSendRequest failed\n");
4022 test_status_code(req
, 200);
4023 InternetCloseHandle(req
);
4025 InternetCloseHandle(con
);
4026 InternetCloseHandle(ses
);
4029 static void test_basic_authentication(int port
)
4031 HINTERNET session
, connect
, request
;
4034 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4035 ok(session
!= NULL
, "InternetOpen failed\n");
4037 connect
= InternetConnectA(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
4038 ok(connect
!= NULL
, "InternetConnect failed\n");
4040 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
4041 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4043 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4044 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4046 test_status_code(request
, 200);
4047 test_request_flags(request
, 0);
4049 InternetCloseHandle(request
);
4050 InternetCloseHandle(connect
);
4051 InternetCloseHandle(session
);
4054 static void test_premature_disconnect(int port
)
4060 open_simple_request(&req
, "localhost", port
, NULL
, "/premature_disconnect");
4062 SetLastError(0xdeadbeef);
4063 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4064 err
= GetLastError();
4065 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
4066 todo_wine
ok(err
== ERROR_HTTP_INVALID_SERVER_RESPONSE
, "got %u\n", err
);
4068 close_request(&req
);
4071 static void test_invalid_response_headers(int port
)
4078 open_simple_request(&req
, "localhost", port
, NULL
, "/testE");
4080 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4081 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4083 test_status_code(req
.request
, 401);
4084 test_request_flags(req
.request
, 0);
4087 size
= sizeof(buffer
);
4088 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
4089 ok(ret
, "HttpQueryInfo failed\n");
4090 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
4091 "headers wrong \"%s\"\n", buffer
);
4094 size
= sizeof(buffer
);
4095 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
4096 ok(ret
, "HttpQueryInfo failed\n");
4097 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
4099 close_request(&req
);
4102 static void test_response_without_headers(int port
)
4105 DWORD r
, count
, size
;
4108 open_simple_request(&req
, "localhost", port
, NULL
, "/testG");
4110 test_request_flags(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
4112 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4113 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
4115 test_request_flags_todo(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
4118 memset(buffer
, 0, sizeof buffer
);
4119 r
= InternetReadFile(req
.request
, buffer
, sizeof buffer
, &count
);
4120 ok(r
, "InternetReadFile failed %u\n", GetLastError());
4121 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
4122 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
4124 test_status_code(req
.request
, 200);
4125 test_request_flags_todo(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
4128 size
= sizeof(buffer
);
4129 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
4130 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
4131 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
4134 size
= sizeof(buffer
);
4135 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
4136 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
4137 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
4140 size
= sizeof(buffer
);
4141 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
4142 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
4143 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
4145 close_request(&req
);
4148 static void test_head_request(int port
)
4150 DWORD len
, content_length
;
4155 open_simple_request(&req
, "localhost", port
, "HEAD", "/test_head");
4157 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4158 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
4160 len
= sizeof(content_length
);
4161 content_length
= -1;
4162 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
, &content_length
, &len
, 0);
4163 ok(ret
, "HttpQueryInfo dailed: %u\n", GetLastError());
4164 ok(len
== sizeof(DWORD
), "len = %u\n", len
);
4165 ok(content_length
== 100, "content_length = %u\n", content_length
);
4168 ret
= InternetReadFile(req
.request
, buf
, sizeof(buf
), &len
);
4169 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
4172 ret
= InternetReadFile(req
.request
, buf
, sizeof(buf
), &len
);
4173 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
4175 close_request(&req
);
4178 static void test_HttpQueryInfo(int port
)
4181 DWORD size
, index
, error
;
4185 open_simple_request(&req
, "localhost", port
, NULL
, "/testD");
4187 size
= sizeof(buffer
);
4188 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
4189 error
= GetLastError();
4190 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
4191 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
4193 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4194 ok(ret
, "HttpSendRequest failed\n");
4197 size
= sizeof(buffer
);
4198 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
4199 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4200 ok(index
== 1, "expected 1 got %u\n", index
);
4203 size
= sizeof(buffer
);
4204 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
4205 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4206 ok(index
== 1, "expected 1 got %u\n", index
);
4209 size
= sizeof(buffer
);
4210 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4211 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4212 ok(index
== 0, "expected 0 got %u\n", index
);
4214 size
= sizeof(buffer
);
4215 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4216 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4217 ok(index
== 0, "expected 0 got %u\n", index
);
4219 index
= 0xdeadbeef; /* invalid start index */
4220 size
= sizeof(buffer
);
4221 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4222 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
4223 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
4224 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
4227 size
= sizeof(buffer
);
4228 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
4229 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4230 ok(index
== 0, "expected 0 got %u\n", index
);
4232 size
= sizeof(buffer
);
4233 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
4234 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4235 ok(index
== 0, "expected 0 got %u\n", index
);
4237 size
= sizeof(buffer
);
4238 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
4239 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4240 ok(index
== 0, "expected 0 got %u\n", index
);
4242 test_status_code(req
.request
, 200);
4245 size
= sizeof(buffer
);
4246 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
4247 ok(!ret
, "HttpQueryInfo succeeded\n");
4248 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
4251 size
= sizeof(buffer
);
4252 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
4253 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4254 ok(index
== 1, "expected 1 got %u\n", index
);
4257 size
= sizeof(buffer
);
4258 strcpy(buffer
, "Server");
4259 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
4260 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4261 ok(index
== 1, "expected 1 got %u\n", index
);
4264 size
= sizeof(buffer
);
4265 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
4266 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4267 ok(index
== 1, "expected 1 got %u\n", index
);
4269 size
= sizeof(buffer
);
4270 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
4271 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4272 ok(index
== 2, "expected 2 got %u\n", index
);
4274 close_request(&req
);
4277 static void test_options(int port
)
4279 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi
;
4280 HINTERNET ses
, con
, req
;
4285 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4286 ok(ses
!= NULL
, "InternetOpen failed\n");
4288 SetLastError(0xdeadbeef);
4289 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
4290 error
= GetLastError();
4291 ok(!ret
, "InternetSetOption succeeded\n");
4292 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4294 SetLastError(0xdeadbeef);
4295 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
4296 ok(!ret
, "InternetSetOption succeeded\n");
4297 error
= GetLastError();
4298 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4300 SetLastError(0xdeadbeef);
4301 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
4302 ok(!ret
, "InternetSetOption succeeded\n");
4303 error
= GetLastError();
4304 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4307 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4308 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4310 SetLastError(0xdeadbeef);
4311 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
4312 error
= GetLastError();
4313 ok(!ret
, "InternetQueryOption succeeded\n");
4314 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4316 SetLastError(0xdeadbeef);
4317 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
4318 error
= GetLastError();
4319 ok(!ret
, "InternetQueryOption succeeded\n");
4320 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4323 SetLastError(0xdeadbeef);
4324 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
4325 error
= GetLastError();
4326 ok(!ret
, "InternetQueryOption succeeded\n");
4327 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
4330 SetLastError(0xdeadbeef);
4331 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4332 error
= GetLastError();
4333 ok(!ret
, "InternetQueryOption succeeded\n");
4334 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
4338 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4339 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4340 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
4342 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4343 ok(con
!= NULL
, "InternetConnect failed\n");
4347 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4348 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4349 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
4352 ret
= InternetSetOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4353 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4357 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4358 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4359 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
4361 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
4362 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4366 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4367 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4368 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
4371 ret
= InternetSetOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4372 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4376 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4377 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4378 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
4380 size
= sizeof(idsi
);
4381 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO
, &idsi
, &size
);
4382 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4385 SetLastError(0xdeadbeef);
4386 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
4387 error
= GetLastError();
4388 ok(!ret
, "InternetQueryOption succeeded\n");
4389 ok(error
== ERROR_INTERNET_INVALID_OPERATION
, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error
);
4391 /* INTERNET_OPTION_PROXY */
4392 SetLastError(0xdeadbeef);
4393 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
4394 error
= GetLastError();
4395 ok(!ret
, "InternetQueryOption succeeded\n");
4396 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4398 SetLastError(0xdeadbeef);
4399 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
4400 error
= GetLastError();
4401 ok(!ret
, "InternetQueryOption succeeded\n");
4402 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4405 SetLastError(0xdeadbeef);
4406 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
4407 error
= GetLastError();
4408 ok(!ret
, "InternetQueryOption succeeded\n");
4409 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
4410 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
4412 InternetCloseHandle(req
);
4413 InternetCloseHandle(con
);
4414 InternetCloseHandle(ses
);
4418 const char *response_text
;
4420 const char *status_text
;
4421 const char *raw_headers
;
4422 } http_status_test_t
;
4424 static const http_status_test_t http_status_tests
[] = {
4426 "HTTP/1.1 200 OK\r\n"
4427 "Content-Length: 1\r\n"
4433 "HTTP/1.1 404 Fail\r\n"
4434 "Content-Length: 1\r\n"
4441 "Content-Length: 1\r\n"
4448 "Content-Length: 1\r\n"
4455 static void test_http_status(int port
)
4462 for(i
=0; i
< sizeof(http_status_tests
)/sizeof(*http_status_tests
); i
++) {
4463 send_buffer
= http_status_tests
[i
].response_text
;
4465 open_simple_request(&req
, "localhost", port
, NULL
, "/send_from_buffer");
4467 res
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4468 ok(res
, "HttpSendRequest failed\n");
4470 test_status_code(req
.request
, http_status_tests
[i
].status_code
);
4473 res
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buf
, &size
, NULL
);
4474 ok(res
, "HttpQueryInfo failed: %u\n", GetLastError());
4475 ok(!strcmp(buf
, http_status_tests
[i
].status_text
), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
4476 i
, buf
, http_status_tests
[i
].status_text
);
4478 close_request(&req
);
4482 static void test_cache_control_verb(int port
)
4484 HINTERNET session
, connect
, request
;
4487 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4488 ok(session
!= NULL
, "InternetOpen failed\n");
4490 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4491 ok(connect
!= NULL
, "InternetConnect failed\n");
4493 request
= HttpOpenRequestA(connect
, "RPC_OUT_DATA", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4494 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4495 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4496 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4497 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4498 test_status_code(request
, 200);
4499 InternetCloseHandle(request
);
4501 request
= HttpOpenRequestA(connect
, "POST", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4502 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4503 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4504 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4505 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4506 test_status_code(request
, 200);
4507 InternetCloseHandle(request
);
4509 request
= HttpOpenRequestA(connect
, "HEAD", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4510 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4511 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4512 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4513 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4514 test_status_code(request
, 200);
4515 InternetCloseHandle(request
);
4517 request
= HttpOpenRequestA(connect
, "GET", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4518 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4519 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4520 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4521 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4522 test_status_code(request
, 200);
4523 InternetCloseHandle(request
);
4525 InternetCloseHandle(connect
);
4526 InternetCloseHandle(session
);
4529 static void test_request_content_length(int port
)
4531 char data
[] = {'t','e','s','t'};
4535 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4537 open_simple_request(&req
, "localhost", port
, "POST", "/test_request_content_length");
4539 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4540 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4541 test_status_code(req
.request
, 200);
4543 SetEvent(hCompleteEvent
);
4545 ret
= HttpSendRequestA(req
.request
, NULL
, 0, data
, sizeof(data
));
4546 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4547 test_status_code(req
.request
, 200);
4549 SetEvent(hCompleteEvent
);
4551 close_request(&req
);
4552 CloseHandle(hCompleteEvent
);
4555 static void test_accept_encoding(int port
)
4557 HINTERNET ses
, con
, req
;
4561 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4562 ok(ses
!= NULL
, "InternetOpen failed\n");
4564 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4565 ok(con
!= NULL
, "InternetConnect failed\n");
4567 req
= HttpOpenRequestA(con
, "GET", "/echo_request", "HTTP/1.0", NULL
, NULL
, 0, 0);
4568 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4570 ret
= HttpAddRequestHeadersA(req
, "Accept-Encoding: gzip\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDREQ_FLAG_ADD
);
4571 ok(ret
, "HttpAddRequestHeaders failed\n");
4573 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4574 ok(ret
, "HttpSendRequestA failed\n");
4576 test_status_code(req
, 200);
4577 receive_simple_request(req
, buf
, sizeof(buf
));
4578 ok(strstr(buf
, "Accept-Encoding: gzip") != NULL
, "Accept-Encoding header not found in %s\n", buf
);
4580 InternetCloseHandle(req
);
4582 req
= HttpOpenRequestA(con
, "GET", "/echo_request", "HTTP/1.0", NULL
, NULL
, 0, 0);
4583 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4585 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", ~0u, NULL
, 0);
4586 ok(ret
, "HttpSendRequestA failed\n");
4588 test_status_code(req
, 200);
4589 receive_simple_request(req
, buf
, sizeof(buf
));
4590 ok(strstr(buf
, "Accept-Encoding: gzip") != NULL
, "Accept-Encoding header not found in %s\n", buf
);
4592 InternetCloseHandle(req
);
4593 InternetCloseHandle(con
);
4594 InternetCloseHandle(ses
);
4597 static void test_basic_auth_credentials_reuse(int port
)
4599 HINTERNET ses
, con
, req
;
4603 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4604 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4606 con
= InternetConnectA( ses
, "localhost", port
, "user", "pwd",
4607 INTERNET_SERVICE_HTTP
, 0, 0 );
4608 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4610 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
4611 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4613 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4614 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4616 status
= 0xdeadbeef;
4617 size
= sizeof(status
);
4618 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4619 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4620 ok( status
== 200, "got %u\n", status
);
4622 InternetCloseHandle( req
);
4623 InternetCloseHandle( con
);
4624 InternetCloseHandle( ses
);
4626 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4627 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4629 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
,
4630 INTERNET_SERVICE_HTTP
, 0, 0 );
4631 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4633 req
= HttpOpenRequestA( con
, "PUT", "/upload2.txt", NULL
, NULL
, NULL
, 0, 0 );
4634 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4636 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4637 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4639 status
= 0xdeadbeef;
4640 size
= sizeof(status
);
4641 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4642 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4643 ok( status
== 200, "got %u\n", status
);
4645 InternetCloseHandle( req
);
4646 InternetCloseHandle( con
);
4647 InternetCloseHandle( ses
);
4650 static void test_async_read(int port
)
4652 HINTERNET ses
, con
, req
;
4653 INTERNET_BUFFERSA ib
;
4655 DWORD pending_reads
;
4656 DWORD res
, count
, bytes
;
4659 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4660 conn_wait_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4662 /* test asynchronous InternetReadFileEx */
4663 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4664 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4665 pInternetSetStatusCallbackA( ses
, &callback
);
4667 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4668 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef );
4669 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4670 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4672 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4673 req
= HttpOpenRequestA( con
, "GET", "/async_read", NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef );
4674 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4675 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4677 SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT
);
4678 SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY
);
4679 SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4680 SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4681 SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST
);
4682 SET_EXPECT( INTERNET_STATUS_REQUEST_SENT
);
4683 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4684 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4685 SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION
);
4686 SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED
);
4687 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4689 SetLastError( 0xdeadbeef );
4690 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4691 ok( !ret
, "HttpSendRequestA unexpectedly succeeded\n" );
4692 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4693 WaitForSingleObject( hCompleteEvent
, INFINITE
);
4694 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4696 CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT
);
4697 CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY
);
4698 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4699 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4700 CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST
);
4701 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT
);
4702 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4703 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4704 CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION
);
4705 CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED
);
4706 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4709 memset( &ib
, 0, sizeof(ib
) );
4710 memset( buffer
, 0, sizeof(buffer
) );
4711 ib
.dwStructSize
= sizeof(ib
);
4712 for (count
= 0; count
< sizeof(buffer
); count
+= ib
.dwBufferLength
)
4714 ib
.lpvBuffer
= buffer
+ count
;
4715 ib
.dwBufferLength
= min(16, sizeof(buffer
) - count
);
4717 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4718 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4720 ret
= InternetReadFileExA( req
, &ib
, 0, 0xdeadbeef );
4721 if (!count
) /* the first part should arrive immediately */
4722 ok( ret
, "InternetReadFileExA failed %u\n", GetLastError() );
4725 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4726 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4727 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4728 if (!pending_reads
++)
4730 res
= WaitForSingleObject( hCompleteEvent
, 0 );
4731 ok( res
== WAIT_TIMEOUT
, "expected WAIT_TIMEOUT, got %u\n", res
);
4732 SetEvent( conn_wait_event
);
4734 res
= WaitForSingleObject( hCompleteEvent
, INFINITE
);
4735 ok( res
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", res
);
4736 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4737 todo_wine_if( pending_reads
> 1 )
4738 ok( ib
.dwBufferLength
!= 0, "expected ib.dwBufferLength != 0\n" );
4739 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4740 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4743 CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4744 CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4745 if (!ib
.dwBufferLength
) break;
4749 ok( pending_reads
== 1, "expected 1 pending read, got %u\n", pending_reads
);
4750 ok( !strcmp(buffer
, page1
), "unexpected buffer content\n" );
4751 close_async_handle( ses
, hCompleteEvent
, 2 );
4752 ResetEvent( conn_wait_event
);
4754 /* test asynchronous InternetReadFile */
4755 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4756 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4757 pInternetSetStatusCallbackA( ses
, &callback
);
4759 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4760 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef );
4761 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4762 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4764 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4765 req
= HttpOpenRequestA( con
, "GET", "/async_read", NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef );
4766 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4767 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4769 SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT
);
4770 SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY
);
4771 SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4772 SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4773 SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST
);
4774 SET_EXPECT( INTERNET_STATUS_REQUEST_SENT
);
4775 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4776 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4777 SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION
);
4778 SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED
);
4779 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4781 SetLastError( 0xdeadbeef );
4782 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4783 ok( !ret
, "HttpSendRequestA unexpectedly succeeded\n" );
4784 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4785 WaitForSingleObject( hCompleteEvent
, INFINITE
);
4786 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4788 CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT
);
4789 CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY
);
4790 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4791 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4792 CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST
);
4793 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT
);
4794 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4795 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4796 CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION
);
4797 CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED
);
4798 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4801 memset( buffer
, 0, sizeof(buffer
) );
4802 for (count
= 0; count
< sizeof(buffer
); count
+= bytes
)
4804 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4805 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4808 ret
= InternetReadFile( req
, buffer
+ count
, min(16, sizeof(buffer
) - count
), &bytes
);
4809 if (!count
) /* the first part should arrive immediately */
4810 ok( ret
, "InternetReadFile failed %u\n", GetLastError() );
4813 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4814 ok( bytes
== 0, "expected 0, got %u\n", bytes
);
4816 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4817 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4818 if (!pending_reads
++)
4820 res
= WaitForSingleObject( hCompleteEvent
, 0 );
4821 ok( res
== WAIT_TIMEOUT
, "expected WAIT_TIMEOUT, got %u\n", res
);
4822 SetEvent( conn_wait_event
);
4824 res
= WaitForSingleObject( hCompleteEvent
, INFINITE
);
4825 ok( res
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", res
);
4826 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4827 todo_wine_if( pending_reads
> 1 )
4828 ok( bytes
!= 0, "expected bytes != 0\n" );
4829 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4830 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4833 CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4834 CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4839 ok( pending_reads
== 1, "expected 1 pending read, got %u\n", pending_reads
);
4840 ok( !strcmp(buffer
, page1
), "unexpected buffer content\n" );
4841 close_async_handle( ses
, hCompleteEvent
, 2 );
4843 CloseHandle( hCompleteEvent
);
4844 CloseHandle( conn_wait_event
);
4847 static void server_send_string(const char *msg
)
4849 send(server_socket
, msg
, strlen(msg
), 0);
4852 static void WINAPI
readex_callback(HINTERNET handle
, DWORD_PTR context
, DWORD status
, void *info
, DWORD info_size
)
4855 case INTERNET_STATUS_RECEIVING_RESPONSE
:
4856 case INTERNET_STATUS_RESPONSE_RECEIVED
:
4859 callback(handle
, context
, status
, info
, info_size
);
4863 static void open_read_test_request(int port
, test_request_t
*req
, const char *response
)
4867 req
->session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4868 ok(req
->session
!= NULL
, "InternetOpenA failed\n");
4869 pInternetSetStatusCallbackA(req
->session
, readex_callback
);
4871 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4872 req
->connection
= InternetConnectA(req
->session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef);
4873 ok(req
->connection
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
4874 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4876 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4877 req
->request
= HttpOpenRequestA(req
->connection
, "GET", "/socket", NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef);
4878 ok(req
->request
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
4879 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4881 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4882 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4883 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4884 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4885 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4886 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4888 SetLastError(0xdeadbeef);
4889 ret
= HttpSendRequestA(req
->request
, NULL
, 0, NULL
, 0);
4890 ok(!ret
, "HttpSendRequestA unexpectedly succeeded\n");
4891 ok(GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError());
4892 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4894 WaitForSingleObject(server_req_rec_event
, INFINITE
);
4896 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4897 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4898 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4899 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4900 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4902 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4904 server_send_string(response
);
4905 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4907 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4908 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4911 #define readex_expect_sync_data_len(a,b,c,d,e,f) _readex_expect_sync_data_len(__LINE__,a,b,c,d,e,f)
4912 static void _readex_expect_sync_data_len(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
4913 DWORD buf_size
, const char *exdata
, DWORD len
)
4917 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4919 memset(buf
->lpvBuffer
, 0xff, buf_size
);
4920 buf
->dwBufferLength
= buf_size
;
4921 ret
= InternetReadFileExW(req
, buf
, flags
, 0xdeadbeef);
4922 ok_(__FILE__
,line
)(ret
, "InternetReadFileExW failed: %u\n", GetLastError());
4923 ok_(__FILE__
,line
)(buf
->dwBufferLength
== len
, "dwBufferLength = %u, expected %u\n", buf
->dwBufferLength
, len
);
4925 ok_(__FILE__
,line
)(!memcmp(buf
->lpvBuffer
, exdata
, len
), "Unexpected data\n");
4927 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4930 #define readex_expect_sync_data(a,b,c,d,e) _readex_expect_sync_data(__LINE__,a,b,c,d,e)
4931 static void _readex_expect_sync_data(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
4932 DWORD buf_size
, const char *exdata
)
4934 _readex_expect_sync_data_len(line
, req
, flags
, buf
, buf_size
, exdata
, strlen(exdata
));
4937 static void send_response_and_wait(const char *response
, BOOL close_connection
, INTERNET_BUFFERSW
*buf
)
4939 DWORD orig_size
= buf
->dwBufferLength
;
4941 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4944 server_send_string(response
);
4946 if(close_connection
) {
4948 SetEvent(conn_wait_event
);
4949 recv(server_socket
, &c
, 1, 0);
4952 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4954 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4956 /* If IRF_NO_WAIT is used, buffer is not changed. */
4957 ok(buf
->dwBufferLength
== orig_size
, "dwBufferLength = %u\n", buf
->dwBufferLength
);
4958 ok(!*(int*)buf
->lpvBuffer
, "buffer data changed\n");
4961 static void send_response_len_and_wait(unsigned len
, BOOL close_connection
, INTERNET_BUFFERSW
*buf
)
4965 response
= HeapAlloc(GetProcessHeap(), 0, len
+1);
4966 memset(response
, 'x', len
);
4968 send_response_and_wait(response
, close_connection
, buf
);
4969 HeapFree(GetProcessHeap(), 0, response
);
4972 static void readex_expect_async(HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
, DWORD buf_size
)
4976 memset(buf
->lpvBuffer
, 0, buf_size
);
4977 buf
->dwBufferLength
= buf_size
;
4978 ret
= InternetReadFileExW(req
, buf
, flags
, 0xdeadbeef);
4979 ok(!ret
&& GetLastError() == ERROR_IO_PENDING
, "InternetReadFileExW returned %x (%u)\n", ret
, GetLastError());
4980 ok(buf
->dwBufferLength
== buf_size
, "dwBufferLength = %u, expected %u\n", buf
->dwBufferLength
, buf_size
);
4981 ok(!*(int*)buf
->lpvBuffer
, "buffer data changed\n");
4984 #define expect_data_available(a,b) _expect_data_available(__LINE__,a,b)
4985 static DWORD
_expect_data_available(unsigned line
, HINTERNET req
, int exsize
)
4990 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
4991 ok_(__FILE__
,line
)(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
4993 ok_(__FILE__
,line
)(size
== exsize
, "size = %u, expected %u\n", size
, exsize
);
4998 static void test_http_read(int port
)
5000 INTERNET_BUFFERSW ib
;
5008 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
5009 conn_wait_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
5010 server_req_rec_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
5012 trace("Testing InternetReadFileExW with IRF_NO_WAIT flag...\n");
5014 open_read_test_request(port
, &req
,
5015 "HTTP/1.1 200 OK\r\n"
5016 "Server: winetest\r\n"
5020 memset(&ib
, 0, sizeof(ib
));
5021 ib
.dwStructSize
= sizeof(ib
);
5024 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "xx");
5026 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5027 send_response_and_wait("1234567890", FALSE
, &ib
);
5028 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, 5, "12345");
5029 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "67890");
5031 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5032 send_response_and_wait("12345", TRUE
, &ib
);
5034 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "12345");
5035 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "");
5037 close_async_handle(req
.session
, hCompleteEvent
, 2);
5039 open_read_test_request(port
, &req
,
5040 "HTTP/1.1 200 OK\r\n"
5041 "Server: winetest\r\n"
5042 "Transfer-Encoding: chunked\r\n"
5045 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123456789");
5046 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5048 send_response_and_wait("\r\n1\r\na\r\n1\r\nb\r", FALSE
, &ib
);
5049 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab");
5050 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5052 send_response_and_wait("\n3\r\nab", FALSE
, &ib
);
5053 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab");
5054 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5056 send_response_and_wait("c", FALSE
, &ib
);
5057 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "c");
5058 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5060 send_response_and_wait("\r\n1\r\nx\r\n0\r\n\r\n", TRUE
, &ib
);
5061 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "x");
5062 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "");
5064 close_async_handle(req
.session
, hCompleteEvent
, 2);
5066 open_read_test_request(port
, &req
,
5067 "HTTP/1.1 200 OK\r\n"
5068 "Server: winetest\r\n"
5069 "Transfer-Encoding: chunked\r\n"
5072 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123");
5073 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5075 send_response_and_wait("0\r\n\r\n", TRUE
, &ib
);
5076 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "");
5078 close_async_handle(req
.session
, hCompleteEvent
, 2);
5080 trace("Testing InternetQueryDataAvailable...\n");
5082 open_read_test_request(port
, &req
,
5083 "HTTP/1.1 200 OK\r\n"
5084 "Server: winetest\r\n"
5087 expect_data_available(req
.request
, 3);
5088 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123");
5089 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5091 send_response_len_and_wait(20000, TRUE
, &ib
);
5092 avail
= expect_data_available(req
.request
, -1);
5093 ok(avail
< 17000, "avail = %u\n", avail
);
5095 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
5096 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
5097 close_async_handle(req
.session
, hCompleteEvent
, 2);
5098 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5099 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5101 CloseHandle(hCompleteEvent
);
5102 CloseHandle(conn_wait_event
);
5103 CloseHandle(server_req_rec_event
);
5106 static void test_long_url(int port
)
5108 char long_path
[INTERNET_MAX_PATH_LENGTH
*2] = "/echo_request?";
5109 char buf
[sizeof(long_path
)*2], url
[sizeof(buf
)];
5117 memset(long_path
+strlen(long_path
), 'x', sizeof(long_path
)-strlen(long_path
));
5118 long_path
[sizeof(long_path
)-1] = 0;
5119 open_simple_request(&req
, "localhost", port
, NULL
, long_path
);
5121 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
5122 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
5123 test_status_code(req
.request
, 200);
5125 receive_simple_request(req
.request
, buf
, sizeof(buf
));
5126 ok(strstr(buf
, long_path
) != NULL
, "long pathnot found in %s\n", buf
);
5128 sprintf(url
, "http://localhost:%u%s", port
, long_path
);
5131 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_URL
, buf
, &size
);
5132 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
5134 ok(size
== len
, "size = %u, expected %u\n", size
, len
);
5135 ok(!strcmp(buf
, url
), "Wrong URL %s, expected %s\n", buf
, url
);
5137 close_request(&req
);
5140 static void test_remove_dot_segments(int port
)
5145 open_simple_request(&req
, "localhost", port
, NULL
, "/A/../B/./C/../../test_remove_dot_segments");
5147 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
5148 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
5149 test_status_code(req
.request
, 200);
5151 close_request(&req
);
5154 static void test_http_connection(void)
5156 struct server_info si
;
5160 si
.hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
5163 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
5164 ok( hThread
!= NULL
, "create thread failed\n");
5166 r
= WaitForSingleObject(si
.hEvent
, 10000);
5167 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
5168 if (r
!= WAIT_OBJECT_0
)
5171 test_basic_request(si
.port
, "GET", "/test1");
5172 test_proxy_indirect(si
.port
);
5173 test_proxy_direct(si
.port
);
5174 test_header_handling_order(si
.port
);
5175 test_basic_request(si
.port
, "POST", "/test5");
5176 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
5177 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
5178 test_basic_request(si
.port
, "GET", "/test6");
5179 test_basic_request(si
.port
, "GET", "/testF");
5180 test_connection_header(si
.port
);
5181 test_header_override(si
.port
);
5182 test_cookie_header(si
.port
);
5183 test_basic_authentication(si
.port
);
5184 test_invalid_response_headers(si
.port
);
5185 test_response_without_headers(si
.port
);
5186 test_HttpQueryInfo(si
.port
);
5187 test_HttpSendRequestW(si
.port
);
5188 test_options(si
.port
);
5189 test_no_content(si
.port
);
5190 test_conn_close(si
.port
);
5191 test_no_cache(si
.port
);
5192 test_cache_read_gzipped(si
.port
);
5193 test_http_status(si
.port
);
5194 test_premature_disconnect(si
.port
);
5195 test_connection_closing(si
.port
);
5196 test_cache_control_verb(si
.port
);
5197 test_successive_HttpSendRequest(si
.port
);
5198 test_head_request(si
.port
);
5199 test_request_content_length(si
.port
);
5200 test_accept_encoding(si
.port
);
5201 test_basic_auth_credentials_reuse(si
.port
);
5202 test_async_read(si
.port
);
5203 test_http_read(si
.port
);
5204 test_long_url(si
.port
);
5205 test_remove_dot_segments(si
.port
);
5207 /* send the basic request again to shutdown the server thread */
5208 test_basic_request(si
.port
, "GET", "/quit");
5210 r
= WaitForSingleObject(hThread
, 3000);
5211 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
5212 CloseHandle(hThread
);
5215 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
5217 LocalFree(info
->lpszSubjectInfo
);
5218 LocalFree(info
->lpszIssuerInfo
);
5219 LocalFree(info
->lpszProtocolName
);
5220 LocalFree(info
->lpszSignatureAlgName
);
5221 LocalFree(info
->lpszEncryptionAlgName
);
5225 const char *ex_subject
;
5226 const char *ex_issuer
;
5227 } cert_struct_test_t
;
5229 static const cert_struct_test_t test_winehq_org_cert
= {
5234 "RapidSSL SHA256 CA"
5237 static const cert_struct_test_t test_winehq_com_cert
= {
5242 "test.winehq.com\r\n"
5243 "webmaster@winehq.org",
5248 "test.winehq.com\r\n"
5249 "webmaster@winehq.org"
5252 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
5254 INTERNET_CERTIFICATE_INFOA info
;
5258 memset(&info
, 0x5, sizeof(info
));
5260 size
= sizeof(info
);
5261 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
5262 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
5263 ok(size
== sizeof(info
), "size = %u\n", size
);
5265 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
5266 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
5267 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
5268 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
5269 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
5270 ok(info
.dwKeySize
>= 128 && info
.dwKeySize
<= 256, "dwKeySize = %u\n", info
.dwKeySize
);
5272 release_cert_info(&info
);
5275 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
5276 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
5278 char url
[INTERNET_MAX_URL_LENGTH
];
5279 const CERT_CHAIN_CONTEXT
*chain
;
5283 if(!pInternetGetSecurityInfoByURLA
) {
5284 win_skip("pInternetGetSecurityInfoByURLA not available\n");
5289 chain
= (void*)0xdeadbeef;
5291 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
5292 if(error
== ERROR_SUCCESS
) {
5293 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
5294 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
5295 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
5296 CertFreeCertificateChain(chain
);
5298 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
5299 "InternetGetSecurityInfoByURLA returned: %x(%u), expected %u\n", res
, GetLastError(), error
);
5303 #define test_secflags_option(a,b,c) _test_secflags_option(__LINE__,a,b,c)
5304 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
, DWORD opt_flags
)
5310 size
= sizeof(flags
);
5311 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
5312 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
5313 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n",
5316 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
5318 size
= sizeof(flags
);
5319 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
5320 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
5321 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n",
5325 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
5326 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
5330 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
5331 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
5334 static void test_security_flags(void)
5336 INTERNET_CERTIFICATE_INFOA
*cert
;
5337 HINTERNET ses
, conn
, req
;
5342 trace("Testing security flags...\n");
5344 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
5346 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5347 ok(ses
!= NULL
, "InternetOpen failed\n");
5349 pInternetSetStatusCallbackA(ses
, &callback
);
5351 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5352 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
5353 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
5354 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
5355 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5357 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5358 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5359 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5361 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5362 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5365 size
= sizeof(flags
);
5366 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
5367 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
5368 win_skip("Incomplete security flags support, skipping\n");
5370 close_async_handle(ses
, hCompleteEvent
, 2);
5371 CloseHandle(hCompleteEvent
);
5375 test_secflags_option(req
, 0, 0);
5376 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5378 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
5379 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
, 0);
5381 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
5382 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
5384 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
5385 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
5387 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
5388 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
5389 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
5391 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
5392 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
5393 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5394 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5395 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5396 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5397 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5398 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5399 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5400 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5401 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5402 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5403 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5404 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5405 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5407 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5408 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5410 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5411 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5413 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
5414 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
5415 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5416 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5417 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5418 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5419 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5420 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5421 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5422 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5423 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5424 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5425 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5427 test_request_flags(req
, 0);
5428 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
5429 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
, 0);
5431 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5432 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5433 ok(size
, "size = 0\n");
5435 /* Collect all existing persistent connections */
5436 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5437 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5439 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5440 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5441 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5443 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5444 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5446 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
5447 res
= InternetSetOptionA(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
5448 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
5450 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5451 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5452 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5453 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5454 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5455 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5456 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5457 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5458 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5459 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5460 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5462 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5463 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5465 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5466 ok(req_error
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| broken(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
),
5467 "req_error = %d\n", req_error
);
5470 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
5471 ok(res
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5472 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %u\n", size
);
5473 cert
= HeapAlloc(GetProcessHeap(), 0, size
);
5474 cert
->lpszSubjectInfo
= NULL
;
5475 cert
->lpszIssuerInfo
= NULL
;
5476 cert
->lpszSignatureAlgName
= (char *)0xdeadbeef;
5477 cert
->lpszEncryptionAlgName
= (char *)0xdeadbeef;
5478 cert
->lpszProtocolName
= (char *)0xdeadbeef;
5479 cert
->dwKeySize
= 0xdeadbeef;
5480 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, cert
, &size
);
5481 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
5484 ok(cert
->lpszSubjectInfo
&& strlen(cert
->lpszSubjectInfo
) > 1, "expected a non-empty subject name\n");
5485 ok(cert
->lpszIssuerInfo
&& strlen(cert
->lpszIssuerInfo
) > 1, "expected a non-empty issuer name\n");
5486 ok(!cert
->lpszSignatureAlgName
, "unexpected signature algorithm name\n");
5487 ok(!cert
->lpszEncryptionAlgName
, "unexpected encryption algorithm name\n");
5488 ok(!cert
->lpszProtocolName
, "unexpected protocol name\n");
5489 ok(cert
->dwKeySize
!= 0xdeadbeef, "unexpected key size\n");
5491 HeapFree(GetProcessHeap(), 0, cert
);
5493 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5494 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5495 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
5496 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
5497 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5498 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5499 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5501 if(req_error
!= ERROR_INTERNET_SEC_CERT_REV_FAILED
) {
5502 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error
);
5504 close_async_handle(ses
, hCompleteEvent
, 3);
5505 CloseHandle(hCompleteEvent
);
5510 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
5511 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
5513 test_request_flags(req
, 8);
5514 /* IE11 finds both rev failure and invalid CA. Previous versions required rev failure
5515 to be ignored before invalid CA was reported. */
5516 test_secflags_option(req
, _SECURITY_FLAG_CERT_REV_FAILED
, _SECURITY_FLAG_CERT_INVALID_CA
);
5518 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
5519 test_secflags_option(req
, _SECURITY_FLAG_CERT_REV_FAILED
|SECURITY_FLAG_IGNORE_REVOCATION
, _SECURITY_FLAG_CERT_INVALID_CA
);
5521 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5522 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5523 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5524 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5525 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5526 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5527 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5529 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5530 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5532 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5533 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
5535 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5536 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5537 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5538 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5539 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5540 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5541 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5543 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
5544 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5545 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5547 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
5548 test_secflags_option(req
, _SECURITY_FLAG_CERT_INVALID_CA
|_SECURITY_FLAG_CERT_REV_FAILED
5549 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
, 0);
5550 test_http_version(req
);
5552 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5553 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5554 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5555 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5556 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5557 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5558 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5559 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5560 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5561 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5562 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5563 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5564 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5566 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5567 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5569 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5570 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5572 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5573 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5574 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5575 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5576 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5577 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5578 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5579 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5580 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5581 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5582 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5584 test_request_flags(req
, 0);
5585 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
5586 |SECURITY_FLAG_STRENGTH_STRONG
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5588 test_cert_struct(req
, &test_winehq_com_cert
);
5589 test_security_info("https://test.winehq.com/data/some_file.html?q", 0,
5590 _SECURITY_FLAG_CERT_INVALID_CA
|_SECURITY_FLAG_CERT_REV_FAILED
);
5592 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5593 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5594 ok(size
, "size = 0\n");
5596 close_async_handle(ses
, hCompleteEvent
, 3);
5598 /* Collect all existing persistent connections */
5599 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5600 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5602 /* Make another request, without setting security flags */
5604 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5605 ok(ses
!= NULL
, "InternetOpen failed\n");
5607 pInternetSetStatusCallbackA(ses
, &callback
);
5609 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5610 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
5611 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
5612 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
5613 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5615 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5616 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5617 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5619 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5620 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5622 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
5623 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5624 test_http_version(req
);
5626 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5627 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5628 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5629 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5630 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5631 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5632 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5633 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5634 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5635 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5636 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5637 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5639 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5640 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5642 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5643 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5645 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5646 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5647 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5648 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5649 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5650 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5651 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5652 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5653 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5654 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5656 test_request_flags(req
, 0);
5657 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
5658 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5660 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5661 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5662 ok(size
, "size = 0\n");
5664 close_async_handle(ses
, hCompleteEvent
, 2);
5666 CloseHandle(hCompleteEvent
);
5668 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5669 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5670 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5673 static void test_secure_connection(void)
5675 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
5676 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
5677 static const WCHAR get
[] = {'G','E','T',0};
5678 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
5679 HINTERNET ses
, con
, req
;
5681 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
5682 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
5685 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5686 ok(ses
!= NULL
, "InternetOpen failed\n");
5688 con
= InternetConnectA(ses
, "test.winehq.org",
5689 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
5690 INTERNET_SERVICE_HTTP
, 0, 0);
5691 ok(con
!= NULL
, "InternetConnect failed\n");
5693 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5694 INTERNET_FLAG_SECURE
, 0);
5695 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5697 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5698 ok(ret
|| broken(GetLastError() == ERROR_INTERNET_CANNOT_CONNECT
),
5699 "HttpSendRequest failed: %d\n", GetLastError());
5702 win_skip("Cannot connect to https.\n");
5706 size
= sizeof(flags
);
5707 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
5708 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5709 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
5711 test_cert_struct(req
, &test_winehq_org_cert
);
5713 /* Querying the same option through InternetQueryOptionW still results in
5714 * ASCII strings being returned.
5717 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5719 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5720 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
5721 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
5722 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5723 certificate_structW
, &size
);
5724 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
5725 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5728 ok(certificate_structA
->lpszSubjectInfo
&&
5729 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
5730 "expected a non-empty subject name\n");
5731 ok(certificate_structA
->lpszIssuerInfo
&&
5732 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
5733 "expected a non-empty issuer name\n");
5734 ok(!certificate_structA
->lpszSignatureAlgName
,
5735 "unexpected signature algorithm name\n");
5736 ok(!certificate_structA
->lpszEncryptionAlgName
,
5737 "unexpected encryption algorithm name\n");
5738 ok(!certificate_structA
->lpszProtocolName
,
5739 "unexpected protocol name\n");
5740 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
5741 release_cert_info(certificate_structA
);
5743 HeapFree(GetProcessHeap(), 0, certificate_structW
);
5745 InternetCloseHandle(req
);
5746 InternetCloseHandle(con
);
5747 InternetCloseHandle(ses
);
5749 /* Repeating the tests with the W functions has the same result: */
5750 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5751 ok(ses
!= NULL
, "InternetOpen failed\n");
5753 con
= InternetConnectW(ses
, testsite
,
5754 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
5755 INTERNET_SERVICE_HTTP
, 0, 0);
5756 ok(con
!= NULL
, "InternetConnect failed\n");
5758 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
5759 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
5760 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5762 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5763 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
5765 size
= sizeof(flags
);
5766 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
5767 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5768 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %x\n", flags
);
5770 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5772 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5773 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
5774 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
5775 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5776 certificate_structA
, &size
);
5777 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5780 ok(certificate_structA
->lpszSubjectInfo
&&
5781 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
5782 "expected a non-empty subject name\n");
5783 ok(certificate_structA
->lpszIssuerInfo
&&
5784 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
5785 "expected a non-empty issuer name\n");
5786 ok(!certificate_structA
->lpszSignatureAlgName
,
5787 "unexpected signature algorithm name\n");
5788 ok(!certificate_structA
->lpszEncryptionAlgName
,
5789 "unexpected encryption algorithm name\n");
5790 ok(!certificate_structA
->lpszProtocolName
,
5791 "unexpected protocol name\n");
5792 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
5793 release_cert_info(certificate_structA
);
5795 HeapFree(GetProcessHeap(), 0, certificate_structA
);
5797 /* Again, querying the same option through InternetQueryOptionW still
5798 * results in ASCII strings being returned.
5801 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5803 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5804 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
5805 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
5806 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5807 certificate_structW
, &size
);
5808 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
5809 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5812 ok(certificate_structA
->lpszSubjectInfo
&&
5813 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
5814 "expected a non-empty subject name\n");
5815 ok(certificate_structA
->lpszIssuerInfo
&&
5816 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
5817 "expected a non-empty issuer name\n");
5818 ok(!certificate_structA
->lpszSignatureAlgName
,
5819 "unexpected signature algorithm name\n");
5820 ok(!certificate_structA
->lpszEncryptionAlgName
,
5821 "unexpected encryption algorithm name\n");
5822 ok(!certificate_structA
->lpszProtocolName
,
5823 "unexpected protocol name\n");
5824 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
5825 release_cert_info(certificate_structA
);
5827 HeapFree(GetProcessHeap(), 0, certificate_structW
);
5830 InternetCloseHandle(req
);
5831 InternetCloseHandle(con
);
5832 InternetCloseHandle(ses
);
5835 static void test_user_agent_header(void)
5837 HINTERNET ses
, con
, req
;
5842 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5843 ok(ses
!= NULL
, "InternetOpen failed\n");
5845 con
= InternetConnectA(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5846 ok(con
!= NULL
, "InternetConnect failed\n");
5848 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
5849 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5851 size
= sizeof(buffer
);
5852 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5853 err
= GetLastError();
5854 ok(!ret
, "HttpQueryInfo succeeded\n");
5855 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
5857 ret
= HttpAddRequestHeadersA(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
5858 ok(ret
, "HttpAddRequestHeaders succeeded\n");
5860 size
= sizeof(buffer
);
5861 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5862 err
= GetLastError();
5863 ok(ret
, "HttpQueryInfo failed\n");
5865 InternetCloseHandle(req
);
5867 req
= HttpOpenRequestA(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
5868 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5870 size
= sizeof(buffer
);
5871 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5872 err
= GetLastError();
5873 ok(!ret
, "HttpQueryInfo succeeded\n");
5874 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
5876 ret
= HttpAddRequestHeadersA(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
5877 ok(ret
, "HttpAddRequestHeaders failed\n");
5880 size
= sizeof(buffer
);
5881 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5882 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
5883 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
5885 InternetCloseHandle(req
);
5886 InternetCloseHandle(con
);
5887 InternetCloseHandle(ses
);
5890 static void test_bogus_accept_types_array(void)
5892 HINTERNET ses
, con
, req
;
5893 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
5898 ses
= InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
5899 con
= InternetConnectA(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5900 req
= HttpOpenRequestA(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
5902 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
5905 size
= sizeof(buffer
);
5906 SetLastError(0xdeadbeef);
5907 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5908 error
= GetLastError();
5909 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
5910 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
5911 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
5912 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
5913 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
5915 InternetCloseHandle(req
);
5916 InternetCloseHandle(con
);
5917 InternetCloseHandle(ses
);
5926 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
5928 INTERNET_ASYNC_RESULT
*result
= info
;
5929 struct context
*ctx
= (struct context
*)context
;
5931 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
5934 case INTERNET_STATUS_REQUEST_COMPLETE
:
5935 trace("request handle: 0x%08lx\n", result
->dwResult
);
5936 ctx
->req
= (HINTERNET
)result
->dwResult
;
5937 SetEvent(ctx
->event
);
5939 case INTERNET_STATUS_HANDLE_CLOSING
: {
5940 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
5942 if (InternetQueryOptionA(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
5943 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
5944 SetEvent(ctx
->event
);
5947 case INTERNET_STATUS_NAME_RESOLVED
:
5948 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
5949 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
5951 ok(str
[0] && str
[1], "Got string: %s\n", str
);
5952 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
5957 static void test_open_url_async(void)
5965 /* Collect all existing persistent connections */
5966 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5967 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5970 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
5971 * other versions never do. They also hang of following tests. We disable it for everything older
5978 ctx
.event
= CreateEventA(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
5980 ses
= InternetOpenA("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5981 ok(ses
!= NULL
, "InternetOpen failed\n");
5983 SetLastError(0xdeadbeef);
5984 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
5985 error
= GetLastError();
5986 ok(!ret
, "InternetSetOptionA succeeded\n");
5987 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
5989 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
5990 error
= GetLastError();
5991 ok(!ret
, "InternetSetOptionA failed\n");
5992 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
5994 pInternetSetStatusCallbackW(ses
, cb
);
5995 ResetEvent(ctx
.event
);
5997 req
= InternetOpenUrlA(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
5998 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
6000 WaitForSingleObject(ctx
.event
, INFINITE
);
6003 size
= sizeof(type
);
6004 ret
= InternetQueryOptionA(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
6005 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
6006 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
6007 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
6010 ret
= HttpQueryInfoA(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
6011 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
6012 ok(size
> 0, "expected size > 0\n");
6014 ResetEvent(ctx
.event
);
6015 InternetCloseHandle(ctx
.req
);
6016 WaitForSingleObject(ctx
.event
, INFINITE
);
6018 InternetCloseHandle(ses
);
6019 CloseHandle(ctx
.event
);
6024 internet_connect
= 1,
6026 http_send_request_ex
,
6029 internet_close_handle
6034 enum api function
; /* api responsible for notification */
6035 unsigned int status
; /* status received */
6036 BOOL async
; /* delivered from another thread? */
6044 const struct notification
*test
;
6050 DWORD expect_result
;
6054 static CRITICAL_SECTION notification_cs
;
6056 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
6058 BOOL status_ok
, function_ok
;
6059 struct info
*info
= (struct info
*)context
;
6062 EnterCriticalSection( ¬ification_cs
);
6064 if(info
->is_aborted
) {
6065 LeaveCriticalSection(¬ification_cs
);
6069 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
6071 DWORD size
= sizeof(struct info
*);
6072 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
6073 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
6074 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
6076 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
6077 if(info
->expect_result
== ERROR_SUCCESS
) {
6078 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
6080 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
6081 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
6086 if (i
>= info
->count
)
6088 LeaveCriticalSection( ¬ification_cs
);
6092 while (info
->test
[i
].status
!= status
&&
6093 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
6094 i
< info
->count
- 1 &&
6095 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
6100 status_ok
= (info
->test
[i
].status
== status
);
6101 function_ok
= (info
->test
[i
].function
== info
->function
);
6103 if (!info
->test
[i
].todo
)
6105 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
6106 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
6108 if (info
->test
[i
].async
)
6109 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
6110 info
->line
, info
->thread
, GetCurrentThreadId());
6114 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
6116 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
6118 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
6121 LeaveCriticalSection( ¬ification_cs
);
6124 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
6126 info
->function
= function
;
6128 info
->expect_result
= expect_result
;
6131 struct notification_data
6133 const struct notification
*test
;
6134 const unsigned int count
;
6139 BOOL expect_conn_failure
;
6142 static const struct notification async_send_request_ex_test
[] =
6144 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6145 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6146 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6147 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6148 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6149 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6150 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
6151 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
6152 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6153 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6154 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6155 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, FALSE
},
6156 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, FALSE
},
6157 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6158 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6159 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6160 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6161 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6162 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6163 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6166 static const struct notification async_send_request_ex_test2
[] =
6168 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6169 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6170 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6171 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6172 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6173 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6174 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
, TRUE
},
6175 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
, TRUE
},
6176 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6177 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6178 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6179 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6180 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6181 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6182 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6183 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6184 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6185 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6188 static const struct notification async_send_request_ex_resolve_failure_test
[] =
6190 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6191 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6192 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6193 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
},
6194 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6195 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6196 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6197 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6198 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6199 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6200 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6203 static const struct notification async_send_request_ex_chunked_test
[] =
6205 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
},
6206 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
},
6207 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6208 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6209 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6210 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6211 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
6212 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
6213 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6214 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6215 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6216 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6217 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6218 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6219 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
},
6220 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
},
6221 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
},
6222 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
}
6225 static const struct notification_data notification_data
[] = {
6227 async_send_request_ex_chunked_test
,
6228 sizeof(async_send_request_ex_chunked_test
)/sizeof(async_send_request_ex_chunked_test
[0]),
6234 async_send_request_ex_test
,
6235 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
6239 "Public ID=codeweavers"
6242 async_send_request_ex_test2
,
6243 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
6249 async_send_request_ex_resolve_failure_test
,
6250 sizeof(async_send_request_ex_resolve_failure_test
)/sizeof(async_send_request_ex_resolve_failure_test
[0]),
6259 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
6262 HINTERNET ses
, req
, con
;
6264 DWORD size
, written
, error
;
6265 INTERNET_BUFFERSA b
;
6266 static const char *accept
[2] = {"*/*", NULL
};
6269 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
6271 InitializeCriticalSection( ¬ification_cs
);
6273 info
.test
= nd
->test
;
6274 info
.count
= nd
->count
;
6276 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
6277 info
.thread
= GetCurrentThreadId();
6278 info
.is_aborted
= FALSE
;
6280 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6281 ok( ses
!= NULL
, "InternetOpen failed\n" );
6283 pInternetSetStatusCallbackA( ses
, check_notification
);
6285 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
6286 con
= InternetConnectA( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
6287 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
6289 WaitForSingleObject( info
.wait
, 10000 );
6291 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
6292 req
= HttpOpenRequestA( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
6293 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
6295 WaitForSingleObject( info
.wait
, 10000 );
6298 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
6299 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
6300 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
6301 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
6302 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
6305 setup_test( &info
, http_send_request_ex
, __LINE__
,
6306 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
6307 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
6308 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
6310 error
= WaitForSingleObject( info
.wait
, 10000 );
6311 if(error
!= WAIT_OBJECT_0
) {
6312 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
6313 info
.is_aborted
= TRUE
;
6317 size
= sizeof(buffer
);
6318 SetLastError( 0xdeadbeef );
6319 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
6320 error
= GetLastError();
6321 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
6322 if(nd
->expect_conn_failure
) {
6323 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
6326 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
6327 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
6333 size
= strlen( nd
->data
);
6334 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
6335 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
6336 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
6337 ok( written
== size
, "expected %u got %u\n", written
, size
);
6339 WaitForSingleObject( info
.wait
, 10000 );
6341 SetLastError( 0xdeadbeef );
6342 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
6343 error
= GetLastError();
6344 ok( !ret
, "HttpEndRequestA succeeded\n" );
6345 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
6348 SetLastError( 0xdeadbeef );
6349 setup_test( &info
, http_end_request
, __LINE__
,
6350 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
6351 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
6352 error
= GetLastError();
6353 ok( !ret
, "HttpEndRequestA succeeded\n" );
6354 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
6356 WaitForSingleObject( info
.wait
, 10000 );
6358 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
6360 InternetCloseHandle( req
);
6361 InternetCloseHandle( con
);
6362 InternetCloseHandle( ses
);
6364 WaitForSingleObject( info
.wait
, 10000 );
6366 CloseHandle( info
.wait
);
6367 DeleteCriticalSection( ¬ification_cs
);
6370 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
6371 static BOOL closetest_closed
;
6373 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
6374 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
6379 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
6381 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
6382 "Unexpected hInternet %p\n", hInternet
);
6383 if(!closetest_closed
)
6387 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
6388 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
6389 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
6390 closetest_req
, res
, GetLastError());
6393 static void test_InternetCloseHandle(void)
6398 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6399 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
6401 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
6403 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
6404 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
6405 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
6407 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
6408 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
6410 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
6411 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
6412 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
6414 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
6416 res
= InternetCloseHandle(closetest_session
);
6417 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
6418 closetest_closed
= TRUE
;
6419 trace("Closed session handle\n");
6421 res
= InternetCloseHandle(closetest_conn
);
6422 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
6423 res
, GetLastError());
6425 res
= InternetCloseHandle(closetest_req
);
6426 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
6427 res
, GetLastError());
6429 len
= sizeof(flags
);
6430 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
6431 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
6432 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
6433 closetest_req
, res
, GetLastError());
6436 static void test_connection_failure(void)
6442 open_simple_request(&req
, "localhost", 1, NULL
, "/");
6444 SetLastError(0xdeadbeef);
6445 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
6446 error
= GetLastError();
6447 ok(!ret
, "unexpected success\n");
6448 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
6450 close_request(&req
);
6453 static void test_default_service_port(void)
6455 HINTERNET session
, connect
, request
;
6463 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
6464 ok(session
!= NULL
, "InternetOpen failed\n");
6466 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6467 INTERNET_SERVICE_HTTP
, 0, 0);
6468 ok(connect
!= NULL
, "InternetConnect failed\n");
6470 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
6471 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6473 SetLastError(0xdeadbeef);
6474 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6475 error
= GetLastError();
6476 ok(!ret
, "HttpSendRequest succeeded\n");
6477 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
6480 size
= sizeof(buffer
);
6481 memset(buffer
, 0, sizeof(buffer
));
6482 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6483 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
6484 ok(!strcmp(buffer
, "test.winehq.org:80"), "Expected test.winehg.org:80, got '%s'\n", buffer
);
6486 InternetCloseHandle(request
);
6487 InternetCloseHandle(connect
);
6489 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6490 INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
6491 ok(connect
!= NULL
, "InternetConnect failed\n");
6493 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
6494 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6496 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6497 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
6499 size
= sizeof(buffer
);
6500 memset(buffer
, 0, sizeof(buffer
));
6501 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6502 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
6503 ok(!strcmp(buffer
, "test.winehq.org"), "Expected test.winehg.org, got '%s'\n", buffer
);
6505 InternetCloseHandle(request
);
6506 InternetCloseHandle(connect
);
6508 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6509 INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
6510 ok(connect
!= NULL
, "InternetConnect failed\n");
6512 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
6513 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6515 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6516 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
6518 size
= sizeof(buffer
);
6519 memset(buffer
, 0, sizeof(buffer
));
6520 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6521 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
6522 ok(!strcmp(buffer
, "test.winehq.org:443"), "Expected test.winehg.org:443, got '%s'\n", buffer
);
6524 InternetCloseHandle(request
);
6525 InternetCloseHandle(connect
);
6526 InternetCloseHandle(session
);
6529 static void init_status_tests(void)
6531 memset(expect
, 0, sizeof(expect
));
6532 memset(optional
, 0, sizeof(optional
));
6533 memset(wine_allow
, 0, sizeof(wine_allow
));
6534 memset(notified
, 0, sizeof(notified
));
6535 memset(status_string
, 0, sizeof(status_string
));
6537 #define STATUS_STRING(status) status_string[status] = #status
6538 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
6539 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
6540 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6541 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6542 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
6543 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
6544 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
6545 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
6546 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
6547 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
6548 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
6549 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
6550 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
6551 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
6552 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
6553 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
6554 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
6555 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
6556 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
6557 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
6558 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
6559 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
6560 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
6561 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
6562 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
6563 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
6564 #undef STATUS_STRING
6567 static void WINAPI
header_cb( HINTERNET handle
, DWORD_PTR ctx
, DWORD status
, LPVOID info
, DWORD len
)
6573 if (status
== INTERNET_STATUS_SENDING_REQUEST
)
6575 ret
= HttpAddRequestHeadersA( handle
, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD
);
6576 ok( ret
, "HttpAddRequestHeadersA failed %u\n", GetLastError() );
6577 SetEvent( (HANDLE
)ctx
);
6579 else if (status
== INTERNET_STATUS_REQUEST_SENT
)
6583 ret
= HttpQueryInfoA( handle
, HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
6584 buf
, &size
, &index
);
6585 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
6586 ok( strstr( buf
, "winetest: winetest" ) != NULL
, "header missing\n" );
6587 SetEvent( (HANDLE
)ctx
);
6591 static void test_concurrent_header_access(void)
6593 HINTERNET ses
, con
, req
;
6596 HANDLE wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
6598 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6599 ok( ses
!= NULL
, "InternetOpenA failed\n" );
6601 con
= InternetConnectA( ses
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
6602 INTERNET_SERVICE_HTTP
, 0, 0 );
6603 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
6605 req
= HttpOpenRequestA( con
, NULL
, "/", NULL
, NULL
, NULL
, 0, (DWORD_PTR
)wait
);
6606 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
6608 pInternetSetStatusCallbackA( req
, header_cb
);
6610 SetLastError( 0xdeadbeef );
6611 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
6612 err
= GetLastError();
6613 ok( !ret
, "HttpSendRequestA succeeded\n" );
6614 ok( err
== ERROR_IO_PENDING
, "got %u\n", ERROR_IO_PENDING
);
6616 WaitForSingleObject( wait
, 5000 );
6617 WaitForSingleObject( wait
, 5000 );
6619 InternetCloseHandle( req
);
6620 InternetCloseHandle( con
);
6621 InternetCloseHandle( ses
);
6622 CloseHandle( wait
);
6628 hdll
= GetModuleHandleA("wininet.dll");
6630 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
6631 win_skip("Too old IE (older than 6.0)\n");
6635 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
6636 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
6637 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
6639 if(!pInternetGetSecurityInfoByURLA
) {
6641 win_skip("IE6 found. It's too old for some tests.\n");
6644 init_status_tests();
6645 test_InternetCloseHandle();
6646 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
6647 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
6648 InternetReadFile_test(0, &test_data
[1]);
6649 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
6650 test_security_flags();
6651 InternetReadFile_test(0, &test_data
[2]);
6652 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
6653 test_open_url_async();
6654 test_async_HttpSendRequestEx(¬ification_data
[0]);
6655 test_async_HttpSendRequestEx(¬ification_data
[1]);
6656 test_async_HttpSendRequestEx(¬ification_data
[2]);
6657 test_async_HttpSendRequestEx(¬ification_data
[3]);
6658 InternetOpenRequest_test();
6660 InternetLockRequestFile_test();
6661 InternetOpenUrlA_test();
6663 test_http_connection();
6664 test_secure_connection();
6665 test_user_agent_header();
6666 test_bogus_accept_types_array();
6667 InternetReadFile_chunked_test();
6668 HttpSendRequestEx_test();
6669 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
6670 test_connection_failure();
6671 test_default_service_port();
6672 test_concurrent_header_access();