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://www.winehq.org/site/about"
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 /* SET_WINE_ALLOW's should be used with an appropriate
47 * todo_wine CHECK_NOTIFIED at a later point in the code */
48 #define SET_WINE_ALLOW2(status, num) \
49 wine_allow[status] = num
51 #define SET_WINE_ALLOW(status) \
52 SET_WINE_ALLOW2(status, 1)
54 #define CHECK_EXPECT(status) \
56 if (!expect[status] && wine_allow[status]) \
58 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
59 status < MAX_INTERNET_STATUS && status_string[status][0] != 0 ? \
60 status_string[status] : "unknown"); \
61 wine_allow[status]--; \
65 ok(expect[status], "unexpected status %d (%s)\n", status, \
66 status < MAX_INTERNET_STATUS && status_string[status][0] != 0 ? \
67 status_string[status] : "unknown"); \
73 /* CLEAR_NOTIFIED used in cases when notification behavior
74 * differs between Windows versions */
75 #define CLEAR_NOTIFIED(status) \
76 expect[status] = wine_allow[status] = notified[status] = 0;
78 #define CHECK_NOTIFIED2(status, num) \
80 ok(notified[status] == (num), "expected status %d (%s) %d times, received %d times\n", \
81 status, status < MAX_INTERNET_STATUS && status_string[status][0] != 0 ? \
82 status_string[status] : "unknown", (num), notified[status]); \
83 CLEAR_NOTIFIED(status); \
86 #define CHECK_NOTIFIED(status) \
87 CHECK_NOTIFIED2(status, 1)
89 #define CHECK_NOT_NOTIFIED(status) \
90 CHECK_NOTIFIED2(status, 0)
92 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
93 #define MAX_STATUS_NAME 50
94 static int expect
[MAX_INTERNET_STATUS
], wine_allow
[MAX_INTERNET_STATUS
],
95 notified
[MAX_INTERNET_STATUS
];
96 static CHAR status_string
[MAX_INTERNET_STATUS
][MAX_STATUS_NAME
];
98 static HANDLE hCompleteEvent
;
100 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackA
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
101 static BOOL (WINAPI
*pInternetTimeFromSystemTimeA
)(CONST SYSTEMTIME
*,DWORD
,LPSTR
,DWORD
);
102 static BOOL (WINAPI
*pInternetTimeFromSystemTimeW
)(CONST SYSTEMTIME
*,DWORD
,LPWSTR
,DWORD
);
103 static BOOL (WINAPI
*pInternetTimeToSystemTimeA
)(LPCSTR
,SYSTEMTIME
*,DWORD
);
104 static BOOL (WINAPI
*pInternetTimeToSystemTimeW
)(LPCWSTR
,SYSTEMTIME
*,DWORD
);
107 static VOID WINAPI
callback(
110 DWORD dwInternetStatus
,
111 LPVOID lpvStatusInformation
,
112 DWORD dwStatusInformationLength
115 CHECK_EXPECT(dwInternetStatus
);
116 switch (dwInternetStatus
)
118 case INTERNET_STATUS_RESOLVING_NAME
:
119 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
120 GetCurrentThreadId(), hInternet
, dwContext
,
121 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
122 *(LPSTR
)lpvStatusInformation
= '\0';
124 case INTERNET_STATUS_NAME_RESOLVED
:
125 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
126 GetCurrentThreadId(), hInternet
, dwContext
,
127 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
128 *(LPSTR
)lpvStatusInformation
= '\0';
130 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
131 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
132 GetCurrentThreadId(), hInternet
, dwContext
,
133 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
134 *(LPSTR
)lpvStatusInformation
= '\0';
136 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
137 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
138 GetCurrentThreadId(), hInternet
, dwContext
,
139 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
140 *(LPSTR
)lpvStatusInformation
= '\0';
142 case INTERNET_STATUS_SENDING_REQUEST
:
143 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
144 GetCurrentThreadId(), hInternet
, dwContext
,
145 lpvStatusInformation
,dwStatusInformationLength
);
147 case INTERNET_STATUS_REQUEST_SENT
:
148 ok(dwStatusInformationLength
== sizeof(DWORD
),
149 "info length should be sizeof(DWORD) instead of %d\n",
150 dwStatusInformationLength
);
151 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
152 GetCurrentThreadId(), hInternet
, dwContext
,
153 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
155 case INTERNET_STATUS_RECEIVING_RESPONSE
:
156 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
157 GetCurrentThreadId(), hInternet
, dwContext
,
158 lpvStatusInformation
,dwStatusInformationLength
);
160 case INTERNET_STATUS_RESPONSE_RECEIVED
:
161 ok(dwStatusInformationLength
== sizeof(DWORD
),
162 "info length should be sizeof(DWORD) instead of %d\n",
163 dwStatusInformationLength
);
164 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
165 GetCurrentThreadId(), hInternet
, dwContext
,
166 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
168 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
169 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
170 GetCurrentThreadId(), hInternet
,dwContext
,
171 lpvStatusInformation
,dwStatusInformationLength
);
173 case INTERNET_STATUS_PREFETCH
:
174 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
175 GetCurrentThreadId(), hInternet
, dwContext
,
176 lpvStatusInformation
,dwStatusInformationLength
);
178 case INTERNET_STATUS_CLOSING_CONNECTION
:
179 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
180 GetCurrentThreadId(), hInternet
, dwContext
,
181 lpvStatusInformation
,dwStatusInformationLength
);
183 case INTERNET_STATUS_CONNECTION_CLOSED
:
184 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
185 GetCurrentThreadId(), hInternet
, dwContext
,
186 lpvStatusInformation
,dwStatusInformationLength
);
188 case INTERNET_STATUS_HANDLE_CREATED
:
189 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
190 "info length should be sizeof(HINTERNET) instead of %d\n",
191 dwStatusInformationLength
);
192 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
193 GetCurrentThreadId(), hInternet
, dwContext
,
194 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
195 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
196 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
198 case INTERNET_STATUS_HANDLE_CLOSING
:
199 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
200 "info length should be sizeof(HINTERNET) instead of %d\n",
201 dwStatusInformationLength
);
202 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
203 GetCurrentThreadId(), hInternet
, dwContext
,
204 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
206 case INTERNET_STATUS_REQUEST_COMPLETE
:
208 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
209 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
210 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
211 dwStatusInformationLength
);
212 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
213 GetCurrentThreadId(), hInternet
, dwContext
,
214 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
215 SetEvent(hCompleteEvent
);
218 case INTERNET_STATUS_REDIRECT
:
219 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
220 GetCurrentThreadId(), hInternet
, dwContext
,
221 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
222 *(LPSTR
)lpvStatusInformation
= '\0';
223 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
224 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
226 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
227 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
228 GetCurrentThreadId(), hInternet
, dwContext
,
229 lpvStatusInformation
, dwStatusInformationLength
);
232 trace("%04x:Callback %p 0x%lx %d %p %d\n",
233 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
234 lpvStatusInformation
, dwStatusInformationLength
);
238 static void InternetReadFile_test(int flags
)
245 const char *types
[2] = { "*", NULL
};
246 HINTERNET hi
, hic
= 0, hor
= 0;
248 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
250 trace("Starting InternetReadFile test with flags 0x%x\n",flags
);
252 trace("InternetOpenA <--\n");
253 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
254 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
255 trace("InternetOpenA -->\n");
257 if (hi
== 0x0) goto abort
;
259 pInternetSetStatusCallbackA(hi
,&callback
);
261 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
263 trace("InternetConnectA <--\n");
264 hic
=InternetConnectA(hi
, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
265 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
266 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
267 trace("InternetConnectA -->\n");
269 if (hic
== 0x0) goto abort
;
271 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
272 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
274 trace("HttpOpenRequestA <--\n");
275 hor
= HttpOpenRequestA(hic
, "GET", "/about/", NULL
, NULL
, types
,
276 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
,
278 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
280 * If the internet name can't be resolved we are probably behind
281 * a firewall or in some other way not directly connected to the
282 * Internet. Not enough reason to fail the test. Just ignore and
286 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
288 trace("HttpOpenRequestA -->\n");
290 if (hor
== 0x0) goto abort
;
292 length
= sizeof(buffer
);
293 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
294 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
295 ok(!strcmp(buffer
, "http://www.winehq.org/about/"), "Wrong URL %s\n", buffer
);
297 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
298 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
299 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
300 if (first_connection_to_test_url
)
302 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
303 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
307 SET_WINE_ALLOW(INTERNET_STATUS_RESOLVING_NAME
);
308 SET_WINE_ALLOW(INTERNET_STATUS_NAME_RESOLVED
);
310 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
311 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
312 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
313 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
314 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
315 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
316 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
317 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
318 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
319 if (flags
& INTERNET_FLAG_ASYNC
)
320 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
322 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
324 trace("HttpSendRequestA -->\n");
325 SetLastError(0xdeadbeef);
326 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
327 if (flags
& INTERNET_FLAG_ASYNC
)
328 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
329 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
331 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
332 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
333 trace("HttpSendRequestA <--\n");
335 if (flags
& INTERNET_FLAG_ASYNC
)
336 WaitForSingleObject(hCompleteEvent
, INFINITE
);
338 if (first_connection_to_test_url
)
340 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
341 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
345 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
346 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
348 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
349 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
350 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
351 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
352 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
353 if (flags
& INTERNET_FLAG_ASYNC
)
354 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
356 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
357 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
358 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
359 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
362 rc
= InternetQueryOptionA(hor
,INTERNET_OPTION_REQUEST_FLAGS
,&out
,&length
);
363 trace("Option 0x17 -> %i %i\n",rc
,out
);
366 rc
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
367 trace("Option 0x22 -> %i %s\n",rc
,buffer
);
370 rc
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
372 trace("Option 0x16 -> %i %s\n",rc
,buffer
);
374 length
= sizeof(buffer
);
375 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
376 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
377 ok(!strcmp(buffer
, "http://www.winehq.org/site/about"), "Wrong URL %s\n", buffer
);
380 rc
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
381 trace("Option 0x5 -> %i %s (%u)\n",rc
,buffer
,GetLastError());
384 rc
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
386 trace("Option 0x1 -> %i %s\n",rc
,buffer
);
388 SetLastError(0xdeadbeef);
389 rc
= InternetReadFile(NULL
, buffer
, 100, &length
);
390 ok(!rc
, "InternetReadFile should have failed\n");
391 ok(GetLastError() == ERROR_INVALID_HANDLE
,
392 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
396 trace("Entering Query loop\n");
398 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
399 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
402 if (flags
& INTERNET_FLAG_ASYNC
)
403 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
404 rc
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
405 ok(!(rc
== 0 && length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
406 ok(rc
!= 0 || ((flags
& INTERNET_FLAG_ASYNC
) && GetLastError() == ERROR_IO_PENDING
),
407 "InternetQueryDataAvailable failed, error %d\n", GetLastError());
408 if (flags
& INTERNET_FLAG_ASYNC
)
412 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
414 else if (GetLastError() == ERROR_IO_PENDING
)
416 WaitForSingleObject(hCompleteEvent
, INFINITE
);
417 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
424 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
426 rc
= InternetReadFile(hor
,buffer
,length
,&length
);
430 trace("ReadFile -> %i %i\n",rc
,length
);
432 HeapFree(GetProcessHeap(),0,buffer
);
437 /* WinXP does not send, but Win98 does */
438 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
439 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
441 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, (hor
!= 0x0) + (hic
!= 0x0));
443 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
444 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
445 SetLastError(0xdeadbeef);
446 rc
= InternetCloseHandle(hor
);
447 ok ((rc
!= 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
448 SetLastError(0xdeadbeef);
449 rc
= InternetCloseHandle(hor
);
450 ok ((rc
== 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
451 ok (GetLastError() == ERROR_INVALID_HANDLE
,
452 "Double close of handle should have set ERROR_INVALID_HANDLE instead of %u\n",
455 /* We intentionally do not close the handle opened by InternetConnectA as this
456 * tickles bug #9479: native closes child internet handles when the parent handles
457 * are closed. This is verified below by checking that the number of
458 * INTERNET_STATUS_HANDLE_CLOSING notifications matches the number expected. */
460 SET_WINE_ALLOW(INTERNET_STATUS_HANDLE_CLOSING
);
461 rc
= InternetCloseHandle(hi
);
462 ok ((rc
!= 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
463 if (flags
& INTERNET_FLAG_ASYNC
)
466 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, (hor
!= 0x0) + (hic
!= 0x0));
467 if (hor
!= 0x0) todo_wine
469 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
470 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
474 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
475 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
477 CloseHandle(hCompleteEvent
);
478 first_connection_to_test_url
= FALSE
;
481 static void InternetReadFileExA_test(int flags
)
485 const char *types
[2] = { "*", NULL
};
486 HINTERNET hi
, hic
= 0, hor
= 0;
487 INTERNET_BUFFERS inetbuffers
;
489 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
491 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
493 trace("InternetOpenA <--\n");
494 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
495 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
496 trace("InternetOpenA -->\n");
498 if (hi
== 0x0) goto abort
;
500 pInternetSetStatusCallbackA(hi
,&callback
);
502 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
504 trace("InternetConnectA <--\n");
505 hic
=InternetConnectA(hi
, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
506 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
507 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
508 trace("InternetConnectA -->\n");
510 if (hic
== 0x0) goto abort
;
512 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
513 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
515 trace("HttpOpenRequestA <--\n");
516 hor
= HttpOpenRequestA(hic
, "GET", "/about/", NULL
, NULL
, types
,
517 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
,
519 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
521 * If the internet name can't be resolved we are probably behind
522 * a firewall or in some other way not directly connected to the
523 * Internet. Not enough reason to fail the test. Just ignore and
527 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
529 trace("HttpOpenRequestA -->\n");
531 if (hor
== 0x0) goto abort
;
533 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
534 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
535 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
536 if (first_connection_to_test_url
)
538 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
539 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
543 SET_WINE_ALLOW(INTERNET_STATUS_RESOLVING_NAME
);
544 SET_WINE_ALLOW(INTERNET_STATUS_NAME_RESOLVED
);
546 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
547 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
548 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
549 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
550 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
551 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
552 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
553 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
554 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
555 if (flags
& INTERNET_FLAG_ASYNC
)
556 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
558 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
560 trace("HttpSendRequestA -->\n");
561 SetLastError(0xdeadbeef);
562 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
563 if (flags
& INTERNET_FLAG_ASYNC
)
564 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
565 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
567 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
568 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
569 trace("HttpSendRequestA <--\n");
571 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
))
572 WaitForSingleObject(hCompleteEvent
, INFINITE
);
574 if (first_connection_to_test_url
)
576 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
577 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
581 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
582 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
584 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
585 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
586 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
587 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
588 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
589 if (flags
& INTERNET_FLAG_ASYNC
)
590 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
592 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
593 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
594 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
595 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
597 /* tests invalid dwStructSize */
598 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
)+1;
599 inetbuffers
.lpcszHeader
= NULL
;
600 inetbuffers
.dwHeadersLength
= 0;
601 inetbuffers
.dwBufferLength
= 10;
602 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
603 inetbuffers
.dwOffsetHigh
= 1234;
604 inetbuffers
.dwOffsetLow
= 5678;
605 rc
= InternetReadFileEx(hor
, &inetbuffers
, 0, 0xdeadcafe);
606 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
607 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
608 rc
? "TRUE" : "FALSE", GetLastError());
609 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
611 /* tests to see whether lpcszHeader is used - it isn't */
612 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
);
613 inetbuffers
.lpcszHeader
= (LPCTSTR
)0xdeadbeef;
614 inetbuffers
.dwHeadersLength
= 255;
615 inetbuffers
.dwBufferLength
= 0;
616 inetbuffers
.lpvBuffer
= NULL
;
617 inetbuffers
.dwOffsetHigh
= 1234;
618 inetbuffers
.dwOffsetLow
= 5678;
619 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
620 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
621 rc
= InternetReadFileEx(hor
, &inetbuffers
, 0, 0xdeadcafe);
622 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
625 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
626 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
629 rc
= InternetReadFileEx(NULL
, &inetbuffers
, 0, 0xdeadcafe);
630 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
631 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
632 rc
? "TRUE" : "FALSE", GetLastError());
635 trace("Entering Query loop\n");
637 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
638 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
641 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
);
642 inetbuffers
.dwBufferLength
= 1024;
643 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
644 inetbuffers
.dwOffsetHigh
= 1234;
645 inetbuffers
.dwOffsetLow
= 5678;
647 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
648 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
649 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
650 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
653 if (GetLastError() == ERROR_IO_PENDING
)
655 trace("InternetReadFileEx -> PENDING\n");
656 ok(flags
& INTERNET_FLAG_ASYNC
,
657 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
658 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
659 WaitForSingleObject(hCompleteEvent
, INFINITE
);
660 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
661 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
665 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
671 trace("InternetReadFileEx -> SUCCEEDED\n");
672 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
673 if (inetbuffers
.dwBufferLength
)
675 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
676 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
680 /* Win98 still sends these when 0 bytes are read, WinXP does not */
681 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
682 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
686 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
687 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
689 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
690 "InternetReadFileEx sets offsets to 0x%x%08x\n",
691 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
693 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
695 if (!inetbuffers
.dwBufferLength
)
698 length
+= inetbuffers
.dwBufferLength
;
700 ok(length
> 0, "failed to read any of the document\n");
701 trace("Finished. Read %d bytes\n", length
);
703 /* WinXP does not send, but Win98 does */
704 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
705 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
707 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, (hor
!= 0x0) + (hic
!= 0x0));
709 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
710 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
711 rc
= InternetCloseHandle(hor
);
712 ok ((rc
!= 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
713 rc
= InternetCloseHandle(hor
);
714 ok ((rc
== 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
717 rc
= InternetCloseHandle(hic
);
718 ok ((rc
!= 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
721 SET_WINE_ALLOW(INTERNET_STATUS_HANDLE_CLOSING
);
722 rc
= InternetCloseHandle(hi
);
723 ok ((rc
!= 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
724 if (flags
& INTERNET_FLAG_ASYNC
)
726 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, (hor
!= 0x0) + (hic
!= 0x0));
728 if (hor
!= 0x0) todo_wine
730 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
731 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
735 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
736 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
738 CloseHandle(hCompleteEvent
);
739 first_connection_to_test_url
= FALSE
;
742 static void InternetOpenUrlA_test(void)
744 HINTERNET myhinternet
, myhttp
;
746 DWORD size
, readbytes
, totalbytes
=0;
749 myhinternet
= InternetOpen("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
750 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
752 ret
= InternetCanonicalizeUrl(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
753 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
756 myhttp
= InternetOpenUrl(myhinternet
, TEST_URL
, 0, 0,
757 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
758 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
759 return; /* WinXP returns this when not connected to the net */
760 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
761 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
762 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
763 totalbytes
+= readbytes
;
764 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
765 totalbytes
+= readbytes
;
766 trace("read 0x%08x bytes\n",totalbytes
);
768 InternetCloseHandle(myhttp
);
769 InternetCloseHandle(myhinternet
);
772 static void InternetTimeFromSystemTimeA_test(void)
775 static const SYSTEMTIME time
= { 2005, 1, 5, 7, 12, 6, 35, 0 };
776 char string
[INTERNET_RFC1123_BUFSIZE
];
777 static const char expect
[] = "Fri, 07 Jan 2005 12:06:35 GMT";
779 ret
= pInternetTimeFromSystemTimeA( &time
, INTERNET_RFC1123_FORMAT
, string
, sizeof(string
) );
780 ok( ret
, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
782 ok( !memcmp( string
, expect
, sizeof(expect
) ),
783 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
786 static void InternetTimeFromSystemTimeW_test(void)
789 static const SYSTEMTIME time
= { 2005, 1, 5, 7, 12, 6, 35, 0 };
790 WCHAR string
[INTERNET_RFC1123_BUFSIZE
+ 1];
791 static const WCHAR expect
[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
792 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
794 ret
= pInternetTimeFromSystemTimeW( &time
, INTERNET_RFC1123_FORMAT
, string
, sizeof(string
) );
795 ok( ret
, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
797 ok( !memcmp( string
, expect
, sizeof(expect
) ),
798 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
801 static void InternetTimeToSystemTimeA_test(void)
805 static const SYSTEMTIME expect
= { 2005, 1, 5, 7, 12, 6, 35, 0 };
806 static const char string
[] = "Fri, 07 Jan 2005 12:06:35 GMT";
807 static const char string2
[] = " fri 7 jan 2005 12 06 35";
809 ret
= pInternetTimeToSystemTimeA( string
, &time
, 0 );
810 ok( ret
, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
811 ok( !memcmp( &time
, &expect
, sizeof(expect
) ),
812 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
814 ret
= pInternetTimeToSystemTimeA( string2
, &time
, 0 );
815 ok( ret
, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
816 ok( !memcmp( &time
, &expect
, sizeof(expect
) ),
817 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
820 static void InternetTimeToSystemTimeW_test(void)
824 static const SYSTEMTIME expect
= { 2005, 1, 5, 7, 12, 6, 35, 0 };
825 static const WCHAR string
[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
826 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
827 static const WCHAR string2
[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
828 '1','2',' ','0','6',' ','3','5',0 };
829 static const WCHAR string3
[] = { 'F','r',0 };
831 ret
= pInternetTimeToSystemTimeW( NULL
, NULL
, 0 );
832 ok( !ret
, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
834 ret
= pInternetTimeToSystemTimeW( NULL
, &time
, 0 );
835 ok( !ret
, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
837 ret
= pInternetTimeToSystemTimeW( string
, NULL
, 0 );
838 ok( !ret
, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
840 ret
= pInternetTimeToSystemTimeW( string
, &time
, 0 );
841 ok( ret
, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
843 ret
= pInternetTimeToSystemTimeW( string
, &time
, 0 );
844 ok( ret
, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
845 ok( !memcmp( &time
, &expect
, sizeof(expect
) ),
846 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
848 ret
= pInternetTimeToSystemTimeW( string2
, &time
, 0 );
849 ok( ret
, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
850 ok( !memcmp( &time
, &expect
, sizeof(expect
) ),
851 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
853 ret
= pInternetTimeToSystemTimeW( string3
, &time
, 0 );
854 ok( ret
, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
857 static void HttpSendRequestEx_test(void)
863 INTERNET_BUFFERS BufferIn
;
864 DWORD dwBytesWritten
;
870 static char szPostData
[] = "mode=Test";
871 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
873 hSession
= InternetOpen("Wine Regression Test",
874 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
875 ok( hSession
!= NULL
,"Unable to open Internet session\n");
876 hConnect
= InternetConnect(hSession
, "crossover.codeweavers.com",
877 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
879 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
880 hRequest
= HttpOpenRequest(hConnect
, "POST", "/posttest.php",
881 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
882 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
884 skip( "Network unreachable, skipping test\n" );
887 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
890 BufferIn
.dwStructSize
= sizeof( INTERNET_BUFFERS
);
891 BufferIn
.Next
= (LPINTERNET_BUFFERS
)0xdeadcab;
892 BufferIn
.lpcszHeader
= szContentType
;
893 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
894 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
895 BufferIn
.lpvBuffer
= szPostData
;
896 BufferIn
.dwBufferLength
= 3;
897 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
898 BufferIn
.dwOffsetLow
= 0;
899 BufferIn
.dwOffsetHigh
= 0;
901 ret
= HttpSendRequestEx(hRequest
, &BufferIn
, NULL
, 0 ,0);
902 ok(ret
, "HttpSendRequestEx Failed with error %u\n", GetLastError());
904 for (i
= 3; szPostData
[i
]; i
++)
905 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
906 "InternetWriteFile failed\n");
908 ok(HttpEndRequest(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
910 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
911 "Unable to read response\n");
912 szBuffer
[dwBytesRead
] = 0;
914 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
915 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0,"Got string %s\n",szBuffer
);
917 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
919 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
920 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
923 static void InternetOpenRequest_test(void)
925 HINTERNET session
, connect
, request
;
926 static const char *types
[] = { "*", "", NULL
};
927 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
928 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
931 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
932 ok(session
!= NULL
,"Unable to open Internet session\n");
934 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
935 INTERNET_SERVICE_HTTP
, 0, 0);
936 ok(connect
== NULL
, "InternetConnectA should have failed\n");
937 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
939 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
940 INTERNET_SERVICE_HTTP
, 0, 0);
941 ok(connect
== NULL
, "InternetConnectA should have failed\n");
942 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
944 connect
= InternetConnectA(session
, "winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
945 INTERNET_SERVICE_HTTP
, 0, 0);
946 ok(connect
!= NULL
, "Unable to connect to http://winehq.org with error %d\n", GetLastError());
948 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
949 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
951 skip( "Network unreachable, skipping test\n" );
954 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
956 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
957 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
958 ok(InternetCloseHandle(request
), "Close request handle failed\n");
960 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
961 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
963 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
964 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
965 ok(InternetCloseHandle(request
), "Close request handle failed\n");
968 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
969 ok(InternetCloseHandle(session
), "Close session handle failed\n");
972 static void test_http_cache(void)
974 HINTERNET session
, connect
, request
;
975 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
976 DWORD size
, file_size
;
981 static const char *types
[] = { "*", "", NULL
};
983 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
984 ok(session
!= NULL
,"Unable to open Internet session\n");
986 connect
= InternetConnectA(session
, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
987 INTERNET_SERVICE_HTTP
, 0, 0);
988 ok(connect
!= NULL
, "Unable to connect to http://winehq.org with error %d\n", GetLastError());
990 request
= HttpOpenRequestA(connect
, NULL
, "/site/about", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
991 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
993 skip( "Network unreachable, skipping test\n" );
995 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
996 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1000 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1003 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1004 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_url) failed: %u\n", GetLastError());
1005 ok(!strcmp(url
, "http://www.winehq.org/site/about"), "Wrong URL %s\n", url
);
1007 size
= sizeof(file_name
);
1008 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1009 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1010 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1011 ok(!size
, "size = %d\n", size
);
1013 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1014 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1016 size
= sizeof(file_name
);
1017 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1018 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1020 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1021 FILE_ATTRIBUTE_NORMAL
, NULL
);
1022 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1023 file_size
= GetFileSize(file
, NULL
);
1024 ok(file_size
== 0, "file size=%d\n", file_size
);
1026 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1027 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1028 ok(size
== sizeof(buf
), "size=%d\n", size
);
1030 file_size
= GetFileSize(file
, NULL
);
1031 ok(file_size
== sizeof(buf
), "file size=%d\n", file_size
);
1034 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1036 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1037 FILE_ATTRIBUTE_NORMAL
, NULL
);
1038 ok(file
== INVALID_HANDLE_VALUE
, "CreateFile succeeded\n");
1039 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError()=%u, expected ERROR_FILE_NOT_FOUND\n", GetLastError());
1041 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1042 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1044 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1045 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1046 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1047 ok(!size
, "size = %d\n", size
);
1049 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1050 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1052 size
= sizeof(file_name
);
1053 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1054 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1055 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1056 ok(!size
, "size = %d\n", size
);
1058 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1059 FILE_ATTRIBUTE_NORMAL
, NULL
);
1060 ok(file
== INVALID_HANDLE_VALUE
, "CreateFile succeeded\n");
1061 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError()=%u, expected ERROR_FILE_NOT_FOUND\n", GetLastError());
1063 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1065 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1066 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1069 static void HttpHeaders_test(void)
1078 hSession
= InternetOpen("Wine Regression Test",
1079 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1080 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1081 hConnect
= InternetConnect(hSession
, "crossover.codeweavers.com",
1082 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1084 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
1085 hRequest
= HttpOpenRequest(hConnect
, "POST", "/posttest.php",
1086 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1087 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1089 skip( "Network unreachable, skipping test\n" );
1092 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1095 len
= sizeof(buffer
);
1096 strcpy(buffer
,"Warning");
1097 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1098 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1100 ok(HttpAddRequestHeaders(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1101 "Failed to add new header\n");
1104 len
= sizeof(buffer
);
1105 strcpy(buffer
,"Warning");
1106 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1107 buffer
,&len
,&index
),"Unable to query header\n");
1108 ok(index
== 1, "Index was not incremented\n");
1109 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1110 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1111 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1112 len
= sizeof(buffer
);
1113 strcpy(buffer
,"Warning");
1114 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1115 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1118 len
= 5; /* could store the string but not the NULL terminator */
1119 strcpy(buffer
,"Warning");
1120 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1121 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1122 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1123 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1125 /* a call with NULL will fail but will return the length */
1127 len
= sizeof(buffer
);
1128 SetLastError(0xdeadbeef);
1129 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1130 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1131 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1132 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1133 ok(index
== 0, "Index was incremented\n");
1135 /* even for a len that is too small */
1138 SetLastError(0xdeadbeef);
1139 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1140 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1141 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1142 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1143 ok(index
== 0, "Index was incremented\n");
1147 SetLastError(0xdeadbeef);
1148 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1149 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1150 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1151 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1152 ok(index
== 0, "Index was incremented\n");
1155 /* a working query */
1157 len
= sizeof(buffer
);
1158 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1159 buffer
,&len
,&index
),"Unable to query header\n");
1160 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1161 ok(strncmp(buffer
, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1162 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1163 ok(index
== 0, "Index was incremented\n");
1167 ok(HttpAddRequestHeaders(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1168 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1171 len
= sizeof(buffer
);
1172 strcpy(buffer
,"Warning");
1173 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1174 buffer
,&len
,&index
),"Unable to query header\n");
1175 ok(index
== 1, "Index was not incremented\n");
1176 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1177 len
= sizeof(buffer
);
1178 strcpy(buffer
,"Warning");
1179 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1180 buffer
,&len
,&index
),"Failed to get second header\n");
1181 ok(index
== 2, "Index was not incremented\n");
1182 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1183 len
= sizeof(buffer
);
1184 strcpy(buffer
,"Warning");
1185 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1186 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1188 ok(HttpAddRequestHeaders(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1191 len
= sizeof(buffer
);
1192 strcpy(buffer
,"Warning");
1193 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1194 buffer
,&len
,&index
),"Unable to query header\n");
1195 ok(index
== 1, "Index was not incremented\n");
1196 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1197 len
= sizeof(buffer
);
1198 strcpy(buffer
,"Warning");
1199 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1200 buffer
,&len
,&index
),"Failed to get second header\n");
1201 ok(index
== 2, "Index was not incremented\n");
1202 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1203 len
= sizeof(buffer
);
1204 strcpy(buffer
,"Warning");
1205 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1206 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1208 ok(HttpAddRequestHeaders(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1211 len
= sizeof(buffer
);
1212 strcpy(buffer
,"Warning");
1213 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1214 buffer
,&len
,&index
),"Unable to query header\n");
1215 ok(index
== 1, "Index was not incremented\n");
1216 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1217 len
= sizeof(buffer
);
1218 strcpy(buffer
,"Warning");
1219 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1220 buffer
,&len
,&index
),"Failed to get second header\n");
1221 ok(index
== 2, "Index was not incremented\n");
1222 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1223 len
= sizeof(buffer
);
1224 strcpy(buffer
,"Warning");
1225 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1226 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1228 ok(HttpAddRequestHeaders(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1231 len
= sizeof(buffer
);
1232 strcpy(buffer
,"Warning");
1233 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1234 buffer
,&len
,&index
),"Unable to query header\n");
1235 ok(index
== 1, "Index was not incremented\n");
1236 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1237 len
= sizeof(buffer
);
1238 strcpy(buffer
,"Warning");
1239 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1240 ok(index
== 2, "Index was not incremented\n");
1241 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1242 len
= sizeof(buffer
);
1243 strcpy(buffer
,"Warning");
1244 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1246 ok(HttpAddRequestHeaders(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1249 len
= sizeof(buffer
);
1250 strcpy(buffer
,"Warning");
1251 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1252 ok(index
== 1, "Index was not incremented\n");
1253 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1254 len
= sizeof(buffer
);
1255 strcpy(buffer
,"Warning");
1256 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1257 ok(index
== 2, "Index was not incremented\n");
1258 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1259 len
= sizeof(buffer
);
1260 strcpy(buffer
,"Warning");
1261 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1263 ok(HttpAddRequestHeaders(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1266 len
= sizeof(buffer
);
1267 strcpy(buffer
,"Warning");
1268 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1269 ok(index
== 1, "Index was not incremented\n");
1270 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1271 len
= sizeof(buffer
);
1272 strcpy(buffer
,"Warning");
1273 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1274 ok(index
== 2, "Index was not incremented\n");
1275 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1276 len
= sizeof(buffer
);
1277 strcpy(buffer
,"Warning");
1278 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1280 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");
1283 len
= sizeof(buffer
);
1284 strcpy(buffer
,"Warning");
1285 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1286 ok(index
== 1, "Index was not incremented\n");
1287 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1288 len
= sizeof(buffer
);
1289 strcpy(buffer
,"Warning");
1290 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1291 ok(index
== 2, "Index was not incremented\n");
1292 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1293 len
= sizeof(buffer
);
1294 strcpy(buffer
,"Warning");
1295 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1298 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1300 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1301 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1304 static const char contmsg
[] =
1305 "HTTP/1.1 100 Continue\r\n";
1307 static const char okmsg
[] =
1308 "HTTP/1.1 200 OK\r\n"
1309 "Server: winetest\r\n"
1312 static const char notokmsg
[] =
1313 "HTTP/1.1 400 Bad Request\r\n"
1314 "Server: winetest\r\n"
1317 static const char noauthmsg
[] =
1318 "HTTP/1.1 401 Unauthorized\r\n"
1319 "Server: winetest\r\n"
1322 static const char proxymsg
[] =
1323 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1324 "Server: winetest\r\n"
1325 "Proxy-Connection: close\r\n"
1326 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1329 static const char page1
[] =
1331 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1332 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1335 struct server_info
{
1340 static DWORD CALLBACK
server_thread(LPVOID param
)
1342 struct server_info
*si
= param
;
1345 struct sockaddr_in sa
;
1348 int last_request
= 0;
1349 char host_header
[22];
1350 static int test_b
= 0;
1352 WSAStartup(MAKEWORD(1,1), &wsaData
);
1354 s
= socket(AF_INET
, SOCK_STREAM
, 0);
1355 if (s
== INVALID_SOCKET
)
1359 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
1361 memset(&sa
, 0, sizeof sa
);
1362 sa
.sin_family
= AF_INET
;
1363 sa
.sin_port
= htons(si
->port
);
1364 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
1366 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
1372 SetEvent(si
->hEvent
);
1374 sprintf(host_header
, "Host: localhost:%d", si
->port
);
1378 c
= accept(s
, NULL
, NULL
);
1380 memset(buffer
, 0, sizeof buffer
);
1381 for(i
=0; i
<(sizeof buffer
-1); i
++)
1383 r
= recv(c
, &buffer
[i
], 1, 0);
1387 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
1388 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
1391 if (strstr(buffer
, "GET /test1"))
1393 if (!strstr(buffer
, "Content-Length: 0"))
1395 send(c
, okmsg
, sizeof okmsg
-1, 0);
1396 send(c
, page1
, sizeof page1
-1, 0);
1399 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1401 if (strstr(buffer
, "/test2"))
1403 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
1405 send(c
, okmsg
, sizeof okmsg
-1, 0);
1406 send(c
, page1
, sizeof page1
-1, 0);
1409 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
1411 if (strstr(buffer
, "/test3"))
1413 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
1414 send(c
, okmsg
, sizeof okmsg
-1, 0);
1416 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
1418 if (strstr(buffer
, "/test4"))
1420 if (strstr(buffer
, "Connection: Close"))
1421 send(c
, okmsg
, sizeof okmsg
-1, 0);
1423 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1425 if (strstr(buffer
, "POST /test5"))
1427 if (strstr(buffer
, "Content-Length: 0"))
1429 send(c
, okmsg
, sizeof okmsg
-1, 0);
1430 send(c
, page1
, sizeof page1
-1, 0);
1433 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1435 if (strstr(buffer
, "GET /test6"))
1437 send(c
, contmsg
, sizeof contmsg
-1, 0);
1438 send(c
, contmsg
, sizeof contmsg
-1, 0);
1439 send(c
, okmsg
, sizeof okmsg
-1, 0);
1440 send(c
, page1
, sizeof page1
-1, 0);
1442 if (strstr(buffer
, "POST /test7"))
1444 if (strstr(buffer
, "Content-Length: 100"))
1446 send(c
, okmsg
, sizeof okmsg
-1, 0);
1447 send(c
, page1
, sizeof page1
-1, 0);
1450 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1452 if (strstr(buffer
, "/test8"))
1454 if (!strstr(buffer
, "Connection: Close") &&
1455 strstr(buffer
, "Connection: Keep-Alive") &&
1456 !strstr(buffer
, "Cache-Control: no-cache") &&
1457 !strstr(buffer
, "Pragma: no-cache") &&
1458 strstr(buffer
, host_header
))
1459 send(c
, okmsg
, sizeof okmsg
-1, 0);
1461 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1463 if (strstr(buffer
, "/test9"))
1465 if (!strstr(buffer
, "Connection: Close") &&
1466 !strstr(buffer
, "Connection: Keep-Alive") &&
1467 !strstr(buffer
, "Cache-Control: no-cache") &&
1468 !strstr(buffer
, "Pragma: no-cache") &&
1469 strstr(buffer
, host_header
))
1470 send(c
, okmsg
, sizeof okmsg
-1, 0);
1472 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1474 if (strstr(buffer
, "/testA"))
1476 if (!strstr(buffer
, "Connection: Close") &&
1477 !strstr(buffer
, "Connection: Keep-Alive") &&
1478 (strstr(buffer
, "Cache-Control: no-cache") ||
1479 strstr(buffer
, "Pragma: no-cache")) &&
1480 strstr(buffer
, host_header
))
1481 send(c
, okmsg
, sizeof okmsg
-1, 0);
1483 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1485 if (!test_b
&& strstr(buffer
, "/testB HTTP/1.1"))
1488 send(c
, okmsg
, sizeof okmsg
-1, 0);
1489 recvfrom(c
, buffer
, sizeof buffer
, 0, NULL
, NULL
);
1490 send(c
, okmsg
, sizeof okmsg
-1, 0);
1492 if (strstr(buffer
, "/testC"))
1494 if (strstr(buffer
, "Cookie: cookie=biscuit"))
1495 send(c
, okmsg
, sizeof okmsg
-1, 0);
1497 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1499 if (strstr(buffer
, "GET /quit"))
1501 send(c
, okmsg
, sizeof okmsg
-1, 0);
1502 send(c
, page1
, sizeof page1
-1, 0);
1508 } while (!last_request
);
1515 static void test_basic_request(int port
, const char *verb
, const char *url
)
1517 HINTERNET hi
, hc
, hr
;
1521 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1522 ok(hi
!= NULL
, "open failed\n");
1524 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1525 ok(hc
!= NULL
, "connect failed\n");
1527 hr
= HttpOpenRequest(hc
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
1528 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1530 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1531 ok(r
, "HttpSendRequest failed\n");
1534 memset(buffer
, 0, sizeof buffer
);
1535 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
1536 ok(r
, "InternetReadFile failed\n");
1537 ok(count
== sizeof page1
- 1, "count was wrong\n");
1538 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
1540 InternetCloseHandle(hr
);
1541 InternetCloseHandle(hc
);
1542 InternetCloseHandle(hi
);
1545 static void test_proxy_indirect(int port
)
1547 HINTERNET hi
, hc
, hr
;
1551 hi
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
1552 ok(hi
!= NULL
, "open failed\n");
1554 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1555 ok(hc
!= NULL
, "connect failed\n");
1557 hr
= HttpOpenRequest(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
1558 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1560 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1561 ok(r
, "HttpSendRequest failed\n");
1564 r
= HttpQueryInfo(hr
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
1565 ok(r
, "HttpQueryInfo failed\n");
1566 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
1569 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1570 ok(r
, "HttpQueryInfo failed\n");
1571 ok(!strcmp(buffer
, "407"), "proxy code wrong\n");
1574 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &val
, &sz
, NULL
);
1575 ok(r
, "HttpQueryInfo failed\n");
1576 ok(val
== 407, "proxy code wrong\n");
1579 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
1580 ok(r
, "HttpQueryInfo failed\n");
1581 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
1584 r
= HttpQueryInfo(hr
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
1585 ok(r
, "HttpQueryInfo failed\n");
1586 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
1589 r
= HttpQueryInfo(hr
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
1590 ok(r
, "HttpQueryInfo failed\n");
1591 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
1594 r
= HttpQueryInfo(hr
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
1595 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
1596 ok(r
== FALSE
, "HttpQueryInfo failed\n");
1598 InternetCloseHandle(hr
);
1599 InternetCloseHandle(hc
);
1600 InternetCloseHandle(hi
);
1603 static void test_proxy_direct(int port
)
1605 HINTERNET hi
, hc
, hr
;
1608 static CHAR username
[] = "mike",
1609 password
[] = "1101";
1611 sprintf(buffer
, "localhost:%d\n", port
);
1612 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
1613 ok(hi
!= NULL
, "open failed\n");
1615 /* try connect without authorization */
1616 hc
= InternetConnect(hi
, "www.winehq.org/", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1617 ok(hc
!= NULL
, "connect failed\n");
1619 hr
= HttpOpenRequest(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
1620 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1622 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1623 ok(r
, "HttpSendRequest failed\n");
1626 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1627 ok(r
, "HttpQueryInfo failed\n");
1628 ok(!strcmp(buffer
, "407"), "proxy code wrong\n");
1631 /* set the user + password then try again */
1633 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
1634 ok(r
, "failed to set user\n");
1636 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
1637 ok(r
, "failed to set password\n");
1640 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1641 ok(r
, "HttpSendRequest failed\n");
1643 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1644 ok(r
, "HttpQueryInfo failed\n");
1646 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
1650 InternetCloseHandle(hr
);
1651 InternetCloseHandle(hc
);
1652 InternetCloseHandle(hi
);
1655 static void test_header_handling_order(int port
)
1657 static char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
1658 static char connection
[] = "Connection: Close";
1660 static const char *types
[2] = { "*", NULL
};
1661 HINTERNET session
, connect
, request
;
1665 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1666 ok(session
!= NULL
, "InternetOpen failed\n");
1668 connect
= InternetConnect(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1669 ok(connect
!= NULL
, "InternetConnect failed\n");
1671 request
= HttpOpenRequest(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1672 ok(request
!= NULL
, "HttpOpenRequest failed\n");
1674 ret
= HttpAddRequestHeaders(request
, authorization
, ~0UL, HTTP_ADDREQ_FLAG_ADD
);
1675 ok(ret
, "HttpAddRequestHeaders failed\n");
1677 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1678 ok(ret
, "HttpSendRequest failed\n");
1681 size
= sizeof(status
);
1682 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1683 ok(ret
, "HttpQueryInfo failed\n");
1684 ok(status
== 200, "request failed with status %u\n", status
);
1686 InternetCloseHandle(request
);
1688 request
= HttpOpenRequest(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1689 ok(request
!= NULL
, "HttpOpenRequest failed\n");
1691 ret
= HttpSendRequest(request
, connection
, ~0UL, NULL
, 0);
1692 ok(ret
, "HttpSendRequest failed\n");
1695 size
= sizeof(status
);
1696 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1697 ok(ret
, "HttpQueryInfo failed\n");
1698 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
1700 InternetCloseHandle(request
);
1702 request
= HttpOpenRequest(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1703 ok(request
!= NULL
, "HttpOpenRequest failed\n");
1705 ret
= HttpAddRequestHeaders(request
, "Content-Length: 100\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
1706 ok(ret
, "HttpAddRequestHeaders failed\n");
1708 ret
= HttpSendRequest(request
, connection
, ~0UL, NULL
, 0);
1709 ok(ret
, "HttpSendRequest failed\n");
1712 size
= sizeof(status
);
1713 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1714 ok(ret
, "HttpQueryInfo failed\n");
1715 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
1717 InternetCloseHandle(request
);
1718 InternetCloseHandle(connect
);
1719 InternetCloseHandle(session
);
1722 static void test_connection_header(int port
)
1724 HINTERNET ses
, con
, req
;
1728 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1729 ok(ses
!= NULL
, "InternetOpen failed\n");
1731 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1732 ok(con
!= NULL
, "InternetConnect failed\n");
1734 req
= HttpOpenRequest(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1735 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1737 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1738 ok(ret
, "HttpSendRequest failed\n");
1741 size
= sizeof(status
);
1742 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1743 ok(ret
, "HttpQueryInfo failed\n");
1744 ok(status
== 200, "request failed with status %u\n", status
);
1746 InternetCloseHandle(req
);
1748 req
= HttpOpenRequest(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
1749 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1751 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1752 ok(ret
, "HttpSendRequest failed\n");
1755 size
= sizeof(status
);
1756 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1757 ok(ret
, "HttpQueryInfo failed\n");
1758 ok(status
== 200, "request failed with status %u\n", status
);
1760 InternetCloseHandle(req
);
1762 req
= HttpOpenRequest(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1763 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1765 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1766 ok(ret
, "HttpSendRequest failed\n");
1769 size
= sizeof(status
);
1770 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1771 ok(ret
, "HttpQueryInfo failed\n");
1772 ok(status
== 200, "request failed with status %u\n", status
);
1774 InternetCloseHandle(req
);
1776 req
= HttpOpenRequest(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1777 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1779 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1780 ok(ret
, "HttpSendRequest failed\n");
1783 size
= sizeof(status
);
1784 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1785 ok(ret
, "HttpQueryInfo failed\n");
1786 ok(status
== 200, "request failed with status %u\n", status
);
1788 InternetCloseHandle(req
);
1789 InternetCloseHandle(con
);
1790 InternetCloseHandle(ses
);
1793 static void test_http1_1(int port
)
1795 HINTERNET ses
, con
, req
;
1798 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1799 ok(ses
!= NULL
, "InternetOpen failed\n");
1801 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1802 ok(con
!= NULL
, "InternetConnect failed\n");
1804 req
= HttpOpenRequest(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1805 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1807 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1810 InternetCloseHandle(req
);
1812 req
= HttpOpenRequest(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1813 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1815 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1817 ok(ret
, "HttpSendRequest failed\n");
1820 InternetCloseHandle(req
);
1821 InternetCloseHandle(con
);
1822 InternetCloseHandle(ses
);
1825 static void test_cookie_header(int port
)
1827 HINTERNET ses
, con
, req
;
1828 DWORD size
, status
, error
;
1832 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1833 ok(ses
!= NULL
, "InternetOpen failed\n");
1835 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1836 ok(con
!= NULL
, "InternetConnect failed\n");
1838 InternetSetCookie("http://localhost", "cookie", "biscuit");
1840 req
= HttpOpenRequest(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1841 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1844 size
= sizeof(buffer
);
1845 SetLastError(0xdeadbeef);
1846 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1847 error
= GetLastError();
1848 ok(!ret
, "HttpQueryInfo succeeded\n");
1849 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
1851 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1852 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1855 size
= sizeof(status
);
1856 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1857 ok(ret
, "HttpQueryInfo failed\n");
1858 ok(status
== 200, "request failed with status %u\n", status
);
1861 size
= sizeof(buffer
);
1862 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1863 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
1864 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
1866 InternetCloseHandle(req
);
1867 InternetCloseHandle(con
);
1868 InternetCloseHandle(ses
);
1871 static void test_http_connection(void)
1873 struct server_info si
;
1877 si
.hEvent
= CreateEvent(NULL
, 0, 0, NULL
);
1880 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
1881 ok( hThread
!= NULL
, "create thread failed\n");
1883 r
= WaitForSingleObject(si
.hEvent
, 10000);
1884 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
1885 if (r
!= WAIT_OBJECT_0
)
1888 test_basic_request(si
.port
, "GET", "/test1");
1889 test_proxy_indirect(si
.port
);
1890 test_proxy_direct(si
.port
);
1891 test_header_handling_order(si
.port
);
1892 test_basic_request(si
.port
, "POST", "/test5");
1893 test_basic_request(si
.port
, "GET", "/test6");
1894 test_connection_header(si
.port
);
1895 test_http1_1(si
.port
);
1896 test_cookie_header(si
.port
);
1898 /* send the basic request again to shutdown the server thread */
1899 test_basic_request(si
.port
, "GET", "/quit");
1901 r
= WaitForSingleObject(hThread
, 3000);
1902 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
1903 CloseHandle(hThread
);
1906 static void test_user_agent_header(void)
1908 HINTERNET ses
, con
, req
;
1913 ses
= InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1914 ok(ses
!= NULL
, "InternetOpen failed\n");
1916 con
= InternetConnect(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1917 ok(con
!= NULL
, "InternetConnect failed\n");
1919 req
= HttpOpenRequest(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
1920 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1922 size
= sizeof(buffer
);
1923 ret
= HttpQueryInfo(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1924 err
= GetLastError();
1925 ok(!ret
, "HttpQueryInfo succeeded\n");
1926 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
1928 ret
= HttpAddRequestHeaders(req
, "User-Agent: Gizmo Project\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
1929 ok(ret
, "HttpAddRequestHeaders succeeded\n");
1931 size
= sizeof(buffer
);
1932 ret
= HttpQueryInfo(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1933 err
= GetLastError();
1934 ok(ret
, "HttpQueryInfo failed\n");
1935 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
1937 InternetCloseHandle(req
);
1939 req
= HttpOpenRequest(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
1940 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1942 size
= sizeof(buffer
);
1943 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1944 err
= GetLastError();
1945 ok(!ret
, "HttpQueryInfo succeeded\n");
1946 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
1948 ret
= HttpAddRequestHeaders(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
1949 ok(ret
, "HttpAddRequestHeaders failed\n");
1952 size
= sizeof(buffer
);
1953 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1954 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
1955 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
1957 InternetCloseHandle(req
);
1958 InternetCloseHandle(con
);
1959 InternetCloseHandle(ses
);
1962 static void test_bogus_accept_types_array(void)
1964 HINTERNET ses
, con
, req
;
1965 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", "*/*", NULL
};
1970 ses
= InternetOpen("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
1971 con
= InternetConnect(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1972 req
= HttpOpenRequest(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
1974 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
1977 size
= sizeof(buffer
);
1978 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1979 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
1980 ok(!strcmp(buffer
, ", */*, %p, , */*") || /* IE6 */
1981 !strcmp(buffer
, "*/*, %p, */*"),
1982 "got '%s' expected '*/*, %%p, */*' or ', */*, %%p, , */*'\n", buffer
);
1984 InternetCloseHandle(req
);
1985 InternetCloseHandle(con
);
1986 InternetCloseHandle(ses
);
1995 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
1997 INTERNET_ASYNC_RESULT
*result
= info
;
1998 struct context
*ctx
= (struct context
*)context
;
2000 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
2002 if (status
== INTERNET_STATUS_REQUEST_COMPLETE
)
2004 trace("request handle: 0x%08lx\n", result
->dwResult
);
2005 ctx
->req
= (HINTERNET
)result
->dwResult
;
2006 SetEvent(ctx
->event
);
2008 if (status
== INTERNET_STATUS_HANDLE_CLOSING
)
2010 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
2012 if (InternetQueryOption(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
2013 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
2014 SetEvent(ctx
->event
);
2018 static void test_open_url_async(void)
2027 ctx
.event
= CreateEvent(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
2029 ses
= InternetOpen("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2030 ok(ses
!= NULL
, "InternetOpen failed\n");
2032 pInternetSetStatusCallbackA(ses
, cb
);
2033 ResetEvent(ctx
.event
);
2035 req
= InternetOpenUrl(ses
, "http://www.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
2036 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
2038 WaitForSingleObject(ctx
.event
, INFINITE
);
2041 size
= sizeof(type
);
2042 ret
= InternetQueryOption(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
2043 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
2044 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
2045 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
2048 ret
= HttpQueryInfo(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
2049 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
2050 ok(size
> 0, "expected size > 0\n");
2052 ResetEvent(ctx
.event
);
2053 InternetCloseHandle(ctx
.req
);
2054 WaitForSingleObject(ctx
.event
, INFINITE
);
2056 InternetCloseHandle(ses
);
2057 CloseHandle(ctx
.event
);
2060 #define STATUS_STRING(status) \
2061 memcpy(status_string[status], #status, sizeof(CHAR) * \
2062 (strlen(#status) < MAX_STATUS_NAME ? \
2064 MAX_STATUS_NAME - 1))
2065 static void init_status_tests(void)
2067 memset(expect
, 0, sizeof(expect
));
2068 memset(wine_allow
, 0, sizeof(wine_allow
));
2069 memset(notified
, 0, sizeof(notified
));
2070 memset(status_string
, 0, sizeof(status_string
));
2071 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
2072 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
2073 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2074 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2075 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
2076 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
2077 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
2078 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
2079 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
2080 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
2081 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
2082 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
2083 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
2084 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
2085 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
2086 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
2087 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
2088 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
2089 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
2090 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
2091 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
2092 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
2093 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
2094 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
2095 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
2096 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
2098 #undef STATUS_STRING
2103 hdll
= GetModuleHandleA("wininet.dll");
2104 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
2105 pInternetTimeFromSystemTimeA
= (void*)GetProcAddress(hdll
, "InternetTimeFromSystemTimeA");
2106 pInternetTimeFromSystemTimeW
= (void*)GetProcAddress(hdll
, "InternetTimeFromSystemTimeW");
2107 pInternetTimeToSystemTimeA
= (void*)GetProcAddress(hdll
, "InternetTimeToSystemTimeA");
2108 pInternetTimeToSystemTimeW
= (void*)GetProcAddress(hdll
, "InternetTimeToSystemTimeW");
2110 if (!pInternetSetStatusCallbackA
)
2111 skip("skipping the InternetReadFile tests\n");
2114 init_status_tests();
2115 InternetReadFile_test(INTERNET_FLAG_ASYNC
);
2116 InternetReadFile_test(0);
2117 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
2118 test_open_url_async();
2120 InternetOpenRequest_test();
2122 InternetOpenUrlA_test();
2123 if (!pInternetTimeFromSystemTimeA
)
2124 skip("skipping the InternetTime tests\n");
2127 InternetTimeFromSystemTimeA_test();
2128 InternetTimeFromSystemTimeW_test();
2129 InternetTimeToSystemTimeA_test();
2130 InternetTimeToSystemTimeW_test();
2132 HttpSendRequestEx_test();
2134 test_http_connection();
2135 test_user_agent_header();
2136 test_bogus_accept_types_array();