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 #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][0] != 0 ? \
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][0] != 0 ? \
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] == (num), "expected status %d (%s) %d times, received %d times\n", \
88 status, status < MAX_INTERNET_STATUS && status_string[status][0] != 0 ? \
89 status_string[status] : "unknown", (num), notified[status]); \
90 CLEAR_NOTIFIED(status); \
93 #define CHECK_NOTIFIED(status) \
94 CHECK_NOTIFIED2(status, 1)
96 #define CHECK_NOT_NOTIFIED(status) \
97 CHECK_NOTIFIED2(status, 0)
99 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
100 #define MAX_STATUS_NAME 50
101 static int expect
[MAX_INTERNET_STATUS
], optional
[MAX_INTERNET_STATUS
],
102 wine_allow
[MAX_INTERNET_STATUS
], notified
[MAX_INTERNET_STATUS
];
103 static CHAR status_string
[MAX_INTERNET_STATUS
][MAX_STATUS_NAME
];
105 static HANDLE hCompleteEvent
;
107 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackA
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
108 static BOOL (WINAPI
*pInternetTimeFromSystemTimeA
)(CONST SYSTEMTIME
*,DWORD
,LPSTR
,DWORD
);
109 static BOOL (WINAPI
*pInternetTimeFromSystemTimeW
)(CONST SYSTEMTIME
*,DWORD
,LPWSTR
,DWORD
);
110 static BOOL (WINAPI
*pInternetTimeToSystemTimeA
)(LPCSTR
,SYSTEMTIME
*,DWORD
);
111 static BOOL (WINAPI
*pInternetTimeToSystemTimeW
)(LPCWSTR
,SYSTEMTIME
*,DWORD
);
114 static VOID WINAPI
callback(
117 DWORD dwInternetStatus
,
118 LPVOID lpvStatusInformation
,
119 DWORD dwStatusInformationLength
122 CHECK_EXPECT(dwInternetStatus
);
123 switch (dwInternetStatus
)
125 case INTERNET_STATUS_RESOLVING_NAME
:
126 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
127 GetCurrentThreadId(), hInternet
, dwContext
,
128 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
129 *(LPSTR
)lpvStatusInformation
= '\0';
131 case INTERNET_STATUS_NAME_RESOLVED
:
132 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
133 GetCurrentThreadId(), hInternet
, dwContext
,
134 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
135 *(LPSTR
)lpvStatusInformation
= '\0';
137 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
138 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
139 GetCurrentThreadId(), hInternet
, dwContext
,
140 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
141 *(LPSTR
)lpvStatusInformation
= '\0';
143 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
144 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
145 GetCurrentThreadId(), hInternet
, dwContext
,
146 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
147 *(LPSTR
)lpvStatusInformation
= '\0';
149 case INTERNET_STATUS_SENDING_REQUEST
:
150 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
151 GetCurrentThreadId(), hInternet
, dwContext
,
152 lpvStatusInformation
,dwStatusInformationLength
);
154 case INTERNET_STATUS_REQUEST_SENT
:
155 ok(dwStatusInformationLength
== sizeof(DWORD
),
156 "info length should be sizeof(DWORD) instead of %d\n",
157 dwStatusInformationLength
);
158 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
159 GetCurrentThreadId(), hInternet
, dwContext
,
160 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
162 case INTERNET_STATUS_RECEIVING_RESPONSE
:
163 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
164 GetCurrentThreadId(), hInternet
, dwContext
,
165 lpvStatusInformation
,dwStatusInformationLength
);
167 case INTERNET_STATUS_RESPONSE_RECEIVED
:
168 ok(dwStatusInformationLength
== sizeof(DWORD
),
169 "info length should be sizeof(DWORD) instead of %d\n",
170 dwStatusInformationLength
);
171 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
172 GetCurrentThreadId(), hInternet
, dwContext
,
173 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
175 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
176 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
177 GetCurrentThreadId(), hInternet
,dwContext
,
178 lpvStatusInformation
,dwStatusInformationLength
);
180 case INTERNET_STATUS_PREFETCH
:
181 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
182 GetCurrentThreadId(), hInternet
, dwContext
,
183 lpvStatusInformation
,dwStatusInformationLength
);
185 case INTERNET_STATUS_CLOSING_CONNECTION
:
186 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
187 GetCurrentThreadId(), hInternet
, dwContext
,
188 lpvStatusInformation
,dwStatusInformationLength
);
190 case INTERNET_STATUS_CONNECTION_CLOSED
:
191 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
192 GetCurrentThreadId(), hInternet
, dwContext
,
193 lpvStatusInformation
,dwStatusInformationLength
);
195 case INTERNET_STATUS_HANDLE_CREATED
:
196 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
197 "info length should be sizeof(HINTERNET) instead of %d\n",
198 dwStatusInformationLength
);
199 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
200 GetCurrentThreadId(), hInternet
, dwContext
,
201 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
202 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
203 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
205 case INTERNET_STATUS_HANDLE_CLOSING
:
206 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
207 "info length should be sizeof(HINTERNET) instead of %d\n",
208 dwStatusInformationLength
);
209 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
210 GetCurrentThreadId(), hInternet
, dwContext
,
211 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
213 case INTERNET_STATUS_REQUEST_COMPLETE
:
215 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
216 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
217 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
218 dwStatusInformationLength
);
219 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
220 GetCurrentThreadId(), hInternet
, dwContext
,
221 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
222 SetEvent(hCompleteEvent
);
225 case INTERNET_STATUS_REDIRECT
:
226 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
227 GetCurrentThreadId(), hInternet
, dwContext
,
228 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
229 *(LPSTR
)lpvStatusInformation
= '\0';
230 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
231 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
233 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
234 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
235 GetCurrentThreadId(), hInternet
, dwContext
,
236 lpvStatusInformation
, dwStatusInformationLength
);
239 trace("%04x:Callback %p 0x%lx %d %p %d\n",
240 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
241 lpvStatusInformation
, dwStatusInformationLength
);
245 static void InternetReadFile_test(int flags
)
252 const char *types
[2] = { "*", NULL
};
253 HINTERNET hi
, hic
= 0, hor
= 0;
255 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
257 trace("Starting InternetReadFile test with flags 0x%x\n",flags
);
259 trace("InternetOpenA <--\n");
260 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
261 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
262 trace("InternetOpenA -->\n");
264 if (hi
== 0x0) goto abort
;
266 pInternetSetStatusCallbackA(hi
,&callback
);
268 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
270 trace("InternetConnectA <--\n");
271 hic
=InternetConnectA(hi
, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
272 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
273 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
274 trace("InternetConnectA -->\n");
276 if (hic
== 0x0) goto abort
;
278 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
279 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
281 trace("HttpOpenRequestA <--\n");
282 hor
= HttpOpenRequestA(hic
, "GET", "/about/", NULL
, NULL
, types
,
283 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
,
285 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
287 * If the internet name can't be resolved we are probably behind
288 * a firewall or in some other way not directly connected to the
289 * Internet. Not enough reason to fail the test. Just ignore and
293 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
295 trace("HttpOpenRequestA -->\n");
297 if (hor
== 0x0) goto abort
;
299 length
= sizeof(buffer
);
300 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
301 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
302 ok(!strcmp(buffer
, "http://www.winehq.org/about/"), "Wrong URL %s\n", buffer
);
304 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
305 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
306 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
307 if (first_connection_to_test_url
)
309 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
310 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
311 SET_WINE_ALLOW(INTERNET_STATUS_RESOLVING_NAME
);
312 SET_WINE_ALLOW(INTERNET_STATUS_NAME_RESOLVED
);
316 SET_WINE_ALLOW2(INTERNET_STATUS_RESOLVING_NAME
,2);
317 SET_WINE_ALLOW2(INTERNET_STATUS_NAME_RESOLVED
,2);
319 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
320 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
321 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
322 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
323 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
324 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
325 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
326 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
327 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
328 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
329 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
330 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
331 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
332 if (flags
& INTERNET_FLAG_ASYNC
)
333 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
335 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
337 trace("HttpSendRequestA -->\n");
338 SetLastError(0xdeadbeef);
339 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
340 if (flags
& INTERNET_FLAG_ASYNC
)
341 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
342 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
344 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
345 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
346 trace("HttpSendRequestA <--\n");
348 if (flags
& INTERNET_FLAG_ASYNC
)
349 WaitForSingleObject(hCompleteEvent
, INFINITE
);
351 todo_wine
if (first_connection_to_test_url
)
353 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
354 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
358 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
359 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
361 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
362 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
363 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
364 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
365 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
366 if (flags
& INTERNET_FLAG_ASYNC
)
367 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
369 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
370 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
371 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
372 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
375 rc
= InternetQueryOptionA(hor
,INTERNET_OPTION_REQUEST_FLAGS
,&out
,&length
);
376 trace("Option 0x17 -> %i %i\n",rc
,out
);
379 rc
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
380 trace("Option 0x22 -> %i %s\n",rc
,buffer
);
383 rc
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
385 trace("Option 0x16 -> %i %s\n",rc
,buffer
);
387 length
= sizeof(buffer
);
388 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
389 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
390 ok(!strcmp(buffer
, "http://www.winehq.org/site/about"), "Wrong URL %s\n", buffer
);
393 rc
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
394 trace("Option 0x5 -> %i %s (%u)\n",rc
,buffer
,GetLastError());
397 rc
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
399 trace("Option 0x1 -> %i %s\n",rc
,buffer
);
401 SetLastError(0xdeadbeef);
402 rc
= InternetReadFile(NULL
, buffer
, 100, &length
);
403 ok(!rc
, "InternetReadFile should have failed\n");
404 ok(GetLastError() == ERROR_INVALID_HANDLE
,
405 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
409 trace("Entering Query loop\n");
411 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
412 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
415 if (flags
& INTERNET_FLAG_ASYNC
)
416 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
417 rc
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
418 ok(!(rc
== 0 && length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
419 ok(rc
!= 0 || ((flags
& INTERNET_FLAG_ASYNC
) && GetLastError() == ERROR_IO_PENDING
),
420 "InternetQueryDataAvailable failed, error %d\n", GetLastError());
421 if (flags
& INTERNET_FLAG_ASYNC
)
425 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
427 else if (GetLastError() == ERROR_IO_PENDING
)
429 WaitForSingleObject(hCompleteEvent
, INFINITE
);
430 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
437 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
439 rc
= InternetReadFile(hor
,buffer
,length
,&length
);
443 trace("ReadFile -> %i %i\n",rc
,length
);
445 HeapFree(GetProcessHeap(),0,buffer
);
450 /* WinXP does not send, but Win98 does */
451 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
452 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
454 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, (hor
!= 0x0) + (hic
!= 0x0));
456 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
457 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
458 SetLastError(0xdeadbeef);
459 rc
= InternetCloseHandle(hor
);
460 ok ((rc
!= 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
461 SetLastError(0xdeadbeef);
462 rc
= InternetCloseHandle(hor
);
463 ok ((rc
== 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
464 ok (GetLastError() == ERROR_INVALID_HANDLE
,
465 "Double close of handle should have set ERROR_INVALID_HANDLE instead of %u\n",
468 /* We intentionally do not close the handle opened by InternetConnectA as this
469 * tickles bug #9479: native closes child internet handles when the parent handles
470 * are closed. This is verified below by checking that the number of
471 * INTERNET_STATUS_HANDLE_CLOSING notifications matches the number expected. */
473 SET_WINE_ALLOW(INTERNET_STATUS_HANDLE_CLOSING
);
474 rc
= InternetCloseHandle(hi
);
475 ok ((rc
!= 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
476 if (flags
& INTERNET_FLAG_ASYNC
)
479 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, (hor
!= 0x0) + (hic
!= 0x0));
480 if (hor
!= 0x0 && (flags
& INTERNET_FLAG_ASYNC
)) todo_wine
482 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
483 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
487 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
488 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
490 CloseHandle(hCompleteEvent
);
491 first_connection_to_test_url
= FALSE
;
494 static void InternetReadFileExA_test(int flags
)
498 const char *types
[2] = { "*", NULL
};
499 HINTERNET hi
, hic
= 0, hor
= 0;
500 INTERNET_BUFFERS inetbuffers
;
502 hCompleteEvent
= CreateEvent(NULL
, FALSE
, FALSE
, NULL
);
504 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
506 trace("InternetOpenA <--\n");
507 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
508 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
509 trace("InternetOpenA -->\n");
511 if (hi
== 0x0) goto abort
;
513 pInternetSetStatusCallbackA(hi
,&callback
);
515 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
517 trace("InternetConnectA <--\n");
518 hic
=InternetConnectA(hi
, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
519 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
520 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
521 trace("InternetConnectA -->\n");
523 if (hic
== 0x0) goto abort
;
525 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
526 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
528 trace("HttpOpenRequestA <--\n");
529 hor
= HttpOpenRequestA(hic
, "GET", "/about/", NULL
, NULL
, types
,
530 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RESYNCHRONIZE
,
532 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
534 * If the internet name can't be resolved we are probably behind
535 * a firewall or in some other way not directly connected to the
536 * Internet. Not enough reason to fail the test. Just ignore and
540 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
542 trace("HttpOpenRequestA -->\n");
544 if (hor
== 0x0) goto abort
;
546 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
547 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
548 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
549 if (first_connection_to_test_url
)
551 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
552 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
553 SET_WINE_ALLOW(INTERNET_STATUS_RESOLVING_NAME
);
554 SET_WINE_ALLOW(INTERNET_STATUS_NAME_RESOLVED
);
558 SET_WINE_ALLOW2(INTERNET_STATUS_RESOLVING_NAME
,2);
559 SET_WINE_ALLOW2(INTERNET_STATUS_NAME_RESOLVED
,2);
561 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
562 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
563 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
564 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
565 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
566 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
567 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
568 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
569 SET_OPTIONAL(INTERNET_STATUS_CLOSING_CONNECTION
);
570 SET_OPTIONAL(INTERNET_STATUS_CONNECTION_CLOSED
);
571 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
572 if (flags
& INTERNET_FLAG_ASYNC
)
573 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
575 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
577 trace("HttpSendRequestA -->\n");
578 SetLastError(0xdeadbeef);
579 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
580 if (flags
& INTERNET_FLAG_ASYNC
)
581 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
582 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
584 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
585 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
586 trace("HttpSendRequestA <--\n");
588 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
))
589 WaitForSingleObject(hCompleteEvent
, INFINITE
);
591 if (first_connection_to_test_url
)
593 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
594 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
598 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
599 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
601 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
602 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
603 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
604 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
605 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
606 if (flags
& INTERNET_FLAG_ASYNC
)
607 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
609 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
610 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
611 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
612 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
614 /* tests invalid dwStructSize */
615 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
)+1;
616 inetbuffers
.lpcszHeader
= NULL
;
617 inetbuffers
.dwHeadersLength
= 0;
618 inetbuffers
.dwBufferLength
= 10;
619 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
620 inetbuffers
.dwOffsetHigh
= 1234;
621 inetbuffers
.dwOffsetLow
= 5678;
622 rc
= InternetReadFileEx(hor
, &inetbuffers
, 0, 0xdeadcafe);
623 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
624 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
625 rc
? "TRUE" : "FALSE", GetLastError());
626 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
628 /* tests to see whether lpcszHeader is used - it isn't */
629 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
);
630 inetbuffers
.lpcszHeader
= (LPCTSTR
)0xdeadbeef;
631 inetbuffers
.dwHeadersLength
= 255;
632 inetbuffers
.dwBufferLength
= 0;
633 inetbuffers
.lpvBuffer
= NULL
;
634 inetbuffers
.dwOffsetHigh
= 1234;
635 inetbuffers
.dwOffsetLow
= 5678;
636 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
637 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
638 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
639 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
640 rc
= InternetReadFileEx(hor
, &inetbuffers
, 0, 0xdeadcafe);
641 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
642 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
645 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
646 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
649 rc
= InternetReadFileEx(NULL
, &inetbuffers
, 0, 0xdeadcafe);
650 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
651 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
652 rc
? "TRUE" : "FALSE", GetLastError());
655 trace("Entering Query loop\n");
657 SET_EXPECT(INTERNET_STATUS_CLOSING_CONNECTION
);
658 SET_EXPECT(INTERNET_STATUS_CONNECTION_CLOSED
);
661 inetbuffers
.dwStructSize
= sizeof(INTERNET_BUFFERS
);
662 inetbuffers
.dwBufferLength
= 1024;
663 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
664 inetbuffers
.dwOffsetHigh
= 1234;
665 inetbuffers
.dwOffsetLow
= 5678;
667 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
668 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
669 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
670 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
673 if (GetLastError() == ERROR_IO_PENDING
)
675 trace("InternetReadFileEx -> PENDING\n");
676 ok(flags
& INTERNET_FLAG_ASYNC
,
677 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
678 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
679 WaitForSingleObject(hCompleteEvent
, INFINITE
);
680 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
681 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
685 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
691 trace("InternetReadFileEx -> SUCCEEDED\n");
692 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
693 if (inetbuffers
.dwBufferLength
)
695 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
696 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
700 /* Win98 still sends these when 0 bytes are read, WinXP does not */
701 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
702 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
706 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
707 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
709 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
710 "InternetReadFileEx sets offsets to 0x%x%08x\n",
711 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
713 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
715 if (!inetbuffers
.dwBufferLength
)
718 length
+= inetbuffers
.dwBufferLength
;
720 todo_wine
ok(length
> 0, "failed to read any of the document\n");
721 trace("Finished. Read %d bytes\n", length
);
723 /* WinXP does not send, but Win98 does */
724 CLEAR_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
725 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
727 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, (hor
!= 0x0) + (hic
!= 0x0));
729 SET_WINE_ALLOW(INTERNET_STATUS_CLOSING_CONNECTION
);
730 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTION_CLOSED
);
731 rc
= InternetCloseHandle(hor
);
732 ok ((rc
!= 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
733 rc
= InternetCloseHandle(hor
);
734 ok ((rc
== 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
737 rc
= InternetCloseHandle(hic
);
738 ok ((rc
!= 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
741 SET_WINE_ALLOW(INTERNET_STATUS_HANDLE_CLOSING
);
742 rc
= InternetCloseHandle(hi
);
743 ok ((rc
!= 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
744 if (flags
& INTERNET_FLAG_ASYNC
)
746 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, (hor
!= 0x0) + (hic
!= 0x0));
748 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CLOSING_CONNECTION
);
749 CHECK_NOT_NOTIFIED(INTERNET_STATUS_CONNECTION_CLOSED
);
750 CloseHandle(hCompleteEvent
);
751 first_connection_to_test_url
= FALSE
;
754 static void InternetOpenUrlA_test(void)
756 HINTERNET myhinternet
, myhttp
;
758 DWORD size
, readbytes
, totalbytes
=0;
761 myhinternet
= InternetOpen("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
762 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
764 ret
= InternetCanonicalizeUrl(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
765 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
768 myhttp
= InternetOpenUrl(myhinternet
, TEST_URL
, 0, 0,
769 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
770 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
771 return; /* WinXP returns this when not connected to the net */
772 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
773 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
774 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
775 totalbytes
+= readbytes
;
776 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
777 totalbytes
+= readbytes
;
778 trace("read 0x%08x bytes\n",totalbytes
);
780 InternetCloseHandle(myhttp
);
781 InternetCloseHandle(myhinternet
);
784 static void InternetTimeFromSystemTimeA_test(void)
787 static const SYSTEMTIME time
= { 2005, 1, 5, 7, 12, 6, 35, 0 };
788 char string
[INTERNET_RFC1123_BUFSIZE
];
789 static const char expect
[] = "Fri, 07 Jan 2005 12:06:35 GMT";
791 ret
= pInternetTimeFromSystemTimeA( &time
, INTERNET_RFC1123_FORMAT
, string
, sizeof(string
) );
792 ok( ret
, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
794 ok( !memcmp( string
, expect
, sizeof(expect
) ),
795 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
798 static void InternetTimeFromSystemTimeW_test(void)
801 static const SYSTEMTIME time
= { 2005, 1, 5, 7, 12, 6, 35, 0 };
802 WCHAR string
[INTERNET_RFC1123_BUFSIZE
+ 1];
803 static const WCHAR expect
[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
804 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
806 ret
= pInternetTimeFromSystemTimeW( &time
, INTERNET_RFC1123_FORMAT
, string
, sizeof(string
) );
807 ok( ret
, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
809 ok( !memcmp( string
, expect
, sizeof(expect
) ),
810 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
813 static void InternetTimeToSystemTimeA_test(void)
817 static const SYSTEMTIME expect
= { 2005, 1, 5, 7, 12, 6, 35, 0 };
818 static const char string
[] = "Fri, 07 Jan 2005 12:06:35 GMT";
819 static const char string2
[] = " fri 7 jan 2005 12 06 35";
821 ret
= pInternetTimeToSystemTimeA( string
, &time
, 0 );
822 ok( ret
, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
823 ok( !memcmp( &time
, &expect
, sizeof(expect
) ),
824 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
826 ret
= pInternetTimeToSystemTimeA( string2
, &time
, 0 );
827 ok( ret
, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
828 ok( !memcmp( &time
, &expect
, sizeof(expect
) ),
829 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
832 static void InternetTimeToSystemTimeW_test(void)
836 static const SYSTEMTIME expect
= { 2005, 1, 5, 7, 12, 6, 35, 0 };
837 static const WCHAR string
[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
838 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
839 static const WCHAR string2
[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
840 '1','2',' ','0','6',' ','3','5',0 };
841 static const WCHAR string3
[] = { 'F','r',0 };
843 ret
= pInternetTimeToSystemTimeW( NULL
, NULL
, 0 );
844 ok( !ret
, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
846 ret
= pInternetTimeToSystemTimeW( NULL
, &time
, 0 );
847 ok( !ret
, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
849 ret
= pInternetTimeToSystemTimeW( string
, NULL
, 0 );
850 ok( !ret
, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
852 ret
= pInternetTimeToSystemTimeW( string
, &time
, 0 );
853 ok( ret
, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
855 ret
= pInternetTimeToSystemTimeW( string
, &time
, 0 );
856 ok( ret
, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
857 ok( !memcmp( &time
, &expect
, sizeof(expect
) ),
858 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
860 ret
= pInternetTimeToSystemTimeW( string2
, &time
, 0 );
861 ok( ret
, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
862 ok( !memcmp( &time
, &expect
, sizeof(expect
) ),
863 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
865 ret
= pInternetTimeToSystemTimeW( string3
, &time
, 0 );
866 ok( ret
, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
869 static void HttpSendRequestEx_test(void)
875 INTERNET_BUFFERS BufferIn
;
876 DWORD dwBytesWritten
;
882 static char szPostData
[] = "mode=Test";
883 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
885 hSession
= InternetOpen("Wine Regression Test",
886 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
887 ok( hSession
!= NULL
,"Unable to open Internet session\n");
888 hConnect
= InternetConnect(hSession
, "crossover.codeweavers.com",
889 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
891 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
892 hRequest
= HttpOpenRequest(hConnect
, "POST", "/posttest.php",
893 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
894 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
896 skip( "Network unreachable, skipping test\n" );
899 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
902 BufferIn
.dwStructSize
= sizeof( INTERNET_BUFFERS
);
903 BufferIn
.Next
= (LPINTERNET_BUFFERS
)0xdeadcab;
904 BufferIn
.lpcszHeader
= szContentType
;
905 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
906 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
907 BufferIn
.lpvBuffer
= szPostData
;
908 BufferIn
.dwBufferLength
= 3;
909 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
910 BufferIn
.dwOffsetLow
= 0;
911 BufferIn
.dwOffsetHigh
= 0;
913 ret
= HttpSendRequestEx(hRequest
, &BufferIn
, NULL
, 0 ,0);
914 ok(ret
, "HttpSendRequestEx Failed with error %u\n", GetLastError());
916 for (i
= 3; szPostData
[i
]; i
++)
917 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
918 "InternetWriteFile failed\n");
920 ok(HttpEndRequest(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
922 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
923 "Unable to read response\n");
924 szBuffer
[dwBytesRead
] = 0;
926 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
927 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0,"Got string %s\n",szBuffer
);
929 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
931 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
932 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
935 static void InternetOpenRequest_test(void)
937 HINTERNET session
, connect
, request
;
938 static const char *types
[] = { "*", "", NULL
};
939 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
940 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
943 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
944 ok(session
!= NULL
,"Unable to open Internet session\n");
946 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
947 INTERNET_SERVICE_HTTP
, 0, 0);
948 ok(connect
== NULL
, "InternetConnectA should have failed\n");
949 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
951 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
952 INTERNET_SERVICE_HTTP
, 0, 0);
953 ok(connect
== NULL
, "InternetConnectA should have failed\n");
954 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
956 connect
= InternetConnectA(session
, "winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
957 INTERNET_SERVICE_HTTP
, 0, 0);
958 ok(connect
!= NULL
, "Unable to connect to http://winehq.org with error %d\n", GetLastError());
960 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
961 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
963 skip( "Network unreachable, skipping test\n" );
966 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
968 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
969 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
970 ok(InternetCloseHandle(request
), "Close request handle failed\n");
972 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
973 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
975 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
976 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
977 ok(InternetCloseHandle(request
), "Close request handle failed\n");
980 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
981 ok(InternetCloseHandle(session
), "Close session handle failed\n");
984 static void test_http_cache(void)
986 HINTERNET session
, connect
, request
;
987 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
988 DWORD size
, file_size
;
993 static const char *types
[] = { "*", "", NULL
};
995 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
996 ok(session
!= NULL
,"Unable to open Internet session\n");
998 connect
= InternetConnectA(session
, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
999 INTERNET_SERVICE_HTTP
, 0, 0);
1000 ok(connect
!= NULL
, "Unable to connect to http://winehq.org with error %d\n", GetLastError());
1002 request
= HttpOpenRequestA(connect
, NULL
, "/site/about", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1003 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1005 skip( "Network unreachable, skipping test\n" );
1007 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1008 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1012 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1015 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1016 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_url) failed: %u\n", GetLastError());
1017 ok(!strcmp(url
, "http://www.winehq.org/site/about"), "Wrong URL %s\n", url
);
1019 size
= sizeof(file_name
);
1020 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1021 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1022 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1023 ok(!size
, "size = %d\n", size
);
1025 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1026 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1028 size
= sizeof(file_name
);
1029 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1030 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1032 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1033 FILE_ATTRIBUTE_NORMAL
, NULL
);
1034 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1035 file_size
= GetFileSize(file
, NULL
);
1036 ok(file_size
== 0, "file size=%d\n", file_size
);
1038 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1039 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1040 ok(size
== sizeof(buf
), "size=%d\n", size
);
1042 file_size
= GetFileSize(file
, NULL
);
1043 ok(file_size
== sizeof(buf
), "file size=%d\n", file_size
);
1046 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1048 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1049 FILE_ATTRIBUTE_NORMAL
, NULL
);
1050 ok(file
== INVALID_HANDLE_VALUE
, "CreateFile succeeded\n");
1051 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError()=%u, expected ERROR_FILE_NOT_FOUND\n", GetLastError());
1053 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1054 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1056 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1057 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1058 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1059 ok(!size
, "size = %d\n", size
);
1061 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1062 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1064 size
= sizeof(file_name
);
1065 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1066 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1067 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1068 ok(!size
, "size = %d\n", size
);
1070 file
= CreateFile(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1071 FILE_ATTRIBUTE_NORMAL
, NULL
);
1072 ok(file
== INVALID_HANDLE_VALUE
, "CreateFile succeeded\n");
1073 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError()=%u, expected ERROR_FILE_NOT_FOUND\n", GetLastError());
1075 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1077 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1078 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1081 static void HttpHeaders_test(void)
1092 hSession
= InternetOpen("Wine Regression Test",
1093 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1094 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1095 hConnect
= InternetConnect(hSession
, "crossover.codeweavers.com",
1096 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1098 ok( hConnect
!= NULL
, "Unable to connect to http://crossover.codeweavers.com\n");
1099 hRequest
= HttpOpenRequest(hConnect
, "POST", "/posttest.php",
1100 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1101 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1103 skip( "Network unreachable, skipping test\n" );
1106 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1109 len
= sizeof(buffer
);
1110 strcpy(buffer
,"Warning");
1111 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1112 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1114 ok(HttpAddRequestHeaders(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1115 "Failed to add new header\n");
1118 len
= sizeof(buffer
);
1119 strcpy(buffer
,"Warning");
1120 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1121 buffer
,&len
,&index
),"Unable to query header\n");
1122 ok(index
== 1, "Index was not incremented\n");
1123 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1124 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1125 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1126 len
= sizeof(buffer
);
1127 strcpy(buffer
,"Warning");
1128 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1129 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1132 len
= 5; /* could store the string but not the NULL terminator */
1133 strcpy(buffer
,"Warning");
1134 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1135 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1136 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1137 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1139 /* a call with NULL will fail but will return the length */
1141 len
= sizeof(buffer
);
1142 SetLastError(0xdeadbeef);
1143 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1144 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1145 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1146 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1147 ok(index
== 0, "Index was incremented\n");
1149 /* even for a len that is too small */
1152 SetLastError(0xdeadbeef);
1153 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1154 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1155 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1156 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1157 ok(index
== 0, "Index was incremented\n");
1161 SetLastError(0xdeadbeef);
1162 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1163 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1164 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1165 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1166 ok(index
== 0, "Index was incremented\n");
1167 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1170 /* a working query */
1172 len
= sizeof(buffer
);
1173 memset(buffer
, 'x', sizeof(buffer
));
1174 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1175 buffer
,&len
,&index
),"Unable to query header\n");
1176 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1177 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1178 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1179 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1180 ok(strncmp(buffer
, "POST /posttest.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1181 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1182 ok(index
== 0, "Index was incremented\n");
1184 /* Like above two tests, but for W version */
1188 SetLastError(0xdeadbeef);
1189 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1190 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1191 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1192 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1193 ok(index
== 0, "Index was incremented\n");
1194 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1196 /* a working query */
1198 len
= sizeof(wbuffer
);
1199 memset(wbuffer
, 'x', sizeof(wbuffer
));
1200 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1201 wbuffer
,&len
,&index
),"Unable to query header\n");
1202 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1203 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1204 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1205 ok(index
== 0, "Index was incremented\n");
1207 /* end of W version tests */
1209 ok(HttpAddRequestHeaders(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1210 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1213 len
= sizeof(buffer
);
1214 strcpy(buffer
,"Warning");
1215 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1216 buffer
,&len
,&index
),"Unable to query header\n");
1217 ok(index
== 1, "Index was not incremented\n");
1218 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1219 len
= sizeof(buffer
);
1220 strcpy(buffer
,"Warning");
1221 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1222 buffer
,&len
,&index
),"Failed to get second header\n");
1223 ok(index
== 2, "Index was not incremented\n");
1224 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1225 len
= sizeof(buffer
);
1226 strcpy(buffer
,"Warning");
1227 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1228 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1230 ok(HttpAddRequestHeaders(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\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
),"Unable to query header\n");
1237 ok(index
== 1, "Index was not incremented\n");
1238 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1239 len
= sizeof(buffer
);
1240 strcpy(buffer
,"Warning");
1241 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1242 buffer
,&len
,&index
),"Failed to get second header\n");
1243 ok(index
== 2, "Index was not incremented\n");
1244 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1245 len
= sizeof(buffer
);
1246 strcpy(buffer
,"Warning");
1247 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1248 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1250 ok(HttpAddRequestHeaders(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1253 len
= sizeof(buffer
);
1254 strcpy(buffer
,"Warning");
1255 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1256 buffer
,&len
,&index
),"Unable to query header\n");
1257 ok(index
== 1, "Index was not incremented\n");
1258 ok(strcmp(buffer
,"test2")==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
,
1262 buffer
,&len
,&index
),"Failed to get second header\n");
1263 ok(index
== 2, "Index was not incremented\n");
1264 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1265 len
= sizeof(buffer
);
1266 strcpy(buffer
,"Warning");
1267 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1268 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1270 ok(HttpAddRequestHeaders(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1273 len
= sizeof(buffer
);
1274 strcpy(buffer
,"Warning");
1275 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1276 buffer
,&len
,&index
),"Unable to query header\n");
1277 ok(index
== 1, "Index was not incremented\n");
1278 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1279 len
= sizeof(buffer
);
1280 strcpy(buffer
,"Warning");
1281 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1282 ok(index
== 2, "Index was not incremented\n");
1283 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1284 len
= sizeof(buffer
);
1285 strcpy(buffer
,"Warning");
1286 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1288 ok(HttpAddRequestHeaders(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1291 len
= sizeof(buffer
);
1292 strcpy(buffer
,"Warning");
1293 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1294 ok(index
== 1, "Index was not incremented\n");
1295 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1296 len
= sizeof(buffer
);
1297 strcpy(buffer
,"Warning");
1298 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1299 ok(index
== 2, "Index was not incremented\n");
1300 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1301 len
= sizeof(buffer
);
1302 strcpy(buffer
,"Warning");
1303 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1305 ok(HttpAddRequestHeaders(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1308 len
= sizeof(buffer
);
1309 strcpy(buffer
,"Warning");
1310 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1311 ok(index
== 1, "Index was not incremented\n");
1312 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1313 len
= sizeof(buffer
);
1314 strcpy(buffer
,"Warning");
1315 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1316 ok(index
== 2, "Index was not incremented\n");
1317 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1318 len
= sizeof(buffer
);
1319 strcpy(buffer
,"Warning");
1320 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1322 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");
1325 len
= sizeof(buffer
);
1326 strcpy(buffer
,"Warning");
1327 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1328 ok(index
== 1, "Index was not incremented\n");
1329 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1330 len
= sizeof(buffer
);
1331 strcpy(buffer
,"Warning");
1332 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1333 ok(index
== 2, "Index was not incremented\n");
1334 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1335 len
= sizeof(buffer
);
1336 strcpy(buffer
,"Warning");
1337 ok(HttpQueryInfo(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1340 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1342 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1343 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1346 static const char contmsg
[] =
1347 "HTTP/1.1 100 Continue\r\n";
1349 static const char okmsg
[] =
1350 "HTTP/1.1 200 OK\r\n"
1351 "Server: winetest\r\n"
1354 static const char notokmsg
[] =
1355 "HTTP/1.1 400 Bad Request\r\n"
1356 "Server: winetest\r\n"
1359 static const char noauthmsg
[] =
1360 "HTTP/1.1 401 Unauthorized\r\n"
1361 "Server: winetest\r\n"
1364 static const char proxymsg
[] =
1365 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1366 "Server: winetest\r\n"
1367 "Proxy-Connection: close\r\n"
1368 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1371 static const char page1
[] =
1373 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
1374 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1377 struct server_info
{
1382 static DWORD CALLBACK
server_thread(LPVOID param
)
1384 struct server_info
*si
= param
;
1387 struct sockaddr_in sa
;
1390 int last_request
= 0;
1391 char host_header
[22];
1392 static int test_b
= 0;
1394 WSAStartup(MAKEWORD(1,1), &wsaData
);
1396 s
= socket(AF_INET
, SOCK_STREAM
, 0);
1397 if (s
== INVALID_SOCKET
)
1401 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
1403 memset(&sa
, 0, sizeof sa
);
1404 sa
.sin_family
= AF_INET
;
1405 sa
.sin_port
= htons(si
->port
);
1406 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
1408 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
1414 SetEvent(si
->hEvent
);
1416 sprintf(host_header
, "Host: localhost:%d", si
->port
);
1420 c
= accept(s
, NULL
, NULL
);
1422 memset(buffer
, 0, sizeof buffer
);
1423 for(i
=0; i
<(sizeof buffer
-1); i
++)
1425 r
= recv(c
, &buffer
[i
], 1, 0);
1429 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
1430 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
1433 if (strstr(buffer
, "GET /test1"))
1435 if (!strstr(buffer
, "Content-Length: 0"))
1437 send(c
, okmsg
, sizeof okmsg
-1, 0);
1438 send(c
, page1
, sizeof page1
-1, 0);
1441 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1443 if (strstr(buffer
, "/test2"))
1445 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
1447 send(c
, okmsg
, sizeof okmsg
-1, 0);
1448 send(c
, page1
, sizeof page1
-1, 0);
1451 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
1453 if (strstr(buffer
, "/test3"))
1455 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
1456 send(c
, okmsg
, sizeof okmsg
-1, 0);
1458 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
1460 if (strstr(buffer
, "/test4"))
1462 if (strstr(buffer
, "Connection: Close"))
1463 send(c
, okmsg
, sizeof okmsg
-1, 0);
1465 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1467 if (strstr(buffer
, "POST /test5"))
1469 if (strstr(buffer
, "Content-Length: 0"))
1471 send(c
, okmsg
, sizeof okmsg
-1, 0);
1472 send(c
, page1
, sizeof page1
-1, 0);
1475 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1477 if (strstr(buffer
, "GET /test6"))
1479 send(c
, contmsg
, sizeof contmsg
-1, 0);
1480 send(c
, contmsg
, sizeof contmsg
-1, 0);
1481 send(c
, okmsg
, sizeof okmsg
-1, 0);
1482 send(c
, page1
, sizeof page1
-1, 0);
1484 if (strstr(buffer
, "POST /test7"))
1486 if (strstr(buffer
, "Content-Length: 100"))
1488 send(c
, okmsg
, sizeof okmsg
-1, 0);
1489 send(c
, page1
, sizeof page1
-1, 0);
1492 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1494 if (strstr(buffer
, "/test8"))
1496 if (!strstr(buffer
, "Connection: Close") &&
1497 strstr(buffer
, "Connection: Keep-Alive") &&
1498 !strstr(buffer
, "Cache-Control: no-cache") &&
1499 !strstr(buffer
, "Pragma: no-cache") &&
1500 strstr(buffer
, host_header
))
1501 send(c
, okmsg
, sizeof okmsg
-1, 0);
1503 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1505 if (strstr(buffer
, "/test9"))
1507 if (!strstr(buffer
, "Connection: Close") &&
1508 !strstr(buffer
, "Connection: Keep-Alive") &&
1509 !strstr(buffer
, "Cache-Control: no-cache") &&
1510 !strstr(buffer
, "Pragma: no-cache") &&
1511 strstr(buffer
, host_header
))
1512 send(c
, okmsg
, sizeof okmsg
-1, 0);
1514 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1516 if (strstr(buffer
, "/testA"))
1518 if (!strstr(buffer
, "Connection: Close") &&
1519 !strstr(buffer
, "Connection: Keep-Alive") &&
1520 (strstr(buffer
, "Cache-Control: no-cache") ||
1521 strstr(buffer
, "Pragma: no-cache")) &&
1522 strstr(buffer
, host_header
))
1523 send(c
, okmsg
, sizeof okmsg
-1, 0);
1525 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1527 if (!test_b
&& strstr(buffer
, "/testB HTTP/1.1"))
1530 send(c
, okmsg
, sizeof okmsg
-1, 0);
1531 recvfrom(c
, buffer
, sizeof buffer
, 0, NULL
, NULL
);
1532 send(c
, okmsg
, sizeof okmsg
-1, 0);
1534 if (strstr(buffer
, "/testC"))
1536 if (strstr(buffer
, "Cookie: cookie=biscuit"))
1537 send(c
, okmsg
, sizeof okmsg
-1, 0);
1539 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
1541 if (strstr(buffer
, "GET /quit"))
1543 send(c
, okmsg
, sizeof okmsg
-1, 0);
1544 send(c
, page1
, sizeof page1
-1, 0);
1550 } while (!last_request
);
1557 static void test_basic_request(int port
, const char *verb
, const char *url
)
1559 HINTERNET hi
, hc
, hr
;
1563 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1564 ok(hi
!= NULL
, "open failed\n");
1566 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1567 ok(hc
!= NULL
, "connect failed\n");
1569 hr
= HttpOpenRequest(hc
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
1570 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1572 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1573 ok(r
, "HttpSendRequest failed\n");
1576 memset(buffer
, 0, sizeof buffer
);
1577 r
= InternetReadFile(hr
, buffer
, sizeof buffer
, &count
);
1578 ok(r
, "InternetReadFile failed\n");
1579 ok(count
== sizeof page1
- 1, "count was wrong\n");
1580 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong\n");
1582 InternetCloseHandle(hr
);
1583 InternetCloseHandle(hc
);
1584 InternetCloseHandle(hi
);
1587 static void test_proxy_indirect(int port
)
1589 HINTERNET hi
, hc
, hr
;
1593 hi
= InternetOpen(NULL
, 0, NULL
, NULL
, 0);
1594 ok(hi
!= NULL
, "open failed\n");
1596 hc
= InternetConnect(hi
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1597 ok(hc
!= NULL
, "connect failed\n");
1599 hr
= HttpOpenRequest(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
1600 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1602 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1603 ok(r
, "HttpSendRequest failed\n");
1606 r
= HttpQueryInfo(hr
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
1607 ok(r
, "HttpQueryInfo failed\n");
1608 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
1611 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1612 ok(r
, "HttpQueryInfo failed\n");
1613 ok(!strcmp(buffer
, "407"), "proxy code wrong\n");
1616 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &val
, &sz
, NULL
);
1617 ok(r
, "HttpQueryInfo failed\n");
1618 ok(val
== 407, "proxy code wrong\n");
1621 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
1622 ok(r
, "HttpQueryInfo failed\n");
1623 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
1626 r
= HttpQueryInfo(hr
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
1627 ok(r
, "HttpQueryInfo failed\n");
1628 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
1631 r
= HttpQueryInfo(hr
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
1632 ok(r
, "HttpQueryInfo failed\n");
1633 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
1636 r
= HttpQueryInfo(hr
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
1637 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
1638 ok(r
== FALSE
, "HttpQueryInfo failed\n");
1640 InternetCloseHandle(hr
);
1641 InternetCloseHandle(hc
);
1642 InternetCloseHandle(hi
);
1645 static void test_proxy_direct(int port
)
1647 HINTERNET hi
, hc
, hr
;
1650 static CHAR username
[] = "mike",
1651 password
[] = "1101";
1653 sprintf(buffer
, "localhost:%d\n", port
);
1654 hi
= InternetOpen(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
1655 ok(hi
!= NULL
, "open failed\n");
1657 /* try connect without authorization */
1658 hc
= InternetConnect(hi
, "www.winehq.org/", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1659 ok(hc
!= NULL
, "connect failed\n");
1661 hr
= HttpOpenRequest(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
1662 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
1664 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1665 ok(r
, "HttpSendRequest failed\n");
1668 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1669 ok(r
, "HttpQueryInfo failed\n");
1670 ok(!strcmp(buffer
, "407"), "proxy code wrong\n");
1673 /* set the user + password then try again */
1675 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
1676 ok(r
, "failed to set user\n");
1678 r
= InternetSetOption(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
1679 ok(r
, "failed to set password\n");
1682 r
= HttpSendRequest(hr
, NULL
, 0, NULL
, 0);
1683 ok(r
, "HttpSendRequest failed\n");
1685 r
= HttpQueryInfo(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
1686 ok(r
, "HttpQueryInfo failed\n");
1688 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
1692 InternetCloseHandle(hr
);
1693 InternetCloseHandle(hc
);
1694 InternetCloseHandle(hi
);
1697 static void test_header_handling_order(int port
)
1699 static char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
1700 static char connection
[] = "Connection: Close";
1702 static const char *types
[2] = { "*", NULL
};
1703 HINTERNET session
, connect
, request
;
1707 session
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1708 ok(session
!= NULL
, "InternetOpen failed\n");
1710 connect
= InternetConnect(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1711 ok(connect
!= NULL
, "InternetConnect failed\n");
1713 request
= HttpOpenRequest(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1714 ok(request
!= NULL
, "HttpOpenRequest failed\n");
1716 ret
= HttpAddRequestHeaders(request
, authorization
, ~0UL, HTTP_ADDREQ_FLAG_ADD
);
1717 ok(ret
, "HttpAddRequestHeaders failed\n");
1719 ret
= HttpSendRequest(request
, NULL
, 0, NULL
, 0);
1720 ok(ret
, "HttpSendRequest failed\n");
1723 size
= sizeof(status
);
1724 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1725 ok(ret
, "HttpQueryInfo failed\n");
1726 ok(status
== 200, "request failed with status %u\n", status
);
1728 InternetCloseHandle(request
);
1730 request
= HttpOpenRequest(connect
, NULL
, "/test4", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1731 ok(request
!= NULL
, "HttpOpenRequest failed\n");
1733 ret
= HttpSendRequest(request
, connection
, ~0UL, NULL
, 0);
1734 ok(ret
, "HttpSendRequest failed\n");
1737 size
= sizeof(status
);
1738 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1739 ok(ret
, "HttpQueryInfo failed\n");
1740 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
1742 InternetCloseHandle(request
);
1744 request
= HttpOpenRequest(connect
, "POST", "/test7", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1745 ok(request
!= NULL
, "HttpOpenRequest failed\n");
1747 ret
= HttpAddRequestHeaders(request
, "Content-Length: 100\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
1748 ok(ret
, "HttpAddRequestHeaders failed\n");
1750 ret
= HttpSendRequest(request
, connection
, ~0UL, NULL
, 0);
1751 ok(ret
, "HttpSendRequest failed\n");
1754 size
= sizeof(status
);
1755 ret
= HttpQueryInfo( request
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1756 ok(ret
, "HttpQueryInfo failed\n");
1757 ok(status
== 200 || status
== 400 /* IE6 */, "got status %u, expected 200 or 400\n", status
);
1759 InternetCloseHandle(request
);
1760 InternetCloseHandle(connect
);
1761 InternetCloseHandle(session
);
1764 static void test_connection_header(int port
)
1766 HINTERNET ses
, con
, req
;
1770 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1771 ok(ses
!= NULL
, "InternetOpen failed\n");
1773 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1774 ok(con
!= NULL
, "InternetConnect failed\n");
1776 req
= HttpOpenRequest(con
, NULL
, "/test8", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 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
);
1790 req
= HttpOpenRequest(con
, NULL
, "/test9", NULL
, NULL
, NULL
, 0, 0);
1791 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1793 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1794 ok(ret
, "HttpSendRequest failed\n");
1797 size
= sizeof(status
);
1798 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1799 ok(ret
, "HttpQueryInfo failed\n");
1800 ok(status
== 200, "request failed with status %u\n", status
);
1802 InternetCloseHandle(req
);
1804 req
= HttpOpenRequest(con
, NULL
, "/test9", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1805 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1807 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1808 ok(ret
, "HttpSendRequest failed\n");
1811 size
= sizeof(status
);
1812 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1813 ok(ret
, "HttpQueryInfo failed\n");
1814 ok(status
== 200, "request failed with status %u\n", status
);
1816 InternetCloseHandle(req
);
1818 req
= HttpOpenRequest(con
, "POST", "/testA", NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1819 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1821 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1822 ok(ret
, "HttpSendRequest failed\n");
1825 size
= sizeof(status
);
1826 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1827 ok(ret
, "HttpQueryInfo failed\n");
1828 ok(status
== 200, "request failed with status %u\n", status
);
1830 InternetCloseHandle(req
);
1831 InternetCloseHandle(con
);
1832 InternetCloseHandle(ses
);
1835 static void test_http1_1(int port
)
1837 HINTERNET ses
, con
, req
;
1840 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1841 ok(ses
!= NULL
, "InternetOpen failed\n");
1843 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1844 ok(con
!= NULL
, "InternetConnect failed\n");
1846 req
= HttpOpenRequest(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1847 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1849 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1852 InternetCloseHandle(req
);
1854 req
= HttpOpenRequest(con
, NULL
, "/testB", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1855 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1857 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1859 ok(ret
, "HttpSendRequest failed\n");
1862 InternetCloseHandle(req
);
1863 InternetCloseHandle(con
);
1864 InternetCloseHandle(ses
);
1867 static void test_cookie_header(int port
)
1869 HINTERNET ses
, con
, req
;
1870 DWORD size
, status
, error
;
1874 ses
= InternetOpen("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1875 ok(ses
!= NULL
, "InternetOpen failed\n");
1877 con
= InternetConnect(ses
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1878 ok(con
!= NULL
, "InternetConnect failed\n");
1880 InternetSetCookie("http://localhost", "cookie", "biscuit");
1882 req
= HttpOpenRequest(con
, NULL
, "/testC", NULL
, NULL
, NULL
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
1883 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1886 size
= sizeof(buffer
);
1887 SetLastError(0xdeadbeef);
1888 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1889 error
= GetLastError();
1890 ok(!ret
, "HttpQueryInfo succeeded\n");
1891 ok(error
== ERROR_HTTP_HEADER_NOT_FOUND
, "got %u expected ERROR_HTTP_HEADER_NOT_FOUND\n", error
);
1893 ret
= HttpSendRequest(req
, NULL
, 0, NULL
, 0);
1894 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1897 size
= sizeof(status
);
1898 ret
= HttpQueryInfo(req
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &status
, &size
, NULL
);
1899 ok(ret
, "HttpQueryInfo failed\n");
1900 ok(status
== 200, "request failed with status %u\n", status
);
1903 size
= sizeof(buffer
);
1904 ret
= HttpQueryInfo(req
, HTTP_QUERY_COOKIE
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1905 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
1906 ok(!strcmp(buffer
, "cookie=biscuit"), "got '%s' expected \'cookie=biscuit\'\n", buffer
);
1908 InternetCloseHandle(req
);
1909 InternetCloseHandle(con
);
1910 InternetCloseHandle(ses
);
1913 static void test_http_connection(void)
1915 struct server_info si
;
1919 si
.hEvent
= CreateEvent(NULL
, 0, 0, NULL
);
1922 hThread
= CreateThread(NULL
, 0, server_thread
, (LPVOID
) &si
, 0, &id
);
1923 ok( hThread
!= NULL
, "create thread failed\n");
1925 r
= WaitForSingleObject(si
.hEvent
, 10000);
1926 ok (r
== WAIT_OBJECT_0
, "failed to start wininet test server\n");
1927 if (r
!= WAIT_OBJECT_0
)
1930 test_basic_request(si
.port
, "GET", "/test1");
1931 test_proxy_indirect(si
.port
);
1932 test_proxy_direct(si
.port
);
1933 test_header_handling_order(si
.port
);
1934 test_basic_request(si
.port
, "POST", "/test5");
1935 test_basic_request(si
.port
, "GET", "/test6");
1936 test_connection_header(si
.port
);
1937 test_http1_1(si
.port
);
1938 test_cookie_header(si
.port
);
1940 /* send the basic request again to shutdown the server thread */
1941 test_basic_request(si
.port
, "GET", "/quit");
1943 r
= WaitForSingleObject(hThread
, 3000);
1944 ok( r
== WAIT_OBJECT_0
, "thread wait failed\n");
1945 CloseHandle(hThread
);
1948 static void test_user_agent_header(void)
1950 HINTERNET ses
, con
, req
;
1955 ses
= InternetOpen("Gizmo5", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
1956 ok(ses
!= NULL
, "InternetOpen failed\n");
1958 con
= InternetConnect(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
1959 ok(con
!= NULL
, "InternetConnect failed\n");
1961 req
= HttpOpenRequest(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
1962 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1964 size
= sizeof(buffer
);
1965 ret
= HttpQueryInfo(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1966 err
= GetLastError();
1967 ok(!ret
, "HttpQueryInfo succeeded\n");
1968 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
1970 ret
= HttpAddRequestHeaders(req
, "User-Agent: Gizmo Project\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
1971 ok(ret
, "HttpAddRequestHeaders succeeded\n");
1973 size
= sizeof(buffer
);
1974 ret
= HttpQueryInfo(req
, HTTP_QUERY_USER_AGENT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1975 err
= GetLastError();
1976 ok(ret
, "HttpQueryInfo failed\n");
1977 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
1979 InternetCloseHandle(req
);
1981 req
= HttpOpenRequest(con
, "GET", "/", "HTTP/1.0", NULL
, NULL
, 0, 0);
1982 ok(req
!= NULL
, "HttpOpenRequest failed\n");
1984 size
= sizeof(buffer
);
1985 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1986 err
= GetLastError();
1987 ok(!ret
, "HttpQueryInfo succeeded\n");
1988 ok(err
== ERROR_HTTP_HEADER_NOT_FOUND
, "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", err
);
1990 ret
= HttpAddRequestHeaders(req
, "Accept: audio/*, image/*, text/*\r\nUser-Agent: Gizmo Project\r\n", ~0UL, HTTP_ADDREQ_FLAG_ADD_IF_NEW
);
1991 ok(ret
, "HttpAddRequestHeaders failed\n");
1994 size
= sizeof(buffer
);
1995 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
1996 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
1997 ok(!strcmp(buffer
, "audio/*, image/*, text/*"), "got '%s' expected 'audio/*, image/*, text/*'\n", buffer
);
1999 InternetCloseHandle(req
);
2000 InternetCloseHandle(con
);
2001 InternetCloseHandle(ses
);
2004 static void test_bogus_accept_types_array(void)
2006 HINTERNET ses
, con
, req
;
2007 static const char *types
[] = { (const char *)6240, "*/*", "%p", "", "*/*", NULL
};
2012 ses
= InternetOpen("MERONG(0.9/;p)", INTERNET_OPEN_TYPE_DIRECT
, "", "", 0);
2013 con
= InternetConnect(ses
, "www.winehq.org", 80, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2014 req
= HttpOpenRequest(con
, "POST", "/post/post_action.php", "HTTP/1.0", "", types
, INTERNET_FLAG_FORMS_SUBMIT
, 0);
2016 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
2019 size
= sizeof(buffer
);
2020 ret
= HttpQueryInfo(req
, HTTP_QUERY_ACCEPT
| HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &size
, NULL
);
2021 ok(ret
, "HttpQueryInfo failed: %u\n", GetLastError());
2022 ok(!strcmp(buffer
, ", */*, %p, , */*") || /* IE6 */
2023 !strcmp(buffer
, "*/*, %p, */*"),
2024 "got '%s' expected '*/*, %%p, */*' or ', */*, %%p, , */*'\n", buffer
);
2026 InternetCloseHandle(req
);
2027 InternetCloseHandle(con
);
2028 InternetCloseHandle(ses
);
2037 static void WINAPI
cb(HINTERNET handle
, DWORD_PTR context
, DWORD status
, LPVOID info
, DWORD size
)
2039 INTERNET_ASYNC_RESULT
*result
= info
;
2040 struct context
*ctx
= (struct context
*)context
;
2042 trace("%p 0x%08lx %u %p 0x%08x\n", handle
, context
, status
, info
, size
);
2044 if (status
== INTERNET_STATUS_REQUEST_COMPLETE
)
2046 trace("request handle: 0x%08lx\n", result
->dwResult
);
2047 ctx
->req
= (HINTERNET
)result
->dwResult
;
2048 SetEvent(ctx
->event
);
2050 if (status
== INTERNET_STATUS_HANDLE_CLOSING
)
2052 DWORD type
= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, size
= sizeof(type
);
2054 if (InternetQueryOption(handle
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
))
2055 ok(type
!= INTERNET_HANDLE_TYPE_CONNECT_HTTP
, "unexpected callback\n");
2056 SetEvent(ctx
->event
);
2060 static void test_open_url_async(void)
2069 ctx
.event
= CreateEvent(NULL
, TRUE
, FALSE
, "Z:_home_hans_jaman-installer.exe_ev1");
2071 ses
= InternetOpen("AdvancedInstaller", 0, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
2072 ok(ses
!= NULL
, "InternetOpen failed\n");
2074 pInternetSetStatusCallbackA(ses
, cb
);
2075 ResetEvent(ctx
.event
);
2077 req
= InternetOpenUrl(ses
, "http://www.winehq.org", NULL
, 0, 0, (DWORD_PTR
)&ctx
);
2078 ok(!req
&& GetLastError() == ERROR_IO_PENDING
, "InternetOpenUrl failed\n");
2080 WaitForSingleObject(ctx
.event
, INFINITE
);
2083 size
= sizeof(type
);
2084 ret
= InternetQueryOption(ctx
.req
, INTERNET_OPTION_HANDLE_TYPE
, &type
, &size
);
2085 ok(ret
, "InternetQueryOption failed: %u\n", GetLastError());
2086 ok(type
== INTERNET_HANDLE_TYPE_HTTP_REQUEST
,
2087 "expected INTERNET_HANDLE_TYPE_HTTP_REQUEST, got %u\n", type
);
2090 ret
= HttpQueryInfo(ctx
.req
, HTTP_QUERY_RAW_HEADERS_CRLF
, NULL
, &size
, NULL
);
2091 ok(!ret
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "HttpQueryInfo failed\n");
2092 ok(size
> 0, "expected size > 0\n");
2094 ResetEvent(ctx
.event
);
2095 InternetCloseHandle(ctx
.req
);
2096 WaitForSingleObject(ctx
.event
, INFINITE
);
2098 InternetCloseHandle(ses
);
2099 CloseHandle(ctx
.event
);
2102 #define STATUS_STRING(status) \
2103 memcpy(status_string[status], #status, sizeof(CHAR) * \
2104 (strlen(#status) < MAX_STATUS_NAME ? \
2106 MAX_STATUS_NAME - 1))
2107 static void init_status_tests(void)
2109 memset(expect
, 0, sizeof(expect
));
2110 memset(optional
, 0, sizeof(optional
));
2111 memset(wine_allow
, 0, sizeof(wine_allow
));
2112 memset(notified
, 0, sizeof(notified
));
2113 memset(status_string
, 0, sizeof(status_string
));
2114 STATUS_STRING(INTERNET_STATUS_RESOLVING_NAME
);
2115 STATUS_STRING(INTERNET_STATUS_NAME_RESOLVED
);
2116 STATUS_STRING(INTERNET_STATUS_CONNECTING_TO_SERVER
);
2117 STATUS_STRING(INTERNET_STATUS_CONNECTED_TO_SERVER
);
2118 STATUS_STRING(INTERNET_STATUS_SENDING_REQUEST
);
2119 STATUS_STRING(INTERNET_STATUS_REQUEST_SENT
);
2120 STATUS_STRING(INTERNET_STATUS_RECEIVING_RESPONSE
);
2121 STATUS_STRING(INTERNET_STATUS_RESPONSE_RECEIVED
);
2122 STATUS_STRING(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
);
2123 STATUS_STRING(INTERNET_STATUS_PREFETCH
);
2124 STATUS_STRING(INTERNET_STATUS_CLOSING_CONNECTION
);
2125 STATUS_STRING(INTERNET_STATUS_CONNECTION_CLOSED
);
2126 STATUS_STRING(INTERNET_STATUS_HANDLE_CREATED
);
2127 STATUS_STRING(INTERNET_STATUS_HANDLE_CLOSING
);
2128 STATUS_STRING(INTERNET_STATUS_DETECTING_PROXY
);
2129 STATUS_STRING(INTERNET_STATUS_REQUEST_COMPLETE
);
2130 STATUS_STRING(INTERNET_STATUS_REDIRECT
);
2131 STATUS_STRING(INTERNET_STATUS_INTERMEDIATE_RESPONSE
);
2132 STATUS_STRING(INTERNET_STATUS_USER_INPUT_REQUIRED
);
2133 STATUS_STRING(INTERNET_STATUS_STATE_CHANGE
);
2134 STATUS_STRING(INTERNET_STATUS_COOKIE_SENT
);
2135 STATUS_STRING(INTERNET_STATUS_COOKIE_RECEIVED
);
2136 STATUS_STRING(INTERNET_STATUS_PRIVACY_IMPACTED
);
2137 STATUS_STRING(INTERNET_STATUS_P3P_HEADER
);
2138 STATUS_STRING(INTERNET_STATUS_P3P_POLICYREF
);
2139 STATUS_STRING(INTERNET_STATUS_COOKIE_HISTORY
);
2141 #undef STATUS_STRING
2146 hdll
= GetModuleHandleA("wininet.dll");
2147 pInternetSetStatusCallbackA
= (void*)GetProcAddress(hdll
, "InternetSetStatusCallbackA");
2148 pInternetTimeFromSystemTimeA
= (void*)GetProcAddress(hdll
, "InternetTimeFromSystemTimeA");
2149 pInternetTimeFromSystemTimeW
= (void*)GetProcAddress(hdll
, "InternetTimeFromSystemTimeW");
2150 pInternetTimeToSystemTimeA
= (void*)GetProcAddress(hdll
, "InternetTimeToSystemTimeA");
2151 pInternetTimeToSystemTimeW
= (void*)GetProcAddress(hdll
, "InternetTimeToSystemTimeW");
2153 if (!pInternetSetStatusCallbackA
)
2154 skip("skipping the InternetReadFile tests\n");
2157 init_status_tests();
2158 InternetReadFile_test(INTERNET_FLAG_ASYNC
);
2159 InternetReadFile_test(0);
2160 InternetReadFileExA_test(INTERNET_FLAG_ASYNC
);
2161 test_open_url_async();
2163 InternetOpenRequest_test();
2165 InternetOpenUrlA_test();
2166 if (!pInternetTimeFromSystemTimeA
)
2167 skip("skipping the InternetTime tests\n");
2170 InternetTimeFromSystemTimeA_test();
2171 InternetTimeFromSystemTimeW_test();
2172 InternetTimeToSystemTimeA_test();
2173 InternetTimeToSystemTimeW_test();
2175 HttpSendRequestEx_test();
2177 test_http_connection();
2178 test_user_agent_header();
2179 test_bogus_accept_types_array();