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 HANDLE hCompleteEvent;
38 static VOID WINAPI callback(
41 DWORD dwInternetStatus,
42 LPVOID lpvStatusInformation,
43 DWORD dwStatusInformationLength
46 switch (dwInternetStatus)
48 case INTERNET_STATUS_RESOLVING_NAME:
49 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
50 GetCurrentThreadId(), hInternet, dwContext,
51 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
53 case INTERNET_STATUS_NAME_RESOLVED:
54 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
55 GetCurrentThreadId(), hInternet, dwContext,
56 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
58 case INTERNET_STATUS_CONNECTING_TO_SERVER:
59 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
60 GetCurrentThreadId(), hInternet, dwContext,
61 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
63 case INTERNET_STATUS_CONNECTED_TO_SERVER:
64 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
65 GetCurrentThreadId(), hInternet, dwContext,
66 (LPCSTR)lpvStatusInformation,dwStatusInformationLength);
68 case INTERNET_STATUS_SENDING_REQUEST:
69 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
70 GetCurrentThreadId(), hInternet, dwContext,
71 lpvStatusInformation,dwStatusInformationLength);
73 case INTERNET_STATUS_REQUEST_SENT:
74 ok(dwStatusInformationLength == sizeof(DWORD),
75 "info length should be sizeof(DWORD) instead of %d\n",
76 dwStatusInformationLength);
77 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
78 GetCurrentThreadId(), hInternet, dwContext,
79 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
81 case INTERNET_STATUS_RECEIVING_RESPONSE:
82 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
83 GetCurrentThreadId(), hInternet, dwContext,
84 lpvStatusInformation,dwStatusInformationLength);
86 case INTERNET_STATUS_RESPONSE_RECEIVED:
87 ok(dwStatusInformationLength == sizeof(DWORD),
88 "info length should be sizeof(DWORD) instead of %d\n",
89 dwStatusInformationLength);
90 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
91 GetCurrentThreadId(), hInternet, dwContext,
92 *(DWORD *)lpvStatusInformation,dwStatusInformationLength);
94 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
95 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
96 GetCurrentThreadId(), hInternet,dwContext,
97 lpvStatusInformation,dwStatusInformationLength);
99 case INTERNET_STATUS_PREFETCH:
100 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
101 GetCurrentThreadId(), hInternet, dwContext,
102 lpvStatusInformation,dwStatusInformationLength);
104 case INTERNET_STATUS_CLOSING_CONNECTION:
105 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
106 GetCurrentThreadId(), hInternet, dwContext,
107 lpvStatusInformation,dwStatusInformationLength);
109 case INTERNET_STATUS_CONNECTION_CLOSED:
110 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
111 GetCurrentThreadId(), hInternet, dwContext,
112 lpvStatusInformation,dwStatusInformationLength);
114 case INTERNET_STATUS_HANDLE_CREATED:
115 ok(dwStatusInformationLength == sizeof(HINTERNET),
116 "info length should be sizeof(HINTERNET) instead of %d\n",
117 dwStatusInformationLength);
118 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
119 GetCurrentThreadId(), hInternet, dwContext,
120 *(HINTERNET *)lpvStatusInformation,dwStatusInformationLength);
122 case INTERNET_STATUS_HANDLE_CLOSING:
123 ok(dwStatusInformationLength == sizeof(HINTERNET),
124 "info length should be sizeof(HINTERNET) instead of %d\n",
125 dwStatusInformationLength);
126 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
127 GetCurrentThreadId(), hInternet, dwContext,
128 *(HINTERNET *)lpvStatusInformation, dwStatusInformationLength);
130 case INTERNET_STATUS_REQUEST_COMPLETE:
132 INTERNET_ASYNC_RESULT *iar = (INTERNET_ASYNC_RESULT *)lpvStatusInformation;
133 ok(dwStatusInformationLength == sizeof(INTERNET_ASYNC_RESULT),
134 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
135 dwStatusInformationLength);
136 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%d,%d} %d\n",
137 GetCurrentThreadId(), hInternet, dwContext,
138 iar->dwResult,iar->dwError,dwStatusInformationLength);
139 SetEvent(hCompleteEvent);
142 case INTERNET_STATUS_REDIRECT:
143 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
144 GetCurrentThreadId(), hInternet, dwContext,
145 (LPCSTR)lpvStatusInformation, dwStatusInformationLength);
147 case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
148 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
149 GetCurrentThreadId(), hInternet, dwContext,
150 lpvStatusInformation, dwStatusInformationLength);
153 trace("%04x:Callback %p 0x%lx %d %p %d\n",
154 GetCurrentThreadId(), hInternet, dwContext, dwInternetStatus,
155 lpvStatusInformation, dwStatusInformationLength);
159 static void InternetReadFile_test(int flags)
165 const char *types[2] = { "*", NULL };
166 HINTERNET hi, hic = 0, hor = 0;
168 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
170 trace("Starting InternetReadFile test with flags 0x%x\n",flags);
172 trace("InternetOpenA <--\n");
173 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
174 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
175 trace("InternetOpenA -->\n");
177 if (hi == 0x0) goto abort;
179 InternetSetStatusCallback(hi,&callback);
181 trace("InternetConnectA <--\n");
182 hic=InternetConnectA(hi, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER,
183 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
184 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
185 trace("InternetConnectA -->\n");
187 if (hic == 0x0) goto abort;
189 trace("HttpOpenRequestA <--\n");
190 hor = HttpOpenRequestA(hic, "GET", "/about/", NULL, NULL, types,
191 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE,
193 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
195 * If the internet name can't be resolved we are probably behind
196 * a firewall or in some other way not directly connected to the
197 * Internet. Not enough reason to fail the test. Just ignore and
201 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
203 trace("HttpOpenRequestA -->\n");
205 if (hor == 0x0) goto abort;
207 trace("HttpSendRequestA -->\n");
208 SetLastError(0xdeadbeef);
209 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
210 if (flags & INTERNET_FLAG_ASYNC)
211 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
212 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
214 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
215 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
216 trace("HttpSendRequestA <--\n");
218 if (flags & INTERNET_FLAG_ASYNC)
219 WaitForSingleObject(hCompleteEvent, INFINITE);
222 rc = InternetQueryOptionA(hor,INTERNET_OPTION_REQUEST_FLAGS,&out,&length);
223 trace("Option 0x17 -> %i %i\n",rc,out);
226 rc = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
227 trace("Option 0x22 -> %i %s\n",rc,buffer);
230 rc = HttpQueryInfoA(hor,HTTP_QUERY_RAW_HEADERS,buffer,&length,0x0);
232 trace("Option 0x16 -> %i %s\n",rc,buffer);
235 rc = InternetQueryOptionA(hor,INTERNET_OPTION_URL,buffer,&length);
237 trace("Option 0x22 -> %i %s\n",rc,buffer);
240 rc = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_LENGTH,&buffer,&length,0x0);
241 trace("Option 0x5 -> %i %s (%u)\n",rc,buffer,GetLastError());
244 rc = HttpQueryInfoA(hor,HTTP_QUERY_CONTENT_TYPE,buffer,&length,0x0);
246 trace("Option 0x1 -> %i %s\n",rc,buffer);
248 SetLastError(0xdeadbeef);
249 rc = InternetReadFile(NULL, buffer, 100, &length);
250 ok(!rc, "InternetReadFile should have failed\n");
251 ok(GetLastError() == ERROR_INVALID_HANDLE,
252 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
256 trace("Entering Query loop\n");
260 rc = InternetQueryDataAvailable(hor,&length,0x0,0x0);
261 ok(!(rc == 0 && length != 0),"InternetQueryDataAvailable failed\n");
266 buffer = HeapAlloc(GetProcessHeap(),0,length+1);
268 rc = InternetReadFile(hor,buffer,length,&length);
272 trace("ReadFile -> %i %i\n",rc,length);
274 HeapFree(GetProcessHeap(),0,buffer);
279 SetLastError(0xdeadbeef);
280 rc = InternetCloseHandle(hor);
281 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
282 SetLastError(0xdeadbeef);
283 rc = InternetCloseHandle(hor);
284 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
285 ok (GetLastError() == ERROR_INVALID_HANDLE,
286 "Double close of handle should have set ERROR_INVALID_HANDLE instead of %u\n",
290 rc = InternetCloseHandle(hic);
291 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
294 rc = InternetCloseHandle(hi);
295 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
296 if (flags & INTERNET_FLAG_ASYNC)
299 CloseHandle(hCompleteEvent);
302 static void InternetReadFileExA_test(int flags)
306 const char *types[2] = { "*", NULL };
307 HINTERNET hi, hic = 0, hor = 0;
308 INTERNET_BUFFERS inetbuffers;
310 hCompleteEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
312 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags);
314 trace("InternetOpenA <--\n");
315 hi = InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, flags);
316 ok((hi != 0x0),"InternetOpen failed with error %u\n", GetLastError());
317 trace("InternetOpenA -->\n");
319 if (hi == 0x0) goto abort;
321 InternetSetStatusCallback(hi,&callback);
323 trace("InternetConnectA <--\n");
324 hic=InternetConnectA(hi, "www.winehq.org", INTERNET_INVALID_PORT_NUMBER,
325 NULL, NULL, INTERNET_SERVICE_HTTP, 0x0, 0xdeadbeef);
326 ok((hic != 0x0),"InternetConnect failed with error %u\n", GetLastError());
327 trace("InternetConnectA -->\n");
329 if (hic == 0x0) goto abort;
331 trace("HttpOpenRequestA <--\n");
332 hor = HttpOpenRequestA(hic, "GET", "/about/", NULL, NULL, types,
333 INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_RESYNCHRONIZE,
335 if (hor == 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED) {
337 * If the internet name can't be resolved we are probably behind
338 * a firewall or in some other way not directly connected to the
339 * Internet. Not enough reason to fail the test. Just ignore and
343 ok((hor != 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
345 trace("HttpOpenRequestA -->\n");
347 if (hor == 0x0) goto abort;
349 trace("HttpSendRequestA -->\n");
350 SetLastError(0xdeadbeef);
351 rc = HttpSendRequestA(hor, "", -1, NULL, 0);
352 if (flags & INTERNET_FLAG_ASYNC)
353 ok(((rc == 0)&&(GetLastError() == ERROR_IO_PENDING)),
354 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
356 ok((rc != 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED,
357 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
358 trace("HttpSendRequestA <--\n");
360 if (!rc && (GetLastError() == ERROR_IO_PENDING))
361 WaitForSingleObject(hCompleteEvent, INFINITE);
363 /* tests invalid dwStructSize */
364 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS)+1;
365 inetbuffers.lpcszHeader = NULL;
366 inetbuffers.dwHeadersLength = 0;
367 inetbuffers.dwBufferLength = 10;
368 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, 10);
369 inetbuffers.dwOffsetHigh = 1234;
370 inetbuffers.dwOffsetLow = 5678;
371 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
372 ok(!rc && (GetLastError() == ERROR_INVALID_PARAMETER),
373 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
374 rc ? "TRUE" : "FALSE", GetLastError());
375 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
377 /* tests to see whether lpcszHeader is used - it isn't */
378 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
379 inetbuffers.lpcszHeader = (LPCTSTR)0xdeadbeef;
380 inetbuffers.dwHeadersLength = 255;
381 inetbuffers.dwBufferLength = 0;
382 inetbuffers.lpvBuffer = NULL;
383 inetbuffers.dwOffsetHigh = 1234;
384 inetbuffers.dwOffsetLow = 5678;
385 rc = InternetReadFileEx(hor, &inetbuffers, 0, 0xdeadcafe);
386 ok(rc, "InternetReadFileEx failed with error %u\n", GetLastError());
388 rc = InternetReadFileEx(NULL, &inetbuffers, 0, 0xdeadcafe);
389 ok(!rc && (GetLastError() == ERROR_INVALID_HANDLE),
390 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
391 rc ? "TRUE" : "FALSE", GetLastError());
394 trace("Entering Query loop\n");
398 inetbuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
399 inetbuffers.dwBufferLength = 1024;
400 inetbuffers.lpvBuffer = HeapAlloc(GetProcessHeap(), 0, inetbuffers.dwBufferLength+1);
401 inetbuffers.dwOffsetHigh = 1234;
402 inetbuffers.dwOffsetLow = 5678;
404 rc = InternetReadFileExA(hor, &inetbuffers, IRF_ASYNC | IRF_USE_CONTEXT, 0xcafebabe);
407 if (GetLastError() == ERROR_IO_PENDING)
409 trace("InternetReadFileEx -> PENDING\n");
410 WaitForSingleObject(hCompleteEvent, INFINITE);
414 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
419 trace("InternetReadFileEx -> SUCCEEDED\n");
421 trace("read %i bytes\n", inetbuffers.dwBufferLength);
422 ((char *)inetbuffers.lpvBuffer)[inetbuffers.dwBufferLength] = '\0';
424 ok(inetbuffers.dwOffsetHigh == 1234 && inetbuffers.dwOffsetLow == 5678,
425 "InternetReadFileEx sets offsets to 0x%x%08x\n",
426 inetbuffers.dwOffsetHigh, inetbuffers.dwOffsetLow);
428 HeapFree(GetProcessHeap(), 0, inetbuffers.lpvBuffer);
430 if (!inetbuffers.dwBufferLength)
433 length += inetbuffers.dwBufferLength;
435 trace("Finished. Read %d bytes\n", length);
439 rc = InternetCloseHandle(hor);
440 ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
441 rc = InternetCloseHandle(hor);
442 ok ((rc == 0), "Double close of handle opened by HttpOpenRequestA succeeded\n");
445 rc = InternetCloseHandle(hic);
446 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed\n");
449 rc = InternetCloseHandle(hi);
450 ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed\n");
451 if (flags & INTERNET_FLAG_ASYNC)
454 CloseHandle(hCompleteEvent);
457 static void InternetOpenUrlA_test(void)
459 HINTERNET myhinternet, myhttp;
461 DWORD size, readbytes, totalbytes=0;
464 myhinternet = InternetOpen("Winetest",0,NULL,NULL,INTERNET_FLAG_NO_CACHE_WRITE);
465 ok((myhinternet != 0), "InternetOpen failed, error %u\n",GetLastError());
467 ret = InternetCanonicalizeUrl(TEST_URL, buffer, &size,ICU_BROWSER_MODE);
468 ok( ret, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
471 myhttp = InternetOpenUrl(myhinternet, TEST_URL, 0, 0,
472 INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_TRANSFER_BINARY,0);
473 if (GetLastError() == 12007)
474 return; /* WinXP returns this when not connected to the net */
475 ok((myhttp != 0),"InternetOpenUrl failed, error %u\n",GetLastError());
476 ret = InternetReadFile(myhttp, buffer,0x400,&readbytes);
477 ok( ret, "InternetReadFile failed, error %u\n",GetLastError());
478 totalbytes += readbytes;
479 while (readbytes && InternetReadFile(myhttp, buffer,0x400,&readbytes))
480 totalbytes += readbytes;
481 trace("read 0x%08x bytes\n",totalbytes);
484 static void InternetTimeFromSystemTimeA_test(void)
487 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
488 char string[INTERNET_RFC1123_BUFSIZE];
489 static const char expect[] = "Fri, 07 Jan 2005 12:06:35 GMT";
491 ret = InternetTimeFromSystemTimeA( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
492 ok( ret, "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
494 ok( !memcmp( string, expect, sizeof(expect) ),
495 "InternetTimeFromSystemTimeA failed (%u)\n", GetLastError() );
498 static void InternetTimeFromSystemTimeW_test(void)
501 static const SYSTEMTIME time = { 2005, 1, 5, 7, 12, 6, 35, 0 };
502 WCHAR string[INTERNET_RFC1123_BUFSIZE + 1];
503 static const WCHAR expect[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
504 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
506 ret = InternetTimeFromSystemTimeW( &time, INTERNET_RFC1123_FORMAT, string, sizeof(string) );
507 ok( ret, "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
509 ok( !memcmp( string, expect, sizeof(expect) ),
510 "InternetTimeFromSystemTimeW failed (%u)\n", GetLastError() );
513 static void InternetTimeToSystemTimeA_test(void)
517 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
518 static const char string[] = "Fri, 07 Jan 2005 12:06:35 GMT";
519 static const char string2[] = " fri 7 jan 2005 12 06 35";
521 ret = InternetTimeToSystemTimeA( string, &time, 0 );
522 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
523 ok( !memcmp( &time, &expect, sizeof(expect) ),
524 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
526 ret = InternetTimeToSystemTimeA( string2, &time, 0 );
527 ok( ret, "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
528 ok( !memcmp( &time, &expect, sizeof(expect) ),
529 "InternetTimeToSystemTimeA failed (%u)\n", GetLastError() );
532 static void InternetTimeToSystemTimeW_test(void)
536 static const SYSTEMTIME expect = { 2005, 1, 5, 7, 12, 6, 35, 0 };
537 static const WCHAR string[] = { 'F','r','i',',',' ','0','7',' ','J','a','n',' ','2','0','0','5',' ',
538 '1','2',':','0','6',':','3','5',' ','G','M','T',0 };
539 static const WCHAR string2[] = { ' ','f','r','i',' ','7',' ','j','a','n',' ','2','0','0','5',' ',
540 '1','2',' ','0','6',' ','3','5',0 };
541 static const WCHAR string3[] = { 'F','r',0 };
543 ret = InternetTimeToSystemTimeW( NULL, NULL, 0 );
544 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
546 ret = InternetTimeToSystemTimeW( NULL, &time, 0 );
547 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
549 ret = InternetTimeToSystemTimeW( string, NULL, 0 );
550 ok( !ret, "InternetTimeToSystemTimeW succeeded (%u)\n", GetLastError() );
552 ret = InternetTimeToSystemTimeW( string, &time, 0 );
553 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
555 ret = InternetTimeToSystemTimeW( string, &time, 0 );
556 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
557 ok( !memcmp( &time, &expect, sizeof(expect) ),
558 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
560 ret = InternetTimeToSystemTimeW( string2, &time, 0 );
561 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
562 ok( !memcmp( &time, &expect, sizeof(expect) ),
563 "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
565 ret = InternetTimeToSystemTimeW( string3, &time, 0 );
566 ok( ret, "InternetTimeToSystemTimeW failed (%u)\n", GetLastError() );
569 static void HttpSendRequestEx_test(void)
575 INTERNET_BUFFERS BufferIn;
576 DWORD dwBytesWritten;
582 static char szPostData[] = "mode=Test";
583 static const char szContentType[] = "Content-Type: application/x-www-form-urlencoded";
585 hSession = InternetOpen("Wine Regression Test",
586 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
587 ok( hSession != NULL ,"Unable to open Internet session\n");
588 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
589 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
591 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
592 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
593 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
594 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
596 trace( "Network unreachable, skipping test\n" );
599 ok( hRequest != NULL, "Failed to open request handle err %u\n", GetLastError());
602 BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS);
603 BufferIn.Next = (LPINTERNET_BUFFERS)0xdeadcab;
604 BufferIn.lpcszHeader = szContentType;
605 BufferIn.dwHeadersLength = sizeof(szContentType);
606 BufferIn.dwHeadersTotal = sizeof(szContentType);
607 BufferIn.lpvBuffer = szPostData;
608 BufferIn.dwBufferLength = 3;
609 BufferIn.dwBufferTotal = sizeof(szPostData)-1;
610 BufferIn.dwOffsetLow = 0;
611 BufferIn.dwOffsetHigh = 0;
613 ret = HttpSendRequestEx(hRequest, &BufferIn, NULL, 0 ,0);
614 ok(ret, "HttpSendRequestEx Failed with error %u\n", GetLastError());
616 for (i = 3; szPostData[i]; i++)
617 ok(InternetWriteFile(hRequest, &szPostData[i], 1, &dwBytesWritten),
618 "InternetWriteFile failed\n");
620 ok(HttpEndRequest(hRequest, NULL, 0, 0), "HttpEndRequest Failed\n");
622 ok(InternetReadFile(hRequest, szBuffer, 255, &dwBytesRead),
623 "Unable to read response\n");
624 szBuffer[dwBytesRead] = 0;
626 ok(dwBytesRead == 13,"Read %u bytes instead of 13\n",dwBytesRead);
627 ok(strncmp(szBuffer,"mode => Test\n",dwBytesRead)==0,"Got string %s\n",szBuffer);
629 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
631 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
632 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
635 static void InternetOpenRequest_test(void)
637 HINTERNET session, connect, request;
638 static const char *types[] = { "*", "", NULL };
639 static const WCHAR slash[] = {'/', 0}, any[] = {'*', 0}, empty[] = {0};
640 static const WCHAR *typesW[] = { any, empty, NULL };
643 session = InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
644 ok(session != NULL ,"Unable to open Internet session\n");
646 connect = InternetConnectA(session, "winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL,
647 INTERNET_SERVICE_HTTP, 0, 0);
648 ok(connect != NULL, "Unable to connect to http://winehq.org\n");
650 request = HttpOpenRequestA(connect, NULL, "/", NULL, NULL, types, INTERNET_FLAG_NO_CACHE_WRITE, 0);
651 if (!request && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
653 trace( "Network unreachable, skipping test\n" );
656 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
658 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
659 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
660 ok(InternetCloseHandle(request), "Close request handle failed\n");
662 request = HttpOpenRequestW(connect, NULL, slash, NULL, NULL, typesW, INTERNET_FLAG_NO_CACHE_WRITE, 0);
663 ok(request != NULL, "Failed to open request handle err %u\n", GetLastError());
665 ret = HttpSendRequest(request, NULL, 0, NULL, 0);
666 ok(ret, "HttpSendRequest failed: %u\n", GetLastError());
667 ok(InternetCloseHandle(request), "Close request handle failed\n");
670 ok(InternetCloseHandle(connect), "Close connect handle failed\n");
671 ok(InternetCloseHandle(session), "Close session handle failed\n");
674 static void HttpHeaders_test(void)
683 hSession = InternetOpen("Wine Regression Test",
684 INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,0);
685 ok( hSession != NULL ,"Unable to open Internet session\n");
686 hConnect = InternetConnect(hSession, "crossover.codeweavers.com",
687 INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0,
689 ok( hConnect != NULL, "Unable to connect to http://crossover.codeweavers.com\n");
690 hRequest = HttpOpenRequest(hConnect, "POST", "/posttest.php",
691 NULL, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0);
692 if (!hRequest && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED)
694 trace( "Network unreachable, skipping test\n" );
697 ok( hRequest != NULL, "Failed to open request handle\n");
700 len = sizeof(buffer);
701 strcpy(buffer,"Warning");
702 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
703 buffer,&len,&index)==0,"Warning hearder reported as Existing\n");
705 ok(HttpAddRequestHeaders(hRequest,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD),
706 "Failed to add new header\n");
709 len = sizeof(buffer);
710 strcpy(buffer,"Warning");
711 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
712 buffer,&len,&index),"Unable to query header\n");
713 ok(index == 1, "Index was not incremented\n");
714 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
715 len = sizeof(buffer);
716 strcpy(buffer,"Warning");
717 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
718 buffer,&len,&index)==0,"Second Index Should Not Exist\n");
720 ok(HttpAddRequestHeaders(hRequest,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD),
721 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
724 len = sizeof(buffer);
725 strcpy(buffer,"Warning");
726 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
727 buffer,&len,&index),"Unable to query header\n");
728 ok(index == 1, "Index was not incremented\n");
729 ok(strcmp(buffer,"test1")==0, "incorrect string was returned(%s)\n",buffer);
730 len = sizeof(buffer);
731 strcpy(buffer,"Warning");
732 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
733 buffer,&len,&index),"Failed to get second header\n");
734 ok(index == 2, "Index was not incremented\n");
735 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
736 len = sizeof(buffer);
737 strcpy(buffer,"Warning");
738 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
739 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
741 ok(HttpAddRequestHeaders(hRequest,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
744 len = sizeof(buffer);
745 strcpy(buffer,"Warning");
746 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
747 buffer,&len,&index),"Unable to query header\n");
748 ok(index == 1, "Index was not incremented\n");
749 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
750 len = sizeof(buffer);
751 strcpy(buffer,"Warning");
752 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
753 buffer,&len,&index),"Failed to get second header\n");
754 ok(index == 2, "Index was not incremented\n");
755 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
756 len = sizeof(buffer);
757 strcpy(buffer,"Warning");
758 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
759 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
761 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
764 len = sizeof(buffer);
765 strcpy(buffer,"Warning");
766 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
767 buffer,&len,&index),"Unable to query header\n");
768 ok(index == 1, "Index was not incremented\n");
769 ok(strcmp(buffer,"test2")==0, "incorrect string was returned(%s)\n",buffer);
770 len = sizeof(buffer);
771 strcpy(buffer,"Warning");
772 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
773 buffer,&len,&index),"Failed to get second header\n");
774 ok(index == 2, "Index was not incremented\n");
775 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
776 len = sizeof(buffer);
777 strcpy(buffer,"Warning");
778 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
779 buffer,&len,&index)==0,"Third Header Should Not Exist\n");
781 ok(HttpAddRequestHeaders(hRequest,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
784 len = sizeof(buffer);
785 strcpy(buffer,"Warning");
786 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS,
787 buffer,&len,&index),"Unable to query header\n");
788 ok(index == 1, "Index was not incremented\n");
789 ok(strcmp(buffer,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer);
790 len = sizeof(buffer);
791 strcpy(buffer,"Warning");
792 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
793 ok(index == 2, "Index was not incremented\n");
794 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
795 len = sizeof(buffer);
796 strcpy(buffer,"Warning");
797 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
799 ok(HttpAddRequestHeaders(hRequest,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
802 len = sizeof(buffer);
803 strcpy(buffer,"Warning");
804 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
805 ok(index == 1, "Index was not incremented\n");
806 ok(strcmp(buffer,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer);
807 len = sizeof(buffer);
808 strcpy(buffer,"Warning");
809 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
810 ok(index == 2, "Index was not incremented\n");
811 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
812 len = sizeof(buffer);
813 strcpy(buffer,"Warning");
814 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
816 ok(HttpAddRequestHeaders(hRequest,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
819 len = sizeof(buffer);
820 strcpy(buffer,"Warning");
821 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
822 ok(index == 1, "Index was not incremented\n");
823 ok(strcmp(buffer,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer);
824 len = sizeof(buffer);
825 strcpy(buffer,"Warning");
826 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
827 ok(index == 2, "Index was not incremented\n");
828 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
829 len = sizeof(buffer);
830 strcpy(buffer,"Warning");
831 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
833 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");
836 len = sizeof(buffer);
837 strcpy(buffer,"Warning");
838 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Unable to query header\n");
839 ok(index == 1, "Index was not incremented\n");
840 ok(strcmp(buffer,"test3")==0, "incorrect string was returned(%s)\n",buffer);
841 len = sizeof(buffer);
842 strcpy(buffer,"Warning");
843 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index),"Failed to get second header\n");
844 ok(index == 2, "Index was not incremented\n");
845 ok(strcmp(buffer,"test7")==0, "incorrect string was returned(%s)\n",buffer);
846 len = sizeof(buffer);
847 strcpy(buffer,"Warning");
848 ok(HttpQueryInfo(hRequest,HTTP_QUERY_CUSTOM|HTTP_QUERY_FLAG_REQUEST_HEADERS, buffer,&len,&index)==0,"Third Header Should Not Exist\n");
851 ok(InternetCloseHandle(hRequest), "Close request handle failed\n");
853 ok(InternetCloseHandle(hConnect), "Close connect handle failed\n");
854 ok(InternetCloseHandle(hSession), "Close session handle failed\n");
857 static const char okmsg[] =
858 "HTTP/1.0 200 OK\r\n"
859 "Server: winetest\r\n"
862 static const char proxymsg[] =
863 "HTTP/1.1 407 Proxy Authentication Required\r\n"
864 "Server: winetest\r\n"
865 "Proxy-Connection: close\r\n"
866 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
869 static const char page1[] =
871 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
872 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
880 static DWORD CALLBACK server_thread(LPVOID param)
882 struct server_info *si = param;
884 struct sockaddr_in sa;
887 int last_request = 0;
889 WSAStartup(MAKEWORD(1,1), &wsaData);
891 s = socket(AF_INET, SOCK_STREAM, 0);
896 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof on);
898 memset(&sa, 0, sizeof sa);
899 sa.sin_family = AF_INET;
900 sa.sin_port = htons(si->port);
901 sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
903 r = bind(s, (struct sockaddr*) &sa, sizeof sa);
909 SetEvent(si->hEvent);
913 c = accept(s, NULL, NULL);
915 memset(buffer, 0, sizeof buffer);
916 for(i=0; i<(sizeof buffer-1); i++)
918 r = recv(c, &buffer[i], 1, 0);
922 if (buffer[i-2] == '\n' && buffer[i] == '\n' &&
923 buffer[i-3] == '\r' && buffer[i-1] == '\r')
927 if (strstr(buffer, "GET /test1"))
929 send(c, okmsg, sizeof okmsg-1, 0);
930 send(c, page1, sizeof page1-1, 0);
933 if (strstr(buffer, "/test2"))
935 if (strstr(buffer, "Proxy-Authorization: Basic bWlrZToxMTAx"))
937 send(c, okmsg, sizeof okmsg-1, 0);
938 send(c, page1, sizeof page1-1, 0);
941 send(c, proxymsg, sizeof proxymsg-1, 0);
944 if (strstr(buffer, "/quit"))
946 send(c, okmsg, sizeof okmsg-1, 0);
947 send(c, page1, sizeof page1-1, 0);
953 } while (!last_request);
960 static void test_basic_request(int port, const char *url)
962 HINTERNET hi, hc, hr;
966 hi = InternetOpen(NULL, 0, NULL, NULL, 0);
967 ok(hi != NULL, "open failed\n");
969 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
970 ok(hc != NULL, "connect failed\n");
972 hr = HttpOpenRequest(hc, NULL, url, NULL, NULL, NULL, 0, 0);
973 ok(hr != NULL, "HttpOpenRequest failed\n");
975 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
976 ok(r, "HttpSendRequest failed\n");
979 memset(buffer, 0, sizeof buffer);
980 r = InternetReadFile(hr, buffer, sizeof buffer, &count);
981 ok(r, "InternetReadFile failed\n");
982 ok(count == sizeof page1 - 1, "count was wrong\n");
983 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
985 InternetCloseHandle(hr);
986 InternetCloseHandle(hc);
987 InternetCloseHandle(hi);
990 static void test_proxy_indirect(int port)
992 HINTERNET hi, hc, hr;
996 hi = InternetOpen(NULL, 0, NULL, NULL, 0);
997 ok(hi != NULL, "open failed\n");
999 hc = InternetConnect(hi, "localhost", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1000 ok(hc != NULL, "connect failed\n");
1002 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
1003 ok(hr != NULL, "HttpOpenRequest failed\n");
1005 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1006 ok(r, "HttpSendRequest failed\n");
1009 r = HttpQueryInfo(hr, HTTP_QUERY_PROXY_AUTHENTICATE, buffer, &sz, NULL);
1010 ok(r, "HttpQueryInfo failed\n");
1011 ok(!strcmp(buffer, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
1014 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1015 ok(r, "HttpQueryInfo failed\n");
1016 ok(!strcmp(buffer, "407"), "proxy code wrong\n");
1019 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE|HTTP_QUERY_FLAG_NUMBER, &val, &sz, NULL);
1020 ok(r, "HttpQueryInfo failed\n");
1021 ok(val == 407, "proxy code wrong\n");
1024 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_TEXT, buffer, &sz, NULL);
1025 ok(r, "HttpQueryInfo failed\n");
1026 ok(!strcmp(buffer, "Proxy Authentication Required"), "proxy text wrong\n");
1029 r = HttpQueryInfo(hr, HTTP_QUERY_VERSION, buffer, &sz, NULL);
1030 ok(r, "HttpQueryInfo failed\n");
1031 ok(!strcmp(buffer, "HTTP/1.1"), "http version wrong\n");
1034 r = HttpQueryInfo(hr, HTTP_QUERY_SERVER, buffer, &sz, NULL);
1035 ok(r, "HttpQueryInfo failed\n");
1036 ok(!strcmp(buffer, "winetest"), "http server wrong\n");
1039 r = HttpQueryInfo(hr, HTTP_QUERY_CONTENT_ENCODING, buffer, &sz, NULL);
1040 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND, "HttpQueryInfo should fail\n");
1041 ok(r == FALSE, "HttpQueryInfo failed\n");
1043 InternetCloseHandle(hr);
1044 InternetCloseHandle(hc);
1045 InternetCloseHandle(hi);
1048 static void test_proxy_direct(int port)
1050 HINTERNET hi, hc, hr;
1053 static CHAR username[] = "mike",
1054 password[] = "1101";
1056 sprintf(buffer, "localhost:%d\n", port);
1057 hi = InternetOpen(NULL, INTERNET_OPEN_TYPE_PROXY, buffer, NULL, 0);
1058 ok(hi != NULL, "open failed\n");
1060 /* try connect without authorization */
1061 hc = InternetConnect(hi, "www.winehq.org/", port, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
1062 ok(hc != NULL, "connect failed\n");
1064 hr = HttpOpenRequest(hc, NULL, "/test2", NULL, NULL, NULL, 0, 0);
1065 ok(hr != NULL, "HttpOpenRequest failed\n");
1067 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1068 ok(r, "HttpSendRequest failed\n");
1071 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1072 ok(r, "HttpQueryInfo failed\n");
1073 ok(!strcmp(buffer, "407"), "proxy code wrong\n");
1076 /* set the user + password then try again */
1078 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_USERNAME, username, 4);
1079 ok(r, "failed to set user\n");
1081 r = InternetSetOption(hr, INTERNET_OPTION_PROXY_PASSWORD, password, 4);
1082 ok(r, "failed to set password\n");
1085 r = HttpSendRequest(hr, NULL, 0, NULL, 0);
1086 ok(r, "HttpSendRequest failed\n");
1088 r = HttpQueryInfo(hr, HTTP_QUERY_STATUS_CODE, buffer, &sz, NULL);
1089 ok(r, "HttpQueryInfo failed\n");
1091 ok(!strcmp(buffer, "200"), "proxy code wrong\n");
1095 InternetCloseHandle(hr);
1096 InternetCloseHandle(hc);
1097 InternetCloseHandle(hi);
1100 static void test_http_connection(void)
1102 struct server_info si;
1106 si.hEvent = CreateEvent(NULL, 0, 0, NULL);
1109 hThread = CreateThread(NULL, 0, server_thread, (LPVOID) &si, 0, &id);
1110 ok( hThread != NULL, "create thread failed\n");
1112 r = WaitForSingleObject(si.hEvent, 10000);
1113 ok (r == WAIT_OBJECT_0, "failed to start wininet test server\n");
1114 if (r != WAIT_OBJECT_0)
1117 test_basic_request(si.port, "/test1");
1118 test_proxy_indirect(si.port);
1119 test_proxy_direct(si.port);
1121 /* send the basic request again to shutdown the server thread */
1122 test_basic_request(si.port, "/quit");
1124 r = WaitForSingleObject(hThread, 3000);
1125 ok( r == WAIT_OBJECT_0, "thread wait failed\n");
1126 CloseHandle(hThread);
1131 InternetReadFile_test(INTERNET_FLAG_ASYNC);
1132 InternetReadFile_test(0);
1133 InternetReadFileExA_test(INTERNET_FLAG_ASYNC);
1134 InternetOpenRequest_test();
1135 InternetOpenUrlA_test();
1136 InternetTimeFromSystemTimeA_test();
1137 InternetTimeFromSystemTimeW_test();
1138 InternetTimeToSystemTimeA_test();
1139 InternetTimeToSystemTimeW_test();
1140 HttpSendRequestEx_test();
1142 test_http_connection();