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",
131 TESTF_CHUNKED|TESTF_ALLOW_COOKIE
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_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
770 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
771 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
772 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST, 2);
773 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT, 2);
774 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
775 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
776 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
777 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
778 SET_EXPECT(INTERNET_STATUS_REDIRECT);
779 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER);
780 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER);
781 if (flags & INTERNET_FLAG_ASYNC)
782 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
784 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE);
786 trace("HttpSendRequestA -->\n");
787 SetLastError(0xdeadbeef);
788 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
789 if (flags & INTERNET_FLAG_ASYNC)
790 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
791 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
793 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
794 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
795 trace("HttpSendRequestA <--\n");
797 if (!rc && (GetLastError() == ERROR_IO_PENDING)) {
798 WaitForSingleObject(hCompleteEvent, INFINITE);
799 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
802 if (first_connection_to_test_url)
804 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
805 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
809 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME);
810 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED);
812 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST, 2);
813 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT, 2);
814 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE, 2);
815 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED, 2);
816 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION, 2);
817 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED, 2);
818 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT);
819 if (flags & INTERNET_FLAG_ASYNC)
820 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
822 todo_wine CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
823 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
824 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
825 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
826 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
828 /* tests invalid dwStructSize */
829 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS)+1;
830 inetbuffers.lpcszHeader = NULL;
831 inetbuffers.dwHeadersLength = 0;
832 inetbuffers.dwBufferLength = 10;
833 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10);
834 inetbuffers.dwOffsetHigh = 1234;
835 inetbuffers.dwOffsetLow = 5678;
836 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
837 ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
838 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
839 rc ? "TRUE" : "FALSE", GetLastError());
840 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
842 /* tests to see whether lpcszHeader is used - it isn't */
843 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
844 inetbuffers.lpcszHeader = (LPCTSTR)0xdeadbeef;
845 inetbuffers.dwHeadersLength = 255;
846 inetbuffers.dwBufferLength = 0;
847 inetbuffers.lpvBuffer = NULL;
848 inetbuffers.dwOffsetHigh = 1234;
849 inetbuffers.dwOffsetLow = 5678;
850 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
851 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
852 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
853 ok(rc, "InternetReadFileEx failed with error %u\n", GetLastError());
854 trace("read %i bytes\n", inetbuffers.dwBufferLength);
857 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
858 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
861 rc = InternetReadFileEx(NULL, &inetbuffers, 0, 0xdeadcafe);
862 ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE),
863 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
864 rc ? "TRUE" : "FALSE", GetLastError());
867 trace("Entering Query loop\n");
871 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
872 inetbuffers.dwBufferLength = 1024;
873 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1);
874 inetbuffers.dwOffsetHigh = 1234;
875 inetbuffers.dwOffsetLow = 5678;
877 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE);
878 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED);
879 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
880 rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe);
883 if (GetLastError() == ERROR_IO_PENDING)
885 trace("InternetReadFileEx -> PENDING\n");
886 ok(flags & INTERNET_FLAG_ASYNC,
887 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
888 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
889 WaitForSingleObject(hCompleteEvent, INFINITE);
890 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
891 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
892 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
896 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
902 trace("InternetReadFileEx -> SUCCEEDED\n");
903 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
904 if (inetbuffers.dwBufferLength)
907 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
908 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
913 /* Win98 still sends these when 0 bytes are read, WinXP does not */
914 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
915 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
919 trace("read %i bytes\n", inetbuffers.dwBufferLength);
920 ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
922 ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678,
923 "InternetReadFileEx sets offsets to 0x%x%08x\n",
924 inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
926 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
928 if (!inetbuffers.dwBufferLength)
931 length += inetbuffers.dwBufferLength;
933 ok(length > 0, "failed to read any of the document\n");
934 trace("Finished. Read %d bytes\n", length);
937 close_async_handle(hi, hCompleteEvent, 2);
938 CloseHandle(hCompleteEvent);
939 first_connection_to_test_url = FALSE;
942 static void InternetOpenUrlA_test(void)
944 HINTERNET myhinternet, myhttp;
946 DWORD size, readbytes, totalbytes=0;
949 myhinternet = InternetOpen("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
950 ok((myhinternet != 0), "InternetOpen failed, error %u\n",GetLastError());
952 ret = InternetCanonicalizeUrl(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
953 ok( ret, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
956 myhttp = InternetOpenUrl(myhinternet, TEST_URL, 0, 0,
957 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
958 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
959 return; /* WinXP returns this when not connected to the net */
960 ok((myhttp != 0),"InternetOpenUrl failed, error %u\n",GetLastError());
961 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
962 ok( ret, "InternetReadFile failed, error %u\n",GetLastError());
963 totalbytes += readbytes;
964 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
965 totalbytes += readbytes;
966 trace("read 0x%08x bytes\n",totalbytes);
968 InternetCloseHandle(myhttp);
969 InternetCloseHandle(myhinternet);
972 static void HttpSendRequestEx_test(void)
978 INTERNET_BUFFERS BufferIn;
979 DWORD dwBytesWritten, dwBytesRead, error;
984 static char szPostData[] = "mode=Test";
985 static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
987 hSession = InternetOpen("Wine Regression Test",
988 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
989 ok( hSession != NULL ,"Unable to open Internet session\n");
990 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
991 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
993 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
994 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
995 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
996 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
998 skip( "Network unreachable, skipping test\n" );
1001 ok( hRequest != NULL, "Failed to open request handle err %u\n", GetLastError());
1004 BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS);
1005 BufferIn.Next = (LPINTERNET_BUFFERS)0xdeadcab;
1006 BufferIn.lpcszHeader = szContentType;
1007 BufferIn.dwHeadersLength = sizeof(szContentType)-1;
1008 BufferIn.dwHeadersTotal = sizeof(szContentType)-1;
1009 BufferIn.lpvBuffer = szPostData;
1010 BufferIn.dwBufferLength = 3;
1011 BufferIn.dwBufferTotal = sizeof(szPostData)-1;
1012 BufferIn.dwOffsetLow = 0;
1013 BufferIn.dwOffsetHigh = 0;
1015 SetLastError(0xdeadbeef);
1016 ret = HttpSendRequestEx(hRequest, &BufferIn, NULL, 0 ,0);
1017 error = GetLastError();
1018 ok(ret, "HttpSendRequestEx Failed with error %u\n", error);
1019 ok(error == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %u\n", error);
1021 for (i = 3; szPostData[i]; i++)
1022 ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten),
1023 "InternetWriteFile failed\n");
1025 ok(HttpEndRequest(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
1027 ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead),
1028 "Unable to read response\n");
1029 szBuffer[dwBytesRead] = 0;
1031 ok(dwBytesRead == 13,"Read %u bytes instead of 13\n",dwBytesRead);
1032 ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0 || broken(proxy_active()),"Got string %s\n",szBuffer);
1034 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1036 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1037 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1040 static void InternetOpenRequest_test(void)
1042 HINTERNET session, connect, request;
1043 static const char *types[] = { "*", "", NULL };
1044 static const WCHAR slash[] = {'/', 0}, any[] = {'*', 0}, empty[] = {0};
1045 static const WCHAR *typesW[] = { any, empty, NULL };
1048 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1049 ok(session != NULL ,"Unable to open Internet session\n");
1051 connect = InternetConnectA(session, NULL, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1052 INTERNET_SERVICE_HTTP, 0, 0);
1053 ok(connect == NULL, "InternetConnectA should have failed\n");
1054 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1056 connect = InternetConnectA(session, "", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1057 INTERNET_SERVICE_HTTP, 0, 0);
1058 ok(connect == NULL, "InternetConnectA should have failed\n");
1059 ok(GetLastError() == ERROR_INVALID_PARAMETER, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1061 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1062 INTERNET_SERVICE_HTTP, 0, 0);
1063 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1065 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1066 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1068 skip( "Network unreachable, skipping test\n" );
1071 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1073 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1074 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1075 ok(InternetCloseHandle(request), "Close request handle failed\n");
1077 request = HttpOpenRequestW(connect, NULL, slash, NULL, NULL, typesW, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1078 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1080 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1081 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1082 ok(InternetCloseHandle(request), "Close request handle failed\n");
1085 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1086 ok(InternetCloseHandle(session), "Close session handle failed\n");
1089 static void test_http_cache(void)
1091 HINTERNET session, connect, request;
1092 char file_name[MAX_PATH], url[INTERNET_MAX_URL_LENGTH];
1093 DWORD size, file_size;
1098 static const char *types[] = { "*", "", NULL };
1100 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
1101 ok(session != NULL ,"Unable to open Internet session\n");
1103 connect = InternetConnectA(session, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
1104 INTERNET_SERVICE_HTTP, 0, 0);
1105 ok(connect != NULL, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1107 request = HttpOpenRequestA(connect, NULL, "/tests/hello.html", NULL, NULL, types, INTERNET_FLAG_NEED_FILE, 0);
1108 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1110 skip( "Network unreachable, skipping test\n" );
1112 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1113 ok(InternetCloseHandle(session), "Close session handle failed\n");
1117 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1120 ret = InternetQueryOptionA(request, INTERNET_OPTION_URL, url, &size);
1121 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1122 ok(!strcmp(url, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url);
1124 size = sizeof(file_name);
1125 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1126 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1127 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1128 ok(!size, "size = %d\n", size);
1130 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1131 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1133 size = sizeof(file_name);
1134 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1135 ok(ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1137 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1138 FILE_ATTRIBUTE_NORMAL, NULL);
1139 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1140 file_size = GetFileSize(file, NULL);
1141 todo_wine ok(file_size == 106, "file size = %u\n", file_size);
1144 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1145 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1146 ok(size == 100, "size = %u\n", size);
1148 file_size = GetFileSize(file, NULL);
1149 todo_wine ok(file_size == 106, "file size = %u\n", file_size);
1152 ok(InternetCloseHandle(request), "Close request handle failed\n");
1154 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1155 FILE_ATTRIBUTE_NORMAL, NULL);
1156 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1159 /* Send the same request, requiring it to be retrieved from the cache */
1160 request = HttpOpenRequest(connect, "GET", "/tests/hello.html", NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
1162 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1163 ok(ret, "HttpSendRequest failed\n");
1166 ret = InternetReadFile(request, buf, sizeof(buf), &size);
1167 ok(ret, "InternetReadFile failed: %u\n", GetLastError());
1168 ok(size == 100, "size = %u\n", size);
1170 ok(InternetCloseHandle(request), "Close request handle failed\n");
1172 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1173 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
1175 size = sizeof(file_name);
1176 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1177 ok(!ret, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1178 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND, "GetLastError()=%u\n", GetLastError());
1179 ok(!size, "size = %d\n", size);
1181 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1182 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
1184 size = sizeof(file_name);
1186 ret = InternetQueryOptionA(request, INTERNET_OPTION_DATAFILE_NAME, file_name, &size);
1189 file = CreateFile(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1190 FILE_ATTRIBUTE_NORMAL, NULL);
1191 ok(file != INVALID_HANDLE_VALUE, "Could not create file: %u\n", GetLastError());
1197 ok(file_name[0] == 0, "Didn't expect a file name\n");
1200 ok(InternetCloseHandle(request), "Close request handle failed\n");
1201 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
1202 ok(InternetCloseHandle(session), "Close session handle failed\n");
1205 static void HttpHeaders_test(void)
1216 hSession = InternetOpen("Wine Regression Test",
1217 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
1218 ok( hSession != NULL ,"Unable to open Internet session\n");
1219 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
1220 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
1222 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
1223 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
1224 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
1225 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
1227 skip( "Network unreachable, skipping test\n" );
1230 ok( hRequest != NULL, "Failed to open request handle\n");
1233 len = sizeof(buffer);
1234 strcpy(buffer,"Warning");
1235 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1236 buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
1238 ok(HttpAddRequestHeaders(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
1239 "Failed to add new header\n");
1242 len = sizeof(buffer);
1243 strcpy(buffer,"Warning");
1244 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1245 buffer,&len,&index),"Unable to query header\n");
1246 ok(index == 1, "Index was not incremented\n");
1247 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1248 ok(len == 5, "Invalid length (exp. 5, got %d)\n", len);
1249 ok((len < sizeof(buffer)) && (buffer[len] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1250 len = sizeof(buffer);
1251 strcpy(buffer,"Warning");
1252 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1253 buffer,&len,&index)==0,"Second Index Should Not Exist\n");
1256 len = 5; /* could store the string but not the NULL terminator */
1257 strcpy(buffer,"Warning");
1258 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1259 buffer,&len,&index) == FALSE,"Query succeeded on a too small buffer\n");
1260 ok(strcmp(buffer,"Warning")==0, "incorrect string was returned(%s)\n",buffer); /* string not touched */
1261 ok(len == 6, "Invalid length (exp. 6, got %d)\n", len); /* unlike success, the length includes the NULL-terminator */
1263 /* a call with NULL will fail but will return the length */
1265 len = sizeof(buffer);
1266 SetLastError(0xdeadbeef);
1267 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1268 NULL,&len,&index) == FALSE,"Query worked\n");
1269 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1270 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1271 ok(index == 0, "Index was incremented\n");
1273 /* even for a len that is too small */
1276 SetLastError(0xdeadbeef);
1277 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1278 NULL,&len,&index) == FALSE,"Query worked\n");
1279 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1280 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1281 ok(index == 0, "Index was incremented\n");
1285 SetLastError(0xdeadbeef);
1286 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1287 NULL,&len,&index) == FALSE,"Query worked\n");
1288 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1289 ok(len > 40, "Invalid length (exp. more than 40, got %d)\n", len);
1290 ok(index == 0, "Index was incremented\n");
1291 oldlen = len; /* bytes; at least long enough to hold buffer & nul */
1294 /* a working query */
1296 len = sizeof(buffer);
1297 memset(buffer, 'x', sizeof(buffer));
1298 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1299 buffer,&len,&index),"Unable to query header\n");
1300 ok(len + sizeof(CHAR) <= oldlen, "Result longer than advertised\n");
1301 ok((len < sizeof(buffer)-sizeof(CHAR)) && (buffer[len/sizeof(CHAR)] == 0),"No NUL at end\n");
1302 ok(len == strlen(buffer) * sizeof(CHAR), "Length wrong\n");
1303 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1304 ok(strncmp(buffer, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1305 ok(strcmp(buffer + strlen(buffer) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1306 ok(index == 0, "Index was incremented\n");
1308 /* Like above two tests, but for W version */
1312 SetLastError(0xdeadbeef);
1313 ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1314 NULL,&len,&index) == FALSE,"Query worked\n");
1315 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Unexpected last error: %d\n", GetLastError());
1316 ok(len > 80, "Invalid length (exp. more than 80, got %d)\n", len);
1317 ok(index == 0, "Index was incremented\n");
1318 oldlen = len; /* bytes; at least long enough to hold buffer & nul */
1320 /* a working query */
1322 len = sizeof(wbuffer);
1323 memset(wbuffer, 'x', sizeof(wbuffer));
1324 ok(HttpQueryInfoW(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1325 wbuffer,&len,&index),"Unable to query header\n");
1326 ok(len + sizeof(WCHAR) <= oldlen, "Result longer than advertised\n");
1327 ok(len == lstrlenW(wbuffer) * sizeof(WCHAR), "Length wrong\n");
1328 ok((len < sizeof(wbuffer)-sizeof(WCHAR)) && (wbuffer[len/sizeof(WCHAR)] == 0),"No NUL at end\n");
1329 ok(index == 0, "Index was incremented\n");
1331 /* end of W version tests */
1333 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1335 len = sizeof(buffer);
1336 memset(buffer, 'x', sizeof(buffer));
1337 ok(HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF,
1338 buffer,&len,&index) == TRUE,"Query failed\n");
1339 ok(len == 2, "Expected 2, got %d\n", len);
1340 ok(strcmp(buffer, "\r\n") == 0, "Expected CRLF, got '%s'\n", buffer);
1341 ok(index == 0, "Index was incremented\n");
1343 ok(HttpAddRequestHeaders(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
1344 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1347 len = sizeof(buffer);
1348 strcpy(buffer,"Warning");
1349 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1350 buffer,&len,&index),"Unable to query header\n");
1351 ok(index == 1, "Index was not incremented\n");
1352 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
1353 len = sizeof(buffer);
1354 strcpy(buffer,"Warning");
1355 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1356 buffer,&len,&index),"Failed to get second header\n");
1357 ok(index == 2, "Index was not incremented\n");
1358 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1359 len = sizeof(buffer);
1360 strcpy(buffer,"Warning");
1361 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1362 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1364 ok(HttpAddRequestHeaders(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1367 len = sizeof(buffer);
1368 strcpy(buffer,"Warning");
1369 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1370 buffer,&len,&index),"Unable to query header\n");
1371 ok(index == 1, "Index was not incremented\n");
1372 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1373 len = sizeof(buffer);
1374 strcpy(buffer,"Warning");
1375 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1376 buffer,&len,&index),"Failed to get second header\n");
1377 ok(index == 2, "Index was not incremented\n");
1378 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1379 len = sizeof(buffer);
1380 strcpy(buffer,"Warning");
1381 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1382 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1384 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1387 len = sizeof(buffer);
1388 strcpy(buffer,"Warning");
1389 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1390 buffer,&len,&index),"Unable to query header\n");
1391 ok(index == 1, "Index was not incremented\n");
1392 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
1393 len = sizeof(buffer);
1394 strcpy(buffer,"Warning");
1395 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1396 buffer,&len,&index),"Failed to get second header\n");
1397 ok(index == 2, "Index was not incremented\n");
1398 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1399 len = sizeof(buffer);
1400 strcpy(buffer,"Warning");
1401 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1402 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1404 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1407 len = sizeof(buffer);
1408 strcpy(buffer,"Warning");
1409 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
1410 buffer,&len,&index),"Unable to query header\n");
1411 ok(index == 1, "Index was not incremented\n");
1412 ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer);
1413 len = sizeof(buffer);
1414 strcpy(buffer,"Warning");
1415 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1416 ok(index == 2, "Index was not incremented\n");
1417 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1418 len = sizeof(buffer);
1419 strcpy(buffer,"Warning");
1420 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1422 ok(HttpAddRequestHeaders(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1425 len = sizeof(buffer);
1426 strcpy(buffer,"Warning");
1427 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1428 ok(index == 1, "Index was not incremented\n");
1429 ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer);
1430 len = sizeof(buffer);
1431 strcpy(buffer,"Warning");
1432 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1433 ok(index == 2, "Index was not incremented\n");
1434 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1435 len = sizeof(buffer);
1436 strcpy(buffer,"Warning");
1437 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1439 ok(HttpAddRequestHeaders(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1442 len = sizeof(buffer);
1443 strcpy(buffer,"Warning");
1444 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1445 ok(index == 1, "Index was not incremented\n");
1446 ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer);
1447 len = sizeof(buffer);
1448 strcpy(buffer,"Warning");
1449 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1450 ok(index == 2, "Index was not incremented\n");
1451 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1452 len = sizeof(buffer);
1453 strcpy(buffer,"Warning");
1454 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1456 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");
1459 len = sizeof(buffer);
1460 strcpy(buffer,"Warning");
1461 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1462 ok(index == 1, "Index was not incremented\n");
1463 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
1464 len = sizeof(buffer);
1465 strcpy(buffer,"Warning");
1466 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
1467 ok(index == 2, "Index was not incremented\n");
1468 ok(strcmp(buffer,"test7")==0, "incorrect string was returned(%s)\n",buffer);
1469 len = sizeof(buffer);
1470 strcpy(buffer,"Warning");
1471 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
1473 /* Ensure that blank headers are ignored and don't cause a failure */
1474 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");
1477 len = sizeof(buffer);
1478 strcpy(buffer,"BlankTest");
1479 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1480 ok(index == 1, "Index was not incremented\n");
1481 ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
1483 /* Ensure that malformed header separators are ignored and don't cause a failure */
1484 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),
1485 "Failed to add header with malformed entries in list\n");
1488 len = sizeof(buffer);
1489 strcpy(buffer,"MalformedTest");
1490 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1491 ok(index == 1, "Index was not incremented\n");
1492 ok(strcmp(buffer,"value")==0, "incorrect string was returned(%s)\n",buffer);
1494 len = sizeof(buffer);
1495 strcpy(buffer,"MalformedTestTwo");
1496 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1497 ok(index == 1, "Index was not incremented\n");
1498 ok(strcmp(buffer,"value2")==0, "incorrect string was returned(%s)\n",buffer);
1500 len = sizeof(buffer);
1501 strcpy(buffer,"MalformedTestThree");
1502 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
1503 ok(index == 1, "Index was not incremented\n");
1504 ok(strcmp(buffer,"value3")==0, "incorrect string was returned(%s)\n",buffer);
1506 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
1508 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
1509 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
1512 static const char garbagemsg[] =
1513 "Garbage: Header\r\n";
1515 static const char contmsg[] =
1516 "HTTP/1.1 100 Continue\r\n";
1518 static const char expandcontmsg[] =
1519 "HTTP/1.1 100 Continue\r\n"
1520 "Server: winecontinue\r\n"
1521 "Tag: something witty\r\n"
1524 static const char okmsg[] =
1525 "HTTP/1.1 200 OK\r\n"
1526 "Server: winetest\r\n"
1529 static const char okmsg2[] =
1530 "HTTP/1.1 200 OK\r\n"
1531 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
1532 "Server: winetest\r\n"
1533 "Content-Length: 0\r\n"
1534 "Set-Cookie: one\r\n"
1535 "Set-Cookie: two\r\n"
1538 static const char notokmsg[] =
1539 "HTTP/1.1 400 Bad Request\r\n"
1540 "Server: winetest\r\n"
1543 static const char noauthmsg[] =
1544 "HTTP/1.1 401 Unauthorized\r\n"
1545 "Server: winetest\r\n"
1546 "Connection: close\r\n"
1547 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1550 static const char noauthmsg2[] =
1551 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
1552 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
1554 "Server: winetest\r\n";
1556 static const char proxymsg[] =
1557 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1558 "Server: winetest\r\n"
1559 "Proxy-Connection: close\r\n"
1560 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1563 static const char page1[] =
1565 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1566 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1569 struct server_info {
1572 int num_testH_retrievals;
1575 static DWORD CALLBACK server_thread(LPVOID param)
1577 struct server_info *si = param;
1580 struct sockaddr_in sa;
1583 int last_request = 0;
1584 char host_header[22];
1585 static int test_b = 0;
1587 WSAStartup(MAKEWORD(1,1), &wsaData);
1589 s = socket(AF_INET, SOCK_STREAM, 0);
1590 if (s == INVALID_SOCKET)
1594 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof on);
1596 memset(&sa, 0, sizeof sa);
1597 sa.sin_family = AF_INET;
1598 sa.sin_port = htons(si->port);
1599 sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
1601 r = bind(s, (struct sockaddr*) &sa, sizeof sa);
1607 SetEvent(si->hEvent);
1609 sprintf(host_header, "Host: localhost:%d", si->port);
1613 c = accept(s, NULL, NULL);
1615 memset(buffer, 0, sizeof buffer);
1616 for(i=0; i<(sizeof buffer-1); i++)
1618 r = recv(c, &buffer[i], 1, 0);
1622 if (buffer[i-2] == '\n' && buffer[i] == '\n' &&
1623 buffer[i-3] == '\r' && buffer[i-1] == '\r')
1626 if (strstr(buffer, "GET /test1"))
1628 if (!strstr(buffer, "Content-Length: 0"))
1630 send(c, okmsg, sizeof okmsg-1, 0);
1631 send(c, page1, sizeof page1-1, 0);
1634 send(c, notokmsg, sizeof notokmsg-1, 0);
1636 if (strstr(buffer, "/test2"))
1638 if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx"))
1640 send(c, okmsg, sizeof okmsg-1, 0);
1641 send(c, page1, sizeof page1-1, 0);
1644 send(c, proxymsg, sizeof proxymsg-1, 0);
1646 if (strstr(buffer, "/test3"))
1648 if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
1649 send(c, okmsg, sizeof okmsg-1, 0);
1651 send(c, noauthmsg, sizeof noauthmsg-1, 0);
1653 if (strstr(buffer, "/test4"))
1655 if (strstr(buffer, "Connection: Close"))
1656 send(c, okmsg, sizeof okmsg-1, 0);
1658 send(c, notokmsg, sizeof notokmsg-1, 0);
1660 if (strstr(buffer, "POST /test5") ||
1661 strstr(buffer, "RPC_IN_DATA /test5") ||
1662 strstr(buffer, "RPC_OUT_DATA /test5"))
1664 if (strstr(buffer, "Content-Length: 0"))
1666 send(c, okmsg, sizeof okmsg-1, 0);
1667 send(c, page1, sizeof page1-1, 0);
1670 send(c, notokmsg, sizeof notokmsg-1, 0);
1672 if (strstr(buffer, "GET /test6"))
1674 send(c, contmsg, sizeof contmsg-1, 0);
1675 send(c, contmsg, sizeof contmsg-1, 0);
1676 send(c, okmsg, sizeof okmsg-1, 0);
1677 send(c, page1, sizeof page1-1, 0);
1679 if (strstr(buffer, "POST /test7"))
1681 if (strstr(buffer, "Content-Length: 100"))
1683 send(c, okmsg, sizeof okmsg-1, 0);
1684 send(c, page1, sizeof page1-1, 0);
1687 send(c, notokmsg, sizeof notokmsg-1, 0);
1689 if (strstr(buffer, "/test8"))
1691 if (!strstr(buffer, "Connection: Close") &&
1692 strstr(buffer, "Connection: Keep-Alive") &&
1693 !strstr(buffer, "Cache-Control: no-cache") &&
1694 !strstr(buffer, "Pragma: no-cache") &&
1695 strstr(buffer, host_header))
1696 send(c, okmsg, sizeof okmsg-1, 0);
1698 send(c, notokmsg, sizeof notokmsg-1, 0);
1700 if (strstr(buffer, "/test9"))
1702 if (!strstr(buffer, "Connection: Close") &&
1703 !strstr(buffer, "Connection: Keep-Alive") &&
1704 !strstr(buffer, "Cache-Control: no-cache") &&
1705 !strstr(buffer, "Pragma: no-cache") &&
1706 strstr(buffer, host_header))
1707 send(c, okmsg, sizeof okmsg-1, 0);
1709 send(c, notokmsg, sizeof notokmsg-1, 0);
1711 if (strstr(buffer, "/testA"))
1713 if (!strstr(buffer, "Connection: Close") &&
1714 !strstr(buffer, "Connection: Keep-Alive") &&
1715 (strstr(buffer, "Cache-Control: no-cache") ||
1716 strstr(buffer, "Pragma: no-cache")) &&
1717 strstr(buffer, host_header))
1718 send(c, okmsg, sizeof okmsg-1, 0);
1720 send(c, notokmsg, sizeof notokmsg-1, 0);
1722 if (!test_b && strstr(buffer, "/testB HTTP/1.1"))
1725 send(c, okmsg, sizeof okmsg-1, 0);
1726 recvfrom(c, buffer, sizeof buffer, 0, NULL, NULL);
1727 send(c, okmsg, sizeof okmsg-1, 0);
1729 if (strstr(buffer, "/testC"))
1731 if (strstr(buffer, "Cookie: cookie=biscuit"))
1732 send(c, okmsg, sizeof okmsg-1, 0);
1734 send(c, notokmsg, sizeof notokmsg-1, 0);
1736 if (strstr(buffer, "/testD"))
1738 send(c, okmsg2, sizeof okmsg2-1, 0);
1740 if (strstr(buffer, "/testE"))
1742 send(c, noauthmsg2, sizeof noauthmsg2-1, 0);
1744 if (strstr(buffer, "GET /quit"))
1746 send(c, okmsg, sizeof okmsg-1, 0);
1747 send(c, page1, sizeof page1-1, 0);
1750 if (strstr(buffer, "GET /testF"))
1752 send(c, expandcontmsg, sizeof expandcontmsg-1, 0);
1753 send(c, garbagemsg, sizeof garbagemsg-1, 0);
1754 send(c, contmsg, sizeof contmsg-1, 0);
1755 send(c, garbagemsg, sizeof garbagemsg-1, 0);
1756 send(c, okmsg, sizeof okmsg-1, 0);
1757 send(c, page1, sizeof page1-1, 0);
1759 if (strstr(buffer, "GET /testG"))
1761 send(c, page1, sizeof page1-1, 0);
1763 if (strstr(buffer, "GET /testH"))
1765 si->num_testH_retrievals++;
1766 if (!strstr(buffer, "Content-Length: 0"))
1768 send(c, okmsg, sizeof okmsg-1, 0);
1769 send(c, page1, sizeof page1-1, 0);
1772 send(c, notokmsg, sizeof notokmsg-1, 0);
1774 if (strstr(buffer, "GET /test_no_content"))
1776 static const char nocontentmsg[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
1777 send(c, nocontentmsg, sizeof(nocontentmsg)-1, 0);
1779 if (strstr(buffer, "GET /test_conn_close"))
1781 static const char conn_close_response[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
1782 send(c, conn_close_response, sizeof(conn_close_response)-1, 0);
1783 WaitForSingleObject(conn_close_event, INFINITE);
1784 trace("closing connection\n");
1789 } while (!last_request);
1796 static void test_basic_request(int port, const char *verb, const char *url)
1798 HINTERNET hi, hc, hr;
1802 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1803 ok(hi != NULL, "open failed\n");
1805 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1806 ok(hc != NULL, "connect failed\n");
1808 hr = HttpOpenRequest(hc, verb, url, NULL, NULL, NULL, 0, 0);
1809 ok(hr != NULL, "HttpOpenRequest failed\n");
1811 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1812 ok(r, "HttpSendRequest failed\n");
1815 memset(buffer, 0, sizeof buffer);
1816 SetLastError(0xdeadbeef);
1817 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
1818 ok(r, "InternetReadFile failed %u\n", GetLastError());
1819 ok(count == sizeof page1 - 1, "count was wrong\n");
1820 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong, got: %s\n", buffer);
1822 InternetCloseHandle(hr);
1823 InternetCloseHandle(hc);
1824 InternetCloseHandle(hi);
1827 static void test_last_error(int port)
1829 HINTERNET hi, hc, hr;
1833 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1834 ok(hi != NULL, "open failed\n");
1836 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1837 ok(hc != NULL, "connect failed\n");
1839 hr = HttpOpenRequest(hc, NULL, "/test1", NULL, NULL, NULL, 0, 0);
1840 ok(hr != NULL, "HttpOpenRequest failed\n");
1842 SetLastError(0xdeadbeef);
1843 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1844 error = GetLastError();
1845 ok(r, "HttpSendRequest failed\n");
1846 ok(error == ERROR_SUCCESS || broken(error != ERROR_SUCCESS), "expected ERROR_SUCCESS, got %u\n", error);
1848 InternetCloseHandle(hr);
1849 InternetCloseHandle(hc);
1850 InternetCloseHandle(hi);
1853 static void test_proxy_indirect(int port)
1855 HINTERNET hi, hc, hr;
1859 hi = InternetOpen(NULL, 0, NULL, NULL, 0);
1860 ok(hi != NULL, "open failed\n");
1862 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1863 ok(hc != NULL, "connect failed\n");
1865 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
1866 ok(hr != NULL, "HttpOpenRequest failed\n");
1868 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1869 ok(r, "HttpSendRequest failed\n");
1872 r = HttpQueryInfo(hr, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL);
1873 ok(r || GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo failed: %d\n", GetLastError());
1876 skip("missing proxy header, not testing remaining proxy headers\n");
1879 ok(!strcmp(buffer, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
1882 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1883 ok(r, "HttpQueryInfo failed\n");
1884 ok(!strcmp(buffer, "407"), "proxy code wrong\n");
1887 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &val, &sz, NULL);
1888 ok(r, "HttpQueryInfo failed\n");
1889 ok(val == 407, "proxy code wrong\n");
1892 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL);
1893 ok(r, "HttpQueryInfo failed\n");
1894 ok(!strcmp(buffer, "Proxy Authentication Required"), "proxy text wrong\n");
1897 r = HttpQueryInfo(hr, HTTP_QUERY_VERSION, buffer, &sz, NULL);
1898 ok(r, "HttpQueryInfo failed\n");
1899 ok(!strcmp(buffer, "HTTP/1.1"), "http version wrong\n");
1902 r = HttpQueryInfo(hr, HTTP_QUERY_SERVER, buffer, &sz, NULL);
1903 ok(r, "HttpQueryInfo failed\n");
1904 ok(!strcmp(buffer, "winetest"), "http server wrong\n");
1907 r = HttpQueryInfo(hr, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL);
1908 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo should fail\n");
1909 ok(r == FALSE, "HttpQueryInfo failed\n");
1912 InternetCloseHandle(hr);
1913 InternetCloseHandle(hc);
1914 InternetCloseHandle(hi);
1917 static void test_proxy_direct(int port)
1919 HINTERNET hi, hc, hr;
1922 static CHAR username[] = "mike",
1923 password[] = "1101";
1925 sprintf(buffer, "localhost:%d\n", port);
1926 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0);
1927 ok(hi != NULL, "open failed\n");
1929 /* try connect without authorization */
1930 hc = InternetConnect(hi, "test.winehq.org/", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1931 ok(hc != NULL, "connect failed\n");
1933 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
1934 ok(hr != NULL, "HttpOpenRequest failed\n");
1936 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1937 ok(r, "HttpSendRequest failed\n");
1940 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1941 ok(r, "HttpQueryInfo failed\n");
1942 ok(!strcmp(buffer, "407"), "proxy code wrong\n");
1945 /* set the user + password then try again */
1947 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_USERNAME, username, 4);
1948 ok(r, "failed to set user\n");
1950 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_PASSWORD, password, 4);
1951 ok(r, "failed to set password\n");
1954 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1955 ok(r, "HttpSendRequest failed\n");
1957 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1958 ok(r, "HttpQueryInfo failed\n");
1960 ok(!strcmp(buffer, "200"), "proxy code wrong\n");
1964 InternetCloseHandle(hr);
1965 InternetCloseHandle(hc);
1966 InternetCloseHandle(hi);
1969 static void test_header_handling_order(int port)
1971 static char authorization[] = "Authorization: Basic dXNlcjpwd2Q=";
1972 static char connection[] = "Connection: Close";
1974 static const char *types[2] = { "*", NULL };
1975 HINTERNET session, connect, request;
1979 session = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
1980 ok(session != NULL, "InternetOpen failed\n");
1982 connect = InternetConnect(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1983 ok(connect != NULL, "InternetConnect failed\n");
1985 request = HttpOpenRequest(connect, NULL, "/test3", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
1986 ok(request != NULL, "HttpOpenRequest failed\n");
1988 ret = HttpAddRequestHeaders(request, authorization, ~0u, HTTP_ADDREQ_FLAG_ADD);
1989 ok(ret, "HttpAddRequestHeaders failed\n");
1991 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
1992 ok(ret, "HttpSendRequest failed\n");
1995 size = sizeof(status);
1996 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
1997 ok(ret, "HttpQueryInfo failed\n");
1998 ok(status == 200, "request failed with status %u\n", status);
2000 InternetCloseHandle(request);
2002 request = HttpOpenRequest(connect, NULL, "/test4", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2003 ok(request != NULL, "HttpOpenRequest failed\n");
2005 ret = HttpSendRequest(request, connection, ~0u, NULL, 0);
2006 ok(ret, "HttpSendRequest failed\n");
2009 size = sizeof(status);
2010 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2011 ok(ret, "HttpQueryInfo failed\n");
2012 ok(status == 200 || status == 400 /* IE6 */, "got status %u, expected 200 or 400\n", status);
2014 InternetCloseHandle(request);
2016 request = HttpOpenRequest(connect, "POST", "/test7", NULL, NULL, types, INTERNET_FLAG_KEEP_CONNECTION, 0);
2017 ok(request != NULL, "HttpOpenRequest failed\n");
2019 ret = HttpAddRequestHeaders(request, "Content-Length: 100\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
2020 ok(ret, "HttpAddRequestHeaders failed\n");
2022 ret = HttpSendRequest(request, connection, ~0u, NULL, 0);
2023 ok(ret, "HttpSendRequest failed\n");
2026 size = sizeof(status);
2027 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2028 ok(ret, "HttpQueryInfo failed\n");
2029 ok(status == 200 || status == 400 /* IE6 */, "got status %u, expected 200 or 400\n", status);
2031 InternetCloseHandle(request);
2032 InternetCloseHandle(connect);
2033 InternetCloseHandle(session);
2036 static void test_connection_header(int port)
2038 HINTERNET ses, con, req;
2042 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2043 ok(ses != NULL, "InternetOpen failed\n");
2045 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2046 ok(con != NULL, "InternetConnect failed\n");
2048 req = HttpOpenRequest(con, NULL, "/test8", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2049 ok(req != NULL, "HttpOpenRequest failed\n");
2051 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2052 ok(ret, "HttpSendRequest failed\n");
2055 size = sizeof(status);
2056 ret = HttpQueryInfo(req, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL);
2057 ok(ret, "HttpQueryInfo failed\n");
2058 ok(status == 200, "request failed with status %u\n", status);
2060 InternetCloseHandle(req);
2062 req = HttpOpenRequest(con, NULL, "/test9", NULL, NULL, NULL, 0, 0);
2063 ok(req != NULL, "HttpOpenRequest failed\n");
2065 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2066 ok(ret, "HttpSendRequest failed\n");
2069 size = sizeof(status);
2070 ret = HttpQueryInfo(req, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL);
2071 ok(ret, "HttpQueryInfo failed\n");
2072 ok(status == 200, "request failed with status %u\n", status);
2074 InternetCloseHandle(req);
2076 req = HttpOpenRequest(con, NULL, "/test9", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
2077 ok(req != NULL, "HttpOpenRequest failed\n");
2079 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2080 ok(ret, "HttpSendRequest failed\n");
2083 size = sizeof(status);
2084 ret = HttpQueryInfo(req, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL);
2085 ok(ret, "HttpQueryInfo failed\n");
2086 ok(status == 200, "request failed with status %u\n", status);
2088 InternetCloseHandle(req);
2090 req = HttpOpenRequest(con, "POST", "/testA", NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
2091 ok(req != NULL, "HttpOpenRequest failed\n");
2093 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2094 ok(ret, "HttpSendRequest failed\n");
2097 size = sizeof(status);
2098 ret = HttpQueryInfo(req, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL);
2099 ok(ret, "HttpQueryInfo failed\n");
2100 ok(status == 200, "request failed with status %u\n", status);
2102 InternetCloseHandle(req);
2103 InternetCloseHandle(con);
2104 InternetCloseHandle(ses);
2107 static void test_http1_1(int port)
2109 HINTERNET ses, con, req;
2112 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2113 ok(ses != NULL, "InternetOpen failed\n");
2115 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2116 ok(con != NULL, "InternetConnect failed\n");
2118 req = HttpOpenRequest(con, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2119 ok(req != NULL, "HttpOpenRequest failed\n");
2121 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2124 InternetCloseHandle(req);
2126 req = HttpOpenRequest(con, NULL, "/testB", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2127 ok(req != NULL, "HttpOpenRequest failed\n");
2129 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2130 ok(ret, "HttpSendRequest failed\n");
2133 InternetCloseHandle(req);
2134 InternetCloseHandle(con);
2135 InternetCloseHandle(ses);
2138 static void test_no_content(int port)
2140 HINTERNET session, connection, req;
2143 trace("Testing 204 no content response...\n");
2145 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
2147 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
2148 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
2150 pInternetSetStatusCallbackA(session, callback);
2152 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2153 connection = InternetConnectA(session, "localhost", port,
2154 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
2155 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
2156 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2158 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2159 req = HttpOpenRequestA(connection, "GET", "/test_no_content", NULL, NULL, NULL,
2160 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
2161 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
2162 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2164 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
2165 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
2166 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
2167 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
2168 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
2169 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
2170 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
2171 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
2172 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
2173 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2175 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
2176 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2177 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2178 WaitForSingleObject(hCompleteEvent, INFINITE);
2179 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2181 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
2182 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
2183 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
2184 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
2185 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
2186 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
2187 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
2188 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
2189 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
2190 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
2192 close_async_handle(session, hCompleteEvent, 2);
2193 CloseHandle(hCompleteEvent);
2196 static void test_conn_close(int port)
2198 HINTERNET session, connection, req;
2199 DWORD res, avail, size;
2202 trace("Testing connection close connection...\n");
2204 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
2205 conn_close_event = CreateEvent(NULL, FALSE, FALSE, NULL);
2207 session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
2208 ok(session != NULL,"InternetOpen failed with error %u\n", GetLastError());
2210 pInternetSetStatusCallbackA(session, callback);
2212 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2213 connection = InternetConnectA(session, "localhost", port,
2214 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
2215 ok(connection != NULL,"InternetConnect failed with error %u\n", GetLastError());
2216 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2218 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED);
2219 req = HttpOpenRequestA(connection, "GET", "/test_conn_close", NULL, NULL, NULL,
2220 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
2221 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
2222 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED);
2224 SET_OPTIONAL(INTERNET_STATUS_COOKIE_SENT);
2225 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER);
2226 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER);
2227 SET_EXPECT(INTERNET_STATUS_SENDING_REQUEST);
2228 SET_EXPECT(INTERNET_STATUS_REQUEST_SENT);
2229 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE);
2230 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED);
2231 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2233 res = HttpSendRequestA(req, NULL, -1, NULL, 0);
2234 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2235 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2236 WaitForSingleObject(hCompleteEvent, INFINITE);
2237 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2239 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT);
2240 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER);
2241 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER);
2242 CHECK_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST);
2243 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_SENT);
2244 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE);
2245 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED);
2246 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
2249 res = InternetQueryDataAvailable(req, &avail, 0, 0);
2250 ok(res, "InternetQueryDataAvailable failed: %u\n", GetLastError());
2251 ok(avail != 0, "avail = 0\n");
2254 res = InternetReadFile(req, buf, avail, &size);
2255 ok(res, "InternetReadFile failed: %u\n", GetLastError());
2257 res = InternetQueryDataAvailable(req, &avail, 0, 0);
2258 ok(!res && (GetLastError() == ERROR_IO_PENDING),
2259 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
2260 ok(!avail, "avail = %u, expected 0\n", avail);
2262 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION);
2263 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED);
2264 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE);
2265 SetEvent(conn_close_event);
2266 WaitForSingleObject(hCompleteEvent, INFINITE);
2267 ok(req_error == ERROR_SUCCESS, "req_error = %u\n", req_error);
2268 CHECK_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION);
2269 CHECK_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED);
2270 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE);
2272 close_async_handle(session, hCompleteEvent, 2);
2273 CloseHandle(hCompleteEvent);
2276 static void test_HttpSendRequestW(int port)
2278 static const WCHAR header[] = {'U','A','-','C','P','U',':',' ','x','8','6',0};
2279 HINTERNET ses, con, req;
2283 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, INTERNET_FLAG_ASYNC);
2284 ok(ses != NULL, "InternetOpen failed\n");
2286 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2287 ok(con != NULL, "InternetConnect failed\n");
2289 req = HttpOpenRequest(con, NULL, "/test1", NULL, NULL, NULL, 0, 0);
2290 ok(req != NULL, "HttpOpenRequest failed\n");
2292 SetLastError(0xdeadbeef);
2293 ret = HttpSendRequestW(req, header, ~0u, NULL, 0);
2294 error = GetLastError();
2295 ok(!ret, "HttpSendRequestW succeeded\n");
2296 ok(error == ERROR_IO_PENDING ||
2297 broken(error == ERROR_HTTP_HEADER_NOT_FOUND) || /* IE6 */
2298 broken(error == ERROR_INVALID_PARAMETER), /* IE5 */
2299 "got %u expected ERROR_IO_PENDING\n", error);
2301 InternetCloseHandle(req);
2302 InternetCloseHandle(con);
2303 InternetCloseHandle(ses);
2306 static void test_cookie_header(int port)
2308 HINTERNET ses, con, req;
2309 DWORD size, status, error;
2313 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2314 ok(ses != NULL, "InternetOpen failed\n");
2316 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2317 ok(con != NULL, "InternetConnect failed\n");
2319 InternetSetCookie("http://localhost", "cookie", "biscuit");
2321 req = HttpOpenRequest(con, NULL, "/testC", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
2322 ok(req != NULL, "HttpOpenRequest failed\n");
2325 size = sizeof(buffer);
2326 SetLastError(0xdeadbeef);
2327 ret = HttpQueryInfo(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
2328 error = GetLastError();
2329 ok(!ret, "HttpQueryInfo succeeded\n");
2330 ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error);
2332 ret = HttpAddRequestHeaders(req, "Cookie: cookie=not biscuit\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD);
2333 ok(ret, "HttpAddRequestHeaders failed: %u\n", GetLastError());
2336 size = sizeof(buffer);
2337 ret = HttpQueryInfo(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
2338 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
2339 ok(!strcmp(buffer, "cookie=not biscuit"), "got '%s' expected \'cookie=not biscuit\'\n", buffer);
2341 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2342 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
2345 size = sizeof(status);
2346 ret = HttpQueryInfo(req, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL);
2347 ok(ret, "HttpQueryInfo failed\n");
2348 ok(status == 200, "request failed with status %u\n", status);
2351 size = sizeof(buffer);
2352 ret = HttpQueryInfo(req, HTTP_QUERY_COOKIE | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
2353 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
2354 ok(!strcmp(buffer, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer);
2356 InternetCloseHandle(req);
2357 InternetCloseHandle(con);
2358 InternetCloseHandle(ses);
2361 static void test_basic_authentication(int port)
2363 HINTERNET session, connect, request;
2367 session = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2368 ok(session != NULL, "InternetOpen failed\n");
2370 connect = InternetConnect(session, "localhost", port, "user", "pwd", INTERNET_SERVICE_HTTP, 0, 0);
2371 ok(connect != NULL, "InternetConnect failed\n");
2373 request = HttpOpenRequest(connect, NULL, "/test3", NULL, NULL, NULL, 0, 0);
2374 ok(request != NULL, "HttpOpenRequest failed\n");
2376 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
2377 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
2380 size = sizeof(status);
2381 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2382 ok(ret, "HttpQueryInfo failed\n");
2383 ok(status == 200, "request failed with status %u\n", status);
2385 InternetCloseHandle(request);
2386 InternetCloseHandle(connect);
2387 InternetCloseHandle(session);
2390 static void test_invalid_response_headers(int port)
2392 HINTERNET session, connect, request;
2397 session = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2398 ok(session != NULL, "InternetOpen failed\n");
2400 connect = InternetConnect(session, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2401 ok(connect != NULL, "InternetConnect failed\n");
2403 request = HttpOpenRequest(connect, NULL, "/testE", NULL, NULL, NULL, 0, 0);
2404 ok(request != NULL, "HttpOpenRequest failed\n");
2406 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
2407 ok(ret, "HttpSendRequest failed %u\n", GetLastError());
2410 size = sizeof(status);
2411 ret = HttpQueryInfo( request, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2412 ok(ret, "HttpQueryInfo failed\n");
2413 ok(status == 401, "unexpected status %u\n", status);
2416 size = sizeof(buffer);
2417 ret = HttpQueryInfo( request, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
2418 ok(ret, "HttpQueryInfo failed\n");
2419 ok(!strcmp(buffer, "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"),
2420 "headers wrong \"%s\"\n", buffer);
2423 size = sizeof(buffer);
2424 ret = HttpQueryInfo( request, HTTP_QUERY_SERVER, buffer, &size, NULL);
2425 ok(ret, "HttpQueryInfo failed\n");
2426 ok(!strcmp(buffer, "winetest"), "server wrong \"%s\"\n", buffer);
2428 InternetCloseHandle(request);
2429 InternetCloseHandle(connect);
2430 InternetCloseHandle(session);
2433 static void test_response_without_headers(int port)
2435 HINTERNET hi, hc, hr;
2436 DWORD r, count, size, status;
2439 SetLastError(0xdeadbeef);
2440 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2441 ok(hi != NULL, "open failed %u\n", GetLastError());
2443 SetLastError(0xdeadbeef);
2444 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2445 ok(hc != NULL, "connect failed %u\n", GetLastError());
2447 SetLastError(0xdeadbeef);
2448 hr = HttpOpenRequest(hc, NULL, "/testG", NULL, NULL, NULL, 0, 0);
2449 ok(hr != NULL, "HttpOpenRequest failed %u\n", GetLastError());
2451 SetLastError(0xdeadbeef);
2452 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
2453 ok(r, "HttpSendRequest failed %u\n", GetLastError());
2456 memset(buffer, 0, sizeof buffer);
2457 SetLastError(0xdeadbeef);
2458 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
2459 ok(r, "InternetReadFile failed %u\n", GetLastError());
2460 todo_wine ok(count == sizeof page1 - 1, "count was wrong\n");
2461 todo_wine ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
2464 size = sizeof(status);
2465 SetLastError(0xdeadbeef);
2466 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &status, &size, NULL );
2467 todo_wine ok(r, "HttpQueryInfo failed %u\n", GetLastError());
2468 todo_wine ok(status == 200, "expected status 200 got %u\n", status);
2471 size = sizeof(buffer);
2472 SetLastError(0xdeadbeef);
2473 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, NULL );
2474 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
2475 ok(!strcmp(buffer, "OK"), "expected OK got: \"%s\"\n", buffer);
2478 size = sizeof(buffer);
2479 SetLastError(0xdeadbeef);
2480 r = HttpQueryInfo(hr, HTTP_QUERY_VERSION, buffer, &size, NULL);
2481 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
2482 ok(!strcmp(buffer, "HTTP/1.0"), "expected HTTP/1.0 got: \"%s\"\n", buffer);
2485 size = sizeof(buffer);
2486 SetLastError(0xdeadbeef);
2487 r = HttpQueryInfo(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, NULL);
2488 ok(r, "HttpQueryInfo failed %u\n", GetLastError());
2489 ok(!strcmp(buffer, "HTTP/1.0 200 OK"), "raw headers wrong: \"%s\"\n", buffer);
2491 InternetCloseHandle(hr);
2492 InternetCloseHandle(hc);
2493 InternetCloseHandle(hi);
2496 static void test_HttpQueryInfo(int port)
2498 HINTERNET hi, hc, hr;
2503 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2504 ok(hi != NULL, "InternetOpen failed\n");
2506 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2507 ok(hc != NULL, "InternetConnect failed\n");
2509 hr = HttpOpenRequest(hc, NULL, "/testD", NULL, NULL, NULL, 0, 0);
2510 ok(hr != NULL, "HttpOpenRequest failed\n");
2512 ret = HttpSendRequest(hr, NULL, 0, NULL, 0);
2513 ok(ret, "HttpSendRequest failed\n");
2516 size = sizeof(buffer);
2517 ret = HttpQueryInfo(hr, HTTP_QUERY_HOST | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, &index);
2518 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2519 ok(index == 1, "expected 1 got %u\n", index);
2522 size = sizeof(buffer);
2523 ret = HttpQueryInfo(hr, HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME, buffer, &size, &index);
2524 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2525 ok(index == 1, "expected 1 got %u\n", index);
2528 size = sizeof(buffer);
2529 ret = HttpQueryInfo(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
2530 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2531 ok(index == 0, "expected 0 got %u\n", index);
2533 size = sizeof(buffer);
2534 ret = HttpQueryInfo(hr, HTTP_QUERY_RAW_HEADERS, buffer, &size, &index);
2535 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2536 ok(index == 0, "expected 0 got %u\n", index);
2538 size = sizeof(buffer);
2539 ret = HttpQueryInfo(hr, HTTP_QUERY_RAW_HEADERS_CRLF, buffer, &size, &index);
2540 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2541 ok(index == 0, "expected 0 got %u\n", index);
2543 size = sizeof(buffer);
2544 ret = HttpQueryInfo(hr, HTTP_QUERY_STATUS_TEXT, buffer, &size, &index);
2545 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2546 ok(index == 0, "expected 0 got %u\n", index);
2548 size = sizeof(buffer);
2549 ret = HttpQueryInfo(hr, HTTP_QUERY_VERSION, buffer, &size, &index);
2550 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2551 ok(index == 0, "expected 0 got %u\n", index);
2554 size = sizeof(buffer);
2555 ret = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &size, &index);
2556 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2557 ok(index == 0, "expected 0 got %u\n", index);
2560 size = sizeof(buffer);
2561 ret = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, buffer, &size, &index);
2562 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2563 ok(index == 0, "expected 0 got %u\n", index);
2566 size = sizeof(buffer);
2567 ret = HttpQueryInfo(hr, HTTP_QUERY_FORWARDED, buffer, &size, &index);
2568 ok(!ret, "HttpQueryInfo succeeded\n");
2569 ok(index == 0xdeadbeef, "expected 0xdeadbeef got %u\n", index);
2572 size = sizeof(buffer);
2573 ret = HttpQueryInfo(hr, HTTP_QUERY_SERVER, buffer, &size, &index);
2574 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2575 ok(index == 1, "expected 1 got %u\n", index);
2578 size = sizeof(buffer);
2579 strcpy(buffer, "Server");
2580 ret = HttpQueryInfo(hr, HTTP_QUERY_CUSTOM, buffer, &size, &index);
2581 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2582 ok(index == 1, "expected 1 got %u\n", index);
2585 size = sizeof(buffer);
2586 ret = HttpQueryInfo(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
2587 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2588 ok(index == 1, "expected 1 got %u\n", index);
2590 size = sizeof(buffer);
2591 ret = HttpQueryInfo(hr, HTTP_QUERY_SET_COOKIE, buffer, &size, &index);
2592 ok(ret, "HttpQueryInfo failed %u\n", GetLastError());
2593 ok(index == 2, "expected 2 got %u\n", index);
2595 InternetCloseHandle(hr);
2596 InternetCloseHandle(hc);
2597 InternetCloseHandle(hi);
2600 static void test_options(int port)
2602 HINTERNET ses, con, req;
2607 ses = InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2608 ok(ses != NULL, "InternetOpen failed\n");
2610 SetLastError(0xdeadbeef);
2611 ret = InternetSetOption(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, 0);
2612 error = GetLastError();
2613 ok(!ret, "InternetSetOption succeeded\n");
2614 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2616 SetLastError(0xdeadbeef);
2617 ret = InternetSetOption(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, sizeof(ctx));
2618 ok(!ret, "InternetSetOption succeeded\n");
2619 error = GetLastError();
2620 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2622 SetLastError(0xdeadbeef);
2623 ret = InternetSetOption(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, 0);
2624 ok(!ret, "InternetSetOption succeeded\n");
2625 error = GetLastError();
2626 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2629 ret = InternetSetOption(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
2630 ok(ret, "InternetSetOption failed %u\n", GetLastError());
2632 SetLastError(0xdeadbeef);
2633 ret = InternetQueryOption(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, NULL);
2634 error = GetLastError();
2635 ok(!ret, "InternetQueryOption succeeded\n");
2636 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2638 SetLastError(0xdeadbeef);
2639 ret = InternetQueryOption(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, NULL);
2640 error = GetLastError();
2641 ok(!ret, "InternetQueryOption succeeded\n");
2642 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2645 SetLastError(0xdeadbeef);
2646 ret = InternetQueryOption(ses, INTERNET_OPTION_CONTEXT_VALUE, NULL, &size);
2647 error = GetLastError();
2648 ok(!ret, "InternetQueryOption succeeded\n");
2649 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
2652 SetLastError(0xdeadbeef);
2653 ret = InternetQueryOption(NULL, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
2654 error = GetLastError();
2655 ok(!ret, "InternetQueryOption succeeded\n");
2656 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %u\n", error);
2660 ret = InternetQueryOption(ses, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
2661 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
2662 ok(ctx == 1, "expected 1 got %lu\n", ctx);
2664 con = InternetConnect(ses, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2665 ok(con != NULL, "InternetConnect failed\n");
2669 ret = InternetQueryOption(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
2670 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
2671 ok(ctx == 0, "expected 0 got %lu\n", ctx);
2674 ret = InternetSetOption(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
2675 ok(ret, "InternetSetOption failed %u\n", GetLastError());
2679 ret = InternetQueryOption(con, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
2680 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
2681 ok(ctx == 2, "expected 2 got %lu\n", ctx);
2683 req = HttpOpenRequest(con, NULL, "/test1", NULL, NULL, NULL, 0, 0);
2684 ok(req != NULL, "HttpOpenRequest failed\n");
2688 ret = InternetQueryOption(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
2689 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
2690 ok(ctx == 0, "expected 0 got %lu\n", ctx);
2693 ret = InternetSetOption(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, sizeof(ctx));
2694 ok(ret, "InternetSetOption failed %u\n", GetLastError());
2698 ret = InternetQueryOption(req, INTERNET_OPTION_CONTEXT_VALUE, &ctx, &size);
2699 ok(ret, "InternetQueryOption failed %u\n", GetLastError());
2700 ok(ctx == 3, "expected 3 got %lu\n", ctx);
2702 /* INTERNET_OPTION_PROXY */
2703 SetLastError(0xdeadbeef);
2704 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, NULL);
2705 error = GetLastError();
2706 ok(!ret, "InternetQueryOption succeeded\n");
2707 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2709 SetLastError(0xdeadbeef);
2710 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, &ctx, NULL);
2711 error = GetLastError();
2712 ok(!ret, "InternetQueryOption succeeded\n");
2713 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2716 SetLastError(0xdeadbeef);
2717 ret = InternetQueryOptionA(ses, INTERNET_OPTION_PROXY, NULL, &size);
2718 error = GetLastError();
2719 ok(!ret, "InternetQueryOption succeeded\n");
2720 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
2721 ok(size >= sizeof(INTERNET_PROXY_INFOA), "expected size to be greater or equal to the struct size\n");
2723 InternetCloseHandle(req);
2724 InternetCloseHandle(con);
2725 InternetCloseHandle(ses);
2728 static void test_url_caching(int port, int *num_retrievals)
2730 HINTERNET hi, hc, hr;
2734 ok(*num_retrievals == 0, "expected 0 retrievals prior to test\n");
2736 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
2737 ok(hi != NULL, "open failed\n");
2739 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
2740 ok(hc != NULL, "connect failed\n");
2742 /* Pre-load the cache: */
2743 hr = HttpOpenRequest(hc, "GET", "/testH", NULL, NULL, NULL, 0, 0);
2744 ok(hr != NULL, "HttpOpenRequest failed\n");
2746 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
2747 ok(r, "HttpSendRequest failed\n");
2749 ok(*num_retrievals == 1, "expected 1 retrievals, got %d\n", *num_retrievals);
2752 memset(buffer, 0, sizeof buffer);
2753 SetLastError(0xdeadbeef);
2754 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
2755 ok(r, "InternetReadFile failed %u\n", GetLastError());
2756 ok(count == sizeof page1 - 1, "count was wrong\n");
2757 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
2759 InternetCloseHandle(hr);
2761 /* Send the same request, requiring it to be retrieved from the cache */
2762 hr = HttpOpenRequest(hc, "GET", "/testH", NULL, NULL, NULL, INTERNET_FLAG_FROM_CACHE, 0);
2763 ok(hr != NULL, "HttpOpenRequest failed\n");
2765 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
2766 /* Older Windows versions succeed with this request, newer ones fail with
2767 * ERROR_FILE_NOT_FOUND. Accept either, as the older version allows us
2768 * to verify that the server isn't contacted.
2771 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
2772 "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
2775 /* The server shouldn't be contacted for this request. */
2777 ok(*num_retrievals == 1, "expected 1 retrievals\n");
2780 memset(buffer, 0, sizeof buffer);
2781 SetLastError(0xdeadbeef);
2782 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
2783 ok(r, "InternetReadFile failed %u\n", GetLastError());
2784 ok(count == sizeof page1 - 1, "count was wrong\n");
2785 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
2788 InternetCloseHandle(hc);
2789 InternetCloseHandle(hi);
2792 static void test_http_connection(void)
2794 struct server_info si;
2798 si.hEvent = CreateEvent(NULL, 0, 0, NULL);
2800 si.num_testH_retrievals = 0;
2802 hThread = CreateThread(NULL, 0, server_thread, (LPVOID) &si, 0, &id);
2803 ok( hThread != NULL, "create thread failed\n");
2805 r = WaitForSingleObject(si.hEvent, 10000);
2806 ok (r == WAIT_OBJECT_0, "failed to start wininet test server\n");
2807 if (r != WAIT_OBJECT_0)
2810 test_basic_request(si.port, "GET", "/test1");
2811 test_proxy_indirect(si.port);
2812 test_proxy_direct(si.port);
2813 test_header_handling_order(si.port);
2814 test_basic_request(si.port, "POST", "/test5");
2815 test_basic_request(si.port, "RPC_IN_DATA", "/test5");
2816 test_basic_request(si.port, "RPC_OUT_DATA", "/test5");
2817 test_basic_request(si.port, "GET", "/test6");
2818 test_basic_request(si.port, "GET", "/testF");
2819 test_connection_header(si.port);
2820 test_http1_1(si.port);
2821 test_cookie_header(si.port);
2822 test_basic_authentication(si.port);
2823 test_invalid_response_headers(si.port);
2824 test_response_without_headers(si.port);
2825 test_HttpQueryInfo(si.port);
2826 test_HttpSendRequestW(si.port);
2827 test_last_error(si.port);
2828 test_options(si.port);
2829 test_url_caching(si.port, &si.num_testH_retrievals);
2830 test_no_content(si.port);
2831 test_conn_close(si.port);
2833 /* send the basic request again to shutdown the server thread */
2834 test_basic_request(si.port, "GET", "/quit");
2836 r = WaitForSingleObject(hThread, 3000);
2837 ok( r == WAIT_OBJECT_0, "thread wait failed\n");
2838 CloseHandle(hThread);
2841 static void release_cert_info(INTERNET_CERTIFICATE_INFOA *info)
2843 LocalFree(info->lpszSubjectInfo);
2844 LocalFree(info->lpszIssuerInfo);
2845 LocalFree(info->lpszProtocolName);
2846 LocalFree(info->lpszSignatureAlgName);
2847 LocalFree(info->lpszEncryptionAlgName);
2850 static void test_secure_connection(void)
2852 static const WCHAR gizmo5[] = {'G','i','z','m','o','5',0};
2853 static const WCHAR testbot[] = {'t','e','s','t','b','o','t','.','w','i','n','e','h','q','.','o','r','g',0};
2854 static const WCHAR get[] = {'G','E','T',0};
2855 static const WCHAR slash[] = {'/',0};
2856 HINTERNET ses, con, req;
2858 INTERNET_CERTIFICATE_INFOA *certificate_structA = NULL;
2859 INTERNET_CERTIFICATE_INFOW *certificate_structW = NULL;
2862 ses = InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
2863 ok(ses != NULL, "InternetOpen failed\n");
2865 con = InternetConnect(ses, "testbot.winehq.org",
2866 INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL,
2867 INTERNET_SERVICE_HTTP, 0, 0);
2868 ok(con != NULL, "InternetConnect failed\n");
2870 req = HttpOpenRequest(con, "GET", "/", NULL, NULL, NULL,
2871 INTERNET_FLAG_SECURE, 0);
2872 ok(req != NULL, "HttpOpenRequest failed\n");
2874 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2875 ok(ret, "HttpSendRequest failed: %d\n", GetLastError());
2877 size = sizeof(flags);
2878 ret = InternetQueryOption(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
2879 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
2880 ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set\n");
2882 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
2884 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
2885 ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %d\n", size);
2886 certificate_structA = HeapAlloc(GetProcessHeap(), 0, size);
2887 ret = InternetQueryOption(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
2888 certificate_structA, &size);
2889 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
2892 ok(certificate_structA->lpszSubjectInfo &&
2893 strlen(certificate_structA->lpszSubjectInfo) > 1,
2894 "expected a non-empty subject name\n");
2895 ok(certificate_structA->lpszIssuerInfo &&
2896 strlen(certificate_structA->lpszIssuerInfo) > 1,
2897 "expected a non-empty issuer name\n");
2898 ok(!certificate_structA->lpszSignatureAlgName,
2899 "unexpected signature algorithm name\n");
2900 ok(!certificate_structA->lpszEncryptionAlgName,
2901 "unexpected encryption algorithm name\n");
2902 ok(!certificate_structA->lpszProtocolName,
2903 "unexpected protocol name\n");
2904 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
2905 release_cert_info(certificate_structA);
2907 HeapFree(GetProcessHeap(), 0, certificate_structA);
2909 /* Querying the same option through InternetQueryOptionW still results in
2910 * ASCII strings being returned.
2913 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
2915 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
2916 ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size);
2917 certificate_structW = HeapAlloc(GetProcessHeap(), 0, size);
2918 ret = InternetQueryOption(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
2919 certificate_structW, &size);
2920 certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW;
2921 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
2924 ok(certificate_structA->lpszSubjectInfo &&
2925 strlen(certificate_structA->lpszSubjectInfo) > 1,
2926 "expected a non-empty subject name\n");
2927 ok(certificate_structA->lpszIssuerInfo &&
2928 strlen(certificate_structA->lpszIssuerInfo) > 1,
2929 "expected a non-empty issuer name\n");
2930 ok(!certificate_structA->lpszSignatureAlgName,
2931 "unexpected signature algorithm name\n");
2932 ok(!certificate_structA->lpszEncryptionAlgName,
2933 "unexpected encryption algorithm name\n");
2934 ok(!certificate_structA->lpszProtocolName,
2935 "unexpected protocol name\n");
2936 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
2937 release_cert_info(certificate_structA);
2939 HeapFree(GetProcessHeap(), 0, certificate_structW);
2941 InternetCloseHandle(req);
2942 InternetCloseHandle(con);
2943 InternetCloseHandle(ses);
2945 /* Repeating the tests with the W functions has the same result: */
2946 ses = InternetOpenW(gizmo5, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
2947 ok(ses != NULL, "InternetOpen failed\n");
2949 con = InternetConnectW(ses, testbot,
2950 INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL,
2951 INTERNET_SERVICE_HTTP, 0, 0);
2952 ok(con != NULL, "InternetConnect failed\n");
2954 req = HttpOpenRequestW(con, get, slash, NULL, NULL, NULL,
2955 INTERNET_FLAG_SECURE, 0);
2956 ok(req != NULL, "HttpOpenRequest failed\n");
2958 ret = HttpSendRequest(req, NULL, 0, NULL, 0);
2959 ok(ret, "HttpSendRequest failed: %d\n", GetLastError());
2961 size = sizeof(flags);
2962 ret = InternetQueryOption(req, INTERNET_OPTION_SECURITY_FLAGS, &flags, &size);
2963 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
2964 ok(flags & SECURITY_FLAG_SECURE, "expected secure flag to be set\n");
2966 ret = InternetQueryOptionA(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
2968 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
2969 ok(size == sizeof(INTERNET_CERTIFICATE_INFOA), "size = %d\n", size);
2970 certificate_structA = HeapAlloc(GetProcessHeap(), 0, size);
2971 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
2972 certificate_structA, &size);
2973 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
2976 ok(certificate_structA->lpszSubjectInfo &&
2977 strlen(certificate_structA->lpszSubjectInfo) > 1,
2978 "expected a non-empty subject name\n");
2979 ok(certificate_structA->lpszIssuerInfo &&
2980 strlen(certificate_structA->lpszIssuerInfo) > 1,
2981 "expected a non-empty issuer name\n");
2982 ok(!certificate_structA->lpszSignatureAlgName,
2983 "unexpected signature algorithm name\n");
2984 ok(!certificate_structA->lpszEncryptionAlgName,
2985 "unexpected encryption algorithm name\n");
2986 ok(!certificate_structA->lpszProtocolName,
2987 "unexpected protocol name\n");
2988 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
2989 release_cert_info(certificate_structA);
2991 HeapFree(GetProcessHeap(), 0, certificate_structA);
2993 /* Again, querying the same option through InternetQueryOptionW still
2994 * results in ASCII strings being returned.
2997 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
2999 ok(ret || GetLastError() == ERROR_INSUFFICIENT_BUFFER, "InternetQueryOption failed: %d\n", GetLastError());
3000 ok(size == sizeof(INTERNET_CERTIFICATE_INFOW), "size = %d\n", size);
3001 certificate_structW = HeapAlloc(GetProcessHeap(), 0, size);
3002 ret = InternetQueryOptionW(req, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
3003 certificate_structW, &size);
3004 certificate_structA = (INTERNET_CERTIFICATE_INFOA *)certificate_structW;
3005 ok(ret, "InternetQueryOption failed: %d\n", GetLastError());
3008 ok(certificate_structA->lpszSubjectInfo &&
3009 strlen(certificate_structA->lpszSubjectInfo) > 1,
3010 "expected a non-empty subject name\n");
3011 ok(certificate_structA->lpszIssuerInfo &&
3012 strlen(certificate_structA->lpszIssuerInfo) > 1,
3013 "expected a non-empty issuer name\n");
3014 ok(!certificate_structA->lpszSignatureAlgName,
3015 "unexpected signature algorithm name\n");
3016 ok(!certificate_structA->lpszEncryptionAlgName,
3017 "unexpected encryption algorithm name\n");
3018 ok(!certificate_structA->lpszProtocolName,
3019 "unexpected protocol name\n");
3020 ok(certificate_structA->dwKeySize, "expected a non-zero key size\n");
3021 release_cert_info(certificate_structA);
3023 HeapFree(GetProcessHeap(), 0, certificate_structW);
3025 InternetCloseHandle(req);
3026 InternetCloseHandle(con);
3027 InternetCloseHandle(ses);
3030 static void test_user_agent_header(void)
3032 HINTERNET ses, con, req;
3037 ses = InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
3038 ok(ses != NULL, "InternetOpen failed\n");
3040 con = InternetConnect(ses, "test.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3041 ok(con != NULL, "InternetConnect failed\n");
3043 req = HttpOpenRequest(con, "GET", "/tests/hello.html", "HTTP/1.0", NULL, NULL, 0, 0);
3044 ok(req != NULL, "HttpOpenRequest failed\n");
3046 size = sizeof(buffer);
3047 ret = HttpQueryInfo(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3048 err = GetLastError();
3049 ok(!ret, "HttpQueryInfo succeeded\n");
3050 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
3052 ret = HttpAddRequestHeaders(req, "User-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
3053 ok(ret, "HttpAddRequestHeaders succeeded\n");
3055 size = sizeof(buffer);
3056 ret = HttpQueryInfo(req, HTTP_QUERY_USER_AGENT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3057 err = GetLastError();
3058 ok(ret, "HttpQueryInfo failed\n");
3059 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
3061 InternetCloseHandle(req);
3063 req = HttpOpenRequest(con, "GET", "/", "HTTP/1.0", NULL, NULL, 0, 0);
3064 ok(req != NULL, "HttpOpenRequest failed\n");
3066 size = sizeof(buffer);
3067 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3068 err = GetLastError();
3069 ok(!ret, "HttpQueryInfo succeeded\n");
3070 ok(err == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err);
3072 ret = HttpAddRequestHeaders(req, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0u, HTTP_ADDREQ_FLAG_ADD_IF_NEW);
3073 ok(ret, "HttpAddRequestHeaders failed\n");
3076 size = sizeof(buffer);
3077 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3078 ok(ret, "HttpQueryInfo failed: %u\n", GetLastError());
3079 ok(!strcmp(buffer, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer);
3081 InternetCloseHandle(req);
3082 InternetCloseHandle(con);
3083 InternetCloseHandle(ses);
3086 static void test_bogus_accept_types_array(void)
3088 HINTERNET ses, con, req;
3089 static const char *types[] = { (const char *)6240, "*/*", "%p", "", (const char *)0xffffffff, "*/*", NULL };
3094 ses = InternetOpen("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT, "", "", 0);
3095 con = InternetConnect(ses, "www.winehq.org", 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
3096 req = HttpOpenRequest(con, "POST", "/post/post_action.php", "HTTP/1.0", "", types, INTERNET_FLAG_FORMS_SUBMIT, 0);
3098 ok(req != NULL, "HttpOpenRequest failed: %u\n", GetLastError());
3101 size = sizeof(buffer);
3102 SetLastError(0xdeadbeef);
3103 ret = HttpQueryInfo(req, HTTP_QUERY_ACCEPT | HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer, &size, NULL);
3104 error = GetLastError();
3105 ok(!ret || broken(ret), "HttpQueryInfo succeeded\n");
3106 if (!ret) ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", error);
3107 ok(broken(!strcmp(buffer, ", */*, %p, , , */*")) /* IE6 */ ||
3108 broken(!strcmp(buffer, "*/*, %p, */*")) /* IE7/8 */ ||
3109 !strcmp(buffer, ""), "got '%s' expected ''\n", buffer);
3111 InternetCloseHandle(req);
3112 InternetCloseHandle(con);
3113 InternetCloseHandle(ses);
3122 static void WINAPI cb(HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID info, DWORD size)
3124 INTERNET_ASYNC_RESULT *result = info;
3125 struct context *ctx = (struct context *)context;
3127 trace("%p 0x%08lx %u %p 0x%08x\n", handle, context, status, info, size);
3129 if (status == INTERNET_STATUS_REQUEST_COMPLETE)
3131 trace("request handle: 0x%08lx\n", result->dwResult);
3132 ctx->req = (HINTERNET)result->dwResult;
3133 SetEvent(ctx->event);
3135 if (status == INTERNET_STATUS_HANDLE_CLOSING)
3137 DWORD type = INTERNET_HANDLE_TYPE_CONNECT_HTTP, size = sizeof(type);
3139 if (InternetQueryOption(handle, INTERNET_OPTION_HANDLE_TYPE, &type, &size))
3140 ok(type != INTERNET_HANDLE_TYPE_CONNECT_HTTP, "unexpected callback\n");
3141 SetEvent(ctx->event);
3145 static void test_open_url_async(void)
3154 ctx.event = CreateEvent(NULL, TRUE, FALSE, "Z:_home_hans_jaman-installer.exe_ev1");
3156 ses = InternetOpen("AdvancedInstaller", 0, NULL, NULL, INTERNET_FLAG_ASYNC);
3157 ok(ses != NULL, "InternetOpen failed\n");
3159 SetLastError(0xdeadbeef);
3160 ret = InternetSetOptionA(NULL, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR));
3161 error = GetLastError();
3162 ok(!ret, "InternetSetOptionA succeeded\n");
3163 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "got %u expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE\n", error);
3165 ret = InternetSetOptionA(ses, INTERNET_OPTION_CALLBACK, &cb, sizeof(DWORD_PTR));
3166 error = GetLastError();
3167 ok(!ret, "InternetSetOptionA failed\n");
3168 ok(error == ERROR_INTERNET_OPTION_NOT_SETTABLE, "got %u expected ERROR_INTERNET_OPTION_NOT_SETTABLE\n", error);
3170 pInternetSetStatusCallbackA(ses, cb);
3171 ResetEvent(ctx.event);
3173 req = InternetOpenUrl(ses, "http://test.winehq.org", NULL, 0, 0, (DWORD_PTR)&ctx);
3174 ok(!req && GetLastError() == ERROR_IO_PENDING, "InternetOpenUrl failed\n");
3176 WaitForSingleObject(ctx.event, INFINITE);
3179 size = sizeof(type);
3180 ret = InternetQueryOption(ctx.req, INTERNET_OPTION_HANDLE_TYPE, &type, &size);
3181 ok(ret, "InternetQueryOption failed: %u\n", GetLastError());
3182 ok(type == INTERNET_HANDLE_TYPE_HTTP_REQUEST,
3183 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type);
3186 ret = HttpQueryInfo(ctx.req, HTTP_QUERY_RAW_HEADERS_CRLF, NULL, &size, NULL);
3187 ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "HttpQueryInfo failed\n");
3188 ok(size > 0, "expected size > 0\n");
3190 ResetEvent(ctx.event);
3191 InternetCloseHandle(ctx.req);
3192 WaitForSingleObject(ctx.event, INFINITE);
3194 InternetCloseHandle(ses);
3195 CloseHandle(ctx.event);
3200 internet_connect = 1,
3202 http_send_request_ex,
3205 internet_close_handle
3210 enum api function; /* api responsible for notification */
3211 unsigned int status; /* status received */
3212 int async; /* delivered from another thread? */
3220 const struct notification *test;
3226 DWORD expect_result;
3230 static CRITICAL_SECTION notification_cs;
3232 static void CALLBACK check_notification( HINTERNET handle, DWORD_PTR context, DWORD status, LPVOID buffer, DWORD buflen )
3234 BOOL status_ok, function_ok;
3235 struct info *info = (struct info *)context;
3238 EnterCriticalSection( ¬ification_cs );
3240 if(info->is_aborted) {
3241 LeaveCriticalSection(¬ification_cs);
3245 if (status == INTERNET_STATUS_HANDLE_CREATED)
3247 DWORD size = sizeof(struct info *);
3248 HttpQueryInfoA( handle, INTERNET_OPTION_CONTEXT_VALUE, &info, &size, 0 );
3249 }else if(status == INTERNET_STATUS_REQUEST_COMPLETE) {
3250 INTERNET_ASYNC_RESULT *ar = (INTERNET_ASYNC_RESULT*)buffer;
3252 ok(buflen == sizeof(*ar), "unexpected buflen = %d\n", buflen);
3253 if(info->expect_result == ERROR_SUCCESS) {
3254 ok(ar->dwResult == 1, "ar->dwResult = %ld, expected 1\n", ar->dwResult);
3256 ok(!ar->dwResult, "ar->dwResult = %ld, expected 1\n", ar->dwResult);
3257 ok(ar->dwError == info->expect_result, "ar->dwError = %d, expected %d\n", ar->dwError, info->expect_result);
3262 if (i >= info->count)
3264 LeaveCriticalSection( ¬ification_cs );
3268 while (info->test[i].status != status &&
3269 (info->test[i].optional || info->test[i].todo) &&
3270 i < info->count - 1 &&
3271 info->test[i].function == info->test[i + 1].function)
3276 status_ok = (info->test[i].status == status);
3277 function_ok = (info->test[i].function == info->function);
3279 if (!info->test[i].todo)
3281 ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status );
3282 ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
3284 if (info->test[i].async)
3285 ok(info->thread != GetCurrentThreadId(), "%u: expected thread %u got %u\n",
3286 info->line, info->thread, GetCurrentThreadId());
3290 todo_wine ok( status_ok, "%u: expected status %u got %u\n", info->line, info->test[i].status, status );
3292 todo_wine ok( function_ok, "%u: expected function %u got %u\n", info->line, info->test[i].function, info->function );
3294 if (i == info->count - 1 || info->test[i].function != info->test[i + 1].function) SetEvent( info->wait );
3297 LeaveCriticalSection( ¬ification_cs );
3300 static void setup_test( struct info *info, enum api function, unsigned int line, DWORD expect_result )
3302 info->function = function;
3304 info->expect_result = expect_result;
3307 struct notification_data
3309 const struct notification *test;
3310 const unsigned int count;
3315 BOOL expect_conn_failure;
3318 static const struct notification async_send_request_ex_test[] =
3320 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, 0 },
3321 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, 0 },
3322 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
3323 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, 1, 0, 1 },
3324 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, 1, 0, 1 },
3325 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, 1, 0, 1 },
3326 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, 1 },
3327 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, 1 },
3328 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, 1 },
3329 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, 1 },
3330 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
3331 { internet_writefile, INTERNET_STATUS_SENDING_REQUEST, 0 },
3332 { internet_writefile, INTERNET_STATUS_REQUEST_SENT, 0 },
3333 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, 1 },
3334 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, 1 },
3335 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
3336 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, 0, 0, 1 },
3337 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, 0, 0, 1 },
3338 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, },
3339 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, }
3342 static const struct notification async_send_request_ex_test2[] =
3344 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, 0 },
3345 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, 0 },
3346 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
3347 { http_send_request_ex, INTERNET_STATUS_COOKIE_SENT, 1, 0, 1 },
3348 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, 1, 0, 1 },
3349 { http_send_request_ex, INTERNET_STATUS_NAME_RESOLVED, 1, 0, 1 },
3350 { http_send_request_ex, INTERNET_STATUS_CONNECTING_TO_SERVER, 1, 1 },
3351 { http_send_request_ex, INTERNET_STATUS_CONNECTED_TO_SERVER, 1, 1 },
3352 { http_send_request_ex, INTERNET_STATUS_SENDING_REQUEST, 1 },
3353 { http_send_request_ex, INTERNET_STATUS_REQUEST_SENT, 1 },
3354 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
3355 { http_end_request, INTERNET_STATUS_RECEIVING_RESPONSE, 1 },
3356 { http_end_request, INTERNET_STATUS_RESPONSE_RECEIVED, 1 },
3357 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
3358 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, 0, 0, 1 },
3359 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, 0, 0, 1 },
3360 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, },
3361 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, }
3364 static const struct notification async_send_request_ex_resolve_failure_test[] =
3366 { internet_connect, INTERNET_STATUS_HANDLE_CREATED, 0 },
3367 { http_open_request, INTERNET_STATUS_HANDLE_CREATED, 0 },
3368 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
3369 { http_send_request_ex, INTERNET_STATUS_RESOLVING_NAME, 1 },
3370 { http_send_request_ex, INTERNET_STATUS_DETECTING_PROXY, 1, 0, 1 },
3371 { http_send_request_ex, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
3372 { http_end_request, INTERNET_STATUS_REQUEST_COMPLETE, 1 },
3373 { internet_close_handle, INTERNET_STATUS_CLOSING_CONNECTION, 0, 0, 1 },
3374 { internet_close_handle, INTERNET_STATUS_CONNECTION_CLOSED, 0, 0, 1 },
3375 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, },
3376 { internet_close_handle, INTERNET_STATUS_HANDLE_CLOSING, 0, }
3379 static const struct notification_data notification_data[] = {
3381 async_send_request_ex_test,
3382 sizeof(async_send_request_ex_test)/sizeof(async_send_request_ex_test[0]),
3385 "tests/posttest.php",
3386 "Public ID=codeweavers"
3389 async_send_request_ex_test2,
3390 sizeof(async_send_request_ex_test)/sizeof(async_send_request_ex_test[0]),
3393 "tests/posttest.php"
3396 async_send_request_ex_resolve_failure_test,
3397 sizeof(async_send_request_ex_resolve_failure_test)/sizeof(async_send_request_ex_resolve_failure_test[0]),
3406 static void test_async_HttpSendRequestEx(const struct notification_data *nd)
3409 HINTERNET ses, req, con;
3411 DWORD size, written, error;
3412 INTERNET_BUFFERSA b;
3413 static const char *accept[2] = {"*/*", NULL};
3416 trace("Async HttpSendRequestEx test (%s %s)\n", nd->method, nd->host);
3418 InitializeCriticalSection( ¬ification_cs );
3420 info.test = nd->test;
3421 info.count = nd->count;
3423 info.wait = CreateEvent( NULL, FALSE, FALSE, NULL );
3424 info.thread = GetCurrentThreadId();
3425 info.is_aborted = FALSE;
3427 ses = InternetOpen( "winetest", 0, NULL, NULL, INTERNET_FLAG_ASYNC );
3428 ok( ses != NULL, "InternetOpen failed\n" );
3430 pInternetSetStatusCallbackA( ses, check_notification );
3432 setup_test( &info, internet_connect, __LINE__, ERROR_SUCCESS );
3433 con = InternetConnect( ses, nd->host, 80, NULL, NULL, INTERNET_SERVICE_HTTP, 0, (DWORD_PTR)&info );
3434 ok( con != NULL, "InternetConnect failed %u\n", GetLastError() );
3436 WaitForSingleObject( info.wait, 10000 );
3438 setup_test( &info, http_open_request, __LINE__, ERROR_SUCCESS );
3439 req = HttpOpenRequest( con, nd->method, nd->path, NULL, NULL, accept, 0, (DWORD_PTR)&info );
3440 ok( req != NULL, "HttpOpenRequest failed %u\n", GetLastError() );
3442 WaitForSingleObject( info.wait, 10000 );
3445 memset( &b, 0, sizeof(INTERNET_BUFFERSA) );
3446 b.dwStructSize = sizeof(INTERNET_BUFFERSA);
3447 b.lpcszHeader = "Content-Type: application/x-www-form-urlencoded";
3448 b.dwHeadersLength = strlen( b.lpcszHeader );
3449 b.dwBufferTotal = nd->data ? strlen( nd->data ) : 0;
3452 setup_test( &info, http_send_request_ex, __LINE__,
3453 nd->expect_conn_failure ? ERROR_INTERNET_NAME_NOT_RESOLVED : ERROR_SUCCESS );
3454 ret = HttpSendRequestExA( req, nd->data ? &b : NULL, NULL, 0x28, 0 );
3455 ok( !ret && GetLastError() == ERROR_IO_PENDING, "HttpSendRequestExA failed %d %u\n", ret, GetLastError() );
3457 error = WaitForSingleObject( info.wait, 10000 );
3458 if(error != WAIT_OBJECT_0) {
3459 skip("WaitForSingleObject returned %d, assuming DNS problem\n", error);
3460 info.is_aborted = TRUE;
3464 size = sizeof(buffer);
3465 SetLastError( 0xdeadbeef );
3466 ret = HttpQueryInfoA( req, HTTP_QUERY_CONTENT_ENCODING, buffer, &size, 0 );
3467 error = GetLastError();
3468 ok( !ret, "HttpQueryInfoA failed %u\n", GetLastError() );
3469 if(nd->expect_conn_failure) {
3470 ok(error == ERROR_HTTP_HEADER_NOT_FOUND, "expected ERROR_HTTP_HEADER_NOT_FOUND got %u\n", error );
3473 ok(error == ERROR_INTERNET_INCORRECT_HANDLE_STATE,
3474 "expected ERROR_INTERNET_INCORRECT_HANDLE_STATE got %u\n", error );
3480 size = strlen( nd->data );
3481 setup_test( &info, internet_writefile, __LINE__, ERROR_SUCCESS );
3482 ret = InternetWriteFile( req, nd->data, size, &written );
3483 ok( ret, "InternetWriteFile failed %u\n", GetLastError() );
3484 ok( written == size, "expected %u got %u\n", written, size );
3486 WaitForSingleObject( info.wait, 10000 );
3488 SetLastError( 0xdeadbeef );
3489 ret = HttpEndRequestA( req, (void *)nd->data, 0x28, 0 );
3490 error = GetLastError();
3491 ok( !ret, "HttpEndRequestA succeeded\n" );
3492 ok( error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER got %u\n", error );
3495 SetLastError( 0xdeadbeef );
3496 setup_test( &info, http_end_request, __LINE__,
3497 nd->expect_conn_failure ? ERROR_INTERNET_OPERATION_CANCELLED : ERROR_SUCCESS);
3498 ret = HttpEndRequestA( req, NULL, 0x28, 0 );
3499 error = GetLastError();
3500 ok( !ret, "HttpEndRequestA succeeded\n" );
3501 ok( error == ERROR_IO_PENDING, "expected ERROR_IO_PENDING got %u\n", error );
3503 WaitForSingleObject( info.wait, 10000 );
3505 setup_test( &info, internet_close_handle, __LINE__, ERROR_SUCCESS );
3507 InternetCloseHandle( req );
3508 InternetCloseHandle( con );
3509 InternetCloseHandle( ses );
3511 WaitForSingleObject( info.wait, 10000 );
3513 CloseHandle( info.wait );
3516 static HINTERNET closetest_session, closetest_req, closetest_conn;
3517 static BOOL closetest_closed;
3519 static void WINAPI closetest_callback(HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus,
3520 LPVOID lpvStatusInformation, DWORD dwStatusInformationLength)
3525 trace("closetest_callback %p: %d\n", hInternet, dwInternetStatus);
3527 ok(hInternet == closetest_session || hInternet == closetest_conn || hInternet == closetest_req,
3528 "Unexpected hInternet %p\n", hInternet);
3529 if(!closetest_closed)
3533 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_HANDLE_TYPE, &type, &len);
3534 ok(!res && GetLastError() == ERROR_INVALID_HANDLE,
3535 "InternetQueryOptionA(%p INTERNET_OPTION_HANDLE_TYPE) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
3536 closetest_req, res, GetLastError());
3539 static void test_InternetCloseHandle(void)
3544 closetest_session = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, INTERNET_FLAG_ASYNC);
3545 ok(closetest_session != NULL,"InternetOpen failed with error %u\n", GetLastError());
3547 pInternetSetStatusCallbackA(closetest_session, closetest_callback);
3549 closetest_conn = InternetConnectA(closetest_session, "source.winehq.org", INTERNET_INVALID_PORT_NUMBER,
3550 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
3551 ok(closetest_conn != NULL,"InternetConnect failed with error %u\n", GetLastError());
3553 closetest_req = HttpOpenRequestA(closetest_conn, "GET", "winegecko.php", NULL, NULL, NULL,
3554 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE, 0xdeadbead);
3556 res = HttpSendRequestA(closetest_req, NULL, -1, NULL, 0);
3557 ok(!res && (GetLastError() == ERROR_IO_PENDING),
3558 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
3560 len = sizeof(flags);
3561 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &len);
3562 ok(res, "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %u\n", closetest_req, GetLastError());
3564 res = InternetCloseHandle(closetest_session);
3565 ok(res, "InternetCloseHandle failed: %u\n", GetLastError());
3566 closetest_closed = TRUE;
3567 trace("Closed session handle\n");
3569 res = InternetCloseHandle(closetest_conn);
3570 ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(conn) failed: %x %u\n",
3571 res, GetLastError());
3573 res = InternetCloseHandle(closetest_req);
3574 ok(!res && GetLastError() == ERROR_INVALID_HANDLE, "InternetCloseConnection(req) failed: %x %u\n",
3575 res, GetLastError());
3577 len = sizeof(flags);
3578 res = InternetQueryOptionA(closetest_req, INTERNET_OPTION_REQUEST_FLAGS, &flags, &len);
3579 ok(!res && GetLastError() == ERROR_INVALID_HANDLE,
3580 "InternetQueryOptionA(%p INTERNET_OPTION_URL) failed: %x %u, expected TRUE ERROR_INVALID_HANDLE\n",
3581 closetest_req, res, GetLastError());
3584 static void init_status_tests(void)
3586 memset(expect, 0, sizeof(expect));
3587 memset(optional, 0, sizeof(optional));
3588 memset(wine_allow, 0, sizeof(wine_allow));
3589 memset(notified, 0, sizeof(notified));
3590 memset(status_string, 0, sizeof(status_string));
3592 #define STATUS_STRING(status) status_string[status] = #status
3593 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME);
3594 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED);
3595 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER);
3596 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER);
3597 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST);
3598 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT);
3599 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE);
3600 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED);
3601 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED);
3602 STATUS_STRING(INTERNET_STATUS_PREFETCH);
3603 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION);
3604 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED);
3605 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED);
3606 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING);
3607 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY);
3608 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE);
3609 STATUS_STRING(INTERNET_STATUS_REDIRECT);
3610 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE);
3611 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED);
3612 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE);
3613 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT);
3614 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED);
3615 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED);
3616 STATUS_STRING(INTERNET_STATUS_P3P_HEADER);
3617 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF);
3618 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY);
3619 #undef STATUS_STRING
3625 hdll = GetModuleHandleA("wininet.dll");
3627 if(!GetProcAddress(hdll, "InternetGetCookieExW")) {
3628 win_skip("Too old IE (older than 6.0)\n");
3632 pInternetSetStatusCallbackA = (void*)GetProcAddress(hdll, "InternetSetStatusCallbackA");
3634 init_status_tests();
3635 test_InternetCloseHandle();
3636 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[0]);
3637 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[1]);
3638 InternetReadFile_test(0, &test_data[1]);
3639 first_connection_to_test_url = TRUE;
3640 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[2]);
3641 InternetReadFile_test(0, &test_data[2]);
3642 InternetReadFileExA_test(INTERNET_FLAG_ASYNC);
3643 test_open_url_async();
3644 test_async_HttpSendRequestEx(¬ification_data[0]);
3645 test_async_HttpSendRequestEx(¬ification_data[1]);
3646 test_async_HttpSendRequestEx(¬ification_data[2]);
3647 InternetOpenRequest_test();
3649 InternetOpenUrlA_test();
3651 test_http_connection();
3652 test_secure_connection();
3653 test_user_agent_header();
3654 test_bogus_accept_types_array();
3655 InternetReadFile_chunked_test();
3656 HttpSendRequestEx_test();
3657 InternetReadFile_test(INTERNET_FLAG_ASYNC, &test_data[3]);