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
, "HEAD /test_auth_host1"))
2473 if (strstr(buffer
, "Authorization: Basic dGVzdDE6cGFzcw=="))
2474 send(c
, okmsg
, sizeof okmsg
-1, 0);
2476 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2478 if (strstr(buffer
, "HEAD /test_auth_host2"))
2480 if (strstr(buffer
, "Authorization: Basic dGVzdDE6cGFzczI="))
2481 send(c
, okmsg
, sizeof okmsg
-1, 0);
2483 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2488 } while (!last_request
);
2491 HeapFree(GetProcessHeap(), 0, buffer
);
2496 static void test_basic_request(int port
, const char *verb
, const char *url
)
2499 DWORD r
, count
, error
;
2502 trace("basic request %s %s\n", verb
, url
);
2504 open_simple_request(&req
, "localhost", port
, verb
, url
);
2506 SetLastError(0xdeadbeef);
2507 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
2508 error
= GetLastError();
2509 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
2510 ok(r
, "HttpSendRequest failed: %u\n", GetLastError());
2513 memset(buffer
, 0, sizeof buffer
);
2514 SetLastError(0xdeadbeef);
2515 r
= InternetReadFile(req
.request
, buffer
, sizeof buffer
, &count
);
2516 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2517 ok(count
== sizeof page1
- 1, "count was wrong\n");
2518 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2520 close_request(&req
);
2523 static void test_proxy_indirect(int port
)
2529 open_simple_request(&req
, "localhost", port
, NULL
, "/test2");
2531 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
2532 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2535 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2536 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
2539 skip("missing proxy header, not testing remaining proxy headers\n");
2542 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2544 test_status_code(req
.request
, 407);
2545 test_request_flags(req
.request
, 0);
2548 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2549 ok(r
, "HttpQueryInfo failed\n");
2550 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2553 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2554 ok(r
, "HttpQueryInfo failed\n");
2555 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2558 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2559 ok(r
, "HttpQueryInfo failed\n");
2560 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2563 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2564 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2565 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2568 close_request(&req
);
2571 static void test_proxy_direct(int port
)
2573 HINTERNET hi
, hc
, hr
;
2575 char buffer
[0x40], *url
;
2576 WCHAR bufferW
[0x40];
2577 static const char url_fmt
[] = "http://test.winehq.org:%u/test2";
2578 static CHAR username
[] = "mike",
2579 password
[] = "1101",
2580 useragent
[] = "winetest";
2581 static const WCHAR usernameW
[] = {'m','i','k','e',0},
2582 passwordW
[] = {'1','1','0','1',0},
2583 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2585 /* specify proxy type without the proxy and bypass */
2586 SetLastError(0xdeadbeef);
2587 hi
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2588 error
= GetLastError();
2589 ok(error
== ERROR_INVALID_PARAMETER
||
2590 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %u\n", error
);
2591 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2593 sprintf(buffer
, "localhost:%d\n", port
);
2594 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2595 ok(hi
!= NULL
, "open failed\n");
2597 /* try connect without authorization */
2598 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2599 ok(hc
!= NULL
, "connect failed\n");
2601 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2602 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2605 SetLastError(0xdeadbeef);
2606 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
2607 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2608 ok(!r
, "unexpected success\n");
2609 ok(sz
== 1, "got %u\n", sz
);
2612 SetLastError(0xdeadbeef);
2613 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
2614 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2615 ok(!r
, "unexpected success\n");
2616 ok(sz
== 1, "got %u\n", sz
);
2618 sz
= sizeof(buffer
);
2619 SetLastError(0xdeadbeef);
2620 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2621 ok(r
, "unexpected failure %u\n", GetLastError());
2622 ok(!sz
, "got %u\n", sz
);
2624 sz
= sizeof(buffer
);
2625 SetLastError(0xdeadbeef);
2626 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2627 ok(r
, "unexpected failure %u\n", GetLastError());
2628 ok(!sz
, "got %u\n", sz
);
2631 SetLastError(0xdeadbeef);
2632 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
2633 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2634 ok(!r
, "unexpected success\n");
2635 ok(sz
== 1, "got %u\n", sz
);
2638 SetLastError(0xdeadbeef);
2639 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
2640 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2641 ok(!r
, "unexpected success\n");
2642 ok(sz
== 1, "got %u\n", sz
);
2644 sz
= sizeof(buffer
);
2645 SetLastError(0xdeadbeef);
2646 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2647 ok(r
, "unexpected failure %u\n", GetLastError());
2648 ok(!sz
, "got %u\n", sz
);
2650 sz
= sizeof(buffer
);
2651 SetLastError(0xdeadbeef);
2652 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2653 ok(r
, "unexpected failure %u\n", GetLastError());
2654 ok(!sz
, "got %u\n", sz
);
2657 SetLastError(0xdeadbeef);
2658 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
2659 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2660 ok(!r
, "unexpected success\n");
2661 ok(sz
== 34, "got %u\n", sz
);
2663 sz
= sizeof(buffer
);
2664 SetLastError(0xdeadbeef);
2665 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2666 ok(r
, "unexpected failure %u\n", GetLastError());
2667 ok(sz
== 33, "got %u\n", sz
);
2669 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2670 ok(r
|| broken(!r
), "HttpSendRequest failed %u\n", GetLastError());
2673 win_skip("skipping proxy tests on broken wininet\n");
2677 test_status_code(hr
, 407);
2679 /* set the user + password then try again */
2680 r
= InternetSetOptionA(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2681 ok(!r
, "unexpected success\n");
2683 r
= InternetSetOptionA(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2684 ok(r
, "failed to set user\n");
2686 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2687 ok(r
, "failed to set user\n");
2691 SetLastError(0xdeadbeef);
2692 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2693 ok(!r
, "unexpected failure %u\n", GetLastError());
2694 ok(!buffer
[0], "got %s\n", buffer
);
2695 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2699 SetLastError(0xdeadbeef);
2700 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2701 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2702 ok(!r
, "unexpected success\n");
2703 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2707 SetLastError(0xdeadbeef);
2708 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2709 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2710 ok(!r
, "unexpected success\n");
2711 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2714 sz
= sizeof(buffer
);
2715 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2716 ok(r
, "failed to get username\n");
2717 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2718 ok(sz
== strlen(username
), "got %u\n", sz
);
2721 sz
= sizeof(bufferW
);
2722 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2723 ok(r
, "failed to get username\n");
2724 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
2725 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2727 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
2728 ok(r
, "failed to set user\n");
2731 sz
= sizeof(buffer
);
2732 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2733 ok(r
, "failed to get username\n");
2734 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2735 ok(sz
== strlen(username
), "got %u\n", sz
);
2737 r
= InternetSetOptionA(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
2738 ok(r
, "failed to set useragent\n");
2742 SetLastError(0xdeadbeef);
2743 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2744 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2745 ok(!r
, "unexpected success\n");
2746 ok(sz
== strlen(useragent
) + 1, "got %u\n", sz
);
2749 sz
= sizeof(buffer
);
2750 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2751 ok(r
, "failed to get user agent\n");
2752 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
2753 ok(sz
== strlen(useragent
), "got %u\n", sz
);
2757 SetLastError(0xdeadbeef);
2758 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2759 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2760 ok(!r
, "unexpected success\n");
2761 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2764 sz
= sizeof(bufferW
);
2765 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2766 ok(r
, "failed to get user agent\n");
2767 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
2768 ok(sz
== lstrlenW(useragentW
), "got %u\n", sz
);
2770 r
= InternetSetOptionA(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
2771 ok(r
, "failed to set user\n");
2775 SetLastError(0xdeadbeef);
2776 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2777 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2778 ok(!r
, "unexpected success\n");
2779 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2782 sz
= sizeof(buffer
);
2783 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2784 ok(r
, "failed to get user\n");
2785 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2786 ok(sz
== strlen(username
), "got %u\n", sz
);
2790 SetLastError(0xdeadbeef);
2791 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2792 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2793 ok(!r
, "unexpected success\n");
2794 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2797 sz
= sizeof(bufferW
);
2798 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2799 ok(r
, "failed to get user\n");
2800 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
2801 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2803 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
2804 ok(r
, "failed to set password\n");
2808 SetLastError(0xdeadbeef);
2809 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2810 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2811 ok(!r
, "unexpected success\n");
2812 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2815 sz
= sizeof(buffer
);
2816 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2817 ok(r
, "failed to get password\n");
2818 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2819 ok(sz
== strlen(password
), "got %u\n", sz
);
2823 SetLastError(0xdeadbeef);
2824 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2825 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2826 ok(!r
, "unexpected success\n");
2827 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2830 sz
= sizeof(bufferW
);
2831 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2832 ok(r
, "failed to get password\n");
2833 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2834 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2836 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
2837 sprintf(url
, url_fmt
, port
);
2840 SetLastError(0xdeadbeef);
2841 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2842 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2843 ok(!r
, "unexpected success\n");
2844 ok(sz
== strlen(url
) + 1, "got %u\n", sz
);
2847 sz
= sizeof(buffer
);
2848 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2849 ok(r
, "failed to get url\n");
2850 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
2851 ok(sz
== strlen(url
), "got %u\n", sz
);
2855 SetLastError(0xdeadbeef);
2856 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2857 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2858 ok(!r
, "unexpected success\n");
2859 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2862 sz
= sizeof(bufferW
);
2863 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2864 ok(r
, "failed to get url\n");
2865 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
2866 ok(sz
== strlen(url
), "got %u\n", sz
);
2867 HeapFree(GetProcessHeap(), 0, url
);
2869 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2870 ok(r
, "failed to set password\n");
2874 SetLastError(0xdeadbeef);
2875 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2876 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2877 ok(!r
, "unexpected success\n");
2878 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2881 sz
= sizeof(buffer
);
2882 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2883 ok(r
, "failed to get password\n");
2884 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2885 ok(sz
== strlen(password
), "got %u\n", sz
);
2889 SetLastError(0xdeadbeef);
2890 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2891 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2892 ok(!r
, "unexpected success\n");
2893 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2896 sz
= sizeof(bufferW
);
2897 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2898 ok(r
, "failed to get password\n");
2899 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2900 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2902 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2905 win_skip("skipping proxy tests on broken wininet\n");
2908 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2910 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2911 ok(r
, "HttpQueryInfo failed\n");
2912 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2914 InternetCloseHandle(hr
);
2915 InternetCloseHandle(hc
);
2916 InternetCloseHandle(hi
);
2918 sprintf(buffer
, "localhost:%d\n", port
);
2919 hi
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2920 ok(hi
!= NULL
, "InternetOpen failed\n");
2922 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2923 ok(hc
!= NULL
, "InternetConnect failed\n");
2925 hr
= HttpOpenRequestA(hc
, "POST", "/test2", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
2926 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2928 r
= HttpSendRequestA(hr
, NULL
, 0, (char *)"data", sizeof("data"));
2929 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2931 test_status_code(hr
, 407);
2934 InternetCloseHandle(hr
);
2935 InternetCloseHandle(hc
);
2936 InternetCloseHandle(hi
);
2939 static void test_header_handling_order(int port
)
2941 static const char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
2942 static const char connection
[] = "Connection: Close";
2943 static const char *types
[2] = { "*", NULL
};
2945 HINTERNET session
, connect
, request
;
2946 DWORD size
, status
, data_len
;
2949 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2950 ok(session
!= NULL
, "InternetOpen failed\n");
2952 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2953 ok(connect
!= NULL
, "InternetConnect failed\n");
2955 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2956 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2958 ret
= HttpAddRequestHeadersA(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
2959 ok(ret
, "HttpAddRequestHeaders failed\n");
2961 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
2962 ok(ret
, "HttpSendRequest failed\n");
2964 test_status_code(request
, 200);
2965 test_request_flags(request
, 0);
2967 InternetCloseHandle(request
);
2969 request
= HttpOpenRequestA(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2970 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2972 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2973 ok(ret
, "HttpSendRequest failed\n");
2976 size
= sizeof(status
);
2977 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2978 ok(ret
, "HttpQueryInfo failed\n");
2979 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2981 InternetCloseHandle(request
);
2982 InternetCloseHandle(connect
);
2984 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2985 ok(connect
!= NULL
, "InternetConnect failed\n");
2987 request
= HttpOpenRequestA(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2988 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2990 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2991 ok(ret
, "HttpAddRequestHeaders failed\n");
2993 ret
= HttpSendRequestA(request
, connection
, ~0u, NULL
, 0);
2994 ok(ret
, "HttpSendRequest failed\n");
2997 size
= sizeof(status
);
2998 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2999 ok(ret
, "HttpQueryInfo failed\n");
3000 ok(status
== 200, "got status %u, expected 200\n", status
);
3002 InternetCloseHandle(request
);
3003 InternetCloseHandle(connect
);
3005 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3006 ok(connect
!= NULL
, "InternetConnect failed\n");
3008 request
= HttpOpenRequestA(connect
, "POST", "/test7b", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3009 ok(request
!= NULL
, "HttpOpenRequest failed\n");
3011 ret
= HttpAddRequestHeadersA(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
3012 ok(ret
, "HttpAddRequestHeaders failed\n");
3014 data_len
= sizeof(data
);
3015 memset(data
, 'a', sizeof(data
));
3016 ret
= HttpSendRequestA(request
, NULL
, 0, data
, data_len
);
3017 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3020 size
= sizeof(status
);
3021 ret
= HttpQueryInfoA( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
3022 ok(ret
, "HttpQueryInfo failed\n");
3023 ok(status
== 200, "got status %u, expected 200\n", status
);
3025 InternetCloseHandle(request
);
3026 InternetCloseHandle(connect
);
3027 InternetCloseHandle(session
);
3030 static void test_connection_header(int port
)
3032 HINTERNET ses
, con
, req
;
3035 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3036 ok(ses
!= NULL
, "InternetOpen failed\n");
3038 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3039 ok(con
!= NULL
, "InternetConnect failed\n");
3041 req
= HttpOpenRequestA(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3042 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3044 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3045 ok(ret
, "HttpSendRequest failed\n");
3047 test_status_code(req
, 200);
3049 InternetCloseHandle(req
);
3051 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
3052 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3054 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3055 ok(ret
, "HttpSendRequest failed\n");
3057 test_status_code(req
, 200);
3059 InternetCloseHandle(req
);
3061 req
= HttpOpenRequestA(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3062 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3064 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3065 ok(ret
, "HttpSendRequest failed\n");
3067 test_status_code(req
, 200);
3069 InternetCloseHandle(req
);
3071 req
= HttpOpenRequestA(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
3072 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3074 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3075 ok(ret
, "HttpSendRequest failed\n");
3077 test_status_code(req
, 200);
3079 InternetCloseHandle(req
);
3080 InternetCloseHandle(con
);
3081 InternetCloseHandle(ses
);
3084 static void test_header_override(int port
)
3086 char buffer
[128], host_header_override
[30], full_url
[128];
3087 HINTERNET ses
, con
, req
;
3088 DWORD size
, count
, err
;
3091 sprintf(host_header_override
, "Host: test.local:%d\r\n", port
);
3092 sprintf(full_url
, "http://localhost:%d/test_host_override", port
);
3094 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3095 ok(ses
!= NULL
, "InternetOpen failed\n");
3097 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3098 ok(con
!= NULL
, "InternetConnect failed\n");
3100 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3101 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3103 size
= sizeof(buffer
) - 1;
3105 memset(buffer
, 0, sizeof(buffer
));
3106 ret
= HttpQueryInfoA(req
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &count
);
3107 err
= GetLastError();
3108 ok(!ret
, "HttpQueryInfo succeeded\n");
3109 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err
);
3111 size
= sizeof(buffer
) - 1;
3112 memset(buffer
, 0, sizeof(buffer
));
3113 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_URL
, buffer
, &size
);
3114 ok(ret
, "InternetQueryOption failed\n");
3115 ok(!strcmp(full_url
, buffer
), "Expected %s, got %s\n", full_url
, buffer
);
3117 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3118 ok(ret
, "HttpAddRequestHeaders failed\n");
3120 size
= sizeof(buffer
) - 1;
3122 memset(buffer
, 0, sizeof(buffer
));
3123 ret
= HttpQueryInfoA(req
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &count
);
3124 ok(ret
, "HttpQueryInfo failed\n");
3126 size
= sizeof(buffer
) - 1;
3127 memset(buffer
, 0, sizeof(buffer
));
3128 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_URL
, buffer
, &size
);
3129 ok(ret
, "InternetQueryOption failed\n");
3130 ok(!strcmp(full_url
, buffer
), "Expected %s, got %s\n", full_url
, buffer
);
3132 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3133 ok(ret
, "HttpSendRequest failed\n");
3135 test_status_code(req
, 200);
3137 InternetCloseHandle(req
);
3138 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3139 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3141 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3142 ok(ret
, "HttpAddRequestHeaders failed\n");
3144 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_COALESCE
);
3145 ok(ret
, "HttpAddRequestHeaders failed\n");
3147 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3148 ok(ret
, "HttpSendRequest failed\n");
3150 test_status_code(req
, 400);
3152 InternetCloseHandle(req
);
3153 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3154 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3156 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3157 ok(ret
, "HttpAddRequestHeaders failed\n");
3159 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3160 ok(ret
, "HttpSendRequest failed\n");
3162 test_status_code(req
, 200);
3164 InternetCloseHandle(req
);
3165 req
= HttpOpenRequestA(con
, NULL
, "/test_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3166 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3168 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_REPLACE
);
3169 if(ret
) { /* win10 returns success */
3170 trace("replacing host header is supported.\n");
3172 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3173 ok(ret
, "HttpSendRequest failed\n");
3175 test_status_code(req
, 200);
3177 trace("replacing host header is not supported.\n");
3179 err
= GetLastError();
3180 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "Expected error ERROR_HTTP_HEADER_NOT_FOUND, got %d\n", err
);
3182 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3183 ok(ret
, "HttpSendRequest failed\n");
3185 test_status_code(req
, 400);
3188 InternetCloseHandle(req
);
3189 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3190 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3191 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3193 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3194 ok(ret
, "HttpAddRequestHeaders failed\n");
3196 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3197 ok(ret
, "HttpSendRequest failed\n");
3199 test_status_code(req
, 200);
3201 InternetCloseHandle(req
);
3202 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_set_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3203 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3205 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3206 ok(ret
, "HttpAddRequestHeaders failed\n");
3208 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3209 ok(ret
, "HttpSendRequest failed\n");
3211 test_status_code(req
, 200);
3213 InternetCloseHandle(req
);
3214 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_check_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3215 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3217 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3218 ok(ret
, "HttpAddRequestHeaders failed\n");
3220 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3221 ok(ret
, "HttpSendRequest failed\n");
3223 test_status_code(req
, 200);
3225 InternetCloseHandle(req
);
3226 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_check_host_override", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3227 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3229 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3230 ok(ret
, "HttpSendRequest failed\n");
3232 test_status_code(req
, 200);
3234 InternetCloseHandle(req
);
3235 InternetSetCookieA("http://test.local", "foo", "bar");
3236 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_check_different_host", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3237 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3239 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3240 ok(ret
, "HttpSendRequest failed\n");
3242 test_status_code(req
, 200);
3244 InternetCloseHandle(req
);
3245 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_check_different_host", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3246 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3248 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3249 ok(ret
, "HttpAddRequestHeaders failed\n");
3251 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3252 ok(ret
, "HttpSendRequest failed\n");
3254 test_status_code(req
, 200);
3256 InternetCloseHandle(req
);
3257 InternetCloseHandle(con
);
3258 InternetCloseHandle(ses
);
3260 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3261 ok(ses
!= NULL
, "InternetOpenA failed\n");
3263 con
= InternetConnectA(ses
, "localhost", port
, "test1", "pass", INTERNET_SERVICE_HTTP
, 0, 0);
3264 ok(con
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
3266 req
= HttpOpenRequestA( con
, "HEAD", "/test_auth_host1", NULL
, NULL
, NULL
, 0, 0);
3267 ok(req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
3269 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3270 ok(ret
, "HttpSendRequestA failed %u\n", GetLastError());
3272 test_status_code(req
, 200);
3274 InternetCloseHandle(req
);
3275 InternetCloseHandle(con
);
3276 InternetCloseHandle(ses
);
3278 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3279 ok(ses
!= NULL
, "InternetOpenA failed\n");
3281 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3282 ok(con
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
3284 req
= HttpOpenRequestA(con
, "HEAD", "/test_auth_host1", NULL
, NULL
, NULL
, 0, 0);
3285 ok(req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
3287 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3288 ok(ret
, "HttpAddRequestHeaders failed\n");
3290 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
3291 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
3293 test_status_code(req
, 200);
3295 InternetCloseHandle(req
);
3296 InternetCloseHandle(con
);
3297 InternetCloseHandle(ses
);
3299 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3300 ok(ses
!= NULL
, "InternetOpenA failed\n");
3302 con
= InternetConnectA(ses
, "localhost", port
, "test1", "pass2", INTERNET_SERVICE_HTTP
, 0, 0);
3303 ok(con
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
3305 req
= HttpOpenRequestA(con
, "HEAD", "/test_auth_host2", NULL
, NULL
, NULL
, 0, 0);
3306 ok(req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
3308 ret
= HttpAddRequestHeadersA(req
, host_header_override
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
3309 ok(ret
, "HttpAddRequestHeaders failed\n");
3311 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3312 ok(ret
, "HttpSendRequestA failed %u\n", GetLastError());
3314 test_status_code(req
, 200);
3316 InternetCloseHandle(req
);
3317 InternetCloseHandle(con
);
3318 InternetCloseHandle(ses
);
3320 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3321 ok(ses
!= NULL
, "InternetOpenA failed\n");
3323 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3324 ok(con
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
3326 req
= HttpOpenRequestA(con
, "HEAD", "/test_auth_host2", NULL
, NULL
, NULL
, 0, 0);
3327 ok(req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
3329 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3330 ok(ret
, "HttpSendRequestA failed %u\n", GetLastError());
3332 test_status_code(req
, 200);
3334 InternetCloseHandle(req
);
3335 InternetCloseHandle(con
);
3336 InternetCloseHandle(ses
);
3339 static void test_connection_closing(int port
)
3341 HINTERNET session
, connection
, req
;
3344 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3346 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3347 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3349 pInternetSetStatusCallbackA(session
, callback
);
3351 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3352 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3353 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3354 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3356 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3357 req
= HttpOpenRequestA(connection
, "GET", "/testJ", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3358 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3359 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3361 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3362 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3363 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3364 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3365 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3366 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3367 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3368 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3369 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3370 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3371 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3373 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3374 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3375 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3376 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3377 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3379 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3380 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3381 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3382 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3383 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3384 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3385 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3386 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3387 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3388 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3389 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3391 test_status_code(req
, 200);
3393 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3394 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3395 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3396 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3397 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3398 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3399 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3400 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3401 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3403 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3404 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3405 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3406 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3407 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3409 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3410 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3411 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3412 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3413 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3414 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3415 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3416 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3417 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3419 test_status_code(req
, 210);
3421 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3422 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3423 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3424 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3425 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3426 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3427 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3428 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3429 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3430 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3431 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3433 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3434 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3435 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3436 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3437 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3439 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3440 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3441 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3442 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3443 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3444 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3445 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3446 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3447 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3448 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3449 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3451 test_status_code(req
, 200);
3453 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3454 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3456 close_async_handle(session
, hCompleteEvent
, 2);
3457 CloseHandle(hCompleteEvent
);
3460 static void test_successive_HttpSendRequest(int port
)
3462 HINTERNET session
, connection
, req
;
3465 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3467 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3468 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3470 pInternetSetStatusCallbackA(session
, callback
);
3472 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3473 connection
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3474 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3475 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3477 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3478 req
= HttpOpenRequestA(connection
, "GET", "/testH", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0xdeadbeaf);
3479 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3480 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3482 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3483 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3484 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3485 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3486 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3487 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3488 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3489 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3490 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3492 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3493 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3494 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3495 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3496 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3498 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3499 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3500 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3501 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3502 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3503 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3504 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3505 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3506 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3508 test_status_code(req
, 210);
3510 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3511 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
3512 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3513 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3514 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3515 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3516 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
3517 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
3518 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3520 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3521 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3522 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3523 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3524 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3526 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3527 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
3528 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3529 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3530 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3531 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3532 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3533 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3534 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3536 test_status_code(req
, 200);
3538 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
3539 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
3541 close_async_handle(session
, hCompleteEvent
, 2);
3542 CloseHandle(hCompleteEvent
);
3545 static void test_no_content(int port
)
3547 HINTERNET session
, connection
, req
;
3550 trace("Testing 204 no content response...\n");
3552 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3554 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3555 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3557 pInternetSetStatusCallbackA(session
, callback
);
3559 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3560 connection
= InternetConnectA(session
, "localhost", port
,
3561 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3562 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3563 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3565 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3566 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
3567 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3568 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3569 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3571 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3572 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3573 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3574 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3575 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3576 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3577 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3578 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3579 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3580 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3582 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3583 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3584 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3585 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3586 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3588 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3589 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3590 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3591 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3592 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3593 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3594 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3595 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3597 close_async_handle(session
, hCompleteEvent
, 2);
3598 CloseHandle(hCompleteEvent
);
3601 * The connection should be closed before closing handle. This is true for most
3602 * wininet versions (including Wine), but some old win2k versions fail to do that.
3604 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3605 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3608 static void test_conn_close(int port
)
3610 HINTERNET session
, connection
, req
;
3611 DWORD res
, avail
, size
;
3614 trace("Testing connection close connection...\n");
3616 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3617 conn_close_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
3619 session
= InternetOpenA("", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3620 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3622 pInternetSetStatusCallbackA(session
, callback
);
3624 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3625 connection
= InternetConnectA(session
, "localhost", port
,
3626 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3627 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3628 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3630 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
3631 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
3632 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3633 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3634 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
3636 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
3637 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3638 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3639 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
3640 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
3641 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
3642 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
3643 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3645 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
3646 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3647 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3648 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3649 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3651 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
3652 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3653 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3654 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
3655 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
3656 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3657 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3658 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3661 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3662 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
3663 ok(avail
!= 0, "avail = 0\n");
3666 res
= InternetReadFile(req
, buf
, avail
, &size
);
3667 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
3669 /* IE11 calls those in InternetQueryDataAvailable call. */
3670 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
3671 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
3673 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
3674 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3675 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3676 ok(!avail
, "avail = %u, expected 0\n", avail
);
3678 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
3680 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
3681 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
3682 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
3683 SetEvent(conn_close_event
);
3684 #ifdef ROSTESTS_73_FIXED
3685 WaitForSingleObject(hCompleteEvent
, INFINITE
);
3686 #else /* ROSTESTS_73_FIXED */
3687 ok(WaitForSingleObject(hCompleteEvent
, 5000) == WAIT_OBJECT_0
, "Wait timed out\n");
3688 #endif /* ROSTESTS_73_FIXED */
3689 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
3690 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
3691 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
3692 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
3693 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
3695 close_async_handle(session
, hCompleteEvent
, 2);
3696 CloseHandle(hCompleteEvent
);
3699 static void test_no_cache(int port
)
3701 static const char cache_control_no_cache
[] = "/test_cache_control_no_cache";
3702 static const char cache_control_no_store
[] = "/test_cache_control_no_store";
3703 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3705 char cache_url
[256], buf
[256];
3706 HINTERNET ses
, con
, req
;
3710 trace("Testing no-cache header\n");
3712 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3713 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3715 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3716 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3718 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3719 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3721 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_cache
);
3722 DeleteUrlCacheEntryA(cache_url
);
3724 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3725 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3727 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3729 ok(size
== 12, "read %d bytes of data\n", size
);
3730 InternetCloseHandle(req
);
3732 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_cache
, NULL
, NULL
, NULL
, 0, 0);
3733 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3735 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3736 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3738 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3740 ok(size
== 0, "read %d bytes of data\n", size
);
3741 InternetCloseHandle(req
);
3742 DeleteUrlCacheEntryA(cache_url
);
3744 req
= HttpOpenRequestA(con
, NULL
, cache_control_no_store
, NULL
, NULL
, NULL
, 0, 0);
3745 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3747 sprintf(cache_url
, cache_url_fmt
, port
, cache_control_no_store
);
3748 DeleteUrlCacheEntryA(cache_url
);
3750 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3751 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3753 while(InternetReadFile(req
, buf
, sizeof(buf
), &read
) && read
)
3755 ok(size
== 12, "read %d bytes of data\n", size
);
3756 InternetCloseHandle(req
);
3758 ret
= DeleteUrlCacheEntryA(cache_url
);
3759 ok(!ret
&& GetLastError()==ERROR_FILE_NOT_FOUND
, "cache entry should not exist\n");
3761 InternetCloseHandle(con
);
3762 InternetCloseHandle(ses
);
3765 static void test_cache_read_gzipped(int port
)
3767 static const char cache_url_fmt
[] = "http://localhost:%d%s";
3768 static const char get_gzip
[] = "/test_cache_gzip";
3769 static const char content
[] = "gzip test\n";
3770 static const char text_html
[] = "text/html";
3771 static const char raw_header
[] = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
3773 HINTERNET ses
, con
, req
;
3775 char cache_url
[256], buf
[256];
3778 trace("Testing reading compressed content from cache\n");
3780 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3781 ok(ses
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3783 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3784 ok(con
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
3786 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3787 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3790 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3791 if(!ret
&& GetLastError()==ERROR_INTERNET_INVALID_OPTION
) {
3792 win_skip("INTERNET_OPTION_HTTP_DECODING not supported\n");
3793 InternetCloseHandle(req
);
3794 InternetCloseHandle(con
);
3795 InternetCloseHandle(ses
);
3798 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3800 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3801 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3803 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-size
, &read
) && read
)
3805 ok(size
== 10, "read %d bytes of data\n", size
);
3807 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3809 size
= sizeof(buf
)-1;
3810 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3811 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3813 ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3815 size
= sizeof(buf
)-1;
3816 ret
= HttpQueryInfoA(req
, HTTP_QUERY_RAW_HEADERS_CRLF
, buf
, &size
, 0);
3817 ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3819 ok(!strncmp(raw_header
, buf
, size
), "buf = %s\n", buf
);
3820 InternetCloseHandle(req
);
3822 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3823 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3826 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3827 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3829 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3830 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3832 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3834 todo_wine
ok(size
== 10, "read %d bytes of data\n", size
);
3836 ok(!strncmp(buf
, content
, size
), "incorrect page content: %s\n", buf
);
3839 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3840 ok(!ret
&& GetLastError()==ERROR_HTTP_HEADER_NOT_FOUND
,
3841 "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) returned %d, %d\n",
3842 ret
, GetLastError());
3844 size
= sizeof(buf
)-1;
3845 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_TYPE
, buf
, &size
, 0);
3846 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_TYPE) failed: %d\n", GetLastError());
3848 todo_wine
ok(!strncmp(text_html
, buf
, size
), "buf = %s\n", buf
);
3849 InternetCloseHandle(req
);
3851 /* Decompression doesn't work while reading from cache */
3852 test_cache_gzip
= 0;
3853 sprintf(cache_url
, cache_url_fmt
, port
, get_gzip
);
3854 DeleteUrlCacheEntryA(cache_url
);
3856 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, 0, 0);
3857 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3859 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3860 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3862 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3864 ok(size
== 31, "read %d bytes of data\n", size
);
3865 InternetCloseHandle(req
);
3867 req
= HttpOpenRequestA(con
, NULL
, get_gzip
, NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
3868 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3871 ret
= InternetSetOptionA(req
, INTERNET_OPTION_HTTP_DECODING
, &ret
, sizeof(ret
));
3872 ok(ret
, "InternetSetOption(INTERNET_OPTION_HTTP_DECODING) failed: %d\n", GetLastError());
3874 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", -1, NULL
, 0);
3875 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
3877 while(InternetReadFile(req
, buf
+size
, sizeof(buf
)-1-size
, &read
) && read
)
3879 todo_wine
ok(size
== 31, "read %d bytes of data\n", size
);
3882 ret
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
3883 todo_wine
ok(ret
, "HttpQueryInfo(HTTP_QUERY_CONTENT_ENCODING) failed: %d\n", GetLastError());
3884 InternetCloseHandle(req
);
3886 InternetCloseHandle(con
);
3887 InternetCloseHandle(ses
);
3889 DeleteUrlCacheEntryA(cache_url
);
3892 static void test_HttpSendRequestW(int port
)
3894 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
3895 HINTERNET ses
, con
, req
;
3899 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3900 ok(ses
!= NULL
, "InternetOpen failed\n");
3902 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3903 ok(con
!= NULL
, "InternetConnect failed\n");
3905 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
3906 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3908 SetLastError(0xdeadbeef);
3909 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
3910 error
= GetLastError();
3911 ok(!ret
, "HttpSendRequestW succeeded\n");
3912 ok(error
== ERROR_IO_PENDING
||
3913 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
3914 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
3915 "got %u expected ERROR_IO_PENDING\n", error
);
3917 InternetCloseHandle(req
);
3918 InternetCloseHandle(con
);
3919 InternetCloseHandle(ses
);
3922 static void test_cookie_header(int port
)
3924 HINTERNET ses
, con
, req
;
3929 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
3930 ok(ses
!= NULL
, "InternetOpen failed\n");
3932 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3933 ok(con
!= NULL
, "InternetConnect failed\n");
3935 InternetSetCookieA("http://localhost", "cookie", "biscuit");
3937 req
= HttpOpenRequestA(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3938 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3941 size
= sizeof(buffer
);
3942 SetLastError(0xdeadbeef);
3943 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3944 error
= GetLastError();
3945 ok(!ret
, "HttpQueryInfo succeeded\n");
3946 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
3948 ret
= HttpAddRequestHeadersA(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
3949 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
3952 size
= sizeof(buffer
);
3953 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3954 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3955 ok(!!strstr(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
3957 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3958 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
3960 test_status_code(req
, 200);
3963 size
= sizeof(buffer
);
3964 ret
= HttpQueryInfoA(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3965 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3966 ok(!strstr(buffer
, "cookie=not biscuit"), "'%s' should not contain \'cookie=not biscuit\'\n", buffer
);
3967 ok(!!strstr(buffer
, "cookie=biscuit"), "'%s' should contain \'cookie=biscuit\'\n", buffer
);
3969 InternetCloseHandle(req
);
3971 InternetSetCookieA("http://localhost/testCCCC", "subcookie", "data");
3973 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_path1", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3974 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3976 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3977 ok(ret
, "HttpSendRequest failed\n");
3979 test_status_code(req
, 200);
3980 InternetCloseHandle(req
);
3982 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_path1/abc", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3983 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3985 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3986 ok(ret
, "HttpSendRequest failed\n");
3988 test_status_code(req
, 200);
3989 InternetCloseHandle(req
);
3991 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_set_path", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
3992 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3994 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
3995 ok(ret
, "HttpSendRequest failed\n");
3997 test_status_code(req
, 200);
3998 InternetCloseHandle(req
);
4000 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_path2", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
4001 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4003 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4004 ok(ret
, "HttpSendRequest failed\n");
4006 test_status_code(req
, 400);
4007 InternetCloseHandle(req
);
4009 req
= HttpOpenRequestA(con
, NULL
, "/test_cookie_merge", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
4010 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4012 ret
= HttpAddRequestHeadersA(req
, "Cookie: manual_cookie=test\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
4013 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
4015 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4016 ok(ret
, "HttpSendRequest failed\n");
4018 test_status_code(req
, 200);
4019 InternetCloseHandle(req
);
4021 InternetCloseHandle(con
);
4022 InternetCloseHandle(ses
);
4025 static void test_basic_authentication(int port
)
4027 HINTERNET session
, connect
, request
;
4030 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4031 ok(session
!= NULL
, "InternetOpen failed\n");
4033 connect
= InternetConnectA(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
4034 ok(connect
!= NULL
, "InternetConnect failed\n");
4036 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
4037 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4039 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4040 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4042 test_status_code(request
, 200);
4043 test_request_flags(request
, 0);
4045 InternetCloseHandle(request
);
4046 InternetCloseHandle(connect
);
4047 InternetCloseHandle(session
);
4050 static void test_premature_disconnect(int port
)
4056 open_simple_request(&req
, "localhost", port
, NULL
, "/premature_disconnect");
4058 SetLastError(0xdeadbeef);
4059 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4060 err
= GetLastError();
4061 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
4062 todo_wine
ok(err
== ERROR_HTTP_INVALID_SERVER_RESPONSE
, "got %u\n", err
);
4064 close_request(&req
);
4067 static void test_invalid_response_headers(int port
)
4074 open_simple_request(&req
, "localhost", port
, NULL
, "/testE");
4076 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4077 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4079 test_status_code(req
.request
, 401);
4080 test_request_flags(req
.request
, 0);
4083 size
= sizeof(buffer
);
4084 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
4085 ok(ret
, "HttpQueryInfo failed\n");
4086 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
4087 "headers wrong \"%s\"\n", buffer
);
4090 size
= sizeof(buffer
);
4091 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
4092 ok(ret
, "HttpQueryInfo failed\n");
4093 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
4095 close_request(&req
);
4098 static void test_response_without_headers(int port
)
4101 DWORD r
, count
, size
;
4104 open_simple_request(&req
, "localhost", port
, NULL
, "/testG");
4106 test_request_flags(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
4108 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4109 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
4111 test_request_flags_todo(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
4114 memset(buffer
, 0, sizeof buffer
);
4115 r
= InternetReadFile(req
.request
, buffer
, sizeof buffer
, &count
);
4116 ok(r
, "InternetReadFile failed %u\n", GetLastError());
4117 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
4118 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
4120 test_status_code(req
.request
, 200);
4121 test_request_flags_todo(req
.request
, INTERNET_REQFLAG_NO_HEADERS
);
4124 size
= sizeof(buffer
);
4125 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
4126 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
4127 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
4130 size
= sizeof(buffer
);
4131 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
4132 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
4133 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
4136 size
= sizeof(buffer
);
4137 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
4138 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
4139 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
4141 close_request(&req
);
4144 static void test_head_request(int port
)
4146 DWORD len
, content_length
;
4151 open_simple_request(&req
, "localhost", port
, "HEAD", "/test_head");
4153 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4154 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
4156 len
= sizeof(content_length
);
4157 content_length
= -1;
4158 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FLAG_NUMBER
|HTTP_QUERY_CONTENT_LENGTH
, &content_length
, &len
, 0);
4159 ok(ret
, "HttpQueryInfo dailed: %u\n", GetLastError());
4160 ok(len
== sizeof(DWORD
), "len = %u\n", len
);
4161 ok(content_length
== 100, "content_length = %u\n", content_length
);
4164 ret
= InternetReadFile(req
.request
, buf
, sizeof(buf
), &len
);
4165 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
4168 ret
= InternetReadFile(req
.request
, buf
, sizeof(buf
), &len
);
4169 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
4171 close_request(&req
);
4174 static void test_HttpQueryInfo(int port
)
4177 DWORD size
, index
, error
;
4181 open_simple_request(&req
, "localhost", port
, NULL
, "/testD");
4183 size
= sizeof(buffer
);
4184 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
4185 error
= GetLastError();
4186 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
4187 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
4189 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4190 ok(ret
, "HttpSendRequest failed\n");
4193 size
= sizeof(buffer
);
4194 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
4195 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4196 ok(index
== 1, "expected 1 got %u\n", index
);
4199 size
= sizeof(buffer
);
4200 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
4201 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4202 ok(index
== 1, "expected 1 got %u\n", index
);
4205 size
= sizeof(buffer
);
4206 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4207 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4208 ok(index
== 0, "expected 0 got %u\n", index
);
4210 size
= sizeof(buffer
);
4211 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4212 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4213 ok(index
== 0, "expected 0 got %u\n", index
);
4215 index
= 0xdeadbeef; /* invalid start index */
4216 size
= sizeof(buffer
);
4217 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
4218 todo_wine
ok(!ret
, "HttpQueryInfo should have failed\n");
4219 todo_wine
ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
4220 "Expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
4223 size
= sizeof(buffer
);
4224 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
4225 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4226 ok(index
== 0, "expected 0 got %u\n", index
);
4228 size
= sizeof(buffer
);
4229 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
4230 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4231 ok(index
== 0, "expected 0 got %u\n", index
);
4233 size
= sizeof(buffer
);
4234 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
4235 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4236 ok(index
== 0, "expected 0 got %u\n", index
);
4238 test_status_code(req
.request
, 200);
4241 size
= sizeof(buffer
);
4242 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
4243 ok(!ret
, "HttpQueryInfo succeeded\n");
4244 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
4247 size
= sizeof(buffer
);
4248 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
4249 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4250 ok(index
== 1, "expected 1 got %u\n", index
);
4253 size
= sizeof(buffer
);
4254 strcpy(buffer
, "Server");
4255 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
4256 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4257 ok(index
== 1, "expected 1 got %u\n", index
);
4260 size
= sizeof(buffer
);
4261 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
4262 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4263 ok(index
== 1, "expected 1 got %u\n", index
);
4265 size
= sizeof(buffer
);
4266 ret
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
4267 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
4268 ok(index
== 2, "expected 2 got %u\n", index
);
4270 close_request(&req
);
4273 static void test_options(int port
)
4275 INTERNET_DIAGNOSTIC_SOCKET_INFO idsi
;
4276 HINTERNET ses
, con
, req
;
4281 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4282 ok(ses
!= NULL
, "InternetOpen failed\n");
4284 SetLastError(0xdeadbeef);
4285 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
4286 error
= GetLastError();
4287 ok(!ret
, "InternetSetOption succeeded\n");
4288 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4290 SetLastError(0xdeadbeef);
4291 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
4292 ok(!ret
, "InternetSetOption succeeded\n");
4293 error
= GetLastError();
4294 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4296 SetLastError(0xdeadbeef);
4297 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
4298 ok(!ret
, "InternetSetOption succeeded\n");
4299 error
= GetLastError();
4300 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4303 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4304 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4306 SetLastError(0xdeadbeef);
4307 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
4308 error
= GetLastError();
4309 ok(!ret
, "InternetQueryOption succeeded\n");
4310 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4312 SetLastError(0xdeadbeef);
4313 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
4314 error
= GetLastError();
4315 ok(!ret
, "InternetQueryOption succeeded\n");
4316 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4319 SetLastError(0xdeadbeef);
4320 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
4321 error
= GetLastError();
4322 ok(!ret
, "InternetQueryOption succeeded\n");
4323 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
4326 SetLastError(0xdeadbeef);
4327 ret
= InternetQueryOptionA(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4328 error
= GetLastError();
4329 ok(!ret
, "InternetQueryOption succeeded\n");
4330 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
4334 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4335 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4336 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
4338 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4339 ok(con
!= NULL
, "InternetConnect failed\n");
4343 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4344 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4345 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
4348 ret
= InternetSetOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4349 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4353 ret
= InternetQueryOptionA(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4354 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4355 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
4357 req
= HttpOpenRequestA(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
4358 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4362 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4363 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4364 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
4367 ret
= InternetSetOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
4368 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
4372 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
4373 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4374 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
4376 size
= sizeof(idsi
);
4377 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_DIAGNOSTIC_SOCKET_INFO
, &idsi
, &size
);
4378 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
4381 SetLastError(0xdeadbeef);
4382 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
4383 error
= GetLastError();
4384 ok(!ret
, "InternetQueryOption succeeded\n");
4385 ok(error
== ERROR_INTERNET_INVALID_OPERATION
, "expected ERROR_INTERNET_INVALID_OPERATION, got %u\n", error
);
4387 /* INTERNET_OPTION_PROXY */
4388 SetLastError(0xdeadbeef);
4389 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
4390 error
= GetLastError();
4391 ok(!ret
, "InternetQueryOption succeeded\n");
4392 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4394 SetLastError(0xdeadbeef);
4395 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
4396 error
= GetLastError();
4397 ok(!ret
, "InternetQueryOption succeeded\n");
4398 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
4401 SetLastError(0xdeadbeef);
4402 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
4403 error
= GetLastError();
4404 ok(!ret
, "InternetQueryOption succeeded\n");
4405 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
4406 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
4408 InternetCloseHandle(req
);
4409 InternetCloseHandle(con
);
4410 InternetCloseHandle(ses
);
4414 const char *response_text
;
4416 const char *status_text
;
4417 const char *raw_headers
;
4418 } http_status_test_t
;
4420 static const http_status_test_t http_status_tests
[] = {
4422 "HTTP/1.1 200 OK\r\n"
4423 "Content-Length: 1\r\n"
4429 "HTTP/1.1 404 Fail\r\n"
4430 "Content-Length: 1\r\n"
4437 "Content-Length: 1\r\n"
4444 "Content-Length: 1\r\n"
4451 static void test_http_status(int port
)
4458 for(i
=0; i
< sizeof(http_status_tests
)/sizeof(*http_status_tests
); i
++) {
4459 send_buffer
= http_status_tests
[i
].response_text
;
4461 open_simple_request(&req
, "localhost", port
, NULL
, "/send_from_buffer");
4463 res
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4464 ok(res
, "HttpSendRequest failed\n");
4466 test_status_code(req
.request
, http_status_tests
[i
].status_code
);
4469 res
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buf
, &size
, NULL
);
4470 ok(res
, "HttpQueryInfo failed: %u\n", GetLastError());
4471 ok(!strcmp(buf
, http_status_tests
[i
].status_text
), "[%u] Unexpected status text \"%s\", expected \"%s\"\n",
4472 i
, buf
, http_status_tests
[i
].status_text
);
4474 close_request(&req
);
4478 static void test_cache_control_verb(int port
)
4480 HINTERNET session
, connect
, request
;
4483 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4484 ok(session
!= NULL
, "InternetOpen failed\n");
4486 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4487 ok(connect
!= NULL
, "InternetConnect failed\n");
4489 request
= HttpOpenRequestA(connect
, "RPC_OUT_DATA", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4490 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4491 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4492 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4493 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4494 test_status_code(request
, 200);
4495 InternetCloseHandle(request
);
4497 request
= HttpOpenRequestA(connect
, "POST", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4498 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4499 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4500 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4501 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4502 test_status_code(request
, 200);
4503 InternetCloseHandle(request
);
4505 request
= HttpOpenRequestA(connect
, "HEAD", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4506 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4507 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4508 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4509 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4510 test_status_code(request
, 200);
4511 InternetCloseHandle(request
);
4513 request
= HttpOpenRequestA(connect
, "GET", "/test_cache_control_verb", NULL
, NULL
, NULL
,
4514 INTERNET_FLAG_NO_CACHE_WRITE
, 0);
4515 ok(request
!= NULL
, "HttpOpenRequest failed\n");
4516 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
4517 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4518 test_status_code(request
, 200);
4519 InternetCloseHandle(request
);
4521 InternetCloseHandle(connect
);
4522 InternetCloseHandle(session
);
4525 static void test_request_content_length(int port
)
4527 char data
[] = {'t','e','s','t'};
4531 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4533 open_simple_request(&req
, "localhost", port
, "POST", "/test_request_content_length");
4535 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
4536 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4537 test_status_code(req
.request
, 200);
4539 SetEvent(hCompleteEvent
);
4541 ret
= HttpSendRequestA(req
.request
, NULL
, 0, data
, sizeof(data
));
4542 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
4543 test_status_code(req
.request
, 200);
4545 SetEvent(hCompleteEvent
);
4547 close_request(&req
);
4548 CloseHandle(hCompleteEvent
);
4551 static void test_accept_encoding(int port
)
4553 HINTERNET ses
, con
, req
;
4557 ses
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
4558 ok(ses
!= NULL
, "InternetOpen failed\n");
4560 con
= InternetConnectA(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
4561 ok(con
!= NULL
, "InternetConnect failed\n");
4563 req
= HttpOpenRequestA(con
, "GET", "/echo_request", "HTTP/1.0", NULL
, NULL
, 0, 0);
4564 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4566 ret
= HttpAddRequestHeadersA(req
, "Accept-Encoding: gzip\r\n", ~0u, HTTP_ADDREQ_FLAG_REPLACE
| HTTP_ADDREQ_FLAG_ADD
);
4567 ok(ret
, "HttpAddRequestHeaders failed\n");
4569 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
4570 ok(ret
, "HttpSendRequestA failed\n");
4572 test_status_code(req
, 200);
4573 receive_simple_request(req
, buf
, sizeof(buf
));
4574 ok(strstr(buf
, "Accept-Encoding: gzip") != NULL
, "Accept-Encoding header not found in %s\n", buf
);
4576 InternetCloseHandle(req
);
4578 req
= HttpOpenRequestA(con
, "GET", "/echo_request", "HTTP/1.0", NULL
, NULL
, 0, 0);
4579 ok(req
!= NULL
, "HttpOpenRequest failed\n");
4581 ret
= HttpSendRequestA(req
, "Accept-Encoding: gzip", ~0u, NULL
, 0);
4582 ok(ret
, "HttpSendRequestA failed\n");
4584 test_status_code(req
, 200);
4585 receive_simple_request(req
, buf
, sizeof(buf
));
4586 ok(strstr(buf
, "Accept-Encoding: gzip") != NULL
, "Accept-Encoding header not found in %s\n", buf
);
4588 InternetCloseHandle(req
);
4589 InternetCloseHandle(con
);
4590 InternetCloseHandle(ses
);
4593 static void test_basic_auth_credentials_reuse(int port
)
4595 HINTERNET ses
, con
, req
;
4599 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4600 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4602 con
= InternetConnectA( ses
, "localhost", port
, "user", "pwd",
4603 INTERNET_SERVICE_HTTP
, 0, 0 );
4604 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4606 req
= HttpOpenRequestA( con
, "HEAD", "/upload.txt", NULL
, NULL
, NULL
, 0, 0 );
4607 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4609 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4610 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4612 status
= 0xdeadbeef;
4613 size
= sizeof(status
);
4614 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4615 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4616 ok( status
== 200, "got %u\n", status
);
4618 InternetCloseHandle( req
);
4619 InternetCloseHandle( con
);
4620 InternetCloseHandle( ses
);
4622 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0 );
4623 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4625 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
,
4626 INTERNET_SERVICE_HTTP
, 0, 0 );
4627 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4629 req
= HttpOpenRequestA( con
, "PUT", "/upload2.txt", NULL
, NULL
, NULL
, 0, 0 );
4630 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4632 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4633 ok( ret
, "HttpSendRequestA failed %u\n", GetLastError() );
4635 status
= 0xdeadbeef;
4636 size
= sizeof(status
);
4637 ret
= HttpQueryInfoA( req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
4638 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
4639 ok( status
== 200, "got %u\n", status
);
4641 InternetCloseHandle( req
);
4642 InternetCloseHandle( con
);
4643 InternetCloseHandle( ses
);
4646 static void test_async_read(int port
)
4648 HINTERNET ses
, con
, req
;
4649 INTERNET_BUFFERSA ib
;
4651 DWORD pending_reads
;
4652 DWORD res
, count
, bytes
;
4655 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4656 conn_wait_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4658 /* test asynchronous InternetReadFileEx */
4659 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4660 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4661 pInternetSetStatusCallbackA( ses
, &callback
);
4663 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4664 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef );
4665 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4666 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4668 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4669 req
= HttpOpenRequestA( con
, "GET", "/async_read", NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef );
4670 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4671 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4673 SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT
);
4674 SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY
);
4675 SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4676 SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4677 SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST
);
4678 SET_EXPECT( INTERNET_STATUS_REQUEST_SENT
);
4679 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4680 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4681 SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION
);
4682 SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED
);
4683 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4685 SetLastError( 0xdeadbeef );
4686 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4687 ok( !ret
, "HttpSendRequestA unexpectedly succeeded\n" );
4688 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4689 WaitForSingleObject( hCompleteEvent
, INFINITE
);
4690 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4692 CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT
);
4693 CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY
);
4694 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4695 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4696 CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST
);
4697 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT
);
4698 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4699 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4700 CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION
);
4701 CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED
);
4702 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4705 memset( &ib
, 0, sizeof(ib
) );
4706 memset( buffer
, 0, sizeof(buffer
) );
4707 ib
.dwStructSize
= sizeof(ib
);
4708 for (count
= 0; count
< sizeof(buffer
); count
+= ib
.dwBufferLength
)
4710 ib
.lpvBuffer
= buffer
+ count
;
4711 ib
.dwBufferLength
= min(16, sizeof(buffer
) - count
);
4713 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4714 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4716 ret
= InternetReadFileExA( req
, &ib
, 0, 0xdeadbeef );
4717 if (!count
) /* the first part should arrive immediately */
4718 ok( ret
, "InternetReadFileExA failed %u\n", GetLastError() );
4721 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4722 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4723 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4724 if (!pending_reads
++)
4726 res
= WaitForSingleObject( hCompleteEvent
, 0 );
4727 ok( res
== WAIT_TIMEOUT
, "expected WAIT_TIMEOUT, got %u\n", res
);
4728 SetEvent( conn_wait_event
);
4730 res
= WaitForSingleObject( hCompleteEvent
, INFINITE
);
4731 ok( res
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", res
);
4732 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4733 todo_wine_if( pending_reads
> 1 )
4734 ok( ib
.dwBufferLength
!= 0, "expected ib.dwBufferLength != 0\n" );
4735 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4736 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4739 CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4740 CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4741 if (!ib
.dwBufferLength
) break;
4745 ok( pending_reads
== 1, "expected 1 pending read, got %u\n", pending_reads
);
4746 ok( !strcmp(buffer
, page1
), "unexpected buffer content\n" );
4747 close_async_handle( ses
, hCompleteEvent
, 2 );
4748 ResetEvent( conn_wait_event
);
4750 /* test asynchronous InternetReadFile */
4751 ses
= InternetOpenA( "winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4752 ok( ses
!= NULL
, "InternetOpenA failed\n" );
4753 pInternetSetStatusCallbackA( ses
, &callback
);
4755 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4756 con
= InternetConnectA( ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef );
4757 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
4758 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4760 SET_EXPECT( INTERNET_STATUS_HANDLE_CREATED
);
4761 req
= HttpOpenRequestA( con
, "GET", "/async_read", NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef );
4762 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
4763 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4765 SET_OPTIONAL( INTERNET_STATUS_COOKIE_SENT
);
4766 SET_OPTIONAL( INTERNET_STATUS_DETECTING_PROXY
);
4767 SET_EXPECT( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4768 SET_EXPECT( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4769 SET_EXPECT( INTERNET_STATUS_SENDING_REQUEST
);
4770 SET_EXPECT( INTERNET_STATUS_REQUEST_SENT
);
4771 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4772 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4773 SET_OPTIONAL( INTERNET_STATUS_CLOSING_CONNECTION
);
4774 SET_OPTIONAL( INTERNET_STATUS_CONNECTION_CLOSED
);
4775 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4777 SetLastError( 0xdeadbeef );
4778 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
4779 ok( !ret
, "HttpSendRequestA unexpectedly succeeded\n" );
4780 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4781 WaitForSingleObject( hCompleteEvent
, INFINITE
);
4782 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4784 CLEAR_NOTIFIED( INTERNET_STATUS_COOKIE_SENT
);
4785 CLEAR_NOTIFIED( INTERNET_STATUS_DETECTING_PROXY
);
4786 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTING_TO_SERVER
);
4787 CHECK_NOTIFIED( INTERNET_STATUS_CONNECTED_TO_SERVER
);
4788 CHECK_NOTIFIED( INTERNET_STATUS_SENDING_REQUEST
);
4789 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_SENT
);
4790 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4791 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4792 CLEAR_NOTIFIED( INTERNET_STATUS_CLOSING_CONNECTION
);
4793 CLEAR_NOTIFIED( INTERNET_STATUS_CONNECTION_CLOSED
);
4794 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4797 memset( buffer
, 0, sizeof(buffer
) );
4798 for (count
= 0; count
< sizeof(buffer
); count
+= bytes
)
4800 SET_EXPECT( INTERNET_STATUS_RECEIVING_RESPONSE
);
4801 SET_EXPECT( INTERNET_STATUS_RESPONSE_RECEIVED
);
4804 ret
= InternetReadFile( req
, buffer
+ count
, min(16, sizeof(buffer
) - count
), &bytes
);
4805 if (!count
) /* the first part should arrive immediately */
4806 ok( ret
, "InternetReadFile failed %u\n", GetLastError() );
4809 ok( GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError() );
4810 ok( bytes
== 0, "expected 0, got %u\n", bytes
);
4812 CHECK_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4813 SET_EXPECT( INTERNET_STATUS_REQUEST_COMPLETE
);
4814 if (!pending_reads
++)
4816 res
= WaitForSingleObject( hCompleteEvent
, 0 );
4817 ok( res
== WAIT_TIMEOUT
, "expected WAIT_TIMEOUT, got %u\n", res
);
4818 SetEvent( conn_wait_event
);
4820 res
= WaitForSingleObject( hCompleteEvent
, INFINITE
);
4821 ok( res
== WAIT_OBJECT_0
, "expected WAIT_OBJECT_0, got %u\n", res
);
4822 ok( req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4823 todo_wine_if( pending_reads
> 1 )
4824 ok( bytes
!= 0, "expected bytes != 0\n" );
4825 CHECK_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4826 CHECK_NOTIFIED( INTERNET_STATUS_REQUEST_COMPLETE
);
4829 CLEAR_NOTIFIED( INTERNET_STATUS_RECEIVING_RESPONSE
);
4830 CLEAR_NOTIFIED( INTERNET_STATUS_RESPONSE_RECEIVED
);
4835 ok( pending_reads
== 1, "expected 1 pending read, got %u\n", pending_reads
);
4836 ok( !strcmp(buffer
, page1
), "unexpected buffer content\n" );
4837 close_async_handle( ses
, hCompleteEvent
, 2 );
4839 CloseHandle( hCompleteEvent
);
4840 CloseHandle( conn_wait_event
);
4843 static void server_send_string(const char *msg
)
4845 send(server_socket
, msg
, strlen(msg
), 0);
4848 static void WINAPI
readex_callback(HINTERNET handle
, DWORD_PTR context
, DWORD status
, void *info
, DWORD info_size
)
4851 case INTERNET_STATUS_RECEIVING_RESPONSE
:
4852 case INTERNET_STATUS_RESPONSE_RECEIVED
:
4855 callback(handle
, context
, status
, info
, info_size
);
4859 static void open_read_test_request(int port
, test_request_t
*req
, const char *response
)
4863 req
->session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
4864 ok(req
->session
!= NULL
, "InternetOpenA failed\n");
4865 pInternetSetStatusCallbackA(req
->session
, readex_callback
);
4867 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4868 req
->connection
= InternetConnectA(req
->session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0xdeadbeef);
4869 ok(req
->connection
!= NULL
, "InternetConnectA failed %u\n", GetLastError());
4870 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
4872 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
4873 req
->request
= HttpOpenRequestA(req
->connection
, "GET", "/socket", NULL
, NULL
, NULL
, INTERNET_FLAG_RELOAD
, 0xdeadbeef);
4874 ok(req
->request
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError());
4875 CHECK_NOTIFIED( INTERNET_STATUS_HANDLE_CREATED
);
4877 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
4878 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
4879 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4880 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4881 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
4882 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
4884 SetLastError(0xdeadbeef);
4885 ret
= HttpSendRequestA(req
->request
, NULL
, 0, NULL
, 0);
4886 ok(!ret
, "HttpSendRequestA unexpectedly succeeded\n");
4887 ok(GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %u\n", GetLastError());
4888 ok(req_error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", req_error
);
4890 WaitForSingleObject(server_req_rec_event
, INFINITE
);
4892 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
4893 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
4894 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
4895 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
4896 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
4898 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4900 server_send_string(response
);
4901 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4903 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
4904 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4907 #define readex_expect_sync_data_len(a,b,c,d,e,f) _readex_expect_sync_data_len(__LINE__,a,b,c,d,e,f)
4908 static void _readex_expect_sync_data_len(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
4909 DWORD buf_size
, const char *exdata
, DWORD len
)
4913 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4915 memset(buf
->lpvBuffer
, 0xff, buf_size
);
4916 buf
->dwBufferLength
= buf_size
;
4917 ret
= InternetReadFileExW(req
, buf
, flags
, 0xdeadbeef);
4918 ok_(__FILE__
,line
)(ret
, "InternetReadFileExW failed: %u\n", GetLastError());
4919 ok_(__FILE__
,line
)(buf
->dwBufferLength
== len
, "dwBufferLength = %u, expected %u\n", buf
->dwBufferLength
, len
);
4921 ok_(__FILE__
,line
)(!memcmp(buf
->lpvBuffer
, exdata
, len
), "Unexpected data\n");
4923 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4926 #define readex_expect_sync_data(a,b,c,d,e) _readex_expect_sync_data(__LINE__,a,b,c,d,e)
4927 static void _readex_expect_sync_data(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
4928 DWORD buf_size
, const char *exdata
)
4930 _readex_expect_sync_data_len(line
, req
, flags
, buf
, buf_size
, exdata
, strlen(exdata
));
4933 static void send_response_and_wait(const char *response
, BOOL close_connection
, INTERNET_BUFFERSW
*buf
)
4935 DWORD orig_size
= buf
->dwBufferLength
;
4937 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4940 server_send_string(response
);
4942 if(close_connection
) {
4944 SetEvent(conn_wait_event
);
4945 recv(server_socket
, &c
, 1, 0);
4948 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4950 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4952 /* If IRF_NO_WAIT is used, buffer is not changed. */
4953 ok(buf
->dwBufferLength
== orig_size
, "dwBufferLength = %u\n", buf
->dwBufferLength
);
4954 ok(!*(int*)buf
->lpvBuffer
, "buffer data changed\n");
4957 static void send_response_len_and_wait(unsigned len
, BOOL close_connection
, INTERNET_BUFFERSW
*buf
)
4961 response
= HeapAlloc(GetProcessHeap(), 0, len
+1);
4962 memset(response
, 'x', len
);
4964 send_response_and_wait(response
, close_connection
, buf
);
4965 HeapFree(GetProcessHeap(), 0, response
);
4968 static void readex_expect_async(HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
, DWORD buf_size
)
4972 memset(buf
->lpvBuffer
, 0, buf_size
);
4973 buf
->dwBufferLength
= buf_size
;
4974 ret
= InternetReadFileExW(req
, buf
, flags
, 0xdeadbeef);
4975 ok(!ret
&& GetLastError() == ERROR_IO_PENDING
, "InternetReadFileExW returned %x (%u)\n", ret
, GetLastError());
4976 ok(buf
->dwBufferLength
== buf_size
, "dwBufferLength = %u, expected %u\n", buf
->dwBufferLength
, buf_size
);
4977 ok(!*(int*)buf
->lpvBuffer
, "buffer data changed\n");
4980 #define expect_data_available(a,b) _expect_data_available(__LINE__,a,b)
4981 static DWORD
_expect_data_available(unsigned line
, HINTERNET req
, int exsize
)
4986 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
4987 ok_(__FILE__
,line
)(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
4989 ok_(__FILE__
,line
)(size
== exsize
, "size = %u, expected %u\n", size
, exsize
);
4994 static void test_http_read(int port
)
4996 INTERNET_BUFFERSW ib
;
5004 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
5005 conn_wait_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
5006 server_req_rec_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
5008 trace("Testing InternetReadFileExW with IRF_NO_WAIT flag...\n");
5010 open_read_test_request(port
, &req
,
5011 "HTTP/1.1 200 OK\r\n"
5012 "Server: winetest\r\n"
5016 memset(&ib
, 0, sizeof(ib
));
5017 ib
.dwStructSize
= sizeof(ib
);
5020 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "xx");
5022 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5023 send_response_and_wait("1234567890", FALSE
, &ib
);
5024 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, 5, "12345");
5025 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "67890");
5027 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5028 send_response_and_wait("12345", TRUE
, &ib
);
5030 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "12345");
5031 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "");
5033 close_async_handle(req
.session
, hCompleteEvent
, 2);
5035 open_read_test_request(port
, &req
,
5036 "HTTP/1.1 200 OK\r\n"
5037 "Server: winetest\r\n"
5038 "Transfer-Encoding: chunked\r\n"
5041 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123456789");
5042 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5044 send_response_and_wait("\r\n1\r\na\r\n1\r\nb\r", FALSE
, &ib
);
5045 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab");
5046 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5048 send_response_and_wait("\n3\r\nab", 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("c", FALSE
, &ib
);
5053 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "c");
5054 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5056 send_response_and_wait("\r\n1\r\nx\r\n0\r\n\r\n", TRUE
, &ib
);
5057 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "x");
5058 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "");
5060 close_async_handle(req
.session
, hCompleteEvent
, 2);
5062 open_read_test_request(port
, &req
,
5063 "HTTP/1.1 200 OK\r\n"
5064 "Server: winetest\r\n"
5065 "Transfer-Encoding: chunked\r\n"
5068 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123");
5069 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5071 send_response_and_wait("0\r\n\r\n", TRUE
, &ib
);
5072 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "");
5074 close_async_handle(req
.session
, hCompleteEvent
, 2);
5076 trace("Testing InternetQueryDataAvailable...\n");
5078 open_read_test_request(port
, &req
,
5079 "HTTP/1.1 200 OK\r\n"
5080 "Server: winetest\r\n"
5083 expect_data_available(req
.request
, 3);
5084 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123");
5085 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5087 send_response_len_and_wait(20000, TRUE
, &ib
);
5088 avail
= expect_data_available(req
.request
, -1);
5089 ok(avail
< 17000, "avail = %u\n", avail
);
5091 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
5092 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
5093 close_async_handle(req
.session
, hCompleteEvent
, 2);
5094 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5095 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5097 CloseHandle(hCompleteEvent
);
5098 CloseHandle(conn_wait_event
);
5099 CloseHandle(server_req_rec_event
);
5102 static void test_long_url(int port
)
5104 char long_path
[INTERNET_MAX_PATH_LENGTH
*2] = "/echo_request?";
5105 char buf
[sizeof(long_path
)*2], url
[sizeof(buf
)];
5113 memset(long_path
+strlen(long_path
), 'x', sizeof(long_path
)-strlen(long_path
));
5114 long_path
[sizeof(long_path
)-1] = 0;
5115 open_simple_request(&req
, "localhost", port
, NULL
, long_path
);
5117 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
5118 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
5119 test_status_code(req
.request
, 200);
5121 receive_simple_request(req
.request
, buf
, sizeof(buf
));
5122 ok(strstr(buf
, long_path
) != NULL
, "long pathnot found in %s\n", buf
);
5124 sprintf(url
, "http://localhost:%u%s", port
, long_path
);
5127 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_URL
, buf
, &size
);
5128 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
5130 ok(size
== len
, "size = %u, expected %u\n", size
, len
);
5131 ok(!strcmp(buf
, url
), "Wrong URL %s, expected %s\n", buf
, url
);
5133 close_request(&req
);
5136 static void test_http_connection(void)
5138 struct server_info si
;
5142 si
.hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
5145 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
5146 ok( hThread
!= NULL
, "create thread failed\n");
5148 r
= WaitForSingleObject(si
.hEvent
, 10000);
5149 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
5150 if (r
!= WAIT_OBJECT_0
)
5153 test_basic_request(si
.port
, "GET", "/test1");
5154 test_proxy_indirect(si
.port
);
5155 test_proxy_direct(si
.port
);
5156 test_header_handling_order(si
.port
);
5157 test_basic_request(si
.port
, "POST", "/test5");
5158 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
5159 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
5160 test_basic_request(si
.port
, "GET", "/test6");
5161 test_basic_request(si
.port
, "GET", "/testF");
5162 test_connection_header(si
.port
);
5163 test_header_override(si
.port
);
5164 test_cookie_header(si
.port
);
5165 test_basic_authentication(si
.port
);
5166 test_invalid_response_headers(si
.port
);
5167 test_response_without_headers(si
.port
);
5168 test_HttpQueryInfo(si
.port
);
5169 test_HttpSendRequestW(si
.port
);
5170 test_options(si
.port
);
5171 test_no_content(si
.port
);
5172 test_conn_close(si
.port
);
5173 test_no_cache(si
.port
);
5174 test_cache_read_gzipped(si
.port
);
5175 test_http_status(si
.port
);
5176 test_premature_disconnect(si
.port
);
5177 test_connection_closing(si
.port
);
5178 test_cache_control_verb(si
.port
);
5179 test_successive_HttpSendRequest(si
.port
);
5180 test_head_request(si
.port
);
5181 test_request_content_length(si
.port
);
5182 test_accept_encoding(si
.port
);
5183 test_basic_auth_credentials_reuse(si
.port
);
5184 test_async_read(si
.port
);
5185 test_http_read(si
.port
);
5186 test_long_url(si
.port
);
5188 /* send the basic request again to shutdown the server thread */
5189 test_basic_request(si
.port
, "GET", "/quit");
5191 r
= WaitForSingleObject(hThread
, 3000);
5192 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
5193 CloseHandle(hThread
);
5196 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
5198 LocalFree(info
->lpszSubjectInfo
);
5199 LocalFree(info
->lpszIssuerInfo
);
5200 LocalFree(info
->lpszProtocolName
);
5201 LocalFree(info
->lpszSignatureAlgName
);
5202 LocalFree(info
->lpszEncryptionAlgName
);
5206 const char *ex_subject
;
5207 const char *ex_issuer
;
5208 } cert_struct_test_t
;
5210 static const cert_struct_test_t test_winehq_org_cert
= {
5215 "RapidSSL SHA256 CA"
5218 static const cert_struct_test_t test_winehq_com_cert
= {
5223 "test.winehq.com\r\n"
5224 "webmaster@winehq.org",
5229 "test.winehq.com\r\n"
5230 "webmaster@winehq.org"
5233 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
5235 INTERNET_CERTIFICATE_INFOA info
;
5239 memset(&info
, 0x5, sizeof(info
));
5241 size
= sizeof(info
);
5242 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
5243 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
5244 ok(size
== sizeof(info
), "size = %u\n", size
);
5246 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
5247 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
5248 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
5249 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
5250 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
5251 ok(info
.dwKeySize
>= 128 && info
.dwKeySize
<= 256, "dwKeySize = %u\n", info
.dwKeySize
);
5253 release_cert_info(&info
);
5256 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
5257 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
5259 char url
[INTERNET_MAX_URL_LENGTH
];
5260 const CERT_CHAIN_CONTEXT
*chain
;
5264 if(!pInternetGetSecurityInfoByURLA
) {
5265 win_skip("pInternetGetSecurityInfoByURLA not available\n");
5270 chain
= (void*)0xdeadbeef;
5272 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
5273 if(error
== ERROR_SUCCESS
) {
5274 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
5275 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
5276 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
5277 CertFreeCertificateChain(chain
);
5279 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
5280 "InternetGetSecurityInfoByURLA returned: %x(%u), expected %u\n", res
, GetLastError(), error
);
5284 #define test_secflags_option(a,b,c) _test_secflags_option(__LINE__,a,b,c)
5285 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
, DWORD opt_flags
)
5291 size
= sizeof(flags
);
5292 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
5293 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
5294 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n",
5297 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
5299 size
= sizeof(flags
);
5300 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
5301 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
5302 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n",
5306 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
5307 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
5311 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
5312 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
5315 static void test_security_flags(void)
5317 INTERNET_CERTIFICATE_INFOA
*cert
;
5318 HINTERNET ses
, conn
, req
;
5323 trace("Testing security flags...\n");
5325 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
5327 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5328 ok(ses
!= NULL
, "InternetOpen failed\n");
5330 pInternetSetStatusCallbackA(ses
, &callback
);
5332 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5333 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
5334 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
5335 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
5336 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5338 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5339 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5340 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5342 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5343 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5346 size
= sizeof(flags
);
5347 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
5348 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
5349 win_skip("Incomplete security flags support, skipping\n");
5351 close_async_handle(ses
, hCompleteEvent
, 2);
5352 CloseHandle(hCompleteEvent
);
5356 test_secflags_option(req
, 0, 0);
5357 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5359 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
5360 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
, 0);
5362 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
5363 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
5365 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
5366 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
5368 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
5369 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
5370 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
5372 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
5373 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
5374 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5375 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5376 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5377 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5378 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5379 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5380 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5381 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5382 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5383 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5384 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5385 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5386 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5388 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5389 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5391 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5392 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5394 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
5395 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
5396 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5397 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5398 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5399 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5400 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5401 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5402 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5403 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5404 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5405 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5406 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5408 test_request_flags(req
, 0);
5409 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
5410 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
, 0);
5412 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5413 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5414 ok(size
, "size = 0\n");
5416 /* Collect all existing persistent connections */
5417 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5418 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5420 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5421 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5422 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5424 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5425 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5427 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
5428 res
= InternetSetOptionA(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
5429 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
5431 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5432 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5433 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5434 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5435 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5436 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5437 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5438 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5439 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5440 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5441 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5443 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5444 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5446 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5447 ok(req_error
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| broken(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
),
5448 "req_error = %d\n", req_error
);
5451 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
5452 ok(res
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5453 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %u\n", size
);
5454 cert
= HeapAlloc(GetProcessHeap(), 0, size
);
5455 cert
->lpszSubjectInfo
= NULL
;
5456 cert
->lpszIssuerInfo
= NULL
;
5457 cert
->lpszSignatureAlgName
= (char *)0xdeadbeef;
5458 cert
->lpszEncryptionAlgName
= (char *)0xdeadbeef;
5459 cert
->lpszProtocolName
= (char *)0xdeadbeef;
5460 cert
->dwKeySize
= 0xdeadbeef;
5461 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, cert
, &size
);
5462 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
5465 ok(cert
->lpszSubjectInfo
&& strlen(cert
->lpszSubjectInfo
) > 1, "expected a non-empty subject name\n");
5466 ok(cert
->lpszIssuerInfo
&& strlen(cert
->lpszIssuerInfo
) > 1, "expected a non-empty issuer name\n");
5467 ok(!cert
->lpszSignatureAlgName
, "unexpected signature algorithm name\n");
5468 ok(!cert
->lpszEncryptionAlgName
, "unexpected encryption algorithm name\n");
5469 ok(!cert
->lpszProtocolName
, "unexpected protocol name\n");
5470 ok(cert
->dwKeySize
!= 0xdeadbeef, "unexpected key size\n");
5472 HeapFree(GetProcessHeap(), 0, cert
);
5474 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5475 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5476 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
5477 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
5478 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5479 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5480 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5482 if(req_error
!= ERROR_INTERNET_SEC_CERT_REV_FAILED
) {
5483 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error
);
5485 close_async_handle(ses
, hCompleteEvent
, 3);
5486 CloseHandle(hCompleteEvent
);
5491 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
5492 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
5494 test_request_flags(req
, 8);
5495 /* IE11 finds both rev failure and invalid CA. Previous versions required rev failure
5496 to be ignored before invalid CA was reported. */
5497 test_secflags_option(req
, _SECURITY_FLAG_CERT_REV_FAILED
, _SECURITY_FLAG_CERT_INVALID_CA
);
5499 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
5500 test_secflags_option(req
, _SECURITY_FLAG_CERT_REV_FAILED
|SECURITY_FLAG_IGNORE_REVOCATION
, _SECURITY_FLAG_CERT_INVALID_CA
);
5502 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5503 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5504 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5505 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5506 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5507 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5508 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5510 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5511 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5513 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5514 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
5516 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5517 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5518 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5519 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5520 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5521 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5522 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5524 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
5525 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5526 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5528 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
5529 test_secflags_option(req
, _SECURITY_FLAG_CERT_INVALID_CA
|_SECURITY_FLAG_CERT_REV_FAILED
5530 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
, 0);
5531 test_http_version(req
);
5533 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5534 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5535 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5536 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5537 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5538 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5539 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5540 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5541 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5542 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5543 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5544 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5545 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5547 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5548 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5550 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5551 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5553 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5554 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5555 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5556 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5557 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5558 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5559 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5560 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5561 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5562 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5563 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5565 test_request_flags(req
, 0);
5566 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
5567 |SECURITY_FLAG_STRENGTH_STRONG
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5569 test_cert_struct(req
, &test_winehq_com_cert
);
5570 test_security_info("https://test.winehq.com/data/some_file.html?q", 0,
5571 _SECURITY_FLAG_CERT_INVALID_CA
|_SECURITY_FLAG_CERT_REV_FAILED
);
5573 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5574 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5575 ok(size
, "size = 0\n");
5577 close_async_handle(ses
, hCompleteEvent
, 3);
5579 /* Collect all existing persistent connections */
5580 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5581 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5583 /* Make another request, without setting security flags */
5585 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5586 ok(ses
!= NULL
, "InternetOpen failed\n");
5588 pInternetSetStatusCallbackA(ses
, &callback
);
5590 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5591 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
5592 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
5593 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
5594 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5596 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5597 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5598 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5600 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5601 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5603 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
5604 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5605 test_http_version(req
);
5607 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5608 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5609 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5610 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5611 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5612 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5613 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5614 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5615 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5616 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5617 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5618 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5620 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5621 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5623 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5624 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5626 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5627 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5628 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5629 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5630 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5631 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5632 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5633 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5634 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5635 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5637 test_request_flags(req
, 0);
5638 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
5639 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5641 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5642 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5643 ok(size
, "size = 0\n");
5645 close_async_handle(ses
, hCompleteEvent
, 2);
5647 CloseHandle(hCompleteEvent
);
5649 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5650 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5651 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5654 static void test_secure_connection(void)
5656 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
5657 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
5658 static const WCHAR get
[] = {'G','E','T',0};
5659 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
5660 HINTERNET ses
, con
, req
;
5662 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
5663 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
5666 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5667 ok(ses
!= NULL
, "InternetOpen failed\n");
5669 con
= InternetConnectA(ses
, "test.winehq.org",
5670 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
5671 INTERNET_SERVICE_HTTP
, 0, 0);
5672 ok(con
!= NULL
, "InternetConnect failed\n");
5674 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5675 INTERNET_FLAG_SECURE
, 0);
5676 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5678 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5679 ok(ret
|| broken(GetLastError() == ERROR_INTERNET_CANNOT_CONNECT
),
5680 "HttpSendRequest failed: %d\n", GetLastError());
5683 win_skip("Cannot connect to https.\n");
5687 size
= sizeof(flags
);
5688 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
5689 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5690 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
5692 test_cert_struct(req
, &test_winehq_org_cert
);
5694 /* Querying the same option through InternetQueryOptionW still results in
5695 * ASCII strings being returned.
5698 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5700 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5701 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
5702 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
5703 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5704 certificate_structW
, &size
);
5705 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
5706 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5709 ok(certificate_structA
->lpszSubjectInfo
&&
5710 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
5711 "expected a non-empty subject name\n");
5712 ok(certificate_structA
->lpszIssuerInfo
&&
5713 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
5714 "expected a non-empty issuer name\n");
5715 ok(!certificate_structA
->lpszSignatureAlgName
,
5716 "unexpected signature algorithm name\n");
5717 ok(!certificate_structA
->lpszEncryptionAlgName
,
5718 "unexpected encryption algorithm name\n");
5719 ok(!certificate_structA
->lpszProtocolName
,
5720 "unexpected protocol name\n");
5721 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
5722 release_cert_info(certificate_structA
);
5724 HeapFree(GetProcessHeap(), 0, certificate_structW
);
5726 InternetCloseHandle(req
);
5727 InternetCloseHandle(con
);
5728 InternetCloseHandle(ses
);
5730 /* Repeating the tests with the W functions has the same result: */
5731 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5732 ok(ses
!= NULL
, "InternetOpen failed\n");
5734 con
= InternetConnectW(ses
, testsite
,
5735 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
5736 INTERNET_SERVICE_HTTP
, 0, 0);
5737 ok(con
!= NULL
, "InternetConnect failed\n");
5739 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
5740 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
5741 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5743 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5744 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
5746 size
= sizeof(flags
);
5747 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
5748 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5749 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %x\n", flags
);
5751 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5753 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5754 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
5755 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
5756 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5757 certificate_structA
, &size
);
5758 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5761 ok(certificate_structA
->lpszSubjectInfo
&&
5762 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
5763 "expected a non-empty subject name\n");
5764 ok(certificate_structA
->lpszIssuerInfo
&&
5765 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
5766 "expected a non-empty issuer name\n");
5767 ok(!certificate_structA
->lpszSignatureAlgName
,
5768 "unexpected signature algorithm name\n");
5769 ok(!certificate_structA
->lpszEncryptionAlgName
,
5770 "unexpected encryption algorithm name\n");
5771 ok(!certificate_structA
->lpszProtocolName
,
5772 "unexpected protocol name\n");
5773 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
5774 release_cert_info(certificate_structA
);
5776 HeapFree(GetProcessHeap(), 0, certificate_structA
);
5778 /* Again, querying the same option through InternetQueryOptionW still
5779 * results in ASCII strings being returned.
5782 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5784 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5785 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
5786 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
5787 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5788 certificate_structW
, &size
);
5789 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
5790 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5793 ok(certificate_structA
->lpszSubjectInfo
&&
5794 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
5795 "expected a non-empty subject name\n");
5796 ok(certificate_structA
->lpszIssuerInfo
&&
5797 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
5798 "expected a non-empty issuer name\n");
5799 ok(!certificate_structA
->lpszSignatureAlgName
,
5800 "unexpected signature algorithm name\n");
5801 ok(!certificate_structA
->lpszEncryptionAlgName
,
5802 "unexpected encryption algorithm name\n");
5803 ok(!certificate_structA
->lpszProtocolName
,
5804 "unexpected protocol name\n");
5805 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
5806 release_cert_info(certificate_structA
);
5808 HeapFree(GetProcessHeap(), 0, certificate_structW
);
5811 InternetCloseHandle(req
);
5812 InternetCloseHandle(con
);
5813 InternetCloseHandle(ses
);
5816 static void test_user_agent_header(void)
5818 HINTERNET ses
, con
, req
;
5823 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5824 ok(ses
!= NULL
, "InternetOpen failed\n");
5826 con
= InternetConnectA(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5827 ok(con
!= NULL
, "InternetConnect failed\n");
5829 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
5830 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5832 size
= sizeof(buffer
);
5833 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5834 err
= GetLastError();
5835 ok(!ret
, "HttpQueryInfo succeeded\n");
5836 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
5838 ret
= HttpAddRequestHeadersA(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
5839 ok(ret
, "HttpAddRequestHeaders succeeded\n");
5841 size
= sizeof(buffer
);
5842 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5843 err
= GetLastError();
5844 ok(ret
, "HttpQueryInfo failed\n");
5846 InternetCloseHandle(req
);
5848 req
= HttpOpenRequestA(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
5849 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5851 size
= sizeof(buffer
);
5852 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| 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
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
5858 ok(ret
, "HttpAddRequestHeaders failed\n");
5861 size
= sizeof(buffer
);
5862 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5863 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
5864 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
5866 InternetCloseHandle(req
);
5867 InternetCloseHandle(con
);
5868 InternetCloseHandle(ses
);
5871 static void test_bogus_accept_types_array(void)
5873 HINTERNET ses
, con
, req
;
5874 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
5879 ses
= InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
5880 con
= InternetConnectA(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5881 req
= HttpOpenRequestA(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
5883 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
5886 size
= sizeof(buffer
);
5887 SetLastError(0xdeadbeef);
5888 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5889 error
= GetLastError();
5890 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
5891 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
5892 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
5893 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
5894 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
5896 InternetCloseHandle(req
);
5897 InternetCloseHandle(con
);
5898 InternetCloseHandle(ses
);
5907 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
5909 INTERNET_ASYNC_RESULT
*result
= info
;
5910 struct context
*ctx
= (struct context
*)context
;
5912 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
5915 case INTERNET_STATUS_REQUEST_COMPLETE
:
5916 trace("request handle: 0x%08lx\n", result
->dwResult
);
5917 ctx
->req
= (HINTERNET
)result
->dwResult
;
5918 SetEvent(ctx
->event
);
5920 case INTERNET_STATUS_HANDLE_CLOSING
: {
5921 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
5923 if (InternetQueryOptionA(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
5924 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
5925 SetEvent(ctx
->event
);
5928 case INTERNET_STATUS_NAME_RESOLVED
:
5929 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
5930 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
5932 ok(str
[0] && str
[1], "Got string: %s\n", str
);
5933 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
5938 static void test_open_url_async(void)
5946 /* Collect all existing persistent connections */
5947 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5948 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5951 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
5952 * other versions never do. They also hang of following tests. We disable it for everything older
5959 ctx
.event
= CreateEventA(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
5961 ses
= InternetOpenA("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5962 ok(ses
!= NULL
, "InternetOpen failed\n");
5964 SetLastError(0xdeadbeef);
5965 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
5966 error
= GetLastError();
5967 ok(!ret
, "InternetSetOptionA succeeded\n");
5968 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
5970 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
5971 error
= GetLastError();
5972 ok(!ret
, "InternetSetOptionA failed\n");
5973 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
5975 pInternetSetStatusCallbackW(ses
, cb
);
5976 ResetEvent(ctx
.event
);
5978 req
= InternetOpenUrlA(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
5979 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
5981 WaitForSingleObject(ctx
.event
, INFINITE
);
5984 size
= sizeof(type
);
5985 ret
= InternetQueryOptionA(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
5986 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
5987 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
5988 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
5991 ret
= HttpQueryInfoA(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
5992 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
5993 ok(size
> 0, "expected size > 0\n");
5995 ResetEvent(ctx
.event
);
5996 InternetCloseHandle(ctx
.req
);
5997 WaitForSingleObject(ctx
.event
, INFINITE
);
5999 InternetCloseHandle(ses
);
6000 CloseHandle(ctx
.event
);
6005 internet_connect
= 1,
6007 http_send_request_ex
,
6010 internet_close_handle
6015 enum api function
; /* api responsible for notification */
6016 unsigned int status
; /* status received */
6017 BOOL async
; /* delivered from another thread? */
6025 const struct notification
*test
;
6031 DWORD expect_result
;
6035 static CRITICAL_SECTION notification_cs
;
6037 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
6039 BOOL status_ok
, function_ok
;
6040 struct info
*info
= (struct info
*)context
;
6043 EnterCriticalSection( ¬ification_cs
);
6045 if(info
->is_aborted
) {
6046 LeaveCriticalSection(¬ification_cs
);
6050 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
6052 DWORD size
= sizeof(struct info
*);
6053 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
6054 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
6055 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
6057 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
6058 if(info
->expect_result
== ERROR_SUCCESS
) {
6059 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
6061 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
6062 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
6067 if (i
>= info
->count
)
6069 LeaveCriticalSection( ¬ification_cs
);
6073 while (info
->test
[i
].status
!= status
&&
6074 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
6075 i
< info
->count
- 1 &&
6076 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
6081 status_ok
= (info
->test
[i
].status
== status
);
6082 function_ok
= (info
->test
[i
].function
== info
->function
);
6084 if (!info
->test
[i
].todo
)
6086 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
6087 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
6089 if (info
->test
[i
].async
)
6090 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
6091 info
->line
, info
->thread
, GetCurrentThreadId());
6095 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
6097 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
6099 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
6102 LeaveCriticalSection( ¬ification_cs
);
6105 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
6107 info
->function
= function
;
6109 info
->expect_result
= expect_result
;
6112 struct notification_data
6114 const struct notification
*test
;
6115 const unsigned int count
;
6120 BOOL expect_conn_failure
;
6123 static const struct notification async_send_request_ex_test
[] =
6125 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6126 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6127 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6128 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6129 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6130 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6131 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
6132 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
6133 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6134 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6135 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6136 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, FALSE
},
6137 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, FALSE
},
6138 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6139 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6140 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6141 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6142 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6143 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6144 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6147 static const struct notification async_send_request_ex_test2
[] =
6149 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6150 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6151 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6152 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6153 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6154 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6155 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
, TRUE
},
6156 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
, TRUE
},
6157 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6158 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6159 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6160 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6161 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6162 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6163 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6164 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6165 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6166 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6169 static const struct notification async_send_request_ex_resolve_failure_test
[] =
6171 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6172 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6173 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6174 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
},
6175 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6176 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6177 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6178 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6179 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6180 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6181 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6184 static const struct notification async_send_request_ex_chunked_test
[] =
6186 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
},
6187 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
},
6188 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6189 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6190 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6191 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6192 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
6193 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
6194 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6195 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6196 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6197 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6198 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6199 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6200 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
},
6201 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
},
6202 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
},
6203 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
}
6206 static const struct notification_data notification_data
[] = {
6208 async_send_request_ex_chunked_test
,
6209 sizeof(async_send_request_ex_chunked_test
)/sizeof(async_send_request_ex_chunked_test
[0]),
6215 async_send_request_ex_test
,
6216 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
6220 "Public ID=codeweavers"
6223 async_send_request_ex_test2
,
6224 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
6230 async_send_request_ex_resolve_failure_test
,
6231 sizeof(async_send_request_ex_resolve_failure_test
)/sizeof(async_send_request_ex_resolve_failure_test
[0]),
6240 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
6243 HINTERNET ses
, req
, con
;
6245 DWORD size
, written
, error
;
6246 INTERNET_BUFFERSA b
;
6247 static const char *accept
[2] = {"*/*", NULL
};
6250 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
6252 InitializeCriticalSection( ¬ification_cs
);
6254 info
.test
= nd
->test
;
6255 info
.count
= nd
->count
;
6257 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
6258 info
.thread
= GetCurrentThreadId();
6259 info
.is_aborted
= FALSE
;
6261 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6262 ok( ses
!= NULL
, "InternetOpen failed\n" );
6264 pInternetSetStatusCallbackA( ses
, check_notification
);
6266 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
6267 con
= InternetConnectA( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
6268 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
6270 WaitForSingleObject( info
.wait
, 10000 );
6272 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
6273 req
= HttpOpenRequestA( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
6274 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
6276 WaitForSingleObject( info
.wait
, 10000 );
6279 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
6280 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
6281 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
6282 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
6283 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
6286 setup_test( &info
, http_send_request_ex
, __LINE__
,
6287 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
6288 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
6289 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
6291 error
= WaitForSingleObject( info
.wait
, 10000 );
6292 if(error
!= WAIT_OBJECT_0
) {
6293 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
6294 info
.is_aborted
= TRUE
;
6298 size
= sizeof(buffer
);
6299 SetLastError( 0xdeadbeef );
6300 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
6301 error
= GetLastError();
6302 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
6303 if(nd
->expect_conn_failure
) {
6304 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
6307 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
6308 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
6314 size
= strlen( nd
->data
);
6315 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
6316 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
6317 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
6318 ok( written
== size
, "expected %u got %u\n", written
, size
);
6320 WaitForSingleObject( info
.wait
, 10000 );
6322 SetLastError( 0xdeadbeef );
6323 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
6324 error
= GetLastError();
6325 ok( !ret
, "HttpEndRequestA succeeded\n" );
6326 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
6329 SetLastError( 0xdeadbeef );
6330 setup_test( &info
, http_end_request
, __LINE__
,
6331 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
6332 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
6333 error
= GetLastError();
6334 ok( !ret
, "HttpEndRequestA succeeded\n" );
6335 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
6337 WaitForSingleObject( info
.wait
, 10000 );
6339 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
6341 InternetCloseHandle( req
);
6342 InternetCloseHandle( con
);
6343 InternetCloseHandle( ses
);
6345 WaitForSingleObject( info
.wait
, 10000 );
6347 CloseHandle( info
.wait
);
6348 DeleteCriticalSection( ¬ification_cs
);
6351 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
6352 static BOOL closetest_closed
;
6354 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
6355 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
6360 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
6362 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
6363 "Unexpected hInternet %p\n", hInternet
);
6364 if(!closetest_closed
)
6368 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
6369 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
6370 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
6371 closetest_req
, res
, GetLastError());
6374 static void test_InternetCloseHandle(void)
6379 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6380 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
6382 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
6384 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
6385 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
6386 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
6388 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
6389 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
6391 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
6392 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
6393 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
6395 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
6397 res
= InternetCloseHandle(closetest_session
);
6398 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
6399 closetest_closed
= TRUE
;
6400 trace("Closed session handle\n");
6402 res
= InternetCloseHandle(closetest_conn
);
6403 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
6404 res
, GetLastError());
6406 res
= InternetCloseHandle(closetest_req
);
6407 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
6408 res
, GetLastError());
6410 len
= sizeof(flags
);
6411 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
6412 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
6413 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
6414 closetest_req
, res
, GetLastError());
6417 static void test_connection_failure(void)
6423 open_simple_request(&req
, "localhost", 1, NULL
, "/");
6425 SetLastError(0xdeadbeef);
6426 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
6427 error
= GetLastError();
6428 ok(!ret
, "unexpected success\n");
6429 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
6431 close_request(&req
);
6434 static void test_default_service_port(void)
6436 HINTERNET session
, connect
, request
;
6444 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
6445 ok(session
!= NULL
, "InternetOpen failed\n");
6447 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6448 INTERNET_SERVICE_HTTP
, 0, 0);
6449 ok(connect
!= NULL
, "InternetConnect failed\n");
6451 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
6452 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6454 SetLastError(0xdeadbeef);
6455 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6456 error
= GetLastError();
6457 ok(!ret
, "HttpSendRequest succeeded\n");
6458 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
6461 size
= sizeof(buffer
);
6462 memset(buffer
, 0, sizeof(buffer
));
6463 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6464 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
6465 ok(!strcmp(buffer
, "test.winehq.org:80"), "Expected test.winehg.org:80, got '%s'\n", buffer
);
6467 InternetCloseHandle(request
);
6468 InternetCloseHandle(connect
);
6470 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6471 INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
6472 ok(connect
!= NULL
, "InternetConnect failed\n");
6474 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
6475 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6477 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6478 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
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"), "Expected test.winehg.org, 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
, 0, 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:443"), "Expected test.winehg.org:443, got '%s'\n", buffer
);
6505 InternetCloseHandle(request
);
6506 InternetCloseHandle(connect
);
6507 InternetCloseHandle(session
);
6510 static void init_status_tests(void)
6512 memset(expect
, 0, sizeof(expect
));
6513 memset(optional
, 0, sizeof(optional
));
6514 memset(wine_allow
, 0, sizeof(wine_allow
));
6515 memset(notified
, 0, sizeof(notified
));
6516 memset(status_string
, 0, sizeof(status_string
));
6518 #define STATUS_STRING(status) status_string[status] = #status
6519 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
6520 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
6521 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6522 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6523 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
6524 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
6525 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
6526 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
6527 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
6528 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
6529 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
6530 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
6531 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
6532 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
6533 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
6534 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
6535 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
6536 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
6537 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
6538 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
6539 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
6540 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
6541 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
6542 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
6543 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
6544 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
6545 #undef STATUS_STRING
6548 static void WINAPI
header_cb( HINTERNET handle
, DWORD_PTR ctx
, DWORD status
, LPVOID info
, DWORD len
)
6554 if (status
== INTERNET_STATUS_SENDING_REQUEST
)
6556 ret
= HttpAddRequestHeadersA( handle
, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD
);
6557 ok( ret
, "HttpAddRequestHeadersA failed %u\n", GetLastError() );
6558 SetEvent( (HANDLE
)ctx
);
6560 else if (status
== INTERNET_STATUS_REQUEST_SENT
)
6564 ret
= HttpQueryInfoA( handle
, HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
6565 buf
, &size
, &index
);
6566 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
6567 ok( strstr( buf
, "winetest: winetest" ) != NULL
, "header missing\n" );
6568 SetEvent( (HANDLE
)ctx
);
6572 static void test_concurrent_header_access(void)
6574 HINTERNET ses
, con
, req
;
6577 HANDLE wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
6579 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6580 ok( ses
!= NULL
, "InternetOpenA failed\n" );
6582 con
= InternetConnectA( ses
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
6583 INTERNET_SERVICE_HTTP
, 0, 0 );
6584 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
6586 req
= HttpOpenRequestA( con
, NULL
, "/", NULL
, NULL
, NULL
, 0, (DWORD_PTR
)wait
);
6587 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
6589 pInternetSetStatusCallbackA( req
, header_cb
);
6591 SetLastError( 0xdeadbeef );
6592 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
6593 err
= GetLastError();
6594 ok( !ret
, "HttpSendRequestA succeeded\n" );
6595 ok( err
== ERROR_IO_PENDING
, "got %u\n", ERROR_IO_PENDING
);
6597 WaitForSingleObject( wait
, 5000 );
6598 WaitForSingleObject( wait
, 5000 );
6600 InternetCloseHandle( req
);
6601 InternetCloseHandle( con
);
6602 InternetCloseHandle( ses
);
6603 CloseHandle( wait
);
6609 hdll
= GetModuleHandleA("wininet.dll");
6611 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
6612 win_skip("Too old IE (older than 6.0)\n");
6616 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
6617 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
6618 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
6620 if(!pInternetGetSecurityInfoByURLA
) {
6622 win_skip("IE6 found. It's too old for some tests.\n");
6625 init_status_tests();
6626 test_InternetCloseHandle();
6627 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
6628 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
6629 InternetReadFile_test(0, &test_data
[1]);
6630 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
6631 test_security_flags();
6632 InternetReadFile_test(0, &test_data
[2]);
6633 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
6634 test_open_url_async();
6635 test_async_HttpSendRequestEx(¬ification_data
[0]);
6636 test_async_HttpSendRequestEx(¬ification_data
[1]);
6637 test_async_HttpSendRequestEx(¬ification_data
[2]);
6638 test_async_HttpSendRequestEx(¬ification_data
[3]);
6639 InternetOpenRequest_test();
6641 InternetLockRequestFile_test();
6642 InternetOpenUrlA_test();
6644 test_http_connection();
6645 test_secure_connection();
6646 test_user_agent_header();
6647 test_bogus_accept_types_array();
6648 InternetReadFile_chunked_test();
6649 HttpSendRequestEx_test();
6650 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
6651 test_connection_failure();
6652 test_default_service_port();
6653 test_concurrent_header_access();