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
[10], 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(a,b,c,d,e) _readex_expect_sync_data(__LINE__,a,b,c,d,e)
4908 static void _readex_expect_sync_data(unsigned line
, HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
,
4909 DWORD buf_size
, const char *exdata
)
4911 DWORD len
= strlen(exdata
);
4914 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4916 memset(buf
->lpvBuffer
, 0xff, buf_size
);
4917 buf
->dwBufferLength
= buf_size
;
4918 ret
= InternetReadFileExW(req
, buf
, flags
, 0xdeadbeef);
4919 ok_(__FILE__
,line
)(ret
, "InternetReadFileExW failed: %u\n", GetLastError());
4920 ok_(__FILE__
,line
)(buf
->dwBufferLength
== len
, "dwBufferLength = %u, expected %u\n", buf
->dwBufferLength
, len
);
4922 ok_(__FILE__
,line
)(!memcmp(buf
->lpvBuffer
, exdata
, len
), "Unexpected data\n");
4924 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4927 static void send_response_and_wait(const char *response
, BOOL close_connection
, INTERNET_BUFFERSW
*buf
)
4929 DWORD orig_size
= buf
->dwBufferLength
;
4931 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
4934 server_send_string(response
);
4936 if(close_connection
) {
4938 SetEvent(conn_wait_event
);
4939 recv(server_socket
, &c
, 1, 0);
4942 WaitForSingleObject(hCompleteEvent
, INFINITE
);
4944 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
4946 /* If IRF_NO_WAIT is used, buffer is not changed. */
4947 ok(buf
->dwBufferLength
== orig_size
, "dwBufferLength = %u\n", buf
->dwBufferLength
);
4948 ok(!*(int*)buf
->lpvBuffer
, "buffer data changed\n");
4951 static void readex_expect_async(HINTERNET req
, DWORD flags
, INTERNET_BUFFERSW
*buf
, DWORD buf_size
)
4955 memset(buf
->lpvBuffer
, 0, buf_size
);
4956 buf
->dwBufferLength
= buf_size
;
4957 ret
= InternetReadFileExW(req
, buf
, flags
, 0xdeadbeef);
4958 ok(!ret
&& GetLastError() == ERROR_IO_PENDING
, "InternetReadFileExW returned %x (%u)\n", ret
, GetLastError());
4959 ok(buf
->dwBufferLength
== buf_size
, "dwBufferLength = %u, expected %u\n", buf
->dwBufferLength
, buf_size
);
4960 ok(!*(int*)buf
->lpvBuffer
, "buffer data changed\n");
4963 static void test_http_read(int port
)
4965 INTERNET_BUFFERSW ib
;
4972 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4973 conn_wait_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4974 server_req_rec_event
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
4976 trace("Testing InternetReadFileExW with IRF_NO_WAIT flag...\n");
4978 open_read_test_request(port
, &req
,
4979 "HTTP/1.1 200 OK\r\n"
4980 "Server: winetest\r\n"
4984 memset(&ib
, 0, sizeof(ib
));
4985 ib
.dwStructSize
= sizeof(ib
);
4988 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "xx");
4990 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
4991 send_response_and_wait("1234567890", FALSE
, &ib
);
4992 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, 5, "12345");
4993 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "67890");
4995 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
4996 send_response_and_wait("12345", TRUE
, &ib
);
4998 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "12345");
4999 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "");
5001 close_async_handle(req
.session
, hCompleteEvent
, 2);
5003 open_read_test_request(port
, &req
,
5004 "HTTP/1.1 200 OK\r\n"
5005 "Server: winetest\r\n"
5006 "Transfer-Encoding: chunked\r\n"
5009 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123456789");
5010 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5012 send_response_and_wait("\r\n1\r\na\r\n1\r\nb\r", FALSE
, &ib
);
5013 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab");
5014 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5016 send_response_and_wait("\n3\r\nab", FALSE
, &ib
);
5017 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "ab");
5018 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5020 send_response_and_wait("c", FALSE
, &ib
);
5021 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "c");
5022 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5024 send_response_and_wait("\r\n1\r\nx\r\n0\r\n\r\n", TRUE
, &ib
);
5025 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "x");
5026 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "");
5028 close_async_handle(req
.session
, hCompleteEvent
, 2);
5030 open_read_test_request(port
, &req
,
5031 "HTTP/1.1 200 OK\r\n"
5032 "Server: winetest\r\n"
5033 "Transfer-Encoding: chunked\r\n"
5036 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "123");
5037 readex_expect_async(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
));
5039 send_response_and_wait("0\r\n\r\n", TRUE
, &ib
);
5040 readex_expect_sync_data(req
.request
, IRF_NO_WAIT
, &ib
, sizeof(buf
), "");
5042 close_async_handle(req
.session
, hCompleteEvent
, 2);
5044 CloseHandle(hCompleteEvent
);
5045 CloseHandle(conn_wait_event
);
5046 CloseHandle(server_req_rec_event
);
5049 static void test_long_url(int port
)
5051 char long_path
[INTERNET_MAX_PATH_LENGTH
*2] = "/echo_request?";
5052 char buf
[sizeof(long_path
)*2], url
[sizeof(buf
)];
5060 memset(long_path
+strlen(long_path
), 'x', sizeof(long_path
)-strlen(long_path
));
5061 long_path
[sizeof(long_path
)-1] = 0;
5062 open_simple_request(&req
, "localhost", port
, NULL
, long_path
);
5064 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
5065 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
5066 test_status_code(req
.request
, 200);
5068 receive_simple_request(req
.request
, buf
, sizeof(buf
));
5069 ok(strstr(buf
, long_path
) != NULL
, "long pathnot found in %s\n", buf
);
5071 sprintf(url
, "http://localhost:%u%s", port
, long_path
);
5074 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_URL
, buf
, &size
);
5075 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
5077 ok(size
== len
, "size = %u, expected %u\n", size
, len
);
5078 ok(!strcmp(buf
, url
), "Wrong URL %s, expected %s\n", buf
, url
);
5080 close_request(&req
);
5083 static void test_http_connection(void)
5085 struct server_info si
;
5089 si
.hEvent
= CreateEventW(NULL
, 0, 0, NULL
);
5092 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
5093 ok( hThread
!= NULL
, "create thread failed\n");
5095 r
= WaitForSingleObject(si
.hEvent
, 10000);
5096 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
5097 if (r
!= WAIT_OBJECT_0
)
5100 test_basic_request(si
.port
, "GET", "/test1");
5101 test_proxy_indirect(si
.port
);
5102 test_proxy_direct(si
.port
);
5103 test_header_handling_order(si
.port
);
5104 test_basic_request(si
.port
, "POST", "/test5");
5105 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
5106 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
5107 test_basic_request(si
.port
, "GET", "/test6");
5108 test_basic_request(si
.port
, "GET", "/testF");
5109 test_connection_header(si
.port
);
5110 test_header_override(si
.port
);
5111 test_cookie_header(si
.port
);
5112 test_basic_authentication(si
.port
);
5113 test_invalid_response_headers(si
.port
);
5114 test_response_without_headers(si
.port
);
5115 test_HttpQueryInfo(si
.port
);
5116 test_HttpSendRequestW(si
.port
);
5117 test_options(si
.port
);
5118 test_no_content(si
.port
);
5119 test_conn_close(si
.port
);
5120 test_no_cache(si
.port
);
5121 test_cache_read_gzipped(si
.port
);
5122 test_http_status(si
.port
);
5123 test_premature_disconnect(si
.port
);
5124 test_connection_closing(si
.port
);
5125 test_cache_control_verb(si
.port
);
5126 test_successive_HttpSendRequest(si
.port
);
5127 test_head_request(si
.port
);
5128 test_request_content_length(si
.port
);
5129 test_accept_encoding(si
.port
);
5130 test_basic_auth_credentials_reuse(si
.port
);
5131 test_async_read(si
.port
);
5132 test_http_read(si
.port
);
5133 test_long_url(si
.port
);
5135 /* send the basic request again to shutdown the server thread */
5136 test_basic_request(si
.port
, "GET", "/quit");
5138 r
= WaitForSingleObject(hThread
, 3000);
5139 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
5140 CloseHandle(hThread
);
5143 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
5145 LocalFree(info
->lpszSubjectInfo
);
5146 LocalFree(info
->lpszIssuerInfo
);
5147 LocalFree(info
->lpszProtocolName
);
5148 LocalFree(info
->lpszSignatureAlgName
);
5149 LocalFree(info
->lpszEncryptionAlgName
);
5153 const char *ex_subject
;
5154 const char *ex_issuer
;
5155 } cert_struct_test_t
;
5157 static const cert_struct_test_t test_winehq_org_cert
= {
5162 "RapidSSL SHA256 CA"
5165 static const cert_struct_test_t test_winehq_com_cert
= {
5170 "test.winehq.com\r\n"
5171 "webmaster@winehq.org",
5176 "test.winehq.com\r\n"
5177 "webmaster@winehq.org"
5180 static void test_cert_struct(HINTERNET req
, const cert_struct_test_t
*test
)
5182 INTERNET_CERTIFICATE_INFOA info
;
5186 memset(&info
, 0x5, sizeof(info
));
5188 size
= sizeof(info
);
5189 res
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, &info
, &size
);
5190 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
5191 ok(size
== sizeof(info
), "size = %u\n", size
);
5193 ok(!strcmp(info
.lpszSubjectInfo
, test
->ex_subject
), "lpszSubjectInfo = %s\n", info
.lpszSubjectInfo
);
5194 ok(!strcmp(info
.lpszIssuerInfo
, test
->ex_issuer
), "lpszIssuerInfo = %s\n", info
.lpszIssuerInfo
);
5195 ok(!info
.lpszSignatureAlgName
, "lpszSignatureAlgName = %s\n", info
.lpszSignatureAlgName
);
5196 ok(!info
.lpszEncryptionAlgName
, "lpszEncryptionAlgName = %s\n", info
.lpszEncryptionAlgName
);
5197 ok(!info
.lpszProtocolName
, "lpszProtocolName = %s\n", info
.lpszProtocolName
);
5198 ok(info
.dwKeySize
>= 128 && info
.dwKeySize
<= 256, "dwKeySize = %u\n", info
.dwKeySize
);
5200 release_cert_info(&info
);
5203 #define test_security_info(a,b,c) _test_security_info(__LINE__,a,b,c)
5204 static void _test_security_info(unsigned line
, const char *urlc
, DWORD error
, DWORD ex_flags
)
5206 char url
[INTERNET_MAX_URL_LENGTH
];
5207 const CERT_CHAIN_CONTEXT
*chain
;
5211 if(!pInternetGetSecurityInfoByURLA
) {
5212 win_skip("pInternetGetSecurityInfoByURLA not available\n");
5217 chain
= (void*)0xdeadbeef;
5219 res
= pInternetGetSecurityInfoByURLA(url
, &chain
, &flags
);
5220 if(error
== ERROR_SUCCESS
) {
5221 ok_(__FILE__
,line
)(res
, "InternetGetSecurityInfoByURLA failed: %u\n", GetLastError());
5222 ok_(__FILE__
,line
)(chain
!= NULL
, "chain = NULL\n");
5223 ok_(__FILE__
,line
)(flags
== ex_flags
, "flags = %x\n", flags
);
5224 CertFreeCertificateChain(chain
);
5226 ok_(__FILE__
,line
)(!res
&& GetLastError() == error
,
5227 "InternetGetSecurityInfoByURLA returned: %x(%u), expected %u\n", res
, GetLastError(), error
);
5231 #define test_secflags_option(a,b,c) _test_secflags_option(__LINE__,a,b,c)
5232 static void _test_secflags_option(unsigned line
, HINTERNET req
, DWORD ex_flags
, DWORD opt_flags
)
5238 size
= sizeof(flags
);
5239 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
5240 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
5241 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS flags = %x, expected %x\n",
5244 /* Option 98 is undocumented and seems to be the same as INTERNET_OPTION_SECURITY_FLAGS */
5246 size
= sizeof(flags
);
5247 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
5248 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(98) failed: %u\n", GetLastError());
5249 ok_(__FILE__
,line
)((flags
& ~opt_flags
) == ex_flags
, "INTERNET_OPTION_SECURITY_FLAGS(98) flags = %x, expected %x\n",
5253 #define set_secflags(a,b,c) _set_secflags(__LINE__,a,b,c)
5254 static void _set_secflags(unsigned line
, HINTERNET req
, BOOL use_undoc
, DWORD flags
)
5258 res
= InternetSetOptionW(req
, use_undoc
? 99 : INTERNET_OPTION_SECURITY_FLAGS
, &flags
, sizeof(flags
));
5259 ok_(__FILE__
,line
)(res
, "InternetSetOption(INTERNET_OPTION_SECURITY_FLAGS) failed: %u\n", GetLastError());
5262 static void test_security_flags(void)
5264 INTERNET_CERTIFICATE_INFOA
*cert
;
5265 HINTERNET ses
, conn
, req
;
5270 trace("Testing security flags...\n");
5272 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
5274 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5275 ok(ses
!= NULL
, "InternetOpen failed\n");
5277 pInternetSetStatusCallbackA(ses
, &callback
);
5279 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5280 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
5281 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
5282 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
5283 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5285 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5286 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5287 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5289 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5290 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5293 size
= sizeof(flags
);
5294 res
= InternetQueryOptionW(req
, 98, &flags
, &size
);
5295 if(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
) {
5296 win_skip("Incomplete security flags support, skipping\n");
5298 close_async_handle(ses
, hCompleteEvent
, 2);
5299 CloseHandle(hCompleteEvent
);
5303 test_secflags_option(req
, 0, 0);
5304 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5306 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_REVOCATION
);
5307 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
, 0);
5309 set_secflags(req
, TRUE
, SECURITY_FLAG_IGNORE_CERT_CN_INVALID
);
5310 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
5312 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
5313 test_secflags_option(req
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
, 0);
5315 flags
= SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_SECURE
;
5316 res
= InternetSetOptionW(req
, 99, &flags
, sizeof(flags
));
5317 ok(!res
&& GetLastError() == ERROR_INTERNET_OPTION_NOT_SETTABLE
, "InternetSetOption(99) failed: %u\n", GetLastError());
5319 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
5320 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
5321 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5322 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5323 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5324 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5325 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5326 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5327 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5328 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5329 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5330 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5331 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5332 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5333 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5335 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5336 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5338 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5339 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5341 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
5342 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
5343 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5344 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5345 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5346 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5347 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5348 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5349 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5350 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5351 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5352 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5353 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5355 test_request_flags(req
, 0);
5356 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
5357 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_CERT_CN_INVALID
|SECURITY_FLAG_STRENGTH_STRONG
, 0);
5359 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5360 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5361 ok(size
, "size = 0\n");
5363 /* Collect all existing persistent connections */
5364 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5365 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5367 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5368 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5369 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5371 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5372 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5374 flags
= INTERNET_ERROR_MASK_COMBINED_SEC_CERT
|INTERNET_ERROR_MASK_LOGIN_FAILURE_DISPLAY_ENTITY_BODY
;
5375 res
= InternetSetOptionA(req
, INTERNET_OPTION_ERROR_MASK
, (void*)&flags
, sizeof(flags
));
5376 ok(res
, "InternetQueryOption(INTERNET_OPTION_ERROR_MASK failed: %u\n", GetLastError());
5378 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5379 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5380 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5381 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5382 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5383 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5384 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5385 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5386 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5387 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5388 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5390 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5391 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5393 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5394 ok(req_error
== ERROR_INTERNET_SEC_CERT_REV_FAILED
|| broken(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
),
5395 "req_error = %d\n", req_error
);
5398 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, NULL
, &size
);
5399 ok(res
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5400 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %u\n", size
);
5401 cert
= HeapAlloc(GetProcessHeap(), 0, size
);
5402 cert
->lpszSubjectInfo
= NULL
;
5403 cert
->lpszIssuerInfo
= NULL
;
5404 cert
->lpszSignatureAlgName
= (char *)0xdeadbeef;
5405 cert
->lpszEncryptionAlgName
= (char *)0xdeadbeef;
5406 cert
->lpszProtocolName
= (char *)0xdeadbeef;
5407 cert
->dwKeySize
= 0xdeadbeef;
5408 res
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
, cert
, &size
);
5409 ok(res
, "InternetQueryOption failed: %u\n", GetLastError());
5412 ok(cert
->lpszSubjectInfo
&& strlen(cert
->lpszSubjectInfo
) > 1, "expected a non-empty subject name\n");
5413 ok(cert
->lpszIssuerInfo
&& strlen(cert
->lpszIssuerInfo
) > 1, "expected a non-empty issuer name\n");
5414 ok(!cert
->lpszSignatureAlgName
, "unexpected signature algorithm name\n");
5415 ok(!cert
->lpszEncryptionAlgName
, "unexpected encryption algorithm name\n");
5416 ok(!cert
->lpszProtocolName
, "unexpected protocol name\n");
5417 ok(cert
->dwKeySize
!= 0xdeadbeef, "unexpected key size\n");
5419 HeapFree(GetProcessHeap(), 0, cert
);
5421 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5422 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5423 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
5424 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
5425 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5426 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5427 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5429 if(req_error
!= ERROR_INTERNET_SEC_CERT_REV_FAILED
) {
5430 win_skip("Unexpected cert errors %u, skipping security flags tests\n", req_error
);
5432 close_async_handle(ses
, hCompleteEvent
, 3);
5433 CloseHandle(hCompleteEvent
);
5438 res
= HttpQueryInfoA(req
, HTTP_QUERY_CONTENT_ENCODING
, buf
, &size
, 0);
5439 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfoA(HTTP_QUERY_CONTENT_ENCODING) failed: %u\n", GetLastError());
5441 test_request_flags(req
, 8);
5442 /* IE11 finds both rev failure and invalid CA. Previous versions required rev failure
5443 to be ignored before invalid CA was reported. */
5444 test_secflags_option(req
, _SECURITY_FLAG_CERT_REV_FAILED
, _SECURITY_FLAG_CERT_INVALID_CA
);
5446 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_REVOCATION
);
5447 test_secflags_option(req
, _SECURITY_FLAG_CERT_REV_FAILED
|SECURITY_FLAG_IGNORE_REVOCATION
, _SECURITY_FLAG_CERT_INVALID_CA
);
5449 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5450 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5451 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
5452 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
5453 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5454 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5455 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5457 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5458 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5460 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5461 ok(req_error
== ERROR_INTERNET_SEC_CERT_ERRORS
, "req_error = %d\n", req_error
);
5463 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5464 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5465 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5466 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5467 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5468 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5469 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5471 test_request_flags(req
, INTERNET_REQFLAG_NO_HEADERS
);
5472 test_secflags_option(req
, SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5473 test_security_info("https://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5475 set_secflags(req
, FALSE
, SECURITY_FLAG_IGNORE_UNKNOWN_CA
);
5476 test_secflags_option(req
, _SECURITY_FLAG_CERT_INVALID_CA
|_SECURITY_FLAG_CERT_REV_FAILED
5477 |SECURITY_FLAG_IGNORE_REVOCATION
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
, 0);
5478 test_http_version(req
);
5480 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5481 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5482 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5483 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5484 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5485 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5486 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5487 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5488 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5489 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5490 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5491 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5492 SET_OPTIONAL(INTERNET_STATUS_DETECTING_PROXY
);
5494 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5495 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5497 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5498 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5500 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5501 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5502 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5503 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5504 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5505 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5506 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5507 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5508 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5509 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5510 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
5512 test_request_flags(req
, 0);
5513 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_IGNORE_REVOCATION
5514 |SECURITY_FLAG_STRENGTH_STRONG
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5516 test_cert_struct(req
, &test_winehq_com_cert
);
5517 test_security_info("https://test.winehq.com/data/some_file.html?q", 0,
5518 _SECURITY_FLAG_CERT_INVALID_CA
|_SECURITY_FLAG_CERT_REV_FAILED
);
5520 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5521 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5522 ok(size
, "size = 0\n");
5524 close_async_handle(ses
, hCompleteEvent
, 3);
5526 /* Collect all existing persistent connections */
5527 res
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5528 ok(res
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5530 /* Make another request, without setting security flags */
5532 ses
= InternetOpenA("WineTest", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5533 ok(ses
!= NULL
, "InternetOpen failed\n");
5535 pInternetSetStatusCallbackA(ses
, &callback
);
5537 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5538 conn
= InternetConnectA(ses
, "test.winehq.com", INTERNET_DEFAULT_HTTPS_PORT
,
5539 NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0xdeadbeef);
5540 ok(conn
!= NULL
, "InternetConnect failed with error %u\n", GetLastError());
5541 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5543 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
5544 req
= HttpOpenRequestA(conn
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5545 INTERNET_FLAG_SECURE
|INTERNET_FLAG_KEEP_CONNECTION
|INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
,
5547 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5548 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
5550 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
5551 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5552 test_http_version(req
);
5554 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
5555 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
5556 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
); /* IE11 calls it, it probably reconnects. */
5557 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
); /* IE11 */
5558 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
); /* IE11 */
5559 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
); /* IE11 */
5560 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
5561 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
5562 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
5563 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
5564 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
5565 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
5567 res
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5568 ok(!res
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequest failed: %u\n", GetLastError());
5570 WaitForSingleObject(hCompleteEvent
, INFINITE
);
5571 ok(req_error
== ERROR_SUCCESS
, "req_error = %d\n", req_error
);
5573 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTING_TO_SERVER
, 2);
5574 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTED_TO_SERVER
, 2);
5575 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
5576 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
5577 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
5578 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
5579 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
5580 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
5581 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
5582 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
5584 test_request_flags(req
, 0);
5585 test_secflags_option(req
, SECURITY_FLAG_SECURE
|SECURITY_FLAG_IGNORE_UNKNOWN_CA
|SECURITY_FLAG_STRENGTH_STRONG
5586 |SECURITY_FLAG_IGNORE_REVOCATION
|_SECURITY_FLAG_CERT_REV_FAILED
|_SECURITY_FLAG_CERT_INVALID_CA
, 0);
5588 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
5589 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
5590 ok(size
, "size = 0\n");
5592 close_async_handle(ses
, hCompleteEvent
, 2);
5594 CloseHandle(hCompleteEvent
);
5596 test_security_info("http://test.winehq.com/data/some_file.html?q", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5597 test_security_info("file:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5598 test_security_info("xxx:///c:/dir/file.txt", ERROR_INTERNET_ITEM_NOT_FOUND
, 0);
5601 static void test_secure_connection(void)
5603 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
5604 static const WCHAR testsite
[] = {'t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',0};
5605 static const WCHAR get
[] = {'G','E','T',0};
5606 static const WCHAR testpage
[] = {'/','t','e','s','t','s','/','h','e','l','l','o','.','h','t','m','l',0};
5607 HINTERNET ses
, con
, req
;
5609 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
5610 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
5613 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5614 ok(ses
!= NULL
, "InternetOpen failed\n");
5616 con
= InternetConnectA(ses
, "test.winehq.org",
5617 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
5618 INTERNET_SERVICE_HTTP
, 0, 0);
5619 ok(con
!= NULL
, "InternetConnect failed\n");
5621 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
,
5622 INTERNET_FLAG_SECURE
, 0);
5623 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5625 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5626 ok(ret
|| broken(GetLastError() == ERROR_INTERNET_CANNOT_CONNECT
),
5627 "HttpSendRequest failed: %d\n", GetLastError());
5630 win_skip("Cannot connect to https.\n");
5634 size
= sizeof(flags
);
5635 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
5636 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5637 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
5639 test_cert_struct(req
, &test_winehq_org_cert
);
5641 /* Querying the same option through InternetQueryOptionW still results in
5642 * ASCII strings being returned.
5645 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5647 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5648 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
5649 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
5650 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5651 certificate_structW
, &size
);
5652 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
5653 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5656 ok(certificate_structA
->lpszSubjectInfo
&&
5657 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
5658 "expected a non-empty subject name\n");
5659 ok(certificate_structA
->lpszIssuerInfo
&&
5660 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
5661 "expected a non-empty issuer name\n");
5662 ok(!certificate_structA
->lpszSignatureAlgName
,
5663 "unexpected signature algorithm name\n");
5664 ok(!certificate_structA
->lpszEncryptionAlgName
,
5665 "unexpected encryption algorithm name\n");
5666 ok(!certificate_structA
->lpszProtocolName
,
5667 "unexpected protocol name\n");
5668 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
5669 release_cert_info(certificate_structA
);
5671 HeapFree(GetProcessHeap(), 0, certificate_structW
);
5673 InternetCloseHandle(req
);
5674 InternetCloseHandle(con
);
5675 InternetCloseHandle(ses
);
5677 /* Repeating the tests with the W functions has the same result: */
5678 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5679 ok(ses
!= NULL
, "InternetOpen failed\n");
5681 con
= InternetConnectW(ses
, testsite
,
5682 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
5683 INTERNET_SERVICE_HTTP
, 0, 0);
5684 ok(con
!= NULL
, "InternetConnect failed\n");
5686 req
= HttpOpenRequestW(con
, get
, testpage
, NULL
, NULL
, NULL
,
5687 INTERNET_FLAG_SECURE
|INTERNET_FLAG_RELOAD
, 0);
5688 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5690 ret
= HttpSendRequestA(req
, NULL
, 0, NULL
, 0);
5691 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
5693 size
= sizeof(flags
);
5694 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
5695 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5696 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set, got %x\n", flags
);
5698 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5700 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5701 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
5702 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
5703 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5704 certificate_structA
, &size
);
5705 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5708 ok(certificate_structA
->lpszSubjectInfo
&&
5709 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
5710 "expected a non-empty subject name\n");
5711 ok(certificate_structA
->lpszIssuerInfo
&&
5712 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
5713 "expected a non-empty issuer name\n");
5714 ok(!certificate_structA
->lpszSignatureAlgName
,
5715 "unexpected signature algorithm name\n");
5716 ok(!certificate_structA
->lpszEncryptionAlgName
,
5717 "unexpected encryption algorithm name\n");
5718 ok(!certificate_structA
->lpszProtocolName
,
5719 "unexpected protocol name\n");
5720 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
5721 release_cert_info(certificate_structA
);
5723 HeapFree(GetProcessHeap(), 0, certificate_structA
);
5725 /* Again, querying the same option through InternetQueryOptionW still
5726 * results in ASCII strings being returned.
5729 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5731 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
5732 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
5733 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
5734 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
5735 certificate_structW
, &size
);
5736 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
5737 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
5740 ok(certificate_structA
->lpszSubjectInfo
&&
5741 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
5742 "expected a non-empty subject name\n");
5743 ok(certificate_structA
->lpszIssuerInfo
&&
5744 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
5745 "expected a non-empty issuer name\n");
5746 ok(!certificate_structA
->lpszSignatureAlgName
,
5747 "unexpected signature algorithm name\n");
5748 ok(!certificate_structA
->lpszEncryptionAlgName
,
5749 "unexpected encryption algorithm name\n");
5750 ok(!certificate_structA
->lpszProtocolName
,
5751 "unexpected protocol name\n");
5752 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
5753 release_cert_info(certificate_structA
);
5755 HeapFree(GetProcessHeap(), 0, certificate_structW
);
5758 InternetCloseHandle(req
);
5759 InternetCloseHandle(con
);
5760 InternetCloseHandle(ses
);
5763 static void test_user_agent_header(void)
5765 HINTERNET ses
, con
, req
;
5770 ses
= InternetOpenA("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
5771 ok(ses
!= NULL
, "InternetOpen failed\n");
5773 con
= InternetConnectA(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5774 ok(con
!= NULL
, "InternetConnect failed\n");
5776 req
= HttpOpenRequestA(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
5777 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5779 size
= sizeof(buffer
);
5780 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5781 err
= GetLastError();
5782 ok(!ret
, "HttpQueryInfo succeeded\n");
5783 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
5785 ret
= HttpAddRequestHeadersA(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
5786 ok(ret
, "HttpAddRequestHeaders succeeded\n");
5788 size
= sizeof(buffer
);
5789 ret
= HttpQueryInfoA(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5790 err
= GetLastError();
5791 ok(ret
, "HttpQueryInfo failed\n");
5793 InternetCloseHandle(req
);
5795 req
= HttpOpenRequestA(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
5796 ok(req
!= NULL
, "HttpOpenRequest failed\n");
5798 size
= sizeof(buffer
);
5799 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5800 err
= GetLastError();
5801 ok(!ret
, "HttpQueryInfo succeeded\n");
5802 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
5804 ret
= HttpAddRequestHeadersA(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
5805 ok(ret
, "HttpAddRequestHeaders failed\n");
5808 size
= sizeof(buffer
);
5809 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5810 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
5811 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
5813 InternetCloseHandle(req
);
5814 InternetCloseHandle(con
);
5815 InternetCloseHandle(ses
);
5818 static void test_bogus_accept_types_array(void)
5820 HINTERNET ses
, con
, req
;
5821 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
5826 ses
= InternetOpenA("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
5827 con
= InternetConnectA(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
5828 req
= HttpOpenRequestA(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
5830 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
5833 size
= sizeof(buffer
);
5834 SetLastError(0xdeadbeef);
5835 ret
= HttpQueryInfoA(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
5836 error
= GetLastError();
5837 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
5838 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
5839 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
5840 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
5841 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
5843 InternetCloseHandle(req
);
5844 InternetCloseHandle(con
);
5845 InternetCloseHandle(ses
);
5854 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
5856 INTERNET_ASYNC_RESULT
*result
= info
;
5857 struct context
*ctx
= (struct context
*)context
;
5859 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
5862 case INTERNET_STATUS_REQUEST_COMPLETE
:
5863 trace("request handle: 0x%08lx\n", result
->dwResult
);
5864 ctx
->req
= (HINTERNET
)result
->dwResult
;
5865 SetEvent(ctx
->event
);
5867 case INTERNET_STATUS_HANDLE_CLOSING
: {
5868 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
5870 if (InternetQueryOptionA(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
5871 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
5872 SetEvent(ctx
->event
);
5875 case INTERNET_STATUS_NAME_RESOLVED
:
5876 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
5877 case INTERNET_STATUS_CONNECTED_TO_SERVER
: {
5879 ok(str
[0] && str
[1], "Got string: %s\n", str
);
5880 ok(size
== strlen(str
)+1, "unexpected size %u\n", size
);
5885 static void test_open_url_async(void)
5893 /* Collect all existing persistent connections */
5894 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_SETTINGS_CHANGED
, NULL
, 0);
5895 ok(ret
, "InternetSetOption(INTERNET_OPTION_END_BROWSER_SESSION) failed: %u\n", GetLastError());
5898 * Some versions of IE6 fail those tests. They pass some notification data as UNICODE string, while
5899 * other versions never do. They also hang of following tests. We disable it for everything older
5906 ctx
.event
= CreateEventA(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
5908 ses
= InternetOpenA("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
5909 ok(ses
!= NULL
, "InternetOpen failed\n");
5911 SetLastError(0xdeadbeef);
5912 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
5913 error
= GetLastError();
5914 ok(!ret
, "InternetSetOptionA succeeded\n");
5915 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
5917 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
5918 error
= GetLastError();
5919 ok(!ret
, "InternetSetOptionA failed\n");
5920 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
5922 pInternetSetStatusCallbackW(ses
, cb
);
5923 ResetEvent(ctx
.event
);
5925 req
= InternetOpenUrlA(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
5926 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
5928 WaitForSingleObject(ctx
.event
, INFINITE
);
5931 size
= sizeof(type
);
5932 ret
= InternetQueryOptionA(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
5933 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
5934 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
5935 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
5938 ret
= HttpQueryInfoA(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
5939 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
5940 ok(size
> 0, "expected size > 0\n");
5942 ResetEvent(ctx
.event
);
5943 InternetCloseHandle(ctx
.req
);
5944 WaitForSingleObject(ctx
.event
, INFINITE
);
5946 InternetCloseHandle(ses
);
5947 CloseHandle(ctx
.event
);
5952 internet_connect
= 1,
5954 http_send_request_ex
,
5957 internet_close_handle
5962 enum api function
; /* api responsible for notification */
5963 unsigned int status
; /* status received */
5964 BOOL async
; /* delivered from another thread? */
5972 const struct notification
*test
;
5978 DWORD expect_result
;
5982 static CRITICAL_SECTION notification_cs
;
5984 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
5986 BOOL status_ok
, function_ok
;
5987 struct info
*info
= (struct info
*)context
;
5990 EnterCriticalSection( ¬ification_cs
);
5992 if(info
->is_aborted
) {
5993 LeaveCriticalSection(¬ification_cs
);
5997 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
5999 DWORD size
= sizeof(struct info
*);
6000 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
6001 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
6002 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
6004 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
6005 if(info
->expect_result
== ERROR_SUCCESS
) {
6006 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
6008 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
6009 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
6014 if (i
>= info
->count
)
6016 LeaveCriticalSection( ¬ification_cs
);
6020 while (info
->test
[i
].status
!= status
&&
6021 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
6022 i
< info
->count
- 1 &&
6023 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
6028 status_ok
= (info
->test
[i
].status
== status
);
6029 function_ok
= (info
->test
[i
].function
== info
->function
);
6031 if (!info
->test
[i
].todo
)
6033 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
6034 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
6036 if (info
->test
[i
].async
)
6037 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
6038 info
->line
, info
->thread
, GetCurrentThreadId());
6042 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
6044 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
6046 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
6049 LeaveCriticalSection( ¬ification_cs
);
6052 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
6054 info
->function
= function
;
6056 info
->expect_result
= expect_result
;
6059 struct notification_data
6061 const struct notification
*test
;
6062 const unsigned int count
;
6067 BOOL expect_conn_failure
;
6070 static const struct notification async_send_request_ex_test
[] =
6072 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6073 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6074 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6075 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6076 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6077 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6078 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
6079 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
6080 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6081 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6082 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6083 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, FALSE
},
6084 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, FALSE
},
6085 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6086 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6087 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6088 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6089 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6090 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6091 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6094 static const struct notification async_send_request_ex_test2
[] =
6096 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6097 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6098 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6099 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6100 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6101 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6102 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
, TRUE
},
6103 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
, TRUE
},
6104 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6105 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6106 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6107 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6108 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6109 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6110 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6111 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6112 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6113 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6116 static const struct notification async_send_request_ex_resolve_failure_test
[] =
6118 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6119 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, FALSE
},
6120 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6121 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
},
6122 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6123 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6124 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6125 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, FALSE
, FALSE
, TRUE
},
6126 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, FALSE
, FALSE
, TRUE
},
6127 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, },
6128 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, FALSE
, }
6131 static const struct notification async_send_request_ex_chunked_test
[] =
6133 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
},
6134 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
},
6135 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, TRUE
, FALSE
, TRUE
},
6136 { http_send_request_ex
, INTERNET_STATUS_COOKIE_SENT
, TRUE
, FALSE
, TRUE
},
6137 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, TRUE
, FALSE
, TRUE
},
6138 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, TRUE
, FALSE
, TRUE
},
6139 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, TRUE
},
6140 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, TRUE
},
6141 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, TRUE
},
6142 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, TRUE
},
6143 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6144 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, TRUE
},
6145 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, TRUE
},
6146 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, TRUE
},
6147 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
},
6148 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
},
6149 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
},
6150 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
}
6153 static const struct notification_data notification_data
[] = {
6155 async_send_request_ex_chunked_test
,
6156 sizeof(async_send_request_ex_chunked_test
)/sizeof(async_send_request_ex_chunked_test
[0]),
6162 async_send_request_ex_test
,
6163 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
6167 "Public ID=codeweavers"
6170 async_send_request_ex_test2
,
6171 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
6177 async_send_request_ex_resolve_failure_test
,
6178 sizeof(async_send_request_ex_resolve_failure_test
)/sizeof(async_send_request_ex_resolve_failure_test
[0]),
6187 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
6190 HINTERNET ses
, req
, con
;
6192 DWORD size
, written
, error
;
6193 INTERNET_BUFFERSA b
;
6194 static const char *accept
[2] = {"*/*", NULL
};
6197 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
6199 InitializeCriticalSection( ¬ification_cs
);
6201 info
.test
= nd
->test
;
6202 info
.count
= nd
->count
;
6204 info
.wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
6205 info
.thread
= GetCurrentThreadId();
6206 info
.is_aborted
= FALSE
;
6208 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6209 ok( ses
!= NULL
, "InternetOpen failed\n" );
6211 pInternetSetStatusCallbackA( ses
, check_notification
);
6213 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
6214 con
= InternetConnectA( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
6215 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
6217 WaitForSingleObject( info
.wait
, 10000 );
6219 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
6220 req
= HttpOpenRequestA( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
6221 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
6223 WaitForSingleObject( info
.wait
, 10000 );
6226 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
6227 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
6228 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
6229 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
6230 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
6233 setup_test( &info
, http_send_request_ex
, __LINE__
,
6234 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
6235 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
6236 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
6238 error
= WaitForSingleObject( info
.wait
, 10000 );
6239 if(error
!= WAIT_OBJECT_0
) {
6240 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
6241 info
.is_aborted
= TRUE
;
6245 size
= sizeof(buffer
);
6246 SetLastError( 0xdeadbeef );
6247 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
6248 error
= GetLastError();
6249 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
6250 if(nd
->expect_conn_failure
) {
6251 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
6254 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
6255 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
6261 size
= strlen( nd
->data
);
6262 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
6263 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
6264 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
6265 ok( written
== size
, "expected %u got %u\n", written
, size
);
6267 WaitForSingleObject( info
.wait
, 10000 );
6269 SetLastError( 0xdeadbeef );
6270 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
6271 error
= GetLastError();
6272 ok( !ret
, "HttpEndRequestA succeeded\n" );
6273 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
6276 SetLastError( 0xdeadbeef );
6277 setup_test( &info
, http_end_request
, __LINE__
,
6278 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
6279 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
6280 error
= GetLastError();
6281 ok( !ret
, "HttpEndRequestA succeeded\n" );
6282 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
6284 WaitForSingleObject( info
.wait
, 10000 );
6286 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
6288 InternetCloseHandle( req
);
6289 InternetCloseHandle( con
);
6290 InternetCloseHandle( ses
);
6292 WaitForSingleObject( info
.wait
, 10000 );
6294 CloseHandle( info
.wait
);
6295 DeleteCriticalSection( ¬ification_cs
);
6298 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
6299 static BOOL closetest_closed
;
6301 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
6302 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
6307 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
6309 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
6310 "Unexpected hInternet %p\n", hInternet
);
6311 if(!closetest_closed
)
6315 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
6316 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
6317 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
6318 closetest_req
, res
, GetLastError());
6321 static void test_InternetCloseHandle(void)
6326 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6327 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
6329 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
6331 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
6332 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
6333 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
6335 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
6336 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
6338 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
6339 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
6340 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
6342 test_request_flags(closetest_req
, INTERNET_REQFLAG_NO_HEADERS
);
6344 res
= InternetCloseHandle(closetest_session
);
6345 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
6346 closetest_closed
= TRUE
;
6347 trace("Closed session handle\n");
6349 res
= InternetCloseHandle(closetest_conn
);
6350 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
6351 res
, GetLastError());
6353 res
= InternetCloseHandle(closetest_req
);
6354 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
6355 res
, GetLastError());
6357 len
= sizeof(flags
);
6358 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
6359 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
6360 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
6361 closetest_req
, res
, GetLastError());
6364 static void test_connection_failure(void)
6370 open_simple_request(&req
, "localhost", 1, NULL
, "/");
6372 SetLastError(0xdeadbeef);
6373 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
6374 error
= GetLastError();
6375 ok(!ret
, "unexpected success\n");
6376 ok(error
== ERROR_INTERNET_CANNOT_CONNECT
, "wrong error %u\n", error
);
6378 close_request(&req
);
6381 static void test_default_service_port(void)
6383 HINTERNET session
, connect
, request
;
6391 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
6392 ok(session
!= NULL
, "InternetOpen failed\n");
6394 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6395 INTERNET_SERVICE_HTTP
, 0, 0);
6396 ok(connect
!= NULL
, "InternetConnect failed\n");
6398 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
6399 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6401 SetLastError(0xdeadbeef);
6402 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6403 error
= GetLastError();
6404 ok(!ret
, "HttpSendRequest succeeded\n");
6405 ok(error
== ERROR_INTERNET_SECURITY_CHANNEL_ERROR
|| error
== ERROR_INTERNET_CANNOT_CONNECT
,
6408 size
= sizeof(buffer
);
6409 memset(buffer
, 0, sizeof(buffer
));
6410 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6411 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
6412 ok(!strcmp(buffer
, "test.winehq.org:80"), "Expected test.winehg.org:80, got '%s'\n", buffer
);
6414 InternetCloseHandle(request
);
6415 InternetCloseHandle(connect
);
6417 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6418 INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
6419 ok(connect
!= NULL
, "InternetConnect failed\n");
6421 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
6422 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6424 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6425 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
6427 size
= sizeof(buffer
);
6428 memset(buffer
, 0, sizeof(buffer
));
6429 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6430 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
6431 ok(!strcmp(buffer
, "test.winehq.org"), "Expected test.winehg.org, got '%s'\n", buffer
);
6433 InternetCloseHandle(request
);
6434 InternetCloseHandle(connect
);
6436 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
, NULL
, NULL
,
6437 INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
6438 ok(connect
!= NULL
, "InternetConnect failed\n");
6440 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, NULL
, 0, 0);
6441 ok(request
!= NULL
, "HttpOpenRequest failed\n");
6443 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
6444 ok(ret
, "HttpSendRequest failed with error %u\n", GetLastError());
6446 size
= sizeof(buffer
);
6447 memset(buffer
, 0, sizeof(buffer
));
6448 ret
= HttpQueryInfoA(request
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
6449 ok(ret
, "HttpQueryInfo failed with error %u\n", GetLastError());
6450 ok(!strcmp(buffer
, "test.winehq.org:443"), "Expected test.winehg.org:443, got '%s'\n", buffer
);
6452 InternetCloseHandle(request
);
6453 InternetCloseHandle(connect
);
6454 InternetCloseHandle(session
);
6457 static void init_status_tests(void)
6459 memset(expect
, 0, sizeof(expect
));
6460 memset(optional
, 0, sizeof(optional
));
6461 memset(wine_allow
, 0, sizeof(wine_allow
));
6462 memset(notified
, 0, sizeof(notified
));
6463 memset(status_string
, 0, sizeof(status_string
));
6465 #define STATUS_STRING(status) status_string[status] = #status
6466 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
6467 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
6468 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
6469 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
6470 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
6471 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
6472 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
6473 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
6474 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
6475 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
6476 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
6477 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
6478 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
6479 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
6480 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
6481 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
6482 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
6483 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
6484 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
6485 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
6486 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
6487 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
6488 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
6489 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
6490 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
6491 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
6492 #undef STATUS_STRING
6495 static void WINAPI
header_cb( HINTERNET handle
, DWORD_PTR ctx
, DWORD status
, LPVOID info
, DWORD len
)
6501 if (status
== INTERNET_STATUS_SENDING_REQUEST
)
6503 ret
= HttpAddRequestHeadersA( handle
, "winetest: winetest", ~0u, HTTP_ADDREQ_FLAG_ADD
);
6504 ok( ret
, "HttpAddRequestHeadersA failed %u\n", GetLastError() );
6505 SetEvent( (HANDLE
)ctx
);
6507 else if (status
== INTERNET_STATUS_REQUEST_SENT
)
6511 ret
= HttpQueryInfoA( handle
, HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
6512 buf
, &size
, &index
);
6513 ok( ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
6514 ok( strstr( buf
, "winetest: winetest" ) != NULL
, "header missing\n" );
6515 SetEvent( (HANDLE
)ctx
);
6519 static void test_concurrent_header_access(void)
6521 HINTERNET ses
, con
, req
;
6524 HANDLE wait
= CreateEventW( NULL
, FALSE
, FALSE
, NULL
);
6526 ses
= InternetOpenA( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
6527 ok( ses
!= NULL
, "InternetOpenA failed\n" );
6529 con
= InternetConnectA( ses
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
6530 INTERNET_SERVICE_HTTP
, 0, 0 );
6531 ok( con
!= NULL
, "InternetConnectA failed %u\n", GetLastError() );
6533 req
= HttpOpenRequestA( con
, NULL
, "/", NULL
, NULL
, NULL
, 0, (DWORD_PTR
)wait
);
6534 ok( req
!= NULL
, "HttpOpenRequestA failed %u\n", GetLastError() );
6536 pInternetSetStatusCallbackA( req
, header_cb
);
6538 SetLastError( 0xdeadbeef );
6539 ret
= HttpSendRequestA( req
, NULL
, 0, NULL
, 0 );
6540 err
= GetLastError();
6541 ok( !ret
, "HttpSendRequestA succeeded\n" );
6542 ok( err
== ERROR_IO_PENDING
, "got %u\n", ERROR_IO_PENDING
);
6544 WaitForSingleObject( wait
, 5000 );
6545 WaitForSingleObject( wait
, 5000 );
6547 InternetCloseHandle( req
);
6548 InternetCloseHandle( con
);
6549 InternetCloseHandle( ses
);
6550 CloseHandle( wait
);
6556 hdll
= GetModuleHandleA("wininet.dll");
6558 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
6559 win_skip("Too old IE (older than 6.0)\n");
6563 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
6564 pInternetSetStatusCallbackW
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackW");
6565 pInternetGetSecurityInfoByURLA
= (void*)GetProcAddress(hdll
, "InternetGetSecurityInfoByURLA");
6567 if(!pInternetGetSecurityInfoByURLA
) {
6569 win_skip("IE6 found. It's too old for some tests.\n");
6572 init_status_tests();
6573 test_InternetCloseHandle();
6574 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
6575 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
6576 InternetReadFile_test(0, &test_data
[1]);
6577 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
6578 test_security_flags();
6579 InternetReadFile_test(0, &test_data
[2]);
6580 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
6581 test_open_url_async();
6582 test_async_HttpSendRequestEx(¬ification_data
[0]);
6583 test_async_HttpSendRequestEx(¬ification_data
[1]);
6584 test_async_HttpSendRequestEx(¬ification_data
[2]);
6585 test_async_HttpSendRequestEx(¬ification_data
[3]);
6586 InternetOpenRequest_test();
6588 InternetLockRequestFile_test();
6589 InternetOpenUrlA_test();
6591 test_http_connection();
6592 test_secure_connection();
6593 test_user_agent_header();
6594 test_bogus_accept_types_array();
6595 InternetReadFile_chunked_test();
6596 HttpSendRequestEx_test();
6597 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);
6598 test_connection_failure();
6599 test_default_service_port();
6600 test_concurrent_header_access();