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
32 #include "wine/test.h"
34 #define TEST_URL "http://test.winehq.org/tests/hello.html"
36 static BOOL first_connection_to_test_url
= TRUE
;
38 /* Adapted from dlls/urlmon/tests/protocol.c */
40 #define SET_EXPECT2(status, num) \
43 #define SET_EXPECT(status) \
44 SET_EXPECT2(status, 1)
46 #define SET_OPTIONAL2(status, num) \
47 optional[status] = num
49 #define SET_OPTIONAL(status) \
50 SET_OPTIONAL2(status, 1)
52 /* SET_WINE_ALLOW's should be used with an appropriate
53 * todo_wine CHECK_NOTIFIED at a later point in the code */
54 #define SET_WINE_ALLOW2(status, num) \
55 wine_allow[status] = num
57 #define SET_WINE_ALLOW(status) \
58 SET_WINE_ALLOW2(status, 1)
60 #define CHECK_EXPECT(status) \
62 if (!expect[status] && !optional[status] && wine_allow[status]) \
64 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
65 status < MAX_INTERNET_STATUS && status_string[status] ? \
66 status_string[status] : "unknown"); \
67 wine_allow[status]--; \
71 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
72 status < MAX_INTERNET_STATUS && status_string[status] ? \
73 status_string[status] : "unknown"); \
74 if (expect[status]) expect[status]--; \
75 else optional[status]--; \
80 /* CLEAR_NOTIFIED used in cases when notification behavior
81 * differs between Windows versions */
82 #define CLEAR_NOTIFIED(status) \
83 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
85 #define CHECK_NOTIFIED2(status, num) \
87 ok(notified[status] + optional[status] == (num), \
88 "expected status %d (%s) %d times, received %d times\n", \
89 status, status < MAX_INTERNET_STATUS && status_string[status] ? \
90 status_string[status] : "unknown", (num), notified[status]); \
91 CLEAR_NOTIFIED(status); \
94 #define CHECK_NOTIFIED(status) \
95 CHECK_NOTIFIED2(status, 1)
97 #define CHECK_NOT_NOTIFIED(status) \
98 CHECK_NOTIFIED2(status, 0)
100 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
101 static int expect
[MAX_INTERNET_STATUS
], optional
[MAX_INTERNET_STATUS
],
102 wine_allow
[MAX_INTERNET_STATUS
], notified
[MAX_INTERNET_STATUS
];
103 static const char *status_string
[MAX_INTERNET_STATUS
];
105 static HANDLE hCompleteEvent
, conn_close_event
;
106 static DWORD req_error
;
108 #define TESTF_REDIRECT 0x01
109 #define TESTF_COMPRESSED 0x02
110 #define TESTF_ALLOW_COOKIE 0x04
111 #define TESTF_CHUNKED 0x08
115 const char *redirected_url
;
120 const char *post_data
;
124 static const test_data_t test_data
[] = {
126 "http://test.winehq.org/tests/data.php",
127 "http://test.winehq.org/tests/data.php",
134 "http://test.winehq.org/tests/redirect",
135 "http://test.winehq.org/tests/hello.html",
142 "http://www.codeweavers.com/",
143 "http://www.codeweavers.com/",
144 "www.codeweavers.com",
146 "Accept-Encoding: gzip, deflate",
147 TESTF_COMPRESSED
|TESTF_ALLOW_COOKIE
150 "http://test.winehq.org/tests/post.php",
151 "http://test.winehq.org/tests/post.php",
154 "Content-Type: application/x-www-form-urlencoded",
161 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackA
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
163 static BOOL
proxy_active(void)
165 HKEY internet_settings
;
169 if (RegOpenKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
170 0, KEY_QUERY_VALUE
, &internet_settings
) != ERROR_SUCCESS
)
173 size
= sizeof(DWORD
);
174 if (RegQueryValueExA(internet_settings
, "ProxyEnable", NULL
, NULL
, (LPBYTE
) &proxy_enable
, &size
) != ERROR_SUCCESS
)
177 RegCloseKey(internet_settings
);
179 return proxy_enable
!= 0;
182 static int close_handle_cnt
;
184 static VOID WINAPI
callback(
187 DWORD dwInternetStatus
,
188 LPVOID lpvStatusInformation
,
189 DWORD dwStatusInformationLength
192 CHECK_EXPECT(dwInternetStatus
);
193 switch (dwInternetStatus
)
195 case INTERNET_STATUS_RESOLVING_NAME
:
196 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
197 GetCurrentThreadId(), hInternet
, dwContext
,
198 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
199 *(LPSTR
)lpvStatusInformation
= '\0';
201 case INTERNET_STATUS_NAME_RESOLVED
:
202 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
203 GetCurrentThreadId(), hInternet
, dwContext
,
204 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
205 *(LPSTR
)lpvStatusInformation
= '\0';
207 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
208 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
209 GetCurrentThreadId(), hInternet
, dwContext
,
210 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
211 *(LPSTR
)lpvStatusInformation
= '\0';
213 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
214 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
215 GetCurrentThreadId(), hInternet
, dwContext
,
216 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
217 *(LPSTR
)lpvStatusInformation
= '\0';
219 case INTERNET_STATUS_SENDING_REQUEST
:
220 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
221 GetCurrentThreadId(), hInternet
, dwContext
,
222 lpvStatusInformation
,dwStatusInformationLength
);
224 case INTERNET_STATUS_REQUEST_SENT
:
225 ok(dwStatusInformationLength
== sizeof(DWORD
),
226 "info length should be sizeof(DWORD) instead of %d\n",
227 dwStatusInformationLength
);
228 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
229 GetCurrentThreadId(), hInternet
, dwContext
,
230 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
232 case INTERNET_STATUS_RECEIVING_RESPONSE
:
233 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
234 GetCurrentThreadId(), hInternet
, dwContext
,
235 lpvStatusInformation
,dwStatusInformationLength
);
237 case INTERNET_STATUS_RESPONSE_RECEIVED
:
238 ok(dwStatusInformationLength
== sizeof(DWORD
),
239 "info length should be sizeof(DWORD) instead of %d\n",
240 dwStatusInformationLength
);
241 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
242 GetCurrentThreadId(), hInternet
, dwContext
,
243 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
245 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
246 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
247 GetCurrentThreadId(), hInternet
,dwContext
,
248 lpvStatusInformation
,dwStatusInformationLength
);
250 case INTERNET_STATUS_PREFETCH
:
251 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
252 GetCurrentThreadId(), hInternet
, dwContext
,
253 lpvStatusInformation
,dwStatusInformationLength
);
255 case INTERNET_STATUS_CLOSING_CONNECTION
:
256 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
257 GetCurrentThreadId(), hInternet
, dwContext
,
258 lpvStatusInformation
,dwStatusInformationLength
);
260 case INTERNET_STATUS_CONNECTION_CLOSED
:
261 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
262 GetCurrentThreadId(), hInternet
, dwContext
,
263 lpvStatusInformation
,dwStatusInformationLength
);
265 case INTERNET_STATUS_HANDLE_CREATED
:
266 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
267 "info length should be sizeof(HINTERNET) instead of %d\n",
268 dwStatusInformationLength
);
269 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
270 GetCurrentThreadId(), hInternet
, dwContext
,
271 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
272 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
273 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
275 case INTERNET_STATUS_HANDLE_CLOSING
:
276 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
277 "info length should be sizeof(HINTERNET) instead of %d\n",
278 dwStatusInformationLength
);
279 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
280 GetCurrentThreadId(), hInternet
, dwContext
,
281 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
282 if(!--close_handle_cnt
)
283 SetEvent(hCompleteEvent
);
285 case INTERNET_STATUS_REQUEST_COMPLETE
:
287 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
288 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
289 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
290 dwStatusInformationLength
);
291 ok(iar
->dwResult
== 1 || iar
->dwResult
== 0, "iar->dwResult = %ld\n", iar
->dwResult
);
292 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
293 GetCurrentThreadId(), hInternet
, dwContext
,
294 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
295 req_error
= iar
->dwError
;
296 SetEvent(hCompleteEvent
);
299 case INTERNET_STATUS_REDIRECT
:
300 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
301 GetCurrentThreadId(), hInternet
, dwContext
,
302 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
303 *(LPSTR
)lpvStatusInformation
= '\0';
304 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
305 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
307 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
308 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
309 GetCurrentThreadId(), hInternet
, dwContext
,
310 lpvStatusInformation
, dwStatusInformationLength
);
313 trace("%04x:Callback %p 0x%lx %d %p %d\n",
314 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
315 lpvStatusInformation
, dwStatusInformationLength
);
319 static void close_async_handle(HINTERNET handle
, HANDLE complete_event
, int handle_cnt
)
323 close_handle_cnt
= handle_cnt
;
325 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
326 res
= InternetCloseHandle(handle
);
327 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
328 WaitForSingleObject(hCompleteEvent
, INFINITE
);
329 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
330 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
333 static void InternetReadFile_test(int flags
, const test_data_t
*test
)
335 char *post_data
= NULL
;
336 BOOL res
, on_async
= TRUE
;
338 DWORD length
, post_len
= 0;
340 const char *types
[2] = { "*", NULL
};
341 HINTERNET hi
, hic
= 0, hor
= 0;
343 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
345 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags
,test
->url
);
347 trace("InternetOpenA <--\n");
348 hi
= InternetOpenA((test
->flags
& TESTF_COMPRESSED
) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
349 INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
350 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
351 trace("InternetOpenA -->\n");
353 if (hi
== 0x0) goto abort
;
355 pInternetSetStatusCallbackA(hi
,&callback
);
357 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
359 trace("InternetConnectA <--\n");
360 hic
=InternetConnectA(hi
, test
->host
, INTERNET_INVALID_PORT_NUMBER
,
361 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
362 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
363 trace("InternetConnectA -->\n");
365 if (hic
== 0x0) goto abort
;
367 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
368 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
370 trace("HttpOpenRequestA <--\n");
371 hor
= HttpOpenRequestA(hic
, test
->post_data
? "POST" : "GET", test
->path
, NULL
, NULL
, types
,
372 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
,
374 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
376 * If the internet name can't be resolved we are probably behind
377 * a firewall or in some other way not directly connected to the
378 * Internet. Not enough reason to fail the test. Just ignore and
382 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
384 trace("HttpOpenRequestA -->\n");
386 if (hor
== 0x0) goto abort
;
388 length
= sizeof(buffer
);
389 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
390 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
391 ok(!strcmp(buffer
, test
->url
), "Wrong URL %s, expected %s\n", buffer
, test
->url
);
393 length
= sizeof(buffer
);
394 res
= HttpQueryInfoA(hor
, HTTP_QUERY_RAW_HEADERS
, buffer
, &length
, 0x0);
395 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
396 ok(length
== 0, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length
);
397 ok(!strcmp(buffer
, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer
);
399 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
400 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
401 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
402 if(test
->flags
& TESTF_ALLOW_COOKIE
) {
403 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
404 SET_OPTIONAL(INTERNET_STATUS_COOKIE_RECEIVED
);
406 if (first_connection_to_test_url
)
408 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
409 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
411 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
412 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
413 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
414 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
415 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
416 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
417 if(test
->flags
& TESTF_REDIRECT
) {
418 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
419 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
421 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
422 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
423 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
424 if (flags
& INTERNET_FLAG_ASYNC
)
425 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
427 if(test
->flags
& TESTF_COMPRESSED
) {
430 res
= InternetSetOption(hor
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
431 ok(res
|| broken(!res
&& GetLastError() == ERROR_INTERNET_INVALID_OPTION
),
432 "InternetSetOption failed: %u\n", GetLastError());
437 trace("HttpSendRequestA -->\n");
438 if(test
->post_data
) {
439 post_len
= strlen(test
->post_data
);
440 post_data
= HeapAlloc(GetProcessHeap(), 0, post_len
);
441 memcpy(post_data
, test
->post_data
, post_len
);
443 SetLastError(0xdeadbeef);
444 res
= HttpSendRequestA(hor
, test
->headers
, -1, post_data
, post_len
);
445 if (flags
& INTERNET_FLAG_ASYNC
)
446 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
447 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
449 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
450 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
451 trace("HttpSendRequestA <--\n");
453 if (flags
& INTERNET_FLAG_ASYNC
) {
454 WaitForSingleObject(hCompleteEvent
, INFINITE
);
455 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
457 HeapFree(GetProcessHeap(), 0, post_data
);
459 if(test
->flags
& TESTF_ALLOW_COOKIE
) {
460 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
461 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED
);
463 if (first_connection_to_test_url
)
465 if (! proxy_active())
467 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
468 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
472 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
473 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
478 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
479 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
481 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
482 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
483 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
484 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
485 if(test
->flags
& TESTF_REDIRECT
)
486 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
487 if (flags
& INTERNET_FLAG_ASYNC
)
488 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
489 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
490 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
491 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
494 res
= InternetQueryOptionA(hor
,INTERNET_OPTION_REQUEST_FLAGS
,&out
,&length
);
495 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_REQUEST) failed with error %d\n", GetLastError());
498 res
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
499 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
501 length
= sizeof(buffer
);
502 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
503 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
506 length
= sizeof(buffer
);
507 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
508 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
509 ok(!strcmp(buffer
, test
->redirected_url
), "Wrong URL %s\n", buffer
);
512 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
513 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res
,buffer
,GetLastError());
514 if(test
->flags
& TESTF_COMPRESSED
)
515 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
516 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res
, GetLastError());
519 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
521 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res
,buffer
);
524 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_ENCODING
,buffer
,&length
,0x0);
526 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res
,buffer
);
528 SetLastError(0xdeadbeef);
529 res
= InternetReadFile(NULL
, buffer
, 100, &length
);
530 ok(!res
, "InternetReadFile should have failed\n");
531 ok(GetLastError() == ERROR_INVALID_HANDLE
,
532 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
536 trace("Entering Query loop\n");
540 if (flags
& INTERNET_FLAG_ASYNC
)
541 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
542 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
543 if (flags
& INTERNET_FLAG_ASYNC
)
547 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
549 else if (GetLastError() == ERROR_IO_PENDING
)
552 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
553 if(!(test
->flags
& TESTF_CHUNKED
))
554 ok(!length
, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length
);
555 WaitForSingleObject(hCompleteEvent
, INFINITE
);
556 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
557 ok(req_error
, "req_error = 0\n");
560 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
563 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
565 trace("LENGTH %d\n", length
);
566 if(test
->flags
& TESTF_CHUNKED
)
567 ok(length
<= 8192, "length = %d, expected <= 8192\n", length
);
571 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
573 res
= InternetReadFile(hor
,buffer
,length
,&length
);
577 trace("ReadFile -> %s %i\n",res
?"TRUE":"FALSE",length
);
580 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
581 HeapFree(GetProcessHeap(),0,buffer
);
583 ok(!on_async
, "Returned zero size in response to request complete\n");
588 if(test
->flags
& TESTF_REDIRECT
) {
589 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
590 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
594 close_async_handle(hi
, hCompleteEvent
, 2);
595 CloseHandle(hCompleteEvent
);
596 first_connection_to_test_url
= FALSE
;
599 static void InternetReadFile_chunked_test(void)
604 const char *types
[2] = { "*", NULL
};
605 HINTERNET hi
, hic
= 0, hor
= 0;
607 trace("Starting InternetReadFile chunked test\n");
609 trace("InternetOpenA <--\n");
610 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
611 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
612 trace("InternetOpenA -->\n");
614 if (hi
== 0x0) goto abort
;
616 trace("InternetConnectA <--\n");
617 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
618 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
619 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
620 trace("InternetConnectA -->\n");
622 if (hic
== 0x0) goto abort
;
624 trace("HttpOpenRequestA <--\n");
625 hor
= HttpOpenRequestA(hic
, "GET", "/tests/chunked", NULL
, NULL
, types
,
626 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
,
628 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
630 * If the internet name can't be resolved we are probably behind
631 * a firewall or in some other way not directly connected to the
632 * Internet. Not enough reason to fail the test. Just ignore and
636 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
638 trace("HttpOpenRequestA -->\n");
640 if (hor
== 0x0) goto abort
;
642 trace("HttpSendRequestA -->\n");
643 SetLastError(0xdeadbeef);
644 res
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
645 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
646 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
647 trace("HttpSendRequestA <--\n");
650 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
652 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
654 SetLastError( 0xdeadbeef );
656 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
658 trace("Option TRANSFER_ENCODING -> %i %s\n",res
,buffer
);
659 ok( res
|| ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
660 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
661 ok( !strcmp( buffer
, "chunked" ) || ( ! res
&& proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
662 "Wrong transfer encoding '%s'\n", buffer
);
664 SetLastError( 0xdeadbeef );
666 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
667 ok( !res
, "Found CONTENT_LENGTH option '%s'\n", buffer
);
668 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Wrong error %u\n", GetLastError() );
671 trace("Entering Query loop\n");
675 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
676 ok(!(!res
&& length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
677 ok(res
, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
678 trace("got %u available\n",length
);
682 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
684 res
= InternetReadFile(hor
,buffer
,length
,&got
);
687 trace("ReadFile -> %i %i\n",res
,got
);
688 ok( length
== got
, "only got %u of %u available\n", got
, length
);
689 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
691 HeapFree(GetProcessHeap(),0,buffer
);
700 res
= InternetCloseHandle(hor
);
701 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
704 res
= InternetCloseHandle(hi
);
705 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
709 static void InternetReadFileExA_test(int flags
)
713 const char *types
[2] = { "*", NULL
};
714 HINTERNET hi
, hic
= 0, hor
= 0;
715 INTERNET_BUFFERS inetbuffers
;
717 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
719 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
721 trace("InternetOpenA <--\n");
722 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
723 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
724 trace("InternetOpenA -->\n");
726 if (hi
== 0x0) goto abort
;
728 pInternetSetStatusCallbackA(hi
,&callback
);
730 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
732 trace("InternetConnectA <--\n");
733 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
734 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
735 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
736 trace("InternetConnectA -->\n");
738 if (hic
== 0x0) goto abort
;
740 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
741 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
743 trace("HttpOpenRequestA <--\n");
744 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
745 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
,
747 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
749 * If the internet name can't be resolved we are probably behind
750 * a firewall or in some other way not directly connected to the
751 * Internet. Not enough reason to fail the test. Just ignore and
755 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
757 trace("HttpOpenRequestA -->\n");
759 if (hor
== 0x0) goto abort
;
761 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
762 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
763 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
764 if (first_connection_to_test_url
)
766 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
767 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
769 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
770 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
771 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
772 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
773 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
774 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
775 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
776 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
777 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
778 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
779 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
780 if (flags
& INTERNET_FLAG_ASYNC
)
781 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
783 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
785 trace("HttpSendRequestA -->\n");
786 SetLastError(0xdeadbeef);
787 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
788 if (flags
& INTERNET_FLAG_ASYNC
)
789 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
790 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
792 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
793 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
794 trace("HttpSendRequestA <--\n");
796 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
797 WaitForSingleObject(hCompleteEvent
, INFINITE
);
798 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
801 if (first_connection_to_test_url
)
803 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
804 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
808 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
809 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
811 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
812 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
813 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
814 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
815 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
816 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
817 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
818 if (flags
& INTERNET_FLAG_ASYNC
)
819 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
821 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
822 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
823 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
824 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
826 /* tests invalid dwStructSize */
827 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
)+1;
828 inetbuffers
.lpcszHeader
= NULL
;
829 inetbuffers
.dwHeadersLength
= 0;
830 inetbuffers
.dwBufferLength
= 10;
831 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
832 inetbuffers
.dwOffsetHigh
= 1234;
833 inetbuffers
.dwOffsetLow
= 5678;
834 rc
= InternetReadFileEx(hor
, &inetbuffers
, 0, 0xdeadcafe);
835 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
836 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
837 rc
? "TRUE" : "FALSE", GetLastError());
838 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
840 /* tests to see whether lpcszHeader is used - it isn't */
841 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
);
842 inetbuffers
.lpcszHeader
= (LPCTSTR
)0xdeadbeef;
843 inetbuffers
.dwHeadersLength
= 255;
844 inetbuffers
.dwBufferLength
= 0;
845 inetbuffers
.lpvBuffer
= NULL
;
846 inetbuffers
.dwOffsetHigh
= 1234;
847 inetbuffers
.dwOffsetLow
= 5678;
848 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
849 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
850 rc
= InternetReadFileEx(hor
, &inetbuffers
, 0, 0xdeadcafe);
851 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
852 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
855 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
856 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
859 rc
= InternetReadFileEx(NULL
, &inetbuffers
, 0, 0xdeadcafe);
860 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
861 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
862 rc
? "TRUE" : "FALSE", GetLastError());
865 trace("Entering Query loop\n");
869 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
);
870 inetbuffers
.dwBufferLength
= 1024;
871 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
872 inetbuffers
.dwOffsetHigh
= 1234;
873 inetbuffers
.dwOffsetLow
= 5678;
875 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
876 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
877 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
878 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
881 if (GetLastError() == ERROR_IO_PENDING
)
883 trace("InternetReadFileEx -> PENDING\n");
884 ok(flags
& INTERNET_FLAG_ASYNC
,
885 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
886 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
887 WaitForSingleObject(hCompleteEvent
, INFINITE
);
888 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
889 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
890 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
894 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
900 trace("InternetReadFileEx -> SUCCEEDED\n");
901 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
902 if (inetbuffers
.dwBufferLength
)
905 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
906 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
911 /* Win98 still sends these when 0 bytes are read, WinXP does not */
912 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
913 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
917 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
918 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
920 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
921 "InternetReadFileEx sets offsets to 0x%x%08x\n",
922 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
924 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
926 if (!inetbuffers
.dwBufferLength
)
929 length
+= inetbuffers
.dwBufferLength
;
931 ok(length
> 0, "failed to read any of the document\n");
932 trace("Finished. Read %d bytes\n", length
);
935 close_async_handle(hi
, hCompleteEvent
, 2);
936 CloseHandle(hCompleteEvent
);
937 first_connection_to_test_url
= FALSE
;
940 static void InternetOpenUrlA_test(void)
942 HINTERNET myhinternet
, myhttp
;
944 DWORD size
, readbytes
, totalbytes
=0;
947 myhinternet
= InternetOpen("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
948 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
950 ret
= InternetCanonicalizeUrl(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
951 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
954 myhttp
= InternetOpenUrl(myhinternet
, TEST_URL
, 0, 0,
955 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
956 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
957 return; /* WinXP returns this when not connected to the net */
958 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
959 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
960 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
961 totalbytes
+= readbytes
;
962 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
963 totalbytes
+= readbytes
;
964 trace("read 0x%08x bytes\n",totalbytes
);
966 InternetCloseHandle(myhttp
);
967 InternetCloseHandle(myhinternet
);
970 static void HttpSendRequestEx_test(void)
976 INTERNET_BUFFERS BufferIn
;
977 DWORD dwBytesWritten
, dwBytesRead
, error
;
982 static char szPostData
[] = "mode=Test";
983 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
985 hSession
= InternetOpen("Wine Regression Test",
986 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
987 ok( hSession
!= NULL
,"Unable to open Internet session\n");
988 hConnect
= InternetConnect(hSession
, "crossover.codeweavers.com",
989 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
991 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
992 hRequest
= HttpOpenRequest(hConnect
, "POST", "/posttest.php",
993 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
994 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
996 skip( "Network unreachable, skipping test\n" );
999 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1002 BufferIn
.dwStructSize
= sizeof( INTERNET_BUFFERS
);
1003 BufferIn
.Next
= (LPINTERNET_BUFFERS
)0xdeadcab;
1004 BufferIn
.lpcszHeader
= szContentType
;
1005 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1006 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1007 BufferIn
.lpvBuffer
= szPostData
;
1008 BufferIn
.dwBufferLength
= 3;
1009 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1010 BufferIn
.dwOffsetLow
= 0;
1011 BufferIn
.dwOffsetHigh
= 0;
1013 SetLastError(0xdeadbeef);
1014 ret
= HttpSendRequestEx(hRequest
, &BufferIn
, NULL
, 0 ,0);
1015 error
= GetLastError();
1016 ok(ret
, "HttpSendRequestEx Failed with error %u\n", error
);
1017 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", error
);
1019 for (i
= 3; szPostData
[i
]; i
++)
1020 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1021 "InternetWriteFile failed\n");
1023 ok(HttpEndRequest(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1025 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1026 "Unable to read response\n");
1027 szBuffer
[dwBytesRead
] = 0;
1029 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
1030 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1032 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1034 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1035 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1038 static void InternetOpenRequest_test(void)
1040 HINTERNET session
, connect
, request
;
1041 static const char *types
[] = { "*", "", NULL
};
1042 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1043 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1046 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1047 ok(session
!= NULL
,"Unable to open Internet session\n");
1049 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1050 INTERNET_SERVICE_HTTP
, 0, 0);
1051 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1052 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1054 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1055 INTERNET_SERVICE_HTTP
, 0, 0);
1056 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1057 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1059 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1060 INTERNET_SERVICE_HTTP
, 0, 0);
1061 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1063 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1064 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1066 skip( "Network unreachable, skipping test\n" );
1069 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1071 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1072 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1073 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1075 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1076 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1078 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1079 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1080 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1083 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1084 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1087 static void test_http_cache(void)
1089 HINTERNET session
, connect
, request
;
1090 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1091 DWORD size
, file_size
;
1096 static const char *types
[] = { "*", "", NULL
};
1098 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1099 ok(session
!= NULL
,"Unable to open Internet session\n");
1101 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1102 INTERNET_SERVICE_HTTP
, 0, 0);
1103 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1105 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1106 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1108 skip( "Network unreachable, skipping test\n" );
1110 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1111 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1115 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1118 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1119 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1120 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1122 size
= sizeof(file_name
);
1123 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1124 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1125 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1126 ok(!size
, "size = %d\n", size
);
1128 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1129 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1131 size
= sizeof(file_name
);
1132 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1133 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1135 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1136 FILE_ATTRIBUTE_NORMAL
, NULL
);
1137 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1138 file_size
= GetFileSize(file
, NULL
);
1139 todo_wine
ok(file_size
== 106, "file size = %u\n", file_size
);
1142 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1143 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1144 ok(size
== 100, "size = %u\n", size
);
1146 file_size
= GetFileSize(file
, NULL
);
1147 todo_wine
ok(file_size
== 106, "file size = %u\n", file_size
);
1150 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1152 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1153 FILE_ATTRIBUTE_NORMAL
, NULL
);
1154 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1157 /* Send the same request, requiring it to be retrieved from the cache */
1158 request
= HttpOpenRequest(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1160 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1161 ok(ret
, "HttpSendRequest failed\n");
1164 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1165 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1166 ok(size
== 100, "size = %u\n", size
);
1168 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1170 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1171 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1173 size
= sizeof(file_name
);
1174 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1175 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1176 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1177 ok(!size
, "size = %d\n", size
);
1179 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1180 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1182 size
= sizeof(file_name
);
1184 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1187 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1188 FILE_ATTRIBUTE_NORMAL
, NULL
);
1189 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1195 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1198 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1199 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1200 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1203 static void HttpHeaders_test(void)
1214 hSession
= InternetOpen("Wine Regression Test",
1215 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1216 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1217 hConnect
= InternetConnect(hSession
, "crossover.codeweavers.com",
1218 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1220 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
1221 hRequest
= HttpOpenRequest(hConnect
, "POST", "/posttest.php",
1222 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1223 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1225 skip( "Network unreachable, skipping test\n" );
1228 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1231 len
= sizeof(buffer
);
1232 strcpy(buffer
,"Warning");
1233 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1234 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1236 ok(HttpAddRequestHeaders(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1237 "Failed to add new header\n");
1240 len
= sizeof(buffer
);
1241 strcpy(buffer
,"Warning");
1242 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1243 buffer
,&len
,&index
),"Unable to query header\n");
1244 ok(index
== 1, "Index was not incremented\n");
1245 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1246 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1247 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1248 len
= sizeof(buffer
);
1249 strcpy(buffer
,"Warning");
1250 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1251 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1254 len
= 5; /* could store the string but not the NULL terminator */
1255 strcpy(buffer
,"Warning");
1256 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1257 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1258 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1259 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1261 /* a call with NULL will fail but will return the length */
1263 len
= sizeof(buffer
);
1264 SetLastError(0xdeadbeef);
1265 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1266 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1267 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1268 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1269 ok(index
== 0, "Index was incremented\n");
1271 /* even for a len that is too small */
1274 SetLastError(0xdeadbeef);
1275 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1276 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1277 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1278 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1279 ok(index
== 0, "Index was incremented\n");
1283 SetLastError(0xdeadbeef);
1284 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1285 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1286 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1287 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1288 ok(index
== 0, "Index was incremented\n");
1289 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1292 /* a working query */
1294 len
= sizeof(buffer
);
1295 memset(buffer
, 'x', sizeof(buffer
));
1296 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1297 buffer
,&len
,&index
),"Unable to query header\n");
1298 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1299 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1300 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1301 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1302 ok(strncmp(buffer
, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1303 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1304 ok(index
== 0, "Index was incremented\n");
1306 /* Like above two tests, but for W version */
1310 SetLastError(0xdeadbeef);
1311 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1312 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1313 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1314 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1315 ok(index
== 0, "Index was incremented\n");
1316 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1318 /* a working query */
1320 len
= sizeof(wbuffer
);
1321 memset(wbuffer
, 'x', sizeof(wbuffer
));
1322 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1323 wbuffer
,&len
,&index
),"Unable to query header\n");
1324 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1325 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1326 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1327 ok(index
== 0, "Index was incremented\n");
1329 /* end of W version tests */
1331 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1333 len
= sizeof(buffer
);
1334 memset(buffer
, 'x', sizeof(buffer
));
1335 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1336 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1337 ok(len
== 2, "Expected 2, got %d\n", len
);
1338 ok(strcmp(buffer
, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer
);
1339 ok(index
== 0, "Index was incremented\n");
1341 ok(HttpAddRequestHeaders(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1342 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1345 len
= sizeof(buffer
);
1346 strcpy(buffer
,"Warning");
1347 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1348 buffer
,&len
,&index
),"Unable to query header\n");
1349 ok(index
== 1, "Index was not incremented\n");
1350 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1351 len
= sizeof(buffer
);
1352 strcpy(buffer
,"Warning");
1353 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1354 buffer
,&len
,&index
),"Failed to get second header\n");
1355 ok(index
== 2, "Index was not incremented\n");
1356 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1357 len
= sizeof(buffer
);
1358 strcpy(buffer
,"Warning");
1359 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1360 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1362 ok(HttpAddRequestHeaders(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1365 len
= sizeof(buffer
);
1366 strcpy(buffer
,"Warning");
1367 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1368 buffer
,&len
,&index
),"Unable to query header\n");
1369 ok(index
== 1, "Index was not incremented\n");
1370 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1371 len
= sizeof(buffer
);
1372 strcpy(buffer
,"Warning");
1373 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1374 buffer
,&len
,&index
),"Failed to get second header\n");
1375 ok(index
== 2, "Index was not incremented\n");
1376 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1377 len
= sizeof(buffer
);
1378 strcpy(buffer
,"Warning");
1379 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1380 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1382 ok(HttpAddRequestHeaders(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1385 len
= sizeof(buffer
);
1386 strcpy(buffer
,"Warning");
1387 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1388 buffer
,&len
,&index
),"Unable to query header\n");
1389 ok(index
== 1, "Index was not incremented\n");
1390 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1391 len
= sizeof(buffer
);
1392 strcpy(buffer
,"Warning");
1393 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1394 buffer
,&len
,&index
),"Failed to get second header\n");
1395 ok(index
== 2, "Index was not incremented\n");
1396 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1397 len
= sizeof(buffer
);
1398 strcpy(buffer
,"Warning");
1399 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1400 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1402 ok(HttpAddRequestHeaders(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1405 len
= sizeof(buffer
);
1406 strcpy(buffer
,"Warning");
1407 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1408 buffer
,&len
,&index
),"Unable to query header\n");
1409 ok(index
== 1, "Index was not incremented\n");
1410 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1411 len
= sizeof(buffer
);
1412 strcpy(buffer
,"Warning");
1413 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1414 ok(index
== 2, "Index was not incremented\n");
1415 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1416 len
= sizeof(buffer
);
1417 strcpy(buffer
,"Warning");
1418 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1420 ok(HttpAddRequestHeaders(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1423 len
= sizeof(buffer
);
1424 strcpy(buffer
,"Warning");
1425 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1426 ok(index
== 1, "Index was not incremented\n");
1427 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1428 len
= sizeof(buffer
);
1429 strcpy(buffer
,"Warning");
1430 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1431 ok(index
== 2, "Index was not incremented\n");
1432 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1433 len
= sizeof(buffer
);
1434 strcpy(buffer
,"Warning");
1435 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1437 ok(HttpAddRequestHeaders(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1440 len
= sizeof(buffer
);
1441 strcpy(buffer
,"Warning");
1442 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1443 ok(index
== 1, "Index was not incremented\n");
1444 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1445 len
= sizeof(buffer
);
1446 strcpy(buffer
,"Warning");
1447 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1448 ok(index
== 2, "Index was not incremented\n");
1449 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1450 len
= sizeof(buffer
);
1451 strcpy(buffer
,"Warning");
1452 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1454 ok(HttpAddRequestHeaders(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");
1457 len
= sizeof(buffer
);
1458 strcpy(buffer
,"Warning");
1459 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1460 ok(index
== 1, "Index was not incremented\n");
1461 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1462 len
= sizeof(buffer
);
1463 strcpy(buffer
,"Warning");
1464 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1465 ok(index
== 2, "Index was not incremented\n");
1466 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1467 len
= sizeof(buffer
);
1468 strcpy(buffer
,"Warning");
1469 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1471 /* Ensure that blank headers are ignored and don't cause a failure */
1472 ok(HttpAddRequestHeaders(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");
1475 len
= sizeof(buffer
);
1476 strcpy(buffer
,"BlankTest");
1477 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1478 ok(index
== 1, "Index was not incremented\n");
1479 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1481 /* Ensure that malformed header separators are ignored and don't cause a failure */
1482 ok(HttpAddRequestHeaders(hRequest
,"\r\rMalformedTest:value\n\nMalformedTestTwo: value2\rMalformedTestThree: value3\n\n\r\r\n",-1, HTTP_ADDREQ_FLAG_ADD
|HTTP_ADDREQ_FLAG_REPLACE
),
1483 "Failed to add header with malformed entries in list\n");
1486 len
= sizeof(buffer
);
1487 strcpy(buffer
,"MalformedTest");
1488 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1489 ok(index
== 1, "Index was not incremented\n");
1490 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1492 len
= sizeof(buffer
);
1493 strcpy(buffer
,"MalformedTestTwo");
1494 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1495 ok(index
== 1, "Index was not incremented\n");
1496 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
1498 len
= sizeof(buffer
);
1499 strcpy(buffer
,"MalformedTestThree");
1500 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1501 ok(index
== 1, "Index was not incremented\n");
1502 ok(strcmp(buffer
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
1504 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1506 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1507 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1510 static const char garbagemsg
[] =
1511 "Garbage: Header\r\n";
1513 static const char contmsg
[] =
1514 "HTTP/1.1 100 Continue\r\n";
1516 static const char expandcontmsg
[] =
1517 "HTTP/1.1 100 Continue\r\n"
1518 "Server: winecontinue\r\n"
1519 "Tag: something witty\r\n"
1522 static const char okmsg
[] =
1523 "HTTP/1.1 200 OK\r\n"
1524 "Server: winetest\r\n"
1527 static const char okmsg2
[] =
1528 "HTTP/1.1 200 OK\r\n"
1529 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1530 "Server: winetest\r\n"
1531 "Content-Length: 0\r\n"
1532 "Set-Cookie: one\r\n"
1533 "Set-Cookie: two\r\n"
1536 static const char notokmsg
[] =
1537 "HTTP/1.1 400 Bad Request\r\n"
1538 "Server: winetest\r\n"
1541 static const char noauthmsg
[] =
1542 "HTTP/1.1 401 Unauthorized\r\n"
1543 "Server: winetest\r\n"
1544 "Connection: close\r\n"
1545 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1548 static const char noauthmsg2
[] =
1549 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
1550 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
1552 "Server: winetest\r\n";
1554 static const char proxymsg
[] =
1555 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1556 "Server: winetest\r\n"
1557 "Proxy-Connection: close\r\n"
1558 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1561 static const char page1
[] =
1563 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1564 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1567 struct server_info
{
1570 int num_testH_retrievals
;
1573 static DWORD CALLBACK
server_thread(LPVOID param
)
1575 struct server_info
*si
= param
;
1578 struct sockaddr_in sa
;
1581 int last_request
= 0;
1582 char host_header
[22];
1583 static int test_b
= 0;
1585 WSAStartup(MAKEWORD(1,1), &wsaData
);
1587 s
= socket(AF_INET
, SOCK_STREAM
, 0);
1588 if (s
== INVALID_SOCKET
)
1592 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
1594 memset(&sa
, 0, sizeof sa
);
1595 sa
.sin_family
= AF_INET
;
1596 sa
.sin_port
= htons(si
->port
);
1597 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
1599 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
1605 SetEvent(si
->hEvent
);
1607 sprintf(host_header
, "Host: localhost:%d", si
->port
);
1611 c
= accept(s
, NULL
, NULL
);
1613 memset(buffer
, 0, sizeof buffer
);
1614 for(i
=0; i
<(sizeof buffer
-1); i
++)
1616 r
= recv(c
, &buffer
[i
], 1, 0);
1620 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
1621 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
1624 if (strstr(buffer
, "GET /test1"))
1626 if (!strstr(buffer
, "Content-Length: 0"))
1628 send(c
, okmsg
, sizeof okmsg
-1, 0);
1629 send(c
, page1
, sizeof page1
-1, 0);
1632 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1634 if (strstr(buffer
, "/test2"))
1636 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
1638 send(c
, okmsg
, sizeof okmsg
-1, 0);
1639 send(c
, page1
, sizeof page1
-1, 0);
1642 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
1644 if (strstr(buffer
, "/test3"))
1646 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
1647 send(c
, okmsg
, sizeof okmsg
-1, 0);
1649 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
1651 if (strstr(buffer
, "/test4"))
1653 if (strstr(buffer
, "Connection: Close"))
1654 send(c
, okmsg
, sizeof okmsg
-1, 0);
1656 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1658 if (strstr(buffer
, "POST /test5") ||
1659 strstr(buffer
, "RPC_IN_DATA /test5") ||
1660 strstr(buffer
, "RPC_OUT_DATA /test5"))
1662 if (strstr(buffer
, "Content-Length: 0"))
1664 send(c
, okmsg
, sizeof okmsg
-1, 0);
1665 send(c
, page1
, sizeof page1
-1, 0);
1668 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1670 if (strstr(buffer
, "GET /test6"))
1672 send(c
, contmsg
, sizeof contmsg
-1, 0);
1673 send(c
, contmsg
, sizeof contmsg
-1, 0);
1674 send(c
, okmsg
, sizeof okmsg
-1, 0);
1675 send(c
, page1
, sizeof page1
-1, 0);
1677 if (strstr(buffer
, "POST /test7"))
1679 if (strstr(buffer
, "Content-Length: 100"))
1681 send(c
, okmsg
, sizeof okmsg
-1, 0);
1682 send(c
, page1
, sizeof page1
-1, 0);
1685 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1687 if (strstr(buffer
, "/test8"))
1689 if (!strstr(buffer
, "Connection: Close") &&
1690 strstr(buffer
, "Connection: Keep-Alive") &&
1691 !strstr(buffer
, "Cache-Control: no-cache") &&
1692 !strstr(buffer
, "Pragma: no-cache") &&
1693 strstr(buffer
, host_header
))
1694 send(c
, okmsg
, sizeof okmsg
-1, 0);
1696 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1698 if (strstr(buffer
, "/test9"))
1700 if (!strstr(buffer
, "Connection: Close") &&
1701 !strstr(buffer
, "Connection: Keep-Alive") &&
1702 !strstr(buffer
, "Cache-Control: no-cache") &&
1703 !strstr(buffer
, "Pragma: no-cache") &&
1704 strstr(buffer
, host_header
))
1705 send(c
, okmsg
, sizeof okmsg
-1, 0);
1707 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1709 if (strstr(buffer
, "/testA"))
1711 if (!strstr(buffer
, "Connection: Close") &&
1712 !strstr(buffer
, "Connection: Keep-Alive") &&
1713 (strstr(buffer
, "Cache-Control: no-cache") ||
1714 strstr(buffer
, "Pragma: no-cache")) &&
1715 strstr(buffer
, host_header
))
1716 send(c
, okmsg
, sizeof okmsg
-1, 0);
1718 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1720 if (!test_b
&& strstr(buffer
, "/testB HTTP/1.1"))
1723 send(c
, okmsg
, sizeof okmsg
-1, 0);
1724 recvfrom(c
, buffer
, sizeof buffer
, 0, NULL
, NULL
);
1725 send(c
, okmsg
, sizeof okmsg
-1, 0);
1727 if (strstr(buffer
, "/testC"))
1729 if (strstr(buffer
, "Cookie: cookie=biscuit"))
1730 send(c
, okmsg
, sizeof okmsg
-1, 0);
1732 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1734 if (strstr(buffer
, "/testD"))
1736 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
1738 if (strstr(buffer
, "/testE"))
1740 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
1742 if (strstr(buffer
, "GET /quit"))
1744 send(c
, okmsg
, sizeof okmsg
-1, 0);
1745 send(c
, page1
, sizeof page1
-1, 0);
1748 if (strstr(buffer
, "GET /testF"))
1750 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
1751 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
1752 send(c
, contmsg
, sizeof contmsg
-1, 0);
1753 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
1754 send(c
, okmsg
, sizeof okmsg
-1, 0);
1755 send(c
, page1
, sizeof page1
-1, 0);
1757 if (strstr(buffer
, "GET /testG"))
1759 send(c
, page1
, sizeof page1
-1, 0);
1761 if (strstr(buffer
, "GET /testH"))
1763 si
->num_testH_retrievals
++;
1764 if (!strstr(buffer
, "Content-Length: 0"))
1766 send(c
, okmsg
, sizeof okmsg
-1, 0);
1767 send(c
, page1
, sizeof page1
-1, 0);
1770 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1772 if (strstr(buffer
, "GET /test_no_content"))
1774 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
1775 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
1777 if (strstr(buffer
, "GET /test_conn_close"))
1779 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
1780 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
1781 WaitForSingleObject(conn_close_event
, INFINITE
);
1782 trace("closing connection\n");
1787 } while (!last_request
);
1794 static void test_basic_request(int port
, const char *verb
, const char *url
)
1796 HINTERNET hi
, hc
, hr
;
1800 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1801 ok(hi
!= NULL
, "open failed\n");
1803 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1804 ok(hc
!= NULL
, "connect failed\n");
1806 hr
= HttpOpenRequest(hc
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
1807 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1809 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1810 ok(r
, "HttpSendRequest failed\n");
1813 memset(buffer
, 0, sizeof buffer
);
1814 SetLastError(0xdeadbeef);
1815 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
1816 ok(r
, "InternetReadFile failed %u\n", GetLastError());
1817 ok(count
== sizeof page1
- 1, "count was wrong\n");
1818 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
1820 InternetCloseHandle(hr
);
1821 InternetCloseHandle(hc
);
1822 InternetCloseHandle(hi
);
1825 static void test_last_error(int port
)
1827 HINTERNET hi
, hc
, hr
;
1831 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1832 ok(hi
!= NULL
, "open failed\n");
1834 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1835 ok(hc
!= NULL
, "connect failed\n");
1837 hr
= HttpOpenRequest(hc
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
1838 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1840 SetLastError(0xdeadbeef);
1841 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1842 error
= GetLastError();
1843 ok(r
, "HttpSendRequest failed\n");
1844 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
1846 InternetCloseHandle(hr
);
1847 InternetCloseHandle(hc
);
1848 InternetCloseHandle(hi
);
1851 static void test_proxy_indirect(int port
)
1853 HINTERNET hi
, hc
, hr
;
1857 hi
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
1858 ok(hi
!= NULL
, "open failed\n");
1860 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1861 ok(hc
!= NULL
, "connect failed\n");
1863 hr
= HttpOpenRequest(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
1864 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1866 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1867 ok(r
, "HttpSendRequest failed\n");
1870 r
= HttpQueryInfo(hr
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
1871 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
1874 skip("missing proxy header, not testing remaining proxy headers\n");
1877 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
1880 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1881 ok(r
, "HttpQueryInfo failed\n");
1882 ok(!strcmp(buffer
, "407"), "proxy code wrong\n");
1885 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &val
, &sz
, NULL
);
1886 ok(r
, "HttpQueryInfo failed\n");
1887 ok(val
== 407, "proxy code wrong\n");
1890 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
1891 ok(r
, "HttpQueryInfo failed\n");
1892 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
1895 r
= HttpQueryInfo(hr
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
1896 ok(r
, "HttpQueryInfo failed\n");
1897 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
1900 r
= HttpQueryInfo(hr
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
1901 ok(r
, "HttpQueryInfo failed\n");
1902 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
1905 r
= HttpQueryInfo(hr
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
1906 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
1907 ok(r
== FALSE
, "HttpQueryInfo failed\n");
1910 InternetCloseHandle(hr
);
1911 InternetCloseHandle(hc
);
1912 InternetCloseHandle(hi
);
1915 static void test_proxy_direct(int port
)
1917 HINTERNET hi
, hc
, hr
;
1920 static CHAR username
[] = "mike",
1921 password
[] = "1101";
1923 sprintf(buffer
, "localhost:%d\n", port
);
1924 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
1925 ok(hi
!= NULL
, "open failed\n");
1927 /* try connect without authorization */
1928 hc
= InternetConnect(hi
, "test.winehq.org/", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1929 ok(hc
!= NULL
, "connect failed\n");
1931 hr
= HttpOpenRequest(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
1932 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1934 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1935 ok(r
, "HttpSendRequest failed\n");
1938 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1939 ok(r
, "HttpQueryInfo failed\n");
1940 ok(!strcmp(buffer
, "407"), "proxy code wrong\n");
1943 /* set the user + password then try again */
1945 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
1946 ok(r
, "failed to set user\n");
1948 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
1949 ok(r
, "failed to set password\n");
1952 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1953 ok(r
, "HttpSendRequest failed\n");
1955 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1956 ok(r
, "HttpQueryInfo failed\n");
1958 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
1962 InternetCloseHandle(hr
);
1963 InternetCloseHandle(hc
);
1964 InternetCloseHandle(hi
);
1967 static void test_header_handling_order(int port
)
1969 static char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
1970 static char connection
[] = "Connection: Close";
1972 static const char *types
[2] = { "*", NULL
};
1973 HINTERNET session
, connect
, request
;
1977 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1978 ok(session
!= NULL
, "InternetOpen failed\n");
1980 connect
= InternetConnect(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1981 ok(connect
!= NULL
, "InternetConnect failed\n");
1983 request
= HttpOpenRequest(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1984 ok(request
!= NULL
, "HttpOpenRequest failed\n");
1986 ret
= HttpAddRequestHeaders(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
1987 ok(ret
, "HttpAddRequestHeaders failed\n");
1989 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1990 ok(ret
, "HttpSendRequest failed\n");
1993 size
= sizeof(status
);
1994 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1995 ok(ret
, "HttpQueryInfo failed\n");
1996 ok(status
== 200, "request failed with status %u\n", status
);
1998 InternetCloseHandle(request
);
2000 request
= HttpOpenRequest(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2001 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2003 ret
= HttpSendRequest(request
, connection
, ~0u, NULL
, 0);
2004 ok(ret
, "HttpSendRequest failed\n");
2007 size
= sizeof(status
);
2008 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2009 ok(ret
, "HttpQueryInfo failed\n");
2010 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2012 InternetCloseHandle(request
);
2014 request
= HttpOpenRequest(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2015 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2017 ret
= HttpAddRequestHeaders(request
, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
2018 ok(ret
, "HttpAddRequestHeaders failed\n");
2020 ret
= HttpSendRequest(request
, connection
, ~0u, NULL
, 0);
2021 ok(ret
, "HttpSendRequest failed\n");
2024 size
= sizeof(status
);
2025 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2026 ok(ret
, "HttpQueryInfo failed\n");
2027 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
2029 InternetCloseHandle(request
);
2030 InternetCloseHandle(connect
);
2031 InternetCloseHandle(session
);
2034 static void test_connection_header(int port
)
2036 HINTERNET ses
, con
, req
;
2040 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2041 ok(ses
!= NULL
, "InternetOpen failed\n");
2043 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2044 ok(con
!= NULL
, "InternetConnect failed\n");
2046 req
= HttpOpenRequest(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2047 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2049 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2050 ok(ret
, "HttpSendRequest failed\n");
2053 size
= sizeof(status
);
2054 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2055 ok(ret
, "HttpQueryInfo failed\n");
2056 ok(status
== 200, "request failed with status %u\n", status
);
2058 InternetCloseHandle(req
);
2060 req
= HttpOpenRequest(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
2061 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2063 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2064 ok(ret
, "HttpSendRequest failed\n");
2067 size
= sizeof(status
);
2068 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2069 ok(ret
, "HttpQueryInfo failed\n");
2070 ok(status
== 200, "request failed with status %u\n", status
);
2072 InternetCloseHandle(req
);
2074 req
= HttpOpenRequest(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2075 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2077 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2078 ok(ret
, "HttpSendRequest failed\n");
2081 size
= sizeof(status
);
2082 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2083 ok(ret
, "HttpQueryInfo failed\n");
2084 ok(status
== 200, "request failed with status %u\n", status
);
2086 InternetCloseHandle(req
);
2088 req
= HttpOpenRequest(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
2089 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2091 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2092 ok(ret
, "HttpSendRequest failed\n");
2095 size
= sizeof(status
);
2096 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2097 ok(ret
, "HttpQueryInfo failed\n");
2098 ok(status
== 200, "request failed with status %u\n", status
);
2100 InternetCloseHandle(req
);
2101 InternetCloseHandle(con
);
2102 InternetCloseHandle(ses
);
2105 static void test_http1_1(int port
)
2107 HINTERNET ses
, con
, req
;
2110 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2111 ok(ses
!= NULL
, "InternetOpen failed\n");
2113 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2114 ok(con
!= NULL
, "InternetConnect failed\n");
2116 req
= HttpOpenRequest(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2117 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2119 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2122 InternetCloseHandle(req
);
2124 req
= HttpOpenRequest(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2125 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2127 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2128 ok(ret
, "HttpSendRequest failed\n");
2131 InternetCloseHandle(req
);
2132 InternetCloseHandle(con
);
2133 InternetCloseHandle(ses
);
2136 static void test_no_content(int port
)
2138 HINTERNET session
, connection
, req
;
2141 trace("Testing 204 no content response...\n");
2143 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2145 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2146 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2148 pInternetSetStatusCallbackA(session
, callback
);
2150 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2151 connection
= InternetConnectA(session
, "localhost", port
,
2152 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2153 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2154 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2156 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2157 req
= HttpOpenRequestA(connection
, "GET", "/test_no_content", NULL
, NULL
, NULL
,
2158 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
2159 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2160 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2162 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2163 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2164 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2165 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2166 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2167 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2168 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2169 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
2170 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
2171 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2173 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
2174 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2175 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2176 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2177 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2179 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2180 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2181 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2182 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2183 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2184 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2185 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2186 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2187 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2188 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2190 close_async_handle(session
, hCompleteEvent
, 2);
2191 CloseHandle(hCompleteEvent
);
2194 static void test_conn_close(int port
)
2196 HINTERNET session
, connection
, req
;
2197 DWORD res
, avail
, size
;
2200 trace("Testing connection close connection...\n");
2202 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2203 conn_close_event
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
2205 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2206 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
2208 pInternetSetStatusCallbackA(session
, callback
);
2210 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2211 connection
= InternetConnectA(session
, "localhost", port
,
2212 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
2213 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
2214 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2216 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
2217 req
= HttpOpenRequestA(connection
, "GET", "/test_conn_close", NULL
, NULL
, NULL
,
2218 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
2219 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2220 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
2222 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT
);
2223 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2224 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2225 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST
);
2226 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT
);
2227 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
2228 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
2229 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2231 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
2232 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2233 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2234 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2235 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2237 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
2238 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2239 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2240 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
2241 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
2242 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
2243 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
2244 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2247 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
2248 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
2249 ok(avail
!= 0, "avail = 0\n");
2252 res
= InternetReadFile(req
, buf
, avail
, &size
);
2253 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
2255 res
= InternetQueryDataAvailable(req
, &avail
, 0, 0);
2256 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
2257 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2258 ok(!avail
, "avail = %u, expected 0\n", avail
);
2260 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
2261 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
2262 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
2263 SetEvent(conn_close_event
);
2264 WaitForSingleObject(hCompleteEvent
, INFINITE
);
2265 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
2266 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
2267 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
2268 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
2270 close_async_handle(session
, hCompleteEvent
, 2);
2271 CloseHandle(hCompleteEvent
);
2274 static void test_HttpSendRequestW(int port
)
2276 static const WCHAR header
[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
2277 HINTERNET ses
, con
, req
;
2281 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2282 ok(ses
!= NULL
, "InternetOpen failed\n");
2284 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2285 ok(con
!= NULL
, "InternetConnect failed\n");
2287 req
= HttpOpenRequest(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
2288 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2290 SetLastError(0xdeadbeef);
2291 ret
= HttpSendRequestW(req
, header
, ~0u, NULL
, 0);
2292 error
= GetLastError();
2293 ok(!ret
, "HttpSendRequestW succeeded\n");
2294 ok(error
== ERROR_IO_PENDING
||
2295 broken(error
== ERROR_HTTP_HEADER_NOT_FOUND
) || /* IE6 */
2296 broken(error
== ERROR_INVALID_PARAMETER
), /* IE5 */
2297 "got %u expected ERROR_IO_PENDING\n", error
);
2299 InternetCloseHandle(req
);
2300 InternetCloseHandle(con
);
2301 InternetCloseHandle(ses
);
2304 static void test_cookie_header(int port
)
2306 HINTERNET ses
, con
, req
;
2307 DWORD size
, status
, error
;
2311 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2312 ok(ses
!= NULL
, "InternetOpen failed\n");
2314 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2315 ok(con
!= NULL
, "InternetConnect failed\n");
2317 InternetSetCookie("http://localhost", "cookie", "biscuit");
2319 req
= HttpOpenRequest(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2320 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2323 size
= sizeof(buffer
);
2324 SetLastError(0xdeadbeef);
2325 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
2326 error
= GetLastError();
2327 ok(!ret
, "HttpQueryInfo succeeded\n");
2328 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
2330 ret
= HttpAddRequestHeaders(req
, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD
);
2331 ok(ret
, "HttpAddRequestHeaders failed: %u\n", GetLastError());
2334 size
= sizeof(buffer
);
2335 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
2336 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
2337 ok(!strcmp(buffer
, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer
);
2339 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2340 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
2343 size
= sizeof(status
);
2344 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2345 ok(ret
, "HttpQueryInfo failed\n");
2346 ok(status
== 200, "request failed with status %u\n", status
);
2349 size
= sizeof(buffer
);
2350 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
2351 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
2352 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
2354 InternetCloseHandle(req
);
2355 InternetCloseHandle(con
);
2356 InternetCloseHandle(ses
);
2359 static void test_basic_authentication(int port
)
2361 HINTERNET session
, connect
, request
;
2365 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2366 ok(session
!= NULL
, "InternetOpen failed\n");
2368 connect
= InternetConnect(session
, "localhost", port
, "user", "pwd", INTERNET_SERVICE_HTTP
, 0, 0);
2369 ok(connect
!= NULL
, "InternetConnect failed\n");
2371 request
= HttpOpenRequest(connect
, NULL
, "/test3", NULL
, NULL
, NULL
, 0, 0);
2372 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2374 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
2375 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
2378 size
= sizeof(status
);
2379 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2380 ok(ret
, "HttpQueryInfo failed\n");
2381 ok(status
== 200, "request failed with status %u\n", status
);
2383 InternetCloseHandle(request
);
2384 InternetCloseHandle(connect
);
2385 InternetCloseHandle(session
);
2388 static void test_invalid_response_headers(int port
)
2390 HINTERNET session
, connect
, request
;
2395 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2396 ok(session
!= NULL
, "InternetOpen failed\n");
2398 connect
= InternetConnect(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2399 ok(connect
!= NULL
, "InternetConnect failed\n");
2401 request
= HttpOpenRequest(connect
, NULL
, "/testE", NULL
, NULL
, NULL
, 0, 0);
2402 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2404 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
2405 ok(ret
, "HttpSendRequest failed %u\n", GetLastError());
2408 size
= sizeof(status
);
2409 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2410 ok(ret
, "HttpQueryInfo failed\n");
2411 ok(status
== 401, "unexpected status %u\n", status
);
2414 size
= sizeof(buffer
);
2415 ret
= HttpQueryInfo( request
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
2416 ok(ret
, "HttpQueryInfo failed\n");
2417 ok(!strcmp(buffer
, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
2418 "headers wrong \"%s\"\n", buffer
);
2421 size
= sizeof(buffer
);
2422 ret
= HttpQueryInfo( request
, HTTP_QUERY_SERVER
, buffer
, &size
, NULL
);
2423 ok(ret
, "HttpQueryInfo failed\n");
2424 ok(!strcmp(buffer
, "winetest"), "server wrong \"%s\"\n", buffer
);
2426 InternetCloseHandle(request
);
2427 InternetCloseHandle(connect
);
2428 InternetCloseHandle(session
);
2431 static void test_response_without_headers(int port
)
2433 HINTERNET hi
, hc
, hr
;
2434 DWORD r
, count
, size
, status
;
2437 SetLastError(0xdeadbeef);
2438 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2439 ok(hi
!= NULL
, "open failed %u\n", GetLastError());
2441 SetLastError(0xdeadbeef);
2442 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2443 ok(hc
!= NULL
, "connect failed %u\n", GetLastError());
2445 SetLastError(0xdeadbeef);
2446 hr
= HttpOpenRequest(hc
, NULL
, "/testG", NULL
, NULL
, NULL
, 0, 0);
2447 ok(hr
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError());
2449 SetLastError(0xdeadbeef);
2450 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
2451 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2454 memset(buffer
, 0, sizeof buffer
);
2455 SetLastError(0xdeadbeef);
2456 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
2457 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2458 todo_wine
ok(count
== sizeof page1
- 1, "count was wrong\n");
2459 todo_wine
ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
2462 size
= sizeof(status
);
2463 SetLastError(0xdeadbeef);
2464 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
2465 todo_wine
ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
2466 todo_wine
ok(status
== 200, "expected status 200 got %u\n", status
);
2469 size
= sizeof(buffer
);
2470 SetLastError(0xdeadbeef);
2471 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, NULL
);
2472 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
2473 ok(!strcmp(buffer
, "OK"), "expected OK got: \"%s\"\n", buffer
);
2476 size
= sizeof(buffer
);
2477 SetLastError(0xdeadbeef);
2478 r
= HttpQueryInfo(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, NULL
);
2479 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
2480 ok(!strcmp(buffer
, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer
);
2483 size
= sizeof(buffer
);
2484 SetLastError(0xdeadbeef);
2485 r
= HttpQueryInfo(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, NULL
);
2486 ok(r
, "HttpQueryInfo failed %u\n", GetLastError());
2487 ok(!strcmp(buffer
, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer
);
2489 InternetCloseHandle(hr
);
2490 InternetCloseHandle(hc
);
2491 InternetCloseHandle(hi
);
2494 static void test_HttpQueryInfo(int port
)
2496 HINTERNET hi
, hc
, hr
;
2501 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2502 ok(hi
!= NULL
, "InternetOpen failed\n");
2504 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2505 ok(hc
!= NULL
, "InternetConnect failed\n");
2507 hr
= HttpOpenRequest(hc
, NULL
, "/testD", NULL
, NULL
, NULL
, 0, 0);
2508 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2510 ret
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
2511 ok(ret
, "HttpSendRequest failed\n");
2514 size
= sizeof(buffer
);
2515 ret
= HttpQueryInfo(hr
, HTTP_QUERY_HOST
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, &index
);
2516 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2517 ok(index
== 1, "expected 1 got %u\n", index
);
2520 size
= sizeof(buffer
);
2521 ret
= HttpQueryInfo(hr
, HTTP_QUERY_DATE
| HTTP_QUERY_FLAG_SYSTEMTIME
, buffer
, &size
, &index
);
2522 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2523 ok(index
== 1, "expected 1 got %u\n", index
);
2526 size
= sizeof(buffer
);
2527 ret
= HttpQueryInfo(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
2528 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2529 ok(index
== 0, "expected 0 got %u\n", index
);
2531 size
= sizeof(buffer
);
2532 ret
= HttpQueryInfo(hr
, HTTP_QUERY_RAW_HEADERS
, buffer
, &size
, &index
);
2533 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2534 ok(index
== 0, "expected 0 got %u\n", index
);
2536 size
= sizeof(buffer
);
2537 ret
= HttpQueryInfo(hr
, HTTP_QUERY_RAW_HEADERS_CRLF
, buffer
, &size
, &index
);
2538 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2539 ok(index
== 0, "expected 0 got %u\n", index
);
2541 size
= sizeof(buffer
);
2542 ret
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &size
, &index
);
2543 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2544 ok(index
== 0, "expected 0 got %u\n", index
);
2546 size
= sizeof(buffer
);
2547 ret
= HttpQueryInfo(hr
, HTTP_QUERY_VERSION
, buffer
, &size
, &index
);
2548 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2549 ok(index
== 0, "expected 0 got %u\n", index
);
2552 size
= sizeof(buffer
);
2553 ret
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &size
, &index
);
2554 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2555 ok(index
== 0, "expected 0 got %u\n", index
);
2558 size
= sizeof(buffer
);
2559 ret
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, buffer
, &size
, &index
);
2560 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2561 ok(index
== 0, "expected 0 got %u\n", index
);
2564 size
= sizeof(buffer
);
2565 ret
= HttpQueryInfo(hr
, HTTP_QUERY_FORWARDED
, buffer
, &size
, &index
);
2566 ok(!ret
, "HttpQueryInfo succeeded\n");
2567 ok(index
== 0xdeadbeef, "expected 0xdeadbeef got %u\n", index
);
2570 size
= sizeof(buffer
);
2571 ret
= HttpQueryInfo(hr
, HTTP_QUERY_SERVER
, buffer
, &size
, &index
);
2572 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2573 ok(index
== 1, "expected 1 got %u\n", index
);
2576 size
= sizeof(buffer
);
2577 strcpy(buffer
, "Server");
2578 ret
= HttpQueryInfo(hr
, HTTP_QUERY_CUSTOM
, buffer
, &size
, &index
);
2579 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2580 ok(index
== 1, "expected 1 got %u\n", index
);
2583 size
= sizeof(buffer
);
2584 ret
= HttpQueryInfo(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
2585 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2586 ok(index
== 1, "expected 1 got %u\n", index
);
2588 size
= sizeof(buffer
);
2589 ret
= HttpQueryInfo(hr
, HTTP_QUERY_SET_COOKIE
, buffer
, &size
, &index
);
2590 ok(ret
, "HttpQueryInfo failed %u\n", GetLastError());
2591 ok(index
== 2, "expected 2 got %u\n", index
);
2593 InternetCloseHandle(hr
);
2594 InternetCloseHandle(hc
);
2595 InternetCloseHandle(hi
);
2598 static void test_options(int port
)
2600 HINTERNET ses
, con
, req
;
2605 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2606 ok(ses
!= NULL
, "InternetOpen failed\n");
2608 SetLastError(0xdeadbeef);
2609 ret
= InternetSetOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, 0);
2610 error
= GetLastError();
2611 ok(!ret
, "InternetSetOption succeeded\n");
2612 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
2614 SetLastError(0xdeadbeef);
2615 ret
= InternetSetOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, sizeof(ctx
));
2616 ok(!ret
, "InternetSetOption succeeded\n");
2617 error
= GetLastError();
2618 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
2620 SetLastError(0xdeadbeef);
2621 ret
= InternetSetOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, 0);
2622 ok(!ret
, "InternetSetOption succeeded\n");
2623 error
= GetLastError();
2624 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
2627 ret
= InternetSetOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
2628 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
2630 SetLastError(0xdeadbeef);
2631 ret
= InternetQueryOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, NULL
);
2632 error
= GetLastError();
2633 ok(!ret
, "InternetQueryOption succeeded\n");
2634 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
2636 SetLastError(0xdeadbeef);
2637 ret
= InternetQueryOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, NULL
);
2638 error
= GetLastError();
2639 ok(!ret
, "InternetQueryOption succeeded\n");
2640 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
2643 SetLastError(0xdeadbeef);
2644 ret
= InternetQueryOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, NULL
, &size
);
2645 error
= GetLastError();
2646 ok(!ret
, "InternetQueryOption succeeded\n");
2647 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
2650 SetLastError(0xdeadbeef);
2651 ret
= InternetQueryOption(NULL
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
2652 error
= GetLastError();
2653 ok(!ret
, "InternetQueryOption succeeded\n");
2654 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error
);
2658 ret
= InternetQueryOption(ses
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
2659 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
2660 ok(ctx
== 1, "expected 1 got %lu\n", ctx
);
2662 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2663 ok(con
!= NULL
, "InternetConnect failed\n");
2667 ret
= InternetQueryOption(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
2668 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
2669 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
2672 ret
= InternetSetOption(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
2673 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
2677 ret
= InternetQueryOption(con
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
2678 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
2679 ok(ctx
== 2, "expected 2 got %lu\n", ctx
);
2681 req
= HttpOpenRequest(con
, NULL
, "/test1", NULL
, NULL
, NULL
, 0, 0);
2682 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2686 ret
= InternetQueryOption(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
2687 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
2688 ok(ctx
== 0, "expected 0 got %lu\n", ctx
);
2691 ret
= InternetSetOption(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, sizeof(ctx
));
2692 ok(ret
, "InternetSetOption failed %u\n", GetLastError());
2696 ret
= InternetQueryOption(req
, INTERNET_OPTION_CONTEXT_VALUE
, &ctx
, &size
);
2697 ok(ret
, "InternetQueryOption failed %u\n", GetLastError());
2698 ok(ctx
== 3, "expected 3 got %lu\n", ctx
);
2700 /* INTERNET_OPTION_PROXY */
2701 SetLastError(0xdeadbeef);
2702 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, NULL
);
2703 error
= GetLastError();
2704 ok(!ret
, "InternetQueryOption succeeded\n");
2705 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
2707 SetLastError(0xdeadbeef);
2708 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, &ctx
, NULL
);
2709 error
= GetLastError();
2710 ok(!ret
, "InternetQueryOption succeeded\n");
2711 ok(error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %u\n", error
);
2714 SetLastError(0xdeadbeef);
2715 ret
= InternetQueryOptionA(ses
, INTERNET_OPTION_PROXY
, NULL
, &size
);
2716 error
= GetLastError();
2717 ok(!ret
, "InternetQueryOption succeeded\n");
2718 ok(error
== ERROR_INSUFFICIENT_BUFFER
, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error
);
2719 ok(size
>= sizeof(INTERNET_PROXY_INFOA
), "expected size to be greater or equal to the struct size\n");
2721 InternetCloseHandle(req
);
2722 InternetCloseHandle(con
);
2723 InternetCloseHandle(ses
);
2726 static void test_url_caching(int port
, int *num_retrievals
)
2728 HINTERNET hi
, hc
, hr
;
2732 ok(*num_retrievals
== 0, "expected 0 retrievals prior to test\n");
2734 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2735 ok(hi
!= NULL
, "open failed\n");
2737 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2738 ok(hc
!= NULL
, "connect failed\n");
2740 /* Pre-load the cache: */
2741 hr
= HttpOpenRequest(hc
, "GET", "/testH", NULL
, NULL
, NULL
, 0, 0);
2742 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2744 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
2745 ok(r
, "HttpSendRequest failed\n");
2747 ok(*num_retrievals
== 1, "expected 1 retrievals, got %d\n", *num_retrievals
);
2750 memset(buffer
, 0, sizeof buffer
);
2751 SetLastError(0xdeadbeef);
2752 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
2753 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2754 ok(count
== sizeof page1
- 1, "count was wrong\n");
2755 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
2757 InternetCloseHandle(hr
);
2759 /* Send the same request, requiring it to be retrieved from the cache */
2760 hr
= HttpOpenRequest(hc
, "GET", "/testH", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
2761 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2763 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
2764 /* Older Windows versions succeed with this request, newer ones fail with
2765 * ERROR_FILE_NOT_FOUND. Accept either, as the older version allows us
2766 * to verify that the server isn't contacted.
2769 ok(GetLastError() == ERROR_FILE_NOT_FOUND
,
2770 "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
2773 /* The server shouldn't be contacted for this request. */
2775 ok(*num_retrievals
== 1, "expected 1 retrievals\n");
2778 memset(buffer
, 0, sizeof buffer
);
2779 SetLastError(0xdeadbeef);
2780 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
2781 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2782 ok(count
== sizeof page1
- 1, "count was wrong\n");
2783 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
2786 InternetCloseHandle(hc
);
2787 InternetCloseHandle(hi
);
2790 static void test_http_connection(void)
2792 struct server_info si
;
2796 si
.hEvent
= CreateEvent(NULL
, 0, 0, NULL
);
2798 si
.num_testH_retrievals
= 0;
2800 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
2801 ok( hThread
!= NULL
, "create thread failed\n");
2803 r
= WaitForSingleObject(si
.hEvent
, 10000);
2804 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
2805 if (r
!= WAIT_OBJECT_0
)
2808 test_basic_request(si
.port
, "GET", "/test1");
2809 test_proxy_indirect(si
.port
);
2810 test_proxy_direct(si
.port
);
2811 test_header_handling_order(si
.port
);
2812 test_basic_request(si
.port
, "POST", "/test5");
2813 test_basic_request(si
.port
, "RPC_IN_DATA", "/test5");
2814 test_basic_request(si
.port
, "RPC_OUT_DATA", "/test5");
2815 test_basic_request(si
.port
, "GET", "/test6");
2816 test_basic_request(si
.port
, "GET", "/testF");
2817 test_connection_header(si
.port
);
2818 test_http1_1(si
.port
);
2819 test_cookie_header(si
.port
);
2820 test_basic_authentication(si
.port
);
2821 test_invalid_response_headers(si
.port
);
2822 test_response_without_headers(si
.port
);
2823 test_HttpQueryInfo(si
.port
);
2824 test_HttpSendRequestW(si
.port
);
2825 test_last_error(si
.port
);
2826 test_options(si
.port
);
2827 test_url_caching(si
.port
, &si
.num_testH_retrievals
);
2828 test_no_content(si
.port
);
2829 test_conn_close(si
.port
);
2831 /* send the basic request again to shutdown the server thread */
2832 test_basic_request(si
.port
, "GET", "/quit");
2834 r
= WaitForSingleObject(hThread
, 3000);
2835 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
2836 CloseHandle(hThread
);
2839 static void release_cert_info(INTERNET_CERTIFICATE_INFOA
*info
)
2841 LocalFree(info
->lpszSubjectInfo
);
2842 LocalFree(info
->lpszIssuerInfo
);
2843 LocalFree(info
->lpszProtocolName
);
2844 LocalFree(info
->lpszSignatureAlgName
);
2845 LocalFree(info
->lpszEncryptionAlgName
);
2848 static void test_secure_connection(void)
2850 static const WCHAR gizmo5
[] = {'G','i','z','m','o','5',0};
2851 static const WCHAR testbot
[] = {'t','e','s','t','b','o','t','.','w','i','n','e','h','q','.','o','r','g',0};
2852 static const WCHAR get
[] = {'G','E','T',0};
2853 static const WCHAR slash
[] = {'/',0};
2854 HINTERNET ses
, con
, req
;
2856 INTERNET_CERTIFICATE_INFOA
*certificate_structA
= NULL
;
2857 INTERNET_CERTIFICATE_INFOW
*certificate_structW
= NULL
;
2860 ses
= InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
2861 ok(ses
!= NULL
, "InternetOpen failed\n");
2863 con
= InternetConnect(ses
, "testbot.winehq.org",
2864 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
2865 INTERNET_SERVICE_HTTP
, 0, 0);
2866 ok(con
!= NULL
, "InternetConnect failed\n");
2868 req
= HttpOpenRequest(con
, "GET", "/", NULL
, NULL
, NULL
,
2869 INTERNET_FLAG_SECURE
, 0);
2870 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2872 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2873 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
2875 size
= sizeof(flags
);
2876 ret
= InternetQueryOption(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
2877 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
2878 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
2880 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
2882 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
2883 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
2884 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
2885 ret
= InternetQueryOption(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
2886 certificate_structA
, &size
);
2887 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
2890 ok(certificate_structA
->lpszSubjectInfo
&&
2891 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
2892 "expected a non-empty subject name\n");
2893 ok(certificate_structA
->lpszIssuerInfo
&&
2894 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
2895 "expected a non-empty issuer name\n");
2896 ok(!certificate_structA
->lpszSignatureAlgName
,
2897 "unexpected signature algorithm name\n");
2898 ok(!certificate_structA
->lpszEncryptionAlgName
,
2899 "unexpected encryption algorithm name\n");
2900 ok(!certificate_structA
->lpszProtocolName
,
2901 "unexpected protocol name\n");
2902 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
2903 release_cert_info(certificate_structA
);
2905 HeapFree(GetProcessHeap(), 0, certificate_structA
);
2907 /* Querying the same option through InternetQueryOptionW still results in
2908 * ASCII strings being returned.
2911 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
2913 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
2914 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
2915 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
2916 ret
= InternetQueryOption(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
2917 certificate_structW
, &size
);
2918 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
2919 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
2922 ok(certificate_structA
->lpszSubjectInfo
&&
2923 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
2924 "expected a non-empty subject name\n");
2925 ok(certificate_structA
->lpszIssuerInfo
&&
2926 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
2927 "expected a non-empty issuer name\n");
2928 ok(!certificate_structA
->lpszSignatureAlgName
,
2929 "unexpected signature algorithm name\n");
2930 ok(!certificate_structA
->lpszEncryptionAlgName
,
2931 "unexpected encryption algorithm name\n");
2932 ok(!certificate_structA
->lpszProtocolName
,
2933 "unexpected protocol name\n");
2934 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
2935 release_cert_info(certificate_structA
);
2937 HeapFree(GetProcessHeap(), 0, certificate_structW
);
2939 InternetCloseHandle(req
);
2940 InternetCloseHandle(con
);
2941 InternetCloseHandle(ses
);
2943 /* Repeating the tests with the W functions has the same result: */
2944 ses
= InternetOpenW(gizmo5
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
2945 ok(ses
!= NULL
, "InternetOpen failed\n");
2947 con
= InternetConnectW(ses
, testbot
,
2948 INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
,
2949 INTERNET_SERVICE_HTTP
, 0, 0);
2950 ok(con
!= NULL
, "InternetConnect failed\n");
2952 req
= HttpOpenRequestW(con
, get
, slash
, NULL
, NULL
, NULL
,
2953 INTERNET_FLAG_SECURE
, 0);
2954 ok(req
!= NULL
, "HttpOpenRequest failed\n");
2956 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
2957 ok(ret
, "HttpSendRequest failed: %d\n", GetLastError());
2959 size
= sizeof(flags
);
2960 ret
= InternetQueryOption(req
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
);
2961 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
2962 ok(flags
& SECURITY_FLAG_SECURE
, "expected secure flag to be set\n");
2964 ret
= InternetQueryOptionA(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
2966 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
2967 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOA
), "size = %d\n", size
);
2968 certificate_structA
= HeapAlloc(GetProcessHeap(), 0, size
);
2969 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
2970 certificate_structA
, &size
);
2971 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
2974 ok(certificate_structA
->lpszSubjectInfo
&&
2975 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
2976 "expected a non-empty subject name\n");
2977 ok(certificate_structA
->lpszIssuerInfo
&&
2978 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
2979 "expected a non-empty issuer name\n");
2980 ok(!certificate_structA
->lpszSignatureAlgName
,
2981 "unexpected signature algorithm name\n");
2982 ok(!certificate_structA
->lpszEncryptionAlgName
,
2983 "unexpected encryption algorithm name\n");
2984 ok(!certificate_structA
->lpszProtocolName
,
2985 "unexpected protocol name\n");
2986 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
2987 release_cert_info(certificate_structA
);
2989 HeapFree(GetProcessHeap(), 0, certificate_structA
);
2991 /* Again, querying the same option through InternetQueryOptionW still
2992 * results in ASCII strings being returned.
2995 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
2997 ok(ret
|| GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "InternetQueryOption failed: %d\n", GetLastError());
2998 ok(size
== sizeof(INTERNET_CERTIFICATE_INFOW
), "size = %d\n", size
);
2999 certificate_structW
= HeapAlloc(GetProcessHeap(), 0, size
);
3000 ret
= InternetQueryOptionW(req
, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
3001 certificate_structW
, &size
);
3002 certificate_structA
= (INTERNET_CERTIFICATE_INFOA
*)certificate_structW
;
3003 ok(ret
, "InternetQueryOption failed: %d\n", GetLastError());
3006 ok(certificate_structA
->lpszSubjectInfo
&&
3007 strlen(certificate_structA
->lpszSubjectInfo
) > 1,
3008 "expected a non-empty subject name\n");
3009 ok(certificate_structA
->lpszIssuerInfo
&&
3010 strlen(certificate_structA
->lpszIssuerInfo
) > 1,
3011 "expected a non-empty issuer name\n");
3012 ok(!certificate_structA
->lpszSignatureAlgName
,
3013 "unexpected signature algorithm name\n");
3014 ok(!certificate_structA
->lpszEncryptionAlgName
,
3015 "unexpected encryption algorithm name\n");
3016 ok(!certificate_structA
->lpszProtocolName
,
3017 "unexpected protocol name\n");
3018 ok(certificate_structA
->dwKeySize
, "expected a non-zero key size\n");
3019 release_cert_info(certificate_structA
);
3021 HeapFree(GetProcessHeap(), 0, certificate_structW
);
3023 InternetCloseHandle(req
);
3024 InternetCloseHandle(con
);
3025 InternetCloseHandle(ses
);
3028 static void test_user_agent_header(void)
3030 HINTERNET ses
, con
, req
;
3035 ses
= InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
3036 ok(ses
!= NULL
, "InternetOpen failed\n");
3038 con
= InternetConnect(ses
, "test.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3039 ok(con
!= NULL
, "InternetConnect failed\n");
3041 req
= HttpOpenRequest(con
, "GET", "/tests/hello.html", "HTTP/1.0", NULL
, NULL
, 0, 0);
3042 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3044 size
= sizeof(buffer
);
3045 ret
= HttpQueryInfo(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3046 err
= GetLastError();
3047 ok(!ret
, "HttpQueryInfo succeeded\n");
3048 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
3050 ret
= HttpAddRequestHeaders(req
, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
3051 ok(ret
, "HttpAddRequestHeaders succeeded\n");
3053 size
= sizeof(buffer
);
3054 ret
= HttpQueryInfo(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3055 err
= GetLastError();
3056 ok(ret
, "HttpQueryInfo failed\n");
3057 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
3059 InternetCloseHandle(req
);
3061 req
= HttpOpenRequest(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
3062 ok(req
!= NULL
, "HttpOpenRequest failed\n");
3064 size
= sizeof(buffer
);
3065 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3066 err
= GetLastError();
3067 ok(!ret
, "HttpQueryInfo succeeded\n");
3068 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
3070 ret
= HttpAddRequestHeaders(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
3071 ok(ret
, "HttpAddRequestHeaders failed\n");
3074 size
= sizeof(buffer
);
3075 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3076 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
3077 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
3079 InternetCloseHandle(req
);
3080 InternetCloseHandle(con
);
3081 InternetCloseHandle(ses
);
3084 static void test_bogus_accept_types_array(void)
3086 HINTERNET ses
, con
, req
;
3087 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL
};
3092 ses
= InternetOpen("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
3093 con
= InternetConnect(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
3094 req
= HttpOpenRequest(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
3096 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
3099 size
= sizeof(buffer
);
3100 SetLastError(0xdeadbeef);
3101 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
3102 error
= GetLastError();
3103 ok(!ret
|| broken(ret
), "HttpQueryInfo succeeded\n");
3104 if (!ret
) ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error
);
3105 ok(broken(!strcmp(buffer
, ", */*, %p, , , */*")) /* IE6 */ ||
3106 broken(!strcmp(buffer
, "*/*, %p, */*")) /* IE7/8 */ ||
3107 !strcmp(buffer
, ""), "got '%s' expected ''\n", buffer
);
3109 InternetCloseHandle(req
);
3110 InternetCloseHandle(con
);
3111 InternetCloseHandle(ses
);
3120 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
3122 INTERNET_ASYNC_RESULT
*result
= info
;
3123 struct context
*ctx
= (struct context
*)context
;
3125 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
3127 if (status
== INTERNET_STATUS_REQUEST_COMPLETE
)
3129 trace("request handle: 0x%08lx\n", result
->dwResult
);
3130 ctx
->req
= (HINTERNET
)result
->dwResult
;
3131 SetEvent(ctx
->event
);
3133 if (status
== INTERNET_STATUS_HANDLE_CLOSING
)
3135 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
3137 if (InternetQueryOption(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
3138 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
3139 SetEvent(ctx
->event
);
3143 static void test_open_url_async(void)
3152 ctx
.event
= CreateEvent(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
3154 ses
= InternetOpen("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3155 ok(ses
!= NULL
, "InternetOpen failed\n");
3157 SetLastError(0xdeadbeef);
3158 ret
= InternetSetOptionA(NULL
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
3159 error
= GetLastError();
3160 ok(!ret
, "InternetSetOptionA succeeded\n");
3161 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_TYPE
, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error
);
3163 ret
= InternetSetOptionA(ses
, INTERNET_OPTION_CALLBACK
, &cb
, sizeof(DWORD_PTR
));
3164 error
= GetLastError();
3165 ok(!ret
, "InternetSetOptionA failed\n");
3166 ok(error
== ERROR_INTERNET_OPTION_NOT_SETTABLE
, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error
);
3168 pInternetSetStatusCallbackA(ses
, cb
);
3169 ResetEvent(ctx
.event
);
3171 req
= InternetOpenUrl(ses
, "http://test.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
3172 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
3174 WaitForSingleObject(ctx
.event
, INFINITE
);
3177 size
= sizeof(type
);
3178 ret
= InternetQueryOption(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
3179 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
3180 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
3181 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
3184 ret
= HttpQueryInfo(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
3185 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
3186 ok(size
> 0, "expected size > 0\n");
3188 ResetEvent(ctx
.event
);
3189 InternetCloseHandle(ctx
.req
);
3190 WaitForSingleObject(ctx
.event
, INFINITE
);
3192 InternetCloseHandle(ses
);
3193 CloseHandle(ctx
.event
);
3198 internet_connect
= 1,
3200 http_send_request_ex
,
3203 internet_close_handle
3208 enum api function
; /* api responsible for notification */
3209 unsigned int status
; /* status received */
3210 int async
; /* delivered from another thread? */
3218 const struct notification
*test
;
3224 DWORD expect_result
;
3228 static CRITICAL_SECTION notification_cs
;
3230 static void CALLBACK
check_notification( HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID buffer
, DWORD buflen
)
3232 BOOL status_ok
, function_ok
;
3233 struct info
*info
= (struct info
*)context
;
3236 EnterCriticalSection( ¬ification_cs
);
3238 if(info
->is_aborted
) {
3239 LeaveCriticalSection(¬ification_cs
);
3243 if (status
== INTERNET_STATUS_HANDLE_CREATED
)
3245 DWORD size
= sizeof(struct info
*);
3246 HttpQueryInfoA( handle
, INTERNET_OPTION_CONTEXT_VALUE
, &info
, &size
, 0 );
3247 }else if(status
== INTERNET_STATUS_REQUEST_COMPLETE
) {
3248 INTERNET_ASYNC_RESULT
*ar
= (INTERNET_ASYNC_RESULT
*)buffer
;
3250 ok(buflen
== sizeof(*ar
), "unexpected buflen = %d\n", buflen
);
3251 if(info
->expect_result
== ERROR_SUCCESS
) {
3252 ok(ar
->dwResult
== 1, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
3254 ok(!ar
->dwResult
, "ar->dwResult = %ld, expected 1\n", ar
->dwResult
);
3255 ok(ar
->dwError
== info
->expect_result
, "ar->dwError = %d, expected %d\n", ar
->dwError
, info
->expect_result
);
3260 if (i
>= info
->count
)
3262 LeaveCriticalSection( ¬ification_cs
);
3266 while (info
->test
[i
].status
!= status
&&
3267 (info
->test
[i
].optional
|| info
->test
[i
].todo
) &&
3268 i
< info
->count
- 1 &&
3269 info
->test
[i
].function
== info
->test
[i
+ 1].function
)
3274 status_ok
= (info
->test
[i
].status
== status
);
3275 function_ok
= (info
->test
[i
].function
== info
->function
);
3277 if (!info
->test
[i
].todo
)
3279 ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
3280 ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
3282 if (info
->test
[i
].async
)
3283 ok(info
->thread
!= GetCurrentThreadId(), "%u: expected thread %u got %u\n",
3284 info
->line
, info
->thread
, GetCurrentThreadId());
3288 todo_wine
ok( status_ok
, "%u: expected status %u got %u\n", info
->line
, info
->test
[i
].status
, status
);
3290 todo_wine
ok( function_ok
, "%u: expected function %u got %u\n", info
->line
, info
->test
[i
].function
, info
->function
);
3292 if (i
== info
->count
- 1 || info
->test
[i
].function
!= info
->test
[i
+ 1].function
) SetEvent( info
->wait
);
3295 LeaveCriticalSection( ¬ification_cs
);
3298 static void setup_test( struct info
*info
, enum api function
, unsigned int line
, DWORD expect_result
)
3300 info
->function
= function
;
3302 info
->expect_result
= expect_result
;
3305 struct notification_data
3307 const struct notification
*test
;
3308 const unsigned int count
;
3313 BOOL expect_conn_failure
;
3316 static const struct notification async_send_request_ex_test
[] =
3318 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
3319 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
3320 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
3321 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, 1, 0, 1 },
3322 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, 1, 0, 1 },
3323 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, 1 },
3324 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, 1 },
3325 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, 1 },
3326 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, 1 },
3327 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
3328 { internet_writefile
, INTERNET_STATUS_SENDING_REQUEST
, 0 },
3329 { internet_writefile
, INTERNET_STATUS_REQUEST_SENT
, 0 },
3330 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, 1 },
3331 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, 1 },
3332 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
3333 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0, 1 },
3334 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0, 1 },
3335 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, },
3336 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, }
3339 static const struct notification async_send_request_ex_test2
[] =
3341 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
3342 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
3343 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
3344 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, 1, 0, 1 },
3345 { http_send_request_ex
, INTERNET_STATUS_NAME_RESOLVED
, 1, 0, 1 },
3346 { http_send_request_ex
, INTERNET_STATUS_CONNECTING_TO_SERVER
, 1, 1 },
3347 { http_send_request_ex
, INTERNET_STATUS_CONNECTED_TO_SERVER
, 1, 1 },
3348 { http_send_request_ex
, INTERNET_STATUS_SENDING_REQUEST
, 1 },
3349 { http_send_request_ex
, INTERNET_STATUS_REQUEST_SENT
, 1 },
3350 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
3351 { http_end_request
, INTERNET_STATUS_RECEIVING_RESPONSE
, 1 },
3352 { http_end_request
, INTERNET_STATUS_RESPONSE_RECEIVED
, 1 },
3353 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
3354 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0, 1 },
3355 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0, 1 },
3356 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, },
3357 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, }
3360 static const struct notification async_send_request_ex_resolve_failure_test
[] =
3362 { internet_connect
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
3363 { http_open_request
, INTERNET_STATUS_HANDLE_CREATED
, 0 },
3364 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
3365 { http_send_request_ex
, INTERNET_STATUS_RESOLVING_NAME
, 1 },
3366 { http_send_request_ex
, INTERNET_STATUS_DETECTING_PROXY
, 1, 0, 1 },
3367 { http_send_request_ex
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
3368 { http_end_request
, INTERNET_STATUS_REQUEST_COMPLETE
, 1 },
3369 { internet_close_handle
, INTERNET_STATUS_CLOSING_CONNECTION
, 0, 0, 1 },
3370 { internet_close_handle
, INTERNET_STATUS_CONNECTION_CLOSED
, 0, 0, 1 },
3371 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, },
3372 { internet_close_handle
, INTERNET_STATUS_HANDLE_CLOSING
, 0, }
3375 static const struct notification_data notification_data
[] = {
3377 async_send_request_ex_test
,
3378 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
3381 "tests/posttest.php",
3382 "Public ID=codeweavers"
3385 async_send_request_ex_test2
,
3386 sizeof(async_send_request_ex_test
)/sizeof(async_send_request_ex_test
[0]),
3389 "tests/posttest.php"
3392 async_send_request_ex_resolve_failure_test
,
3393 sizeof(async_send_request_ex_resolve_failure_test
)/sizeof(async_send_request_ex_resolve_failure_test
[0]),
3402 static void test_async_HttpSendRequestEx(const struct notification_data
*nd
)
3405 HINTERNET ses
, req
, con
;
3407 DWORD size
, written
, error
;
3408 INTERNET_BUFFERSA b
;
3409 static const char *accept
[2] = {"*/*", NULL
};
3412 trace("Async HttpSendRequestEx test (%s %s)\n", nd
->method
, nd
->host
);
3414 InitializeCriticalSection( ¬ification_cs
);
3416 info
.test
= nd
->test
;
3417 info
.count
= nd
->count
;
3419 info
.wait
= CreateEvent( NULL
, FALSE
, FALSE
, NULL
);
3420 info
.thread
= GetCurrentThreadId();
3421 info
.is_aborted
= FALSE
;
3423 ses
= InternetOpen( "winetest", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3424 ok( ses
!= NULL
, "InternetOpen failed\n" );
3426 pInternetSetStatusCallbackA( ses
, check_notification
);
3428 setup_test( &info
, internet_connect
, __LINE__
, ERROR_SUCCESS
);
3429 con
= InternetConnect( ses
, nd
->host
, 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, (DWORD_PTR
)&info
);
3430 ok( con
!= NULL
, "InternetConnect failed %u\n", GetLastError() );
3432 WaitForSingleObject( info
.wait
, 10000 );
3434 setup_test( &info
, http_open_request
, __LINE__
, ERROR_SUCCESS
);
3435 req
= HttpOpenRequest( con
, nd
->method
, nd
->path
, NULL
, NULL
, accept
, 0, (DWORD_PTR
)&info
);
3436 ok( req
!= NULL
, "HttpOpenRequest failed %u\n", GetLastError() );
3438 WaitForSingleObject( info
.wait
, 10000 );
3441 memset( &b
, 0, sizeof(INTERNET_BUFFERSA
) );
3442 b
.dwStructSize
= sizeof(INTERNET_BUFFERSA
);
3443 b
.lpcszHeader
= "Content-Type: application/x-www-form-urlencoded";
3444 b
.dwHeadersLength
= strlen( b
.lpcszHeader
);
3445 b
.dwBufferTotal
= nd
->data
? strlen( nd
->data
) : 0;
3448 setup_test( &info
, http_send_request_ex
, __LINE__
,
3449 nd
->expect_conn_failure
? ERROR_INTERNET_NAME_NOT_RESOLVED
: ERROR_SUCCESS
);
3450 ret
= HttpSendRequestExA( req
, nd
->data
? &b
: NULL
, NULL
, 0x28, 0 );
3451 ok( !ret
&& GetLastError() == ERROR_IO_PENDING
, "HttpSendRequestExA failed %d %u\n", ret
, GetLastError() );
3453 error
= WaitForSingleObject( info
.wait
, 10000 );
3454 if(error
!= WAIT_OBJECT_0
) {
3455 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error
);
3456 info
.is_aborted
= TRUE
;
3460 size
= sizeof(buffer
);
3461 SetLastError( 0xdeadbeef );
3462 ret
= HttpQueryInfoA( req
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &size
, 0 );
3463 error
= GetLastError();
3464 ok( !ret
, "HttpQueryInfoA failed %u\n", GetLastError() );
3465 if(nd
->expect_conn_failure
) {
3466 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error
);
3469 ok(error
== ERROR_INTERNET_INCORRECT_HANDLE_STATE
,
3470 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error
);
3476 size
= strlen( nd
->data
);
3477 setup_test( &info
, internet_writefile
, __LINE__
, ERROR_SUCCESS
);
3478 ret
= InternetWriteFile( req
, nd
->data
, size
, &written
);
3479 ok( ret
, "InternetWriteFile failed %u\n", GetLastError() );
3480 ok( written
== size
, "expected %u got %u\n", written
, size
);
3482 WaitForSingleObject( info
.wait
, 10000 );
3484 SetLastError( 0xdeadbeef );
3485 ret
= HttpEndRequestA( req
, (void *)nd
->data
, 0x28, 0 );
3486 error
= GetLastError();
3487 ok( !ret
, "HttpEndRequestA succeeded\n" );
3488 ok( error
== ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER got %u\n", error
);
3491 SetLastError( 0xdeadbeef );
3492 setup_test( &info
, http_end_request
, __LINE__
,
3493 nd
->expect_conn_failure
? ERROR_INTERNET_OPERATION_CANCELLED
: ERROR_SUCCESS
);
3494 ret
= HttpEndRequestA( req
, NULL
, 0x28, 0 );
3495 error
= GetLastError();
3496 ok( !ret
, "HttpEndRequestA succeeded\n" );
3497 ok( error
== ERROR_IO_PENDING
, "expected ERROR_IO_PENDING got %u\n", error
);
3499 WaitForSingleObject( info
.wait
, 10000 );
3501 setup_test( &info
, internet_close_handle
, __LINE__
, ERROR_SUCCESS
);
3503 InternetCloseHandle( req
);
3504 InternetCloseHandle( con
);
3505 InternetCloseHandle( ses
);
3507 WaitForSingleObject( info
.wait
, 10000 );
3509 CloseHandle( info
.wait
);
3512 static HINTERNET closetest_session
, closetest_req
, closetest_conn
;
3513 static BOOL closetest_closed
;
3515 static void WINAPI
closetest_callback(HINTERNET hInternet
, DWORD_PTR dwContext
, DWORD dwInternetStatus
,
3516 LPVOID lpvStatusInformation
, DWORD dwStatusInformationLength
)
3521 trace("closetest_callback %p: %d\n", hInternet
, dwInternetStatus
);
3523 ok(hInternet
== closetest_session
|| hInternet
== closetest_conn
|| hInternet
== closetest_req
,
3524 "Unexpected hInternet %p\n", hInternet
);
3525 if(!closetest_closed
)
3529 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &len
);
3530 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
3531 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
3532 closetest_req
, res
, GetLastError());
3535 static void test_InternetCloseHandle(void)
3540 closetest_session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
3541 ok(closetest_session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
3543 pInternetSetStatusCallbackA(closetest_session
, closetest_callback
);
3545 closetest_conn
= InternetConnectA(closetest_session
, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
3546 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
3547 ok(closetest_conn
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
3549 closetest_req
= HttpOpenRequestA(closetest_conn
, "GET", "winegecko.php", NULL
, NULL
, NULL
,
3550 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
, 0xdeadbead);
3552 res
= HttpSendRequestA(closetest_req
, NULL
, -1, NULL
, 0);
3553 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
3554 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3556 len
= sizeof(flags
);
3557 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
3558 ok(res
, "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %u\n", closetest_req
, GetLastError());
3560 res
= InternetCloseHandle(closetest_session
);
3561 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
3562 closetest_closed
= TRUE
;
3563 trace("Closed session handle\n");
3565 res
= InternetCloseHandle(closetest_conn
);
3566 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(conn) failed: %x %u\n",
3567 res
, GetLastError());
3569 res
= InternetCloseHandle(closetest_req
);
3570 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
, "InternetCloseConnection(req) failed: %x %u\n",
3571 res
, GetLastError());
3573 len
= sizeof(flags
);
3574 res
= InternetQueryOptionA(closetest_req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &len
);
3575 ok(!res
&& GetLastError() == ERROR_INVALID_HANDLE
,
3576 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
3577 closetest_req
, res
, GetLastError());
3580 static void init_status_tests(void)
3582 memset(expect
, 0, sizeof(expect
));
3583 memset(optional
, 0, sizeof(optional
));
3584 memset(wine_allow
, 0, sizeof(wine_allow
));
3585 memset(notified
, 0, sizeof(notified
));
3586 memset(status_string
, 0, sizeof(status_string
));
3588 #define STATUS_STRING(status) status_string[status] = #status
3589 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
3590 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
3591 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
3592 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
3593 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
3594 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
3595 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
3596 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
3597 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
3598 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
3599 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
3600 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
3601 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
3602 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
3603 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
3604 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
3605 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
3606 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
3607 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
3608 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
3609 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
3610 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
3611 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
3612 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
3613 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
3614 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
3615 #undef STATUS_STRING
3621 hdll
= GetModuleHandleA("wininet.dll");
3623 if(!GetProcAddress(hdll
, "InternetGetCookieExW")) {
3624 win_skip("Too old IE (older than 6.0)\n");
3628 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
3630 init_status_tests();
3631 test_InternetCloseHandle();
3632 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[0]);
3633 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[1]);
3634 InternetReadFile_test(0, &test_data
[1]);
3635 first_connection_to_test_url
= TRUE
;
3636 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[2]);
3637 InternetReadFile_test(0, &test_data
[2]);
3638 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
3639 test_open_url_async();
3640 test_async_HttpSendRequestEx(¬ification_data
[0]);
3641 test_async_HttpSendRequestEx(¬ification_data
[1]);
3642 test_async_HttpSendRequestEx(¬ification_data
[2]);
3643 InternetOpenRequest_test();
3645 InternetOpenUrlA_test();
3647 test_http_connection();
3648 test_secure_connection();
3649 test_user_agent_header();
3650 test_bogus_accept_types_array();
3651 InternetReadFile_chunked_test();
3652 HttpSendRequestEx_test();
3653 InternetReadFile_test(INTERNET_FLAG_ASYNC
, &test_data
[3]);