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
27 #define WIN32_NO_STATUS
38 #include <wine/test.h>
40 /* Undocumented security flags */
41 #define _SECURITY_FLAG_CERT_REV_FAILED 0x00800000
42 #define _SECURITY_FLAG_CERT_INVALID_CA 0x01000000
43 #define _SECURITY_FLAG_CERT_INVALID_CN 0x02000000
44 #define _SECURITY_FLAG_CERT_INVALID_DATE 0x04000000
46 #define TEST_URL "http://test.winehq.org/tests/hello.html"
48 static BOOL first_connection_to_test_url
= TRUE
;
50 /* Adapted from dlls/urlmon/tests/protocol.c */
52 #define SET_EXPECT2(status, num) \
55 #define SET_EXPECT(status) \
56 SET_EXPECT2(status, 1)
58 #define SET_OPTIONAL2(status, num) \
59 optional[status] = num
61 #define SET_OPTIONAL(status) \
62 SET_OPTIONAL2(status, 1)
64 /* SET_WINE_ALLOW's should be used with an appropriate
65 * todo_wine CHECK_NOTIFIED at a later point in the code */
66 #define SET_WINE_ALLOW2(status, num) \
67 wine_allow[status] = num
69 #define SET_WINE_ALLOW(status) \
70 SET_WINE_ALLOW2(status, 1)
72 #define CHECK_EXPECT(status) \
74 if (!expect[status] && !optional[status] && wine_allow[status]) \
76 todo_wine ok(expect[status], "unexpected status %d (%s)\n", status, \
77 status < MAX_INTERNET_STATUS && status_string[status] ? \
78 status_string[status] : "unknown"); \
79 wine_allow[status]--; \
83 ok(expect[status] || optional[status], "unexpected status %d (%s)\n", status, \
84 status < MAX_INTERNET_STATUS && status_string[status] ? \
85 status_string[status] : "unknown"); \
86 if (expect[status]) expect[status]--; \
87 else if(optional[status]) optional[status]--; \
92 /* CLEAR_NOTIFIED used in cases when notification behavior
93 * differs between Windows versions */
94 #define CLEAR_NOTIFIED(status) \
95 expect[status] = optional[status] = wine_allow[status] = notified[status] = 0;
97 #define CHECK_NOTIFIED2(status, num) \
99 ok(notified[status] + optional[status] == (num), \
100 "expected status %d (%s) %d times, received %d times\n", \
101 status, status < MAX_INTERNET_STATUS && status_string[status] ? \
102 status_string[status] : "unknown", (num), notified[status]); \
103 CLEAR_NOTIFIED(status); \
106 #define CHECK_NOTIFIED(status) \
107 CHECK_NOTIFIED2(status, 1)
109 #define CHECK_NOT_NOTIFIED(status) \
110 CHECK_NOTIFIED2(status, 0)
112 #define MAX_INTERNET_STATUS (INTERNET_STATUS_COOKIE_HISTORY+1)
113 static int expect
[MAX_INTERNET_STATUS
], optional
[MAX_INTERNET_STATUS
],
114 wine_allow
[MAX_INTERNET_STATUS
], notified
[MAX_INTERNET_STATUS
];
115 static const char *status_string
[MAX_INTERNET_STATUS
];
117 static HANDLE hCompleteEvent
, conn_close_event
, conn_wait_event
, server_req_rec_event
;
118 static DWORD req_error
;
120 #define TESTF_REDIRECT 0x01
121 #define TESTF_COMPRESSED 0x02
122 #define TESTF_CHUNKED 0x04
126 const char *redirected_url
;
131 const char *post_data
;
135 static const test_data_t test_data
[] = {
137 "http://test.winehq.org/tests/data.php",
138 "http://test.winehq.org/tests/data.php",
145 "http://test.winehq.org/tests/redirect",
146 "http://test.winehq.org/tests/hello.html",
153 "http://test.winehq.org/tests/gzip.php",
154 "http://test.winehq.org/tests/gzip.php",
157 "Accept-Encoding: gzip, deflate",
161 "http://test.winehq.org/tests/post.php",
162 "http://test.winehq.org/tests/post.php",
165 "Content-Type: application/x-www-form-urlencoded",
172 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackA
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
173 static INTERNET_STATUS_CALLBACK (WINAPI
*pInternetSetStatusCallbackW
)(HINTERNET
,INTERNET_STATUS_CALLBACK
);
174 static BOOL (WINAPI
*pInternetGetSecurityInfoByURLA
)(LPSTR
,PCCERT_CHAIN_CONTEXT
*,DWORD
*);
176 static int strcmp_wa(LPCWSTR strw
, const char *stra
)
179 MultiByteToWideChar(CP_ACP
, 0, stra
, -1, buf
, sizeof(buf
)/sizeof(WCHAR
));
180 return lstrcmpW(strw
, buf
);
183 static BOOL
proxy_active(void)
185 HKEY internet_settings
;
189 if (RegOpenKeyExA(HKEY_CURRENT_USER
, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
190 0, KEY_QUERY_VALUE
, &internet_settings
) != ERROR_SUCCESS
)
193 size
= sizeof(DWORD
);
194 if (RegQueryValueExA(internet_settings
, "ProxyEnable", NULL
, NULL
, (LPBYTE
) &proxy_enable
, &size
) != ERROR_SUCCESS
)
197 RegCloseKey(internet_settings
);
199 return proxy_enable
!= 0;
202 #define test_status_code(a,b) _test_status_code(__LINE__,a,b, FALSE)
203 #define test_status_code_todo(a,b) _test_status_code(__LINE__,a,b, TRUE)
204 static void _test_status_code(unsigned line
, HINTERNET req
, DWORD excode
, BOOL is_todo
)
206 DWORD code
, size
, index
;
207 char exbuf
[10], bufa
[10];
213 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, NULL
);
214 ok_(__FILE__
,line
)(res
, "[1] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number) failed: %u\n", GetLastError());
215 todo_wine_if (is_todo
)
216 ok_(__FILE__
,line
)(code
== excode
, "code = %d, expected %d\n", code
, excode
);
217 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
222 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
223 ok_(__FILE__
,line
)(res
, "[2] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE|number index) failed: %u\n", GetLastError());
224 ok_(__FILE__
,line
)(!index
, "index = %d, expected 0\n", index
);
225 ok_(__FILE__
,line
)(size
== sizeof(code
), "size = %u\n", size
);
227 sprintf(exbuf
, "%u", excode
);
230 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, bufa
, &size
, NULL
);
231 ok_(__FILE__
,line
)(res
, "[3] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
232 todo_wine_if (is_todo
)
233 ok_(__FILE__
,line
)(!strcmp(bufa
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
234 ok_(__FILE__
,line
)(size
== strlen(exbuf
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
237 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
238 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
239 "[4] HttpQueryInfoA(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
240 ok_(__FILE__
,line
)(size
== strlen(exbuf
)+1, "unexpected size %d for \"%s\"\n", size
, exbuf
);
243 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
244 ok_(__FILE__
,line
)(res
, "[5] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
245 todo_wine_if (is_todo
)
246 ok_(__FILE__
,line
)(!strcmp_wa(bufw
, exbuf
), "unexpected status code %s, expected %s\n", bufa
, exbuf
);
247 ok_(__FILE__
,line
)(size
== strlen(exbuf
)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
250 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, bufw
, &size
, NULL
);
251 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_INSUFFICIENT_BUFFER
,
252 "[6] HttpQueryInfoW(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
253 ok_(__FILE__
,line
)(size
== (strlen(exbuf
)+1)*sizeof(WCHAR
), "unexpected size %d for \"%s\"\n", size
, exbuf
);
257 res
= HttpQueryInfoW(req
, HTTP_QUERY_STATUS_CODE
, NULL
, &size
, NULL
);
258 ok(!res
&& GetLastError() == ERROR_INVALID_PARAMETER
, "HttpQueryInfo(HTTP_QUERY_STATUS_CODE) failed: %u\n", GetLastError());
259 ok(size
== sizeof(bufw
), "unexpected size %d\n", size
);
265 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_NUMBER
, &code
, &size
, &index
);
266 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
267 "[7] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
271 res
= HttpQueryInfoA(req
, HTTP_QUERY_STATUS_CODE
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, &code
, &size
, NULL
);
272 ok_(__FILE__
,line
)(!res
&& GetLastError() == ERROR_HTTP_INVALID_QUERY_REQUEST
,
273 "[8] HttpQueryInfoA failed: %x(%d)\n", res
, GetLastError());
276 #define test_request_flags(a,b) _test_request_flags(__LINE__,a,b,FALSE)
277 #define test_request_flags_todo(a,b) _test_request_flags(__LINE__,a,b,TRUE)
278 static void _test_request_flags(unsigned line
, HINTERNET req
, DWORD exflags
, BOOL is_todo
)
284 size
= sizeof(flags
);
285 res
= InternetQueryOptionW(req
, INTERNET_OPTION_REQUEST_FLAGS
, &flags
, &size
);
286 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_REQUEST_FLAGS) failed: %u\n", GetLastError());
288 /* FIXME: Remove once we have INTERNET_REQFLAG_CACHE_WRITE_DISABLED implementation */
289 flags
&= ~INTERNET_REQFLAG_CACHE_WRITE_DISABLED
;
290 todo_wine_if (is_todo
)
291 ok_(__FILE__
,line
)(flags
== exflags
, "flags = %x, expected %x\n", flags
, exflags
);
294 #define test_http_version(a) _test_http_version(__LINE__,a)
295 static void _test_http_version(unsigned line
, HINTERNET req
)
297 HTTP_VERSION_INFO v
= {0xdeadbeef, 0xdeadbeef};
302 res
= InternetQueryOptionW(req
, INTERNET_OPTION_HTTP_VERSION
, &v
, &size
);
303 ok_(__FILE__
,line
)(res
, "InternetQueryOptionW(INTERNET_OPTION_HTTP_VERSION) failed: %u\n", GetLastError());
304 ok_(__FILE__
,line
)(v
.dwMajorVersion
== 1, "dwMajorVersion = %d\n", v
.dwMajorVersion
);
305 ok_(__FILE__
,line
)(v
.dwMinorVersion
== 1, "dwMinorVersion = %d\n", v
.dwMinorVersion
);
308 static int close_handle_cnt
;
310 static VOID WINAPI
callback(
313 DWORD dwInternetStatus
,
314 LPVOID lpvStatusInformation
,
315 DWORD dwStatusInformationLength
318 CHECK_EXPECT(dwInternetStatus
);
319 switch (dwInternetStatus
)
321 case INTERNET_STATUS_RESOLVING_NAME
:
322 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESOLVING_NAME \"%s\" %d\n",
323 GetCurrentThreadId(), hInternet
, dwContext
,
324 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
325 *(LPSTR
)lpvStatusInformation
= '\0';
327 case INTERNET_STATUS_NAME_RESOLVED
:
328 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_NAME_RESOLVED \"%s\" %d\n",
329 GetCurrentThreadId(), hInternet
, dwContext
,
330 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
331 *(LPSTR
)lpvStatusInformation
= '\0';
333 case INTERNET_STATUS_CONNECTING_TO_SERVER
:
334 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTING_TO_SERVER \"%s\" %d\n",
335 GetCurrentThreadId(), hInternet
, dwContext
,
336 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
337 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
338 dwStatusInformationLength
);
339 *(LPSTR
)lpvStatusInformation
= '\0';
341 case INTERNET_STATUS_CONNECTED_TO_SERVER
:
342 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTED_TO_SERVER \"%s\" %d\n",
343 GetCurrentThreadId(), hInternet
, dwContext
,
344 (LPCSTR
)lpvStatusInformation
,dwStatusInformationLength
);
345 ok(dwStatusInformationLength
== strlen(lpvStatusInformation
)+1, "unexpected size %u\n",
346 dwStatusInformationLength
);
347 *(LPSTR
)lpvStatusInformation
= '\0';
349 case INTERNET_STATUS_SENDING_REQUEST
:
350 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_SENDING_REQUEST %p %d\n",
351 GetCurrentThreadId(), hInternet
, dwContext
,
352 lpvStatusInformation
,dwStatusInformationLength
);
354 case INTERNET_STATUS_REQUEST_SENT
:
355 ok(dwStatusInformationLength
== sizeof(DWORD
),
356 "info length should be sizeof(DWORD) instead of %d\n",
357 dwStatusInformationLength
);
358 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_SENT 0x%x %d\n",
359 GetCurrentThreadId(), hInternet
, dwContext
,
360 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
362 case INTERNET_STATUS_RECEIVING_RESPONSE
:
363 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RECEIVING_RESPONSE %p %d\n",
364 GetCurrentThreadId(), hInternet
, dwContext
,
365 lpvStatusInformation
,dwStatusInformationLength
);
367 case INTERNET_STATUS_RESPONSE_RECEIVED
:
368 ok(dwStatusInformationLength
== sizeof(DWORD
),
369 "info length should be sizeof(DWORD) instead of %d\n",
370 dwStatusInformationLength
);
371 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_RESPONSE_RECEIVED 0x%x %d\n",
372 GetCurrentThreadId(), hInternet
, dwContext
,
373 *(DWORD
*)lpvStatusInformation
,dwStatusInformationLength
);
375 case INTERNET_STATUS_CTL_RESPONSE_RECEIVED
:
376 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CTL_RESPONSE_RECEIVED %p %d\n",
377 GetCurrentThreadId(), hInternet
,dwContext
,
378 lpvStatusInformation
,dwStatusInformationLength
);
380 case INTERNET_STATUS_PREFETCH
:
381 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_PREFETCH %p %d\n",
382 GetCurrentThreadId(), hInternet
, dwContext
,
383 lpvStatusInformation
,dwStatusInformationLength
);
385 case INTERNET_STATUS_CLOSING_CONNECTION
:
386 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CLOSING_CONNECTION %p %d\n",
387 GetCurrentThreadId(), hInternet
, dwContext
,
388 lpvStatusInformation
,dwStatusInformationLength
);
390 case INTERNET_STATUS_CONNECTION_CLOSED
:
391 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_CONNECTION_CLOSED %p %d\n",
392 GetCurrentThreadId(), hInternet
, dwContext
,
393 lpvStatusInformation
,dwStatusInformationLength
);
395 case INTERNET_STATUS_HANDLE_CREATED
:
396 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
397 "info length should be sizeof(HINTERNET) instead of %d\n",
398 dwStatusInformationLength
);
399 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CREATED %p %d\n",
400 GetCurrentThreadId(), hInternet
, dwContext
,
401 *(HINTERNET
*)lpvStatusInformation
,dwStatusInformationLength
);
402 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
403 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
405 case INTERNET_STATUS_HANDLE_CLOSING
:
406 ok(dwStatusInformationLength
== sizeof(HINTERNET
),
407 "info length should be sizeof(HINTERNET) instead of %d\n",
408 dwStatusInformationLength
);
409 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_HANDLE_CLOSING %p %d\n",
410 GetCurrentThreadId(), hInternet
, dwContext
,
411 *(HINTERNET
*)lpvStatusInformation
, dwStatusInformationLength
);
412 if(!InterlockedDecrement(&close_handle_cnt
))
413 SetEvent(hCompleteEvent
);
415 case INTERNET_STATUS_REQUEST_COMPLETE
:
417 INTERNET_ASYNC_RESULT
*iar
= (INTERNET_ASYNC_RESULT
*)lpvStatusInformation
;
418 ok(dwStatusInformationLength
== sizeof(INTERNET_ASYNC_RESULT
),
419 "info length should be sizeof(INTERNET_ASYNC_RESULT) instead of %d\n",
420 dwStatusInformationLength
);
421 ok(iar
->dwResult
== 1 || iar
->dwResult
== 0, "iar->dwResult = %ld\n", iar
->dwResult
);
422 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REQUEST_COMPLETE {%ld,%d} %d\n",
423 GetCurrentThreadId(), hInternet
, dwContext
,
424 iar
->dwResult
,iar
->dwError
,dwStatusInformationLength
);
425 req_error
= iar
->dwError
;
426 if(!close_handle_cnt
)
427 SetEvent(hCompleteEvent
);
430 case INTERNET_STATUS_REDIRECT
:
431 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_REDIRECT \"%s\" %d\n",
432 GetCurrentThreadId(), hInternet
, dwContext
,
433 (LPCSTR
)lpvStatusInformation
, dwStatusInformationLength
);
434 *(LPSTR
)lpvStatusInformation
= '\0';
435 CLEAR_NOTIFIED(INTERNET_STATUS_DETECTING_PROXY
);
436 SET_EXPECT(INTERNET_STATUS_DETECTING_PROXY
);
438 case INTERNET_STATUS_INTERMEDIATE_RESPONSE
:
439 trace("%04x:Callback %p 0x%lx INTERNET_STATUS_INTERMEDIATE_RESPONSE %p %d\n",
440 GetCurrentThreadId(), hInternet
, dwContext
,
441 lpvStatusInformation
, dwStatusInformationLength
);
444 trace("%04x:Callback %p 0x%lx %d %p %d\n",
445 GetCurrentThreadId(), hInternet
, dwContext
, dwInternetStatus
,
446 lpvStatusInformation
, dwStatusInformationLength
);
452 HINTERNET connection
;
456 #define open_simple_request(a,b,c,d,e) _open_simple_request(__LINE__,a,b,c,d,e)
457 static void _open_simple_request(unsigned line
, test_request_t
*req
, const char *host
,
458 int port
, const char *verb
, const char *url
)
460 req
->session
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
461 ok_(__FILE__
,line
)(req
->session
!= NULL
, "InternetOpenA failed: %u\n", GetLastError());
463 req
->connection
= InternetConnectA(req
->session
, host
, port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
464 ok_(__FILE__
,line
)(req
->connection
!= NULL
, "InternetConnectA failed: %u\n", GetLastError());
466 req
->request
= HttpOpenRequestA(req
->connection
, verb
, url
, NULL
, NULL
, NULL
, 0, 0);
467 ok_(__FILE__
,line
)(req
->request
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
470 #define close_request(a) _close_request(__LINE__,a)
471 static void _close_request(unsigned line
, test_request_t
*req
)
475 ret
= InternetCloseHandle(req
->request
);
476 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(request) failed: %u\n", GetLastError());
477 ret
= InternetCloseHandle(req
->connection
);
478 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(connection) failed: %u\n", GetLastError());
479 ret
= InternetCloseHandle(req
->session
);
480 ok_(__FILE__
,line
)(ret
, "InternetCloseHandle(session) failed: %u\n", GetLastError());
483 #define receive_simple_request(a,b,c) _receive_simple_request(__LINE__,a,b,c)
484 static DWORD
_receive_simple_request(unsigned line
, HINTERNET req
, char *buf
, size_t buf_size
)
489 ret
= InternetReadFile(req
, buf
, buf_size
, &read
);
490 ok_(__FILE__
,line
)(ret
, "InternetReadFile failed: %u\n", GetLastError());
495 static void close_async_handle(HINTERNET handle
, HANDLE complete_event
, int handle_cnt
)
499 close_handle_cnt
= handle_cnt
;
501 SET_EXPECT2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
502 res
= InternetCloseHandle(handle
);
503 ok(res
, "InternetCloseHandle failed: %u\n", GetLastError());
504 WaitForSingleObject(hCompleteEvent
, INFINITE
);
505 CHECK_NOTIFIED2(INTERNET_STATUS_HANDLE_CLOSING
, handle_cnt
);
508 static void InternetReadFile_test(int flags
, const test_data_t
*test
)
510 char *post_data
= NULL
;
511 BOOL res
, on_async
= TRUE
;
514 DWORD length
, length2
, index
, exlen
= 0, post_len
= 0;
515 const char *types
[2] = { "*", NULL
};
516 HINTERNET hi
, hic
= 0, hor
= 0;
518 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
520 trace("Starting InternetReadFile test with flags 0x%x on url %s\n",flags
,test
->url
);
522 trace("InternetOpenA <--\n");
523 hi
= InternetOpenA((test
->flags
& TESTF_COMPRESSED
) ? "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" : "",
524 INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
525 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
526 trace("InternetOpenA -->\n");
528 if (hi
== 0x0) goto abort
;
530 pInternetSetStatusCallbackA(hi
,&callback
);
532 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
534 trace("InternetConnectA <--\n");
535 hic
=InternetConnectA(hi
, test
->host
, INTERNET_INVALID_PORT_NUMBER
,
536 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
537 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
538 trace("InternetConnectA -->\n");
540 if (hic
== 0x0) goto abort
;
542 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
543 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
545 trace("HttpOpenRequestA <--\n");
546 hor
= HttpOpenRequestA(hic
, test
->post_data
? "POST" : "GET", test
->path
, NULL
, NULL
, types
,
547 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
549 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
551 * If the internet name can't be resolved we are probably behind
552 * a firewall or in some other way not directly connected to the
553 * Internet. Not enough reason to fail the test. Just ignore and
557 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
559 trace("HttpOpenRequestA -->\n");
561 if (hor
== 0x0) goto abort
;
563 test_request_flags(hor
, INTERNET_REQFLAG_NO_HEADERS
);
565 length
= sizeof(buffer
);
566 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
567 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
568 ok(!strcmp(buffer
, test
->url
), "Wrong URL %s, expected %s\n", buffer
, test
->url
);
570 length
= sizeof(buffer
);
571 res
= HttpQueryInfoA(hor
, HTTP_QUERY_RAW_HEADERS
, buffer
, &length
, 0x0);
572 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
573 ok(length
== 0 || (length
== 1 && !*buffer
) /* win10 */, "HTTP_QUERY_RAW_HEADERS: expected length 0, but got %d\n", length
);
574 ok(!strcmp(buffer
, ""), "HTTP_QUERY_RAW_HEADERS: expected string \"\", but got \"%s\"\n", buffer
);
576 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
577 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
578 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
579 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
,2);
580 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_RECEIVED
,2);
581 if (first_connection_to_test_url
)
583 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
584 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
586 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
587 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
588 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
589 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
590 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
591 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
592 if(test
->flags
& TESTF_REDIRECT
) {
593 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
594 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
596 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
597 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
598 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
599 if (flags
& INTERNET_FLAG_ASYNC
)
600 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
602 if(test
->flags
& TESTF_COMPRESSED
) {
605 res
= InternetSetOptionA(hor
, INTERNET_OPTION_HTTP_DECODING
, &b
, sizeof(b
));
606 ok(res
|| broken(!res
&& GetLastError() == ERROR_INTERNET_INVALID_OPTION
),
607 "InternetSetOption failed: %u\n", GetLastError());
612 test_status_code(hor
, 0);
614 trace("HttpSendRequestA -->\n");
615 if(test
->post_data
) {
616 post_len
= strlen(test
->post_data
);
617 post_data
= HeapAlloc(GetProcessHeap(), 0, post_len
);
618 memcpy(post_data
, test
->post_data
, post_len
);
620 SetLastError(0xdeadbeef);
621 res
= HttpSendRequestA(hor
, test
->headers
, -1, post_data
, post_len
);
622 if (flags
& INTERNET_FLAG_ASYNC
)
623 ok(!res
&& (GetLastError() == ERROR_IO_PENDING
),
624 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
626 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
627 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
628 trace("HttpSendRequestA <--\n");
630 if (flags
& INTERNET_FLAG_ASYNC
) {
631 WaitForSingleObject(hCompleteEvent
, INFINITE
);
632 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
634 HeapFree(GetProcessHeap(), 0, post_data
);
636 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
637 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_RECEIVED
);
638 if (first_connection_to_test_url
)
640 if (! proxy_active())
642 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
643 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
647 CLEAR_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
648 CLEAR_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
653 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
654 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
656 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
657 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
658 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
659 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, (test
->flags
& TESTF_REDIRECT
) ? 2 : 1);
660 if(test
->flags
& TESTF_REDIRECT
)
661 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
662 if (flags
& INTERNET_FLAG_ASYNC
)
663 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
664 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
665 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
666 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
668 test_request_flags(hor
, 0);
671 res
= InternetQueryOptionA(hor
,INTERNET_OPTION_URL
,buffer
,&length
);
672 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed with error %d\n", GetLastError());
674 length
= sizeof(buffer
)-1;
675 memset(buffer
, 0x77, sizeof(buffer
));
676 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length
,0x0);
677 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
678 /* show that the function writes data past the length returned */
679 ok(buffer
[length
-2], "Expected any header character, got 0x00\n");
680 ok(!buffer
[length
-1], "Expected 0x00, got %02X\n", buffer
[length
-1]);
681 ok(!buffer
[length
], "Expected 0x00, got %02X\n", buffer
[length
]);
682 ok(buffer
[length
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length
+1]);
685 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
686 ok(!res
, "Expected 0x00, got %d\n", res
);
687 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
688 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
689 /* the in length of the buffer must be +1 but the length returned does not count this */
691 memset(buffer
, 0x77, sizeof(buffer
));
692 res
= HttpQueryInfoA(hor
,HTTP_QUERY_RAW_HEADERS
,buffer
,&length2
,0x0);
693 ok(res
, "HttpQueryInfoA(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
694 ok(buffer
[length2
] == 0x00, "Expected 0x00, got %02X\n", buffer
[length2
]);
695 ok(buffer
[length2
+1] == 0x77, "Expected 0x77, got %02X\n", buffer
[length2
+1]);
696 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
698 length
= sizeof(wbuffer
)-sizeof(WCHAR
);
699 memset(wbuffer
, 0x77, sizeof(wbuffer
));
700 res
= HttpQueryInfoW(hor
, HTTP_QUERY_RAW_HEADERS
, wbuffer
, &length
, 0x0);
701 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
702 ok(length
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length
);
703 length
/= sizeof(WCHAR
);
704 /* show that the function writes data past the length returned */
705 ok(wbuffer
[length
-2], "Expected any header character, got 0x0000\n");
706 ok(!wbuffer
[length
-1], "Expected 0x0000, got %04X\n", wbuffer
[length
-1]);
707 ok(!wbuffer
[length
], "Expected 0x0000, got %04X\n", wbuffer
[length
]);
708 ok(wbuffer
[length
+1] == 0x7777 || broken(wbuffer
[length
+1] != 0x7777),
709 "Expected 0x7777, got %04X\n", wbuffer
[length
+1]);
711 length2
= length
*sizeof(WCHAR
);
712 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
713 ok(!res
, "Expected 0x00, got %d\n", res
);
714 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
715 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
716 length2
/= sizeof(WCHAR
);
717 ok(length2
== length
+1, "Expected %d, got %d\n", length
+1, length2
);
718 /* the in length of the buffer must be +1 but the length returned does not count this */
719 length2
= (length
+1)*sizeof(WCHAR
);
720 memset(wbuffer
, 0x77, sizeof(wbuffer
));
721 res
= HttpQueryInfoW(hor
,HTTP_QUERY_RAW_HEADERS
,wbuffer
,&length2
,0x0);
722 ok(res
, "HttpQueryInfoW(HTTP_QUERY_RAW_HEADERS) failed with error %d\n", GetLastError());
723 ok(length2
% sizeof(WCHAR
) == 0, "Expected that length is a multiple of sizeof(WCHAR), got %d.\n", length2
);
724 length2
/= sizeof(WCHAR
);
725 ok(!wbuffer
[length2
], "Expected 0x0000, got %04X\n", wbuffer
[length2
]);
726 ok(wbuffer
[length2
+1] == 0x7777, "Expected 0x7777, got %04X\n", wbuffer
[length2
+1]);
727 ok(length2
== length
, "Value should not have changed: %d != %d\n", length2
, length
);
729 length
= sizeof(buffer
);
730 res
= InternetQueryOptionA(hor
, INTERNET_OPTION_URL
, buffer
, &length
);
731 ok(res
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
732 ok(!strcmp(buffer
, test
->redirected_url
), "Wrong URL %s\n", buffer
);
736 SetLastError(0xdeadbeef);
737 ok(HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,NULL
,&length
,&index
) == FALSE
,"Query worked\n");
738 if(test
->flags
& TESTF_COMPRESSED
)
739 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
740 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %u\n", GetLastError());
741 ok(index
== 0, "Index was incremented\n");
745 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,&index
);
746 trace("Option HTTP_QUERY_CONTENT_LENGTH -> %i %s (%u)\n",res
,buffer
,GetLastError());
747 if(test
->flags
& TESTF_COMPRESSED
)
748 ok(!res
&& GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
,
749 "expected ERROR_HTTP_HEADER_NOT_FOUND, got %x (%u)\n", res
, GetLastError());
750 ok(!res
|| index
== 1, "Index was not incremented although result is %x (index = %u)\n", res
, index
);
753 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
755 trace("Option HTTP_QUERY_CONTENT_TYPE -> %i %s\n",res
,buffer
);
758 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_ENCODING
,buffer
,&length
,0x0);
760 trace("Option HTTP_QUERY_CONTENT_ENCODING -> %i %s\n",res
,buffer
);
762 SetLastError(0xdeadbeef);
763 res
= InternetReadFile(NULL
, buffer
, 100, &length
);
764 ok(!res
, "InternetReadFile should have failed\n");
765 ok(GetLastError() == ERROR_INVALID_HANDLE
,
766 "InternetReadFile should have set last error to ERROR_INVALID_HANDLE instead of %u\n",
770 trace("Entering Query loop\n");
774 if (flags
& INTERNET_FLAG_ASYNC
)
775 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
777 /* IE11 calls those in InternetQueryDataAvailable call. */
778 SET_OPTIONAL(INTERNET_STATUS_RECEIVING_RESPONSE
);
779 SET_OPTIONAL(INTERNET_STATUS_RESPONSE_RECEIVED
);
782 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
784 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
786 if (flags
& INTERNET_FLAG_ASYNC
)
790 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
792 ok(length
>= exlen
, "length %u < exlen %u\n", length
, exlen
);
796 else if (GetLastError() == ERROR_IO_PENDING
)
799 /* on some tests, InternetQueryDataAvailable returns non-zero length and ERROR_IO_PENDING */
800 if(!(test
->flags
& TESTF_CHUNKED
))
801 ok(!length
, "InternetQueryDataAvailable returned ERROR_IO_PENDING and %u length\n", length
);
802 WaitForSingleObject(hCompleteEvent
, INFINITE
);
804 ok(exlen
, "length = 0\n");
805 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
806 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
807 ok(req_error
, "req_error = 0\n");
810 ok(0, "InternetQueryDataAvailable failed: %u\n", GetLastError());
813 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
815 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
817 trace("LENGTH %d\n", length
);
818 if(test
->flags
& TESTF_CHUNKED
)
819 ok(length
<= 8192, "length = %d, expected <= 8192\n", length
);
823 buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
825 res
= InternetReadFile(hor
,buffer
,length
,&length
);
829 trace("ReadFile -> %s %i\n",res
?"TRUE":"FALSE",length
);
832 ok(!strcmp(buffer
, test
->content
), "buffer = '%s', expected '%s'\n", buffer
, test
->content
);
833 HeapFree(GetProcessHeap(),0,buffer
);
835 ok(!on_async
, "Returned zero size in response to request complete\n");
840 if(test
->flags
& TESTF_REDIRECT
) {
841 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
842 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
846 close_async_handle(hi
, hCompleteEvent
, 2);
847 CloseHandle(hCompleteEvent
);
848 first_connection_to_test_url
= FALSE
;
851 static void InternetReadFile_chunked_test(void)
856 const char *types
[2] = { "*", NULL
};
857 HINTERNET hi
, hic
= 0, hor
= 0;
859 trace("Starting InternetReadFile chunked test\n");
861 trace("InternetOpenA <--\n");
862 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
863 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
864 trace("InternetOpenA -->\n");
866 if (hi
== 0x0) goto abort
;
868 trace("InternetConnectA <--\n");
869 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
870 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
871 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
872 trace("InternetConnectA -->\n");
874 if (hic
== 0x0) goto abort
;
876 trace("HttpOpenRequestA <--\n");
877 hor
= HttpOpenRequestA(hic
, "GET", "/tests/chunked", NULL
, NULL
, types
,
878 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
880 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
882 * If the internet name can't be resolved we are probably behind
883 * a firewall or in some other way not directly connected to the
884 * Internet. Not enough reason to fail the test. Just ignore and
888 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
890 trace("HttpOpenRequestA -->\n");
892 if (hor
== 0x0) goto abort
;
894 trace("HttpSendRequestA -->\n");
895 SetLastError(0xdeadbeef);
896 res
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
897 ok(res
|| (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
),
898 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
899 trace("HttpSendRequestA <--\n");
901 test_request_flags(hor
, 0);
904 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_TYPE
,buffer
,&length
,0x0);
906 trace("Option CONTENT_TYPE -> %i %s\n",res
,buffer
);
908 SetLastError( 0xdeadbeef );
910 res
= HttpQueryInfoA(hor
,HTTP_QUERY_TRANSFER_ENCODING
,buffer
,&length
,0x0);
912 trace("Option TRANSFER_ENCODING -> %i %s\n",res
,buffer
);
913 ok( res
|| ( proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
914 "Failed to get TRANSFER_ENCODING option, error %u\n", GetLastError() );
915 ok( !strcmp( buffer
, "chunked" ) || ( ! res
&& proxy_active() && GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
),
916 "Wrong transfer encoding '%s'\n", buffer
);
918 SetLastError( 0xdeadbeef );
920 res
= HttpQueryInfoA(hor
,HTTP_QUERY_CONTENT_LENGTH
,&buffer
,&length
,0x0);
921 ok( !res
, "Found CONTENT_LENGTH option '%s'\n", buffer
);
922 ok( GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "Wrong error %u\n", GetLastError() );
925 trace("Entering Query loop\n");
929 res
= InternetQueryDataAvailable(hor
,&length
,0x0,0x0);
930 ok(!(!res
&& length
!= 0),"InternetQueryDataAvailable failed with non-zero length\n");
931 ok(res
, "InternetQueryDataAvailable failed, error %d\n", GetLastError());
932 trace("got %u available\n",length
);
935 char *buffer
= HeapAlloc(GetProcessHeap(),0,length
+1);
937 res
= InternetReadFile(hor
,buffer
,length
,&got
);
940 trace("ReadFile -> %i %i\n",res
,got
);
941 ok( length
== got
, "only got %u of %u available\n", got
, length
);
942 ok( buffer
[got
-1] == '\n', "received partial line '%s'\n", buffer
);
944 HeapFree(GetProcessHeap(),0,buffer
);
950 res
= InternetReadFile( hor
, buffer
, 1, &got
);
951 ok( res
, "InternetReadFile failed: %u\n", GetLastError() );
952 ok( !got
, "got %u\n", got
);
959 res
= InternetCloseHandle(hor
);
960 ok (res
, "InternetCloseHandle of handle opened by HttpOpenRequestA failed\n");
963 res
= InternetCloseHandle(hi
);
964 ok (res
, "InternetCloseHandle of handle opened by InternetOpenA failed\n");
968 static void InternetReadFileExA_test(int flags
)
972 const char *types
[2] = { "*", NULL
};
973 HINTERNET hi
, hic
= 0, hor
= 0;
974 INTERNET_BUFFERSA inetbuffers
;
976 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
978 trace("Starting InternetReadFileExA test with flags 0x%x\n",flags
);
980 trace("InternetOpenA <--\n");
981 hi
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, flags
);
982 ok((hi
!= 0x0),"InternetOpen failed with error %u\n", GetLastError());
983 trace("InternetOpenA -->\n");
985 if (hi
== 0x0) goto abort
;
987 pInternetSetStatusCallbackA(hi
,&callback
);
989 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
991 trace("InternetConnectA <--\n");
992 hic
=InternetConnectA(hi
, "test.winehq.org", INTERNET_INVALID_PORT_NUMBER
,
993 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
994 ok((hic
!= 0x0),"InternetConnect failed with error %u\n", GetLastError());
995 trace("InternetConnectA -->\n");
997 if (hic
== 0x0) goto abort
;
999 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1000 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1002 trace("HttpOpenRequestA <--\n");
1003 hor
= HttpOpenRequestA(hic
, "GET", "/tests/redirect", NULL
, NULL
, types
,
1004 INTERNET_FLAG_KEEP_CONNECTION
| INTERNET_FLAG_RELOAD
,
1006 if (hor
== 0x0 && GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
) {
1008 * If the internet name can't be resolved we are probably behind
1009 * a firewall or in some other way not directly connected to the
1010 * Internet. Not enough reason to fail the test. Just ignore and
1014 ok((hor
!= 0x0),"HttpOpenRequest failed with error %u\n", GetLastError());
1016 trace("HttpOpenRequestA -->\n");
1018 if (hor
== 0x0) goto abort
;
1020 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1021 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1022 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1023 if (first_connection_to_test_url
)
1025 SET_EXPECT(INTERNET_STATUS_RESOLVING_NAME
);
1026 SET_EXPECT(INTERNET_STATUS_NAME_RESOLVED
);
1028 SET_OPTIONAL2(INTERNET_STATUS_COOKIE_SENT
, 2);
1029 SET_EXPECT(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1030 SET_EXPECT(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1031 SET_EXPECT2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1032 SET_EXPECT2(INTERNET_STATUS_REQUEST_SENT
, 2);
1033 SET_EXPECT2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1034 SET_EXPECT2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1035 SET_OPTIONAL2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1036 SET_OPTIONAL2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1037 SET_EXPECT(INTERNET_STATUS_REDIRECT
);
1038 SET_OPTIONAL(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1039 SET_OPTIONAL(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1040 if (flags
& INTERNET_FLAG_ASYNC
)
1041 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1043 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1045 trace("HttpSendRequestA -->\n");
1046 SetLastError(0xdeadbeef);
1047 rc
= HttpSendRequestA(hor
, "", -1, NULL
, 0);
1048 if (flags
& INTERNET_FLAG_ASYNC
)
1049 ok(((rc
== 0)&&(GetLastError() == ERROR_IO_PENDING
)),
1050 "Asynchronous HttpSendRequest NOT returning 0 with error ERROR_IO_PENDING\n");
1052 ok((rc
!= 0) || GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
,
1053 "Synchronous HttpSendRequest returning 0, error %u\n", GetLastError());
1054 trace("HttpSendRequestA <--\n");
1056 if (!rc
&& (GetLastError() == ERROR_IO_PENDING
)) {
1057 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1058 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1061 if (first_connection_to_test_url
)
1063 CHECK_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1064 CHECK_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1068 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESOLVING_NAME
);
1069 CHECK_NOT_NOTIFIED(INTERNET_STATUS_NAME_RESOLVED
);
1071 CHECK_NOTIFIED2(INTERNET_STATUS_SENDING_REQUEST
, 2);
1072 CHECK_NOTIFIED2(INTERNET_STATUS_REQUEST_SENT
, 2);
1073 CHECK_NOTIFIED2(INTERNET_STATUS_RECEIVING_RESPONSE
, 2);
1074 CHECK_NOTIFIED2(INTERNET_STATUS_RESPONSE_RECEIVED
, 2);
1075 CHECK_NOTIFIED2(INTERNET_STATUS_CLOSING_CONNECTION
, 2);
1076 CHECK_NOTIFIED2(INTERNET_STATUS_CONNECTION_CLOSED
, 2);
1077 CHECK_NOTIFIED(INTERNET_STATUS_REDIRECT
);
1078 if (flags
& INTERNET_FLAG_ASYNC
)
1079 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1081 todo_wine
CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1082 CLEAR_NOTIFIED(INTERNET_STATUS_COOKIE_SENT
);
1083 /* Sent on WinXP only if first_connection_to_test_url is TRUE, on Win98 always sent */
1084 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1085 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1087 rc
= InternetReadFileExW(hor
, NULL
, 0, 0xdeadcafe);
1088 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1089 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1090 rc
? "TRUE" : "FALSE", GetLastError());
1092 /* tests invalid dwStructSize */
1093 inetbuffers
.dwStructSize
= sizeof(inetbuffers
)+1;
1094 inetbuffers
.lpcszHeader
= NULL
;
1095 inetbuffers
.dwHeadersLength
= 0;
1096 inetbuffers
.dwBufferLength
= 10;
1097 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, 10);
1098 inetbuffers
.dwOffsetHigh
= 1234;
1099 inetbuffers
.dwOffsetLow
= 5678;
1100 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1101 ok(!rc
&& (GetLastError() == ERROR_INVALID_PARAMETER
),
1102 "InternetReadFileEx should have failed with ERROR_INVALID_PARAMETER instead of %s, %u\n",
1103 rc
? "TRUE" : "FALSE", GetLastError());
1104 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1106 test_request_flags(hor
, 0);
1108 /* tests to see whether lpcszHeader is used - it isn't */
1109 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1110 inetbuffers
.lpcszHeader
= (LPCSTR
)0xdeadbeef;
1111 inetbuffers
.dwHeadersLength
= 255;
1112 inetbuffers
.dwBufferLength
= 0;
1113 inetbuffers
.lpvBuffer
= NULL
;
1114 inetbuffers
.dwOffsetHigh
= 1234;
1115 inetbuffers
.dwOffsetLow
= 5678;
1116 SET_EXPECT(INTERNET_STATUS_RECEIVING_RESPONSE
);
1117 SET_EXPECT(INTERNET_STATUS_RESPONSE_RECEIVED
);
1118 rc
= InternetReadFileExA(hor
, &inetbuffers
, 0, 0xdeadcafe);
1119 ok(rc
, "InternetReadFileEx failed with error %u\n", GetLastError());
1120 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1123 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1124 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1127 rc
= InternetReadFileExA(NULL
, &inetbuffers
, 0, 0xdeadcafe);
1128 ok(!rc
&& (GetLastError() == ERROR_INVALID_HANDLE
),
1129 "InternetReadFileEx should have failed with ERROR_INVALID_HANDLE instead of %s, %u\n",
1130 rc
? "TRUE" : "FALSE", GetLastError());
1133 trace("Entering Query loop\n");
1137 inetbuffers
.dwStructSize
= sizeof(inetbuffers
);
1138 inetbuffers
.dwBufferLength
= 1024;
1139 inetbuffers
.lpvBuffer
= HeapAlloc(GetProcessHeap(), 0, inetbuffers
.dwBufferLength
+1);
1140 inetbuffers
.dwOffsetHigh
= 1234;
1141 inetbuffers
.dwOffsetLow
= 5678;
1143 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1144 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1145 SET_EXPECT(INTERNET_STATUS_REQUEST_COMPLETE
);
1146 rc
= InternetReadFileExA(hor
, &inetbuffers
, IRF_ASYNC
| IRF_USE_CONTEXT
, 0xcafebabe);
1149 if (GetLastError() == ERROR_IO_PENDING
)
1151 trace("InternetReadFileEx -> PENDING\n");
1152 ok(flags
& INTERNET_FLAG_ASYNC
,
1153 "Should not get ERROR_IO_PENDING without INTERNET_FLAG_ASYNC\n");
1154 CHECK_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1155 WaitForSingleObject(hCompleteEvent
, INFINITE
);
1156 CHECK_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1157 CHECK_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1158 ok(req_error
== ERROR_SUCCESS
, "req_error = %u\n", req_error
);
1162 trace("InternetReadFileEx -> FAILED %u\n", GetLastError());
1168 trace("InternetReadFileEx -> SUCCEEDED\n");
1169 CHECK_NOT_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1170 if (inetbuffers
.dwBufferLength
)
1173 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1174 CHECK_NOT_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1179 /* Win98 still sends these when 0 bytes are read, WinXP does not */
1180 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1181 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1185 trace("read %i bytes\n", inetbuffers
.dwBufferLength
);
1186 ((char *)inetbuffers
.lpvBuffer
)[inetbuffers
.dwBufferLength
] = '\0';
1188 ok(inetbuffers
.dwOffsetHigh
== 1234 && inetbuffers
.dwOffsetLow
== 5678,
1189 "InternetReadFileEx sets offsets to 0x%x%08x\n",
1190 inetbuffers
.dwOffsetHigh
, inetbuffers
.dwOffsetLow
);
1192 HeapFree(GetProcessHeap(), 0, inetbuffers
.lpvBuffer
);
1194 if (!inetbuffers
.dwBufferLength
)
1197 length
+= inetbuffers
.dwBufferLength
;
1199 ok(length
> 0, "failed to read any of the document\n");
1200 trace("Finished. Read %d bytes\n", length
);
1203 close_async_handle(hi
, hCompleteEvent
, 2);
1204 CloseHandle(hCompleteEvent
);
1205 first_connection_to_test_url
= FALSE
;
1208 static void InternetOpenUrlA_test(void)
1210 HINTERNET myhinternet
, myhttp
;
1212 DWORD size
, readbytes
, totalbytes
=0;
1215 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1216 ok(ret
|| GetLastError() == ERROR_FILE_NOT_FOUND
,
1217 "DeleteUrlCacheEntry returned %x, GetLastError() = %d\n", ret
, GetLastError());
1219 myhinternet
= InternetOpenA("Winetest",0,NULL
,NULL
,INTERNET_FLAG_NO_CACHE_WRITE
);
1220 ok((myhinternet
!= 0), "InternetOpen failed, error %u\n",GetLastError());
1222 ret
= InternetCanonicalizeUrlA(TEST_URL
, buffer
, &size
,ICU_BROWSER_MODE
);
1223 ok( ret
, "InternetCanonicalizeUrl failed, error %u\n",GetLastError());
1226 myhttp
= InternetOpenUrlA(myhinternet
, TEST_URL
, 0, 0,
1227 INTERNET_FLAG_RELOAD
|INTERNET_FLAG_NO_CACHE_WRITE
|INTERNET_FLAG_TRANSFER_BINARY
,0);
1228 if (GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1229 return; /* WinXP returns this when not connected to the net */
1230 ok((myhttp
!= 0),"InternetOpenUrl failed, error %u\n",GetLastError());
1231 ret
= InternetReadFile(myhttp
, buffer
,0x400,&readbytes
);
1232 ok( ret
, "InternetReadFile failed, error %u\n",GetLastError());
1233 totalbytes
+= readbytes
;
1234 while (readbytes
&& InternetReadFile(myhttp
, buffer
,0x400,&readbytes
))
1235 totalbytes
+= readbytes
;
1236 trace("read 0x%08x bytes\n",totalbytes
);
1238 InternetCloseHandle(myhttp
);
1239 InternetCloseHandle(myhinternet
);
1241 ret
= DeleteUrlCacheEntryA(TEST_URL
);
1242 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "INTERNET_FLAG_NO_CACHE_WRITE flag doesn't work\n");
1245 static void HttpSendRequestEx_test(void)
1251 INTERNET_BUFFERSA BufferIn
;
1252 DWORD dwBytesWritten
, dwBytesRead
, error
;
1257 static char szPostData
[] = "mode=Test";
1258 static const char szContentType
[] = "Content-Type: application/x-www-form-urlencoded";
1260 hSession
= InternetOpenA("Wine Regression Test",
1261 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1262 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1263 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1264 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1266 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1267 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1268 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1269 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1271 skip( "Network unreachable, skipping test\n" );
1274 ok( hRequest
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1276 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1278 BufferIn
.dwStructSize
= sizeof(BufferIn
);
1279 BufferIn
.Next
= (INTERNET_BUFFERSA
*)0xdeadcab;
1280 BufferIn
.lpcszHeader
= szContentType
;
1281 BufferIn
.dwHeadersLength
= sizeof(szContentType
)-1;
1282 BufferIn
.dwHeadersTotal
= sizeof(szContentType
)-1;
1283 BufferIn
.lpvBuffer
= szPostData
;
1284 BufferIn
.dwBufferLength
= 3;
1285 BufferIn
.dwBufferTotal
= sizeof(szPostData
)-1;
1286 BufferIn
.dwOffsetLow
= 0;
1287 BufferIn
.dwOffsetHigh
= 0;
1289 SetLastError(0xdeadbeef);
1290 ret
= HttpSendRequestExA(hRequest
, &BufferIn
, NULL
, 0 ,0);
1291 error
= GetLastError();
1292 ok(ret
, "HttpSendRequestEx Failed with error %u\n", error
);
1293 ok(error
== ERROR_SUCCESS
, "expected ERROR_SUCCESS, got %u\n", error
);
1295 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1297 for (i
= 3; szPostData
[i
]; i
++)
1298 ok(InternetWriteFile(hRequest
, &szPostData
[i
], 1, &dwBytesWritten
),
1299 "InternetWriteFile failed\n");
1301 test_request_flags(hRequest
, INTERNET_REQFLAG_NO_HEADERS
);
1303 ok(HttpEndRequestA(hRequest
, NULL
, 0, 0), "HttpEndRequest Failed\n");
1305 test_request_flags(hRequest
, 0);
1307 ok(InternetReadFile(hRequest
, szBuffer
, 255, &dwBytesRead
),
1308 "Unable to read response\n");
1309 szBuffer
[dwBytesRead
] = 0;
1311 ok(dwBytesRead
== 13,"Read %u bytes instead of 13\n",dwBytesRead
);
1312 ok(strncmp(szBuffer
,"mode => Test\n",dwBytesRead
)==0 || broken(proxy_active()),"Got string %s\n",szBuffer
);
1314 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1316 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1317 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1320 static void InternetOpenRequest_test(void)
1322 HINTERNET session
, connect
, request
;
1323 static const char *types
[] = { "*", "", NULL
};
1324 static const WCHAR slash
[] = {'/', 0}, any
[] = {'*', 0}, empty
[] = {0};
1325 static const WCHAR
*typesW
[] = { any
, empty
, NULL
};
1328 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1329 ok(session
!= NULL
,"Unable to open Internet session\n");
1331 connect
= InternetConnectA(session
, NULL
, INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1332 INTERNET_SERVICE_HTTP
, 0, 0);
1333 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1334 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with NULL server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1336 connect
= InternetConnectA(session
, "", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1337 INTERNET_SERVICE_HTTP
, 0, 0);
1338 ok(connect
== NULL
, "InternetConnectA should have failed\n");
1339 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "InternetConnectA with blank server named should have failed with ERROR_INVALID_PARAMETER instead of %d\n", GetLastError());
1341 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1342 INTERNET_SERVICE_HTTP
, 0, 0);
1343 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1345 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1346 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1348 skip( "Network unreachable, skipping test\n" );
1351 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1353 ret
= HttpSendRequestW(request
, NULL
, 0, NULL
, 0);
1354 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1355 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1357 request
= HttpOpenRequestW(connect
, NULL
, slash
, NULL
, NULL
, typesW
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1358 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1360 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1361 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1362 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1365 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1366 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1369 static void test_cache_read(void)
1371 HINTERNET session
, connection
, req
;
1372 FILETIME now
, tomorrow
, yesterday
;
1373 BYTE content
[1000], buf
[2000];
1374 char file_path
[MAX_PATH
];
1381 static const char cache_only_url
[] = "http://test.winehq.org/tests/cache-only";
1382 BYTE cache_headers
[] = "HTTP/1.1 200 OK\r\n\r\n";
1384 trace("Testing cache read...\n");
1386 hCompleteEvent
= CreateEventW(NULL
, FALSE
, FALSE
, NULL
);
1388 for(i
= 0; i
< sizeof(content
); i
++)
1389 content
[i
] = '0' + (i
%10);
1391 GetSystemTimeAsFileTime(&now
);
1392 li
.u
.HighPart
= now
.dwHighDateTime
;
1393 li
.u
.LowPart
= now
.dwLowDateTime
;
1394 li
.QuadPart
+= (LONGLONG
)10000000 * 3600 * 24;
1395 tomorrow
.dwHighDateTime
= li
.u
.HighPart
;
1396 tomorrow
.dwLowDateTime
= li
.u
.LowPart
;
1397 li
.QuadPart
-= (LONGLONG
)10000000 * 3600 * 24 * 2;
1398 yesterday
.dwHighDateTime
= li
.u
.HighPart
;
1399 yesterday
.dwLowDateTime
= li
.u
.LowPart
;
1401 res
= CreateUrlCacheEntryA(cache_only_url
, sizeof(content
), "", file_path
, 0);
1402 ok(res
, "CreateUrlCacheEntryA failed: %u\n", GetLastError());
1404 file
= CreateFileA(file_path
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1405 ok(file
!= INVALID_HANDLE_VALUE
, "CreateFile failed\n");
1407 WriteFile(file
, content
, sizeof(content
), &size
, NULL
);
1410 res
= CommitUrlCacheEntryA(cache_only_url
, file_path
, tomorrow
, yesterday
, NORMAL_CACHE_ENTRY
,
1411 cache_headers
, sizeof(cache_headers
)-1, "", 0);
1412 ok(res
, "CommitUrlCacheEntryA failed: %u\n", GetLastError());
1414 session
= InternetOpenA("", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, INTERNET_FLAG_ASYNC
);
1415 ok(session
!= NULL
,"InternetOpen failed with error %u\n", GetLastError());
1417 pInternetSetStatusCallbackA(session
, callback
);
1419 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1420 connection
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
,
1421 NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0x0, 0xdeadbeef);
1422 ok(connection
!= NULL
,"InternetConnect failed with error %u\n", GetLastError());
1423 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1425 SET_EXPECT(INTERNET_STATUS_HANDLE_CREATED
);
1426 req
= HttpOpenRequestA(connection
, "GET", "/tests/cache-only", NULL
, NULL
, NULL
, 0, 0xdeadbead);
1427 ok(req
!= NULL
, "HttpOpenRequest failed: %u\n", GetLastError());
1428 CHECK_NOTIFIED(INTERNET_STATUS_HANDLE_CREATED
);
1430 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1431 SET_WINE_ALLOW(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1432 SET_WINE_ALLOW(INTERNET_STATUS_SENDING_REQUEST
);
1433 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_SENT
);
1434 SET_WINE_ALLOW(INTERNET_STATUS_RECEIVING_RESPONSE
);
1435 SET_WINE_ALLOW(INTERNET_STATUS_RESPONSE_RECEIVED
);
1436 SET_WINE_ALLOW(INTERNET_STATUS_REQUEST_COMPLETE
);
1438 res
= HttpSendRequestA(req
, NULL
, -1, NULL
, 0);
1440 ok(res
, "HttpSendRequest failed: %u\n", GetLastError());
1444 res
= InternetQueryDataAvailable(req
, &size
, 0, 0);
1445 ok(res
, "InternetQueryDataAvailable failed: %u\n", GetLastError());
1446 ok(size
== sizeof(content
), "size = %u\n", size
);
1449 res
= InternetReadFile(req
, buf
, sizeof(buf
), &size
);
1450 ok(res
, "InternetReadFile failed: %u\n", GetLastError());
1451 ok(size
== sizeof(content
), "size = %u\n", size
);
1452 ok(!memcmp(content
, buf
, sizeof(content
)), "unexpected content\n");
1455 close_async_handle(session
, hCompleteEvent
, 2);
1457 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTING_TO_SERVER
);
1458 CLEAR_NOTIFIED(INTERNET_STATUS_CONNECTED_TO_SERVER
);
1459 CLEAR_NOTIFIED(INTERNET_STATUS_SENDING_REQUEST
);
1460 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_SENT
);
1461 CLEAR_NOTIFIED(INTERNET_STATUS_RECEIVING_RESPONSE
);
1462 CLEAR_NOTIFIED(INTERNET_STATUS_RESPONSE_RECEIVED
);
1463 CLEAR_NOTIFIED(INTERNET_STATUS_REQUEST_COMPLETE
);
1465 res
= DeleteUrlCacheEntryA(cache_only_url
);
1466 ok(res
, "DeleteUrlCacheEntryA failed: %u\n", GetLastError());
1468 CloseHandle(hCompleteEvent
);
1471 static void test_http_cache(void)
1473 HINTERNET session
, connect
, request
;
1474 char file_name
[MAX_PATH
], url
[INTERNET_MAX_URL_LENGTH
];
1475 DWORD size
, file_size
;
1479 FILETIME filetime_zero
= {0};
1481 static const char cached_content
[] = "data read from cache";
1482 static const char *types
[] = { "*", "", NULL
};
1484 session
= InternetOpenA("Wine Regression Test", INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
1485 ok(session
!= NULL
,"Unable to open Internet session\n");
1487 connect
= InternetConnectA(session
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
,
1488 INTERNET_SERVICE_HTTP
, 0, 0);
1489 ok(connect
!= NULL
, "Unable to connect to http://test.winehq.org with error %d\n", GetLastError());
1491 request
= HttpOpenRequestA(connect
, NULL
, "/tests/hello.html", NULL
, NULL
, types
, INTERNET_FLAG_NEED_FILE
, 0);
1492 if (!request
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1494 skip( "Network unreachable, skipping test\n" );
1496 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1497 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1501 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1504 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_URL
, url
, &size
);
1505 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_URL) failed: %u\n", GetLastError());
1506 ok(!strcmp(url
, "http://test.winehq.org/tests/hello.html"), "Wrong URL %s\n", url
);
1508 size
= sizeof(file_name
);
1509 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1510 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1511 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1512 ok(!size
, "size = %d\n", size
);
1514 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1515 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1517 size
= sizeof(file_name
);
1518 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1519 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1521 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
1522 FILE_ATTRIBUTE_NORMAL
, NULL
);
1523 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1524 file_size
= GetFileSize(file
, NULL
);
1525 ok(file_size
== 106, "file size = %u\n", file_size
);
1528 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1529 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1530 ok(size
== 100, "size = %u\n", size
);
1532 file_size
= GetFileSize(file
, NULL
);
1533 ok(file_size
== 106, "file size = %u\n", file_size
);
1536 ret
= DeleteFileA(file_name
);
1537 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1539 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1541 file
= CreateFileA(file_name
, GENERIC_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1542 FILE_ATTRIBUTE_NORMAL
, NULL
);
1543 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1544 ret
= WriteFile(file
, cached_content
, sizeof(cached_content
), &size
, NULL
);
1545 ok(ret
&& size
, "WriteFile failed: %d, %d\n", ret
, size
);
1546 ret
= CommitUrlCacheEntryA(url
, file_name
, filetime_zero
, filetime_zero
, NORMAL_CACHE_ENTRY
, NULL
, 0, NULL
, 0);
1547 ok(ret
, "CommitUrlCacheEntry failed: %d\n", GetLastError());
1550 /* Send the same request, requiring it to be retrieved from the cache */
1551 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1553 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1554 ok(ret
, "HttpSendRequest failed\n");
1557 ret
= InternetReadFile(request
, buf
, sizeof(buf
), &size
);
1558 ok(ret
, "InternetReadFile failed: %u\n", GetLastError());
1559 ok(size
== 100, "size = %u\n", size
);
1561 todo_wine
ok(!strcmp((char*)buf
, cached_content
), "incorrect page data: %s\n", (char*)buf
);
1563 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1565 DeleteUrlCacheEntryA(url
);
1566 request
= HttpOpenRequestA(connect
, "GET", "/tests/hello.html", NULL
, NULL
, NULL
, INTERNET_FLAG_FROM_CACHE
, 0);
1567 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1568 todo_wine
ok(!ret
, "HttpSendRequest succeeded\n");
1570 ok(GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError() = %d\n", GetLastError());
1571 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1573 request
= HttpOpenRequestA(connect
, NULL
, "/", NULL
, NULL
, types
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1574 ok(request
!= NULL
, "Failed to open request handle err %u\n", GetLastError());
1576 size
= sizeof(file_name
);
1577 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1578 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1579 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1580 ok(!size
, "size = %d\n", size
);
1582 ret
= HttpSendRequestA(request
, NULL
, 0, NULL
, 0);
1583 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1585 size
= sizeof(file_name
);
1587 ret
= InternetQueryOptionA(request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1590 file
= CreateFileA(file_name
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
,
1591 FILE_ATTRIBUTE_NORMAL
, NULL
);
1592 ok(file
!= INVALID_HANDLE_VALUE
, "Could not create file: %u\n", GetLastError());
1598 ok(file_name
[0] == 0, "Didn't expect a file name\n");
1601 ok(InternetCloseHandle(request
), "Close request handle failed\n");
1602 ok(InternetCloseHandle(connect
), "Close connect handle failed\n");
1603 ok(InternetCloseHandle(session
), "Close session handle failed\n");
1608 static void InternetLockRequestFile_test(void)
1610 char file_name
[MAX_PATH
];
1616 open_simple_request(&req
, "test.winehq.org", INTERNET_DEFAULT_HTTP_PORT
, NULL
, "/tests/hello.html");
1618 size
= sizeof(file_name
);
1619 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1620 ok(!ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) succeeded\n");
1621 ok(GetLastError() == ERROR_INTERNET_ITEM_NOT_FOUND
, "GetLastError()=%u\n", GetLastError());
1622 ok(!size
, "size = %d\n", size
);
1625 ret
= InternetLockRequestFile(req
.request
, &lock
);
1626 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1628 ret
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
1629 ok(ret
, "HttpSendRequest failed: %u\n", GetLastError());
1631 size
= sizeof(file_name
);
1632 ret
= InternetQueryOptionA(req
.request
, INTERNET_OPTION_DATAFILE_NAME
, file_name
, &size
);
1633 ok(ret
, "InternetQueryOptionA(INTERNET_OPTION_DATAFILE_NAME) failed: %u\n", GetLastError());
1635 ret
= InternetLockRequestFile(req
.request
, &lock
);
1636 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1637 ok(lock
!= NULL
, "lock == NULL\n");
1639 ret
= InternetLockRequestFile(req
.request
, &lock2
);
1640 ok(ret
, "InternetLockRequestFile returned: %x(%u)\n", ret
, GetLastError());
1641 ok(lock
== lock2
, "lock != lock2\n");
1643 ret
= InternetUnlockRequestFile(lock2
);
1644 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1646 ret
= DeleteFileA(file_name
);
1647 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1649 ok(InternetCloseHandle(req
.request
), "Close request handle failed\n");
1651 ret
= DeleteFileA(file_name
);
1652 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1654 ret
= InternetUnlockRequestFile(lock
);
1655 ok(ret
, "InternetUnlockRequestFile failed: %u\n", GetLastError());
1657 ret
= DeleteFileA(file_name
);
1658 ok(ret
, "Deleting file returned %x(%u)\n", ret
, GetLastError());
1661 static void HttpHeaders_test(void)
1673 hSession
= InternetOpenA("Wine Regression Test",
1674 INTERNET_OPEN_TYPE_PRECONFIG
,NULL
,NULL
,0);
1675 ok( hSession
!= NULL
,"Unable to open Internet session\n");
1676 hConnect
= InternetConnectA(hSession
, "test.winehq.org",
1677 INTERNET_DEFAULT_HTTP_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0,
1679 ok( hConnect
!= NULL
, "Unable to connect to http://test.winehq.org\n");
1680 hRequest
= HttpOpenRequestA(hConnect
, "POST", "/tests/post.php",
1681 NULL
, NULL
, NULL
, INTERNET_FLAG_NO_CACHE_WRITE
, 0);
1682 if (!hRequest
&& GetLastError() == ERROR_INTERNET_NAME_NOT_RESOLVED
)
1684 skip( "Network unreachable, skipping test\n" );
1687 ok( hRequest
!= NULL
, "Failed to open request handle\n");
1690 len
= sizeof(buffer
);
1691 strcpy(buffer
,"Warning");
1692 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1693 buffer
,&len
,&index
)==0,"Warning hearder reported as Existing\n");
1695 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test1",-1,HTTP_ADDREQ_FLAG_ADD
),
1696 "Failed to add new header\n");
1699 len
= sizeof(buffer
);
1700 strcpy(buffer
,"Warning");
1701 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1702 buffer
,&len
,&index
),"Unable to query header\n");
1703 ok(index
== 1, "Index was not incremented\n");
1704 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1705 ok(len
== 5, "Invalid length (exp. 5, got %d)\n", len
);
1706 ok((len
< sizeof(buffer
)) && (buffer
[len
] == 0), "Buffer not NULL-terminated\n"); /* len show only 5 characters but the buffer is NULL-terminated*/
1707 len
= sizeof(buffer
);
1708 strcpy(buffer
,"Warning");
1709 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1710 buffer
,&len
,&index
)==0,"Second Index Should Not Exist\n");
1713 len
= 5; /* could store the string but not the NULL terminator */
1714 strcpy(buffer
,"Warning");
1715 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1716 buffer
,&len
,&index
) == FALSE
,"Query succeeded on a too small buffer\n");
1717 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1718 ok(index
== 0, "Index was incremented\n");
1719 ok(strcmp(buffer
,"Warning")==0, "incorrect string was returned(%s)\n",buffer
); /* string not touched */
1720 ok(len
== 6, "Invalid length (exp. 6, got %d)\n", len
); /* unlike success, the length includes the NULL-terminator */
1722 /* a call with NULL will fail but will return the length */
1724 len
= sizeof(buffer
);
1725 SetLastError(0xdeadbeef);
1726 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1727 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1728 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1729 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1730 ok(index
== 0, "Index was incremented\n");
1732 /* even for a len that is too small */
1735 SetLastError(0xdeadbeef);
1736 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1737 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1738 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1739 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1740 ok(index
== 0, "Index was incremented\n");
1744 SetLastError(0xdeadbeef);
1745 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1746 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1747 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1748 ok(len
> 40, "Invalid length (exp. more than 40, got %d)\n", len
);
1749 ok(index
== 0, "Index was incremented\n");
1750 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1753 /* a working query */
1755 len
= sizeof(buffer
);
1756 memset(buffer
, 'x', sizeof(buffer
));
1757 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1758 buffer
,&len
,&index
),"Unable to query header\n");
1759 ok(len
+ sizeof(CHAR
) <= oldlen
, "Result longer than advertised\n");
1760 ok((len
< sizeof(buffer
)-sizeof(CHAR
)) && (buffer
[len
/sizeof(CHAR
)] == 0),"No NUL at end\n");
1761 ok(len
== strlen(buffer
) * sizeof(CHAR
), "Length wrong\n");
1762 /* what's in the middle differs between Wine and Windows so currently we check only the beginning and the end */
1763 ok(strncmp(buffer
, "POST /tests/post.php HTTP/1", 25)==0, "Invalid beginning of headers string\n");
1764 ok(strcmp(buffer
+ strlen(buffer
) - 4, "\r\n\r\n")==0, "Invalid end of headers string\n");
1765 ok(index
== 0, "Index was incremented\n");
1767 /* Like above two tests, but for W version */
1771 SetLastError(0xdeadbeef);
1772 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1773 NULL
,&len
,&index
) == FALSE
,"Query worked\n");
1774 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "Unexpected last error: %d\n", GetLastError());
1775 ok(len
> 80, "Invalid length (exp. more than 80, got %d)\n", len
);
1776 ok(index
== 0, "Index was incremented\n");
1777 oldlen
= len
; /* bytes; at least long enough to hold buffer & nul */
1779 /* a working query */
1781 len
= sizeof(wbuffer
);
1782 memset(wbuffer
, 'x', sizeof(wbuffer
));
1783 ok(HttpQueryInfoW(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1784 wbuffer
,&len
,&index
),"Unable to query header\n");
1785 ok(len
+ sizeof(WCHAR
) <= oldlen
, "Result longer than advertised\n");
1786 ok(len
== lstrlenW(wbuffer
) * sizeof(WCHAR
), "Length wrong\n");
1787 ok((len
< sizeof(wbuffer
)-sizeof(WCHAR
)) && (wbuffer
[len
/sizeof(WCHAR
)] == 0),"No NUL at end\n");
1788 ok(index
== 0, "Index was incremented\n");
1790 /* end of W version tests */
1792 /* Without HTTP_QUERY_FLAG_REQUEST_HEADERS */
1794 len
= sizeof(buffer
);
1795 memset(buffer
, 'x', sizeof(buffer
));
1796 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_RAW_HEADERS_CRLF
,
1797 buffer
,&len
,&index
) == TRUE
,"Query failed\n");
1798 ok(len
== 2 || len
== 4 /* win10 */, "Expected 2 or 4, got %d\n", len
);
1799 ok(memcmp(buffer
, "\r\n\r\n", len
) == 0, "Expected CRLF, got '%s'\n", buffer
);
1800 ok(index
== 0, "Index was incremented\n");
1802 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test2",-1,HTTP_ADDREQ_FLAG_ADD
),
1803 "Failed to add duplicate header using HTTP_ADDREQ_FLAG_ADD\n");
1806 len
= sizeof(buffer
);
1807 strcpy(buffer
,"Warning");
1808 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1809 buffer
,&len
,&index
),"Unable to query header\n");
1810 ok(index
== 1, "Index was not incremented\n");
1811 ok(strcmp(buffer
,"test1")==0, "incorrect string was returned(%s)\n",buffer
);
1812 len
= sizeof(buffer
);
1813 strcpy(buffer
,"Warning");
1814 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1815 buffer
,&len
,&index
),"Failed to get second header\n");
1816 ok(index
== 2, "Index was not incremented\n");
1817 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1818 len
= sizeof(buffer
);
1819 strcpy(buffer
,"Warning");
1820 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1821 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1823 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test3",-1,HTTP_ADDREQ_FLAG_REPLACE
), "Failed to replace header using HTTP_ADDREQ_FLAG_REPLACE\n");
1826 len
= sizeof(buffer
);
1827 strcpy(buffer
,"Warning");
1828 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1829 buffer
,&len
,&index
),"Unable to query header\n");
1830 ok(index
== 1, "Index was not incremented\n");
1831 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1832 len
= sizeof(buffer
);
1833 strcpy(buffer
,"Warning");
1834 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1835 buffer
,&len
,&index
),"Failed to get second header\n");
1836 ok(index
== 2, "Index was not incremented\n");
1837 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1838 len
= sizeof(buffer
);
1839 strcpy(buffer
,"Warning");
1840 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1841 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1843 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1,HTTP_ADDREQ_FLAG_ADD_IF_NEW
)==0, "HTTP_ADDREQ_FLAG_ADD_IF_NEW replaced existing header\n");
1846 len
= sizeof(buffer
);
1847 strcpy(buffer
,"Warning");
1848 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1849 buffer
,&len
,&index
),"Unable to query header\n");
1850 ok(index
== 1, "Index was not incremented\n");
1851 ok(strcmp(buffer
,"test2")==0, "incorrect string was returned(%s)\n",buffer
);
1852 len
= sizeof(buffer
);
1853 strcpy(buffer
,"Warning");
1854 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1855 buffer
,&len
,&index
),"Failed to get second header\n");
1856 ok(index
== 2, "Index was not incremented\n");
1857 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1858 len
= sizeof(buffer
);
1859 strcpy(buffer
,"Warning");
1860 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1861 buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1863 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test4",-1, HTTP_ADDREQ_FLAG_COALESCE
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1866 len
= sizeof(buffer
);
1867 strcpy(buffer
,"Warning");
1868 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
,
1869 buffer
,&len
,&index
),"Unable to query header\n");
1870 ok(index
== 1, "Index was not incremented\n");
1871 ok(strcmp(buffer
,"test2, test4")==0, "incorrect string was returned(%s)\n", buffer
);
1872 len
= sizeof(buffer
);
1873 strcpy(buffer
,"Warning");
1874 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1875 ok(index
== 2, "Index was not incremented\n");
1876 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1877 len
= sizeof(buffer
);
1878 strcpy(buffer
,"Warning");
1879 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1881 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test5",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1884 len
= sizeof(buffer
);
1885 strcpy(buffer
,"Warning");
1886 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1887 ok(index
== 1, "Index was not incremented\n");
1888 ok(strcmp(buffer
,"test2, test4, test5")==0, "incorrect string was returned(%s)\n",buffer
);
1889 len
= sizeof(buffer
);
1890 strcpy(buffer
,"Warning");
1891 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1892 ok(index
== 2, "Index was not incremented\n");
1893 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1894 len
= sizeof(buffer
);
1895 strcpy(buffer
,"Warning");
1896 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1898 ok(HttpAddRequestHeadersA(hRequest
,"Warning:test6",-1, HTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON
), "HTTP_ADDREQ_FLAG_COALESCE Did not work\n");
1901 len
= sizeof(buffer
);
1902 strcpy(buffer
,"Warning");
1903 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1904 ok(index
== 1, "Index was not incremented\n");
1905 ok(strcmp(buffer
,"test2, test4, test5; test6")==0, "incorrect string was returned(%s)\n",buffer
);
1906 len
= sizeof(buffer
);
1907 strcpy(buffer
,"Warning");
1908 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1909 ok(index
== 2, "Index was not incremented\n");
1910 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1911 len
= sizeof(buffer
);
1912 strcpy(buffer
,"Warning");
1913 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1915 ok(HttpAddRequestHeadersA(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");
1918 len
= sizeof(buffer
);
1919 strcpy(buffer
,"Warning");
1920 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1921 ok(index
== 1, "Index was not incremented\n");
1922 ok(strcmp(buffer
,"test3")==0, "incorrect string was returned(%s)\n",buffer
);
1923 len
= sizeof(buffer
);
1924 strcpy(buffer
,"Warning");
1925 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Failed to get second header\n");
1926 ok(index
== 2, "Index was not incremented\n");
1927 ok(strcmp(buffer
,"test7")==0, "incorrect string was returned(%s)\n",buffer
);
1928 len
= sizeof(buffer
);
1929 strcpy(buffer
,"Warning");
1930 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
)==0,"Third Header Should Not Exist\n");
1932 /* Ensure that blank headers are ignored and don't cause a failure */
1933 ok(HttpAddRequestHeadersA(hRequest
,"\r\nBlankTest:value\r\n\r\n",-1, HTTP_ADDREQ_FLAG_ADD_IF_NEW
), "Failed to add header with blank entries in list\n");
1936 len
= sizeof(buffer
);
1937 strcpy(buffer
,"BlankTest");
1938 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1939 ok(index
== 1, "Index was not incremented\n");
1940 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1942 /* Ensure that malformed header separators are ignored and don't cause a failure */
1943 ok(HttpAddRequestHeadersA(hRequest
,"\r\rMalformedTest:value\n\nMalformedTestTwo: value2\rMalformedTestThree: value3\n\n\r\r\n",-1, HTTP_ADDREQ_FLAG_ADD
|HTTP_ADDREQ_FLAG_REPLACE
),
1944 "Failed to add header with malformed entries in list\n");
1947 len
= sizeof(buffer
);
1948 strcpy(buffer
,"MalformedTest");
1949 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1950 ok(index
== 1, "Index was not incremented\n");
1951 ok(strcmp(buffer
,"value")==0, "incorrect string was returned(%s)\n",buffer
);
1953 len
= sizeof(buffer
);
1954 strcpy(buffer
,"MalformedTestTwo");
1955 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1956 ok(index
== 1, "Index was not incremented\n");
1957 ok(strcmp(buffer
,"value2")==0, "incorrect string was returned(%s)\n",buffer
);
1959 len
= sizeof(buffer
);
1960 strcpy(buffer
,"MalformedTestThree");
1961 ok(HttpQueryInfoA(hRequest
,HTTP_QUERY_CUSTOM
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
,&len
,&index
),"Unable to query header\n");
1962 ok(index
== 1, "Index was not incremented\n");
1963 ok(strcmp(buffer
,"value3")==0, "incorrect string was returned(%s)\n",buffer
);
1965 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization: Basic\r\n", -1, HTTP_ADDREQ_FLAG_ADD
);
1966 ok(ret
, "unable to add header %u\n", GetLastError());
1970 len
= sizeof(buffer
);
1971 ret
= HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
);
1972 ok(ret
, "unable to query header %u\n", GetLastError());
1973 ok(index
== 1, "index was not incremented\n");
1974 ok(!strcmp(buffer
, "Basic"), "incorrect string was returned (%s)\n", buffer
);
1976 ret
= HttpAddRequestHeadersA(hRequest
, "Authorization:\r\n", -1, HTTP_ADDREQ_FLAG_REPLACE
);
1977 ok(ret
, "unable to remove header %u\n", GetLastError());
1980 len
= sizeof(buffer
);
1981 SetLastError(0xdeadbeef);
1982 ok(!HttpQueryInfoA(hRequest
, HTTP_QUERY_AUTHORIZATION
|HTTP_QUERY_FLAG_REQUEST_HEADERS
, buffer
, &len
, &index
),
1983 "header still present\n");
1984 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "got %u\n", GetLastError());
1986 ok(InternetCloseHandle(hRequest
), "Close request handle failed\n");
1988 ok(InternetCloseHandle(hConnect
), "Close connect handle failed\n");
1989 ok(InternetCloseHandle(hSession
), "Close session handle failed\n");
1992 static const char garbagemsg
[] =
1993 "Garbage: Header\r\n";
1995 static const char contmsg
[] =
1996 "HTTP/1.1 100 Continue\r\n";
1998 static const char expandcontmsg
[] =
1999 "HTTP/1.1 100 Continue\r\n"
2000 "Server: winecontinue\r\n"
2001 "Tag: something witty\r\n";
2003 static const char okmsg
[] =
2004 "HTTP/1.1 200 OK\r\n"
2005 "Server: winetest\r\n"
2008 static const char okmsg2
[] =
2009 "HTTP/1.1 200 OK\r\n"
2010 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
2011 "Server: winetest\r\n"
2012 "Content-Length: 0\r\n"
2013 "Set-Cookie: one\r\n"
2014 "Set-Cookie: two\r\n"
2017 static const char okmsg_cookie_path
[] =
2018 "HTTP/1.1 200 OK\r\n"
2019 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
2020 "Server: winetest\r\n"
2021 "Content-Length: 0\r\n"
2022 "Set-Cookie: subcookie2=data; path=/test_cookie_set_path\r\n"
2025 static const char okmsg_cookie
[] =
2026 "HTTP/1.1 200 OK\r\n"
2027 "Date: Mon, 01 Dec 2008 13:44:34 GMT\r\n"
2028 "Server: winetest\r\n"
2029 "Content-Length: 0\r\n"
2030 "Set-Cookie: testcookie=testvalue\r\n"
2033 static const char notokmsg
[] =
2034 "HTTP/1.1 400 Bad Request\r\n"
2035 "Server: winetest\r\n"
2038 static const char noauthmsg
[] =
2039 "HTTP/1.1 401 Unauthorized\r\n"
2040 "Server: winetest\r\n"
2041 "Connection: close\r\n"
2042 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
2045 static const char noauthmsg2
[] =
2046 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed\r\n"
2047 "HTTP/1.0 401 Anonymous requests or requests on unsecure channel are not allowed"
2049 "Server: winetest\r\n";
2051 static const char proxymsg
[] =
2052 "HTTP/1.1 407 Proxy Authentication Required\r\n"
2053 "Server: winetest\r\n"
2054 "Proxy-Connection: close\r\n"
2055 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
2058 static const char page1
[] =
2060 "<HEAD><TITLE>wininet test page</TITLE></HEAD>\r\n"
2061 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
2064 static const char ok_with_length
[] =
2065 "HTTP/1.1 200 OK\r\n"
2066 "Connection: Keep-Alive\r\n"
2067 "Content-Length: 18\r\n\r\n"
2068 "HTTP/1.1 211 OK\r\n\r\n";
2070 static const char ok_with_length2
[] =
2071 "HTTP/1.1 210 OK\r\n"
2072 "Connection: Keep-Alive\r\n"
2073 "Content-Length: 19\r\n\r\n"
2074 "HTTP/1.1 211 OK\r\n\r\n";
2076 struct server_info
{
2081 static int test_cache_gzip
;
2082 static const char *send_buffer
;
2083 static int server_socket
;
2085 static DWORD CALLBACK
server_thread(LPVOID param
)
2087 struct server_info
*si
= param
;
2088 int r
, c
= -1, i
, on
, count
= 0;
2090 struct sockaddr_in sa
;
2094 int last_request
= 0;
2095 char host_header
[22];
2096 char host_header_override
[30];
2097 static int test_no_cache
= 0;
2099 WSAStartup(MAKEWORD(1,1), &wsaData
);
2101 s
= socket(AF_INET
, SOCK_STREAM
, 0);
2102 if (s
== INVALID_SOCKET
)
2106 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, (char*)&on
, sizeof on
);
2108 memset(&sa
, 0, sizeof sa
);
2109 sa
.sin_family
= AF_INET
;
2110 sa
.sin_port
= htons(si
->port
);
2111 sa
.sin_addr
.S_un
.S_addr
= inet_addr("127.0.0.1");
2113 r
= bind(s
, (struct sockaddr
*) &sa
, sizeof sa
);
2119 SetEvent(si
->hEvent
);
2121 sprintf(host_header
, "Host: localhost:%d", si
->port
);
2122 sprintf(host_header_override
, "Host: test.local:%d\r\n", si
->port
);
2123 buffer
= HeapAlloc(GetProcessHeap(), 0, buffer_size
= 1000);
2128 c
= accept(s
, NULL
, NULL
);
2130 memset(buffer
, 0, buffer_size
);
2133 if(i
== buffer_size
)
2134 buffer
= HeapReAlloc(GetProcessHeap(), 0, buffer
, buffer_size
*= 2);
2136 r
= recv(c
, buffer
+i
, 1, 0);
2140 if (buffer
[i
-2] == '\n' && buffer
[i
] == '\n' &&
2141 buffer
[i
-3] == '\r' && buffer
[i
-1] == '\r')
2144 if (strstr(buffer
, "GET /test1"))
2146 if (!strstr(buffer
, "Content-Length: 0"))
2148 send(c
, okmsg
, sizeof okmsg
-1, 0);
2149 send(c
, page1
, sizeof page1
-1, 0);
2152 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2154 if (strstr(buffer
, "CONNECT "))
2156 if (!strstr(buffer
, "Content-Length: 0"))
2157 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2159 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2161 if (strstr(buffer
, "/test2"))
2163 if (strstr(buffer
, "Proxy-Authorization: Basic bWlrZToxMTAx"))
2165 send(c
, okmsg
, sizeof okmsg
-1, 0);
2166 send(c
, page1
, sizeof page1
-1, 0);
2169 send(c
, proxymsg
, sizeof proxymsg
-1, 0);
2171 if (strstr(buffer
, "/test3"))
2173 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2174 send(c
, okmsg
, sizeof okmsg
-1, 0);
2176 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2178 if (strstr(buffer
, "/test4"))
2180 if (strstr(buffer
, "Connection: Close"))
2181 send(c
, okmsg
, sizeof okmsg
-1, 0);
2183 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2185 if (strstr(buffer
, "POST /test5") ||
2186 strstr(buffer
, "RPC_IN_DATA /test5") ||
2187 strstr(buffer
, "RPC_OUT_DATA /test5"))
2189 if (strstr(buffer
, "Content-Length: 0"))
2191 send(c
, okmsg
, sizeof okmsg
-1, 0);
2192 send(c
, page1
, sizeof page1
-1, 0);
2195 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2197 if (strstr(buffer
, "GET /test6"))
2199 send(c
, contmsg
, sizeof contmsg
-1, 0);
2200 send(c
, contmsg
, sizeof contmsg
-1, 0);
2201 send(c
, okmsg
, sizeof okmsg
-1, 0);
2202 send(c
, page1
, sizeof page1
-1, 0);
2204 if (strstr(buffer
, "POST /test7"))
2206 if (strstr(buffer
, "Content-Length: 100"))
2208 if (strstr(buffer
, "POST /test7b"))
2209 recvfrom(c
, buffer
, buffer_size
, 0, NULL
, NULL
);
2210 send(c
, okmsg
, sizeof okmsg
-1, 0);
2211 send(c
, page1
, sizeof page1
-1, 0);
2214 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2216 if (strstr(buffer
, "/test8"))
2218 if (!strstr(buffer
, "Connection: Close") &&
2219 strstr(buffer
, "Connection: Keep-Alive") &&
2220 !strstr(buffer
, "Cache-Control: no-cache") &&
2221 !strstr(buffer
, "Pragma: no-cache") &&
2222 strstr(buffer
, host_header
))
2223 send(c
, okmsg
, sizeof okmsg
-1, 0);
2225 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2227 if (strstr(buffer
, "/test9"))
2229 if (!strstr(buffer
, "Connection: Close") &&
2230 !strstr(buffer
, "Connection: Keep-Alive") &&
2231 !strstr(buffer
, "Cache-Control: no-cache") &&
2232 !strstr(buffer
, "Pragma: no-cache") &&
2233 strstr(buffer
, host_header
))
2234 send(c
, okmsg
, sizeof okmsg
-1, 0);
2236 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2238 if (strstr(buffer
, "/testA"))
2240 if (!strstr(buffer
, "Connection: Close") &&
2241 !strstr(buffer
, "Connection: Keep-Alive") &&
2242 (strstr(buffer
, "Cache-Control: no-cache") ||
2243 strstr(buffer
, "Pragma: no-cache")) &&
2244 strstr(buffer
, host_header
))
2245 send(c
, okmsg
, sizeof okmsg
-1, 0);
2247 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2249 if (strstr(buffer
, "/testC"))
2251 if (strstr(buffer
, "cookie=biscuit"))
2252 send(c
, okmsg
, sizeof okmsg
-1, 0);
2254 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2256 if (strstr(buffer
, "/testD"))
2258 send(c
, okmsg2
, sizeof okmsg2
-1, 0);
2260 if (strstr(buffer
, "/testE"))
2262 send(c
, noauthmsg2
, sizeof noauthmsg2
-1, 0);
2264 if (strstr(buffer
, "GET /quit"))
2266 send(c
, okmsg
, sizeof okmsg
-1, 0);
2267 send(c
, page1
, sizeof page1
-1, 0);
2270 if (strstr(buffer
, "GET /testF"))
2272 send(c
, expandcontmsg
, sizeof expandcontmsg
-1, 0);
2273 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2274 send(c
, contmsg
, sizeof contmsg
-1, 0);
2275 send(c
, garbagemsg
, sizeof garbagemsg
-1, 0);
2276 send(c
, okmsg
, sizeof okmsg
-1, 0);
2277 send(c
, page1
, sizeof page1
-1, 0);
2279 if (strstr(buffer
, "GET /testG"))
2281 send(c
, page1
, sizeof page1
-1, 0);
2284 if (strstr(buffer
, "GET /testJ"))
2289 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2293 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2297 if (strstr(buffer
, "GET /testH"))
2299 send(c
, ok_with_length2
, sizeof(ok_with_length2
)-1, 0);
2300 recvfrom(c
, buffer
, buffer_size
, 0, NULL
, NULL
);
2301 send(c
, ok_with_length
, sizeof(ok_with_length
)-1, 0);
2304 if (strstr(buffer
, "GET /test_no_content"))
2306 static const char nocontentmsg
[] = "HTTP/1.1 204 No Content\r\nConnection: close\r\n\r\n";
2307 send(c
, nocontentmsg
, sizeof(nocontentmsg
)-1, 0);
2309 if (strstr(buffer
, "GET /test_conn_close"))
2311 static const char conn_close_response
[] = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\nsome content";
2312 send(c
, conn_close_response
, sizeof(conn_close_response
)-1, 0);
2313 WaitForSingleObject(conn_close_event
, INFINITE
);
2314 trace("closing connection\n");
2316 if (strstr(buffer
, "GET /test_cache_control_no_cache"))
2318 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: no-cache\r\n\r\nsome content";
2319 if(!test_no_cache
++)
2320 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2322 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2324 if (strstr(buffer
, "GET /test_cache_control_no_store"))
2326 static const char no_cache_response
[] = "HTTP/1.1 200 OK\r\nCache-Control: junk, \t No-StOrE\r\n\r\nsome content";
2327 send(c
, no_cache_response
, sizeof(no_cache_response
)-1, 0);
2329 if (strstr(buffer
, "GET /test_cache_gzip"))
2331 static const char gzip_response
[] = "HTTP/1.1 200 OK\r\nContent-Encoding: gzip\r\nContent-Type: text/html\r\n\r\n"
2332 "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\x4b\xaf\xca\x2c\x50\x28"
2333 "\x49\x2d\x2e\xe1\x02\x00\x62\x92\xc7\x6c\x0a\x00\x00\x00";
2334 if(!test_cache_gzip
++)
2335 send(c
, gzip_response
, sizeof(gzip_response
), 0);
2337 send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2339 if (strstr(buffer
, "HEAD /test_head")) {
2340 static const char head_response
[] =
2341 "HTTP/1.1 200 OK\r\n"
2342 "Connection: Keep-Alive\r\n"
2343 "Content-Length: 100\r\n"
2346 send(c
, head_response
, sizeof(head_response
), 0);
2349 if (strstr(buffer
, "GET /send_from_buffer"))
2350 send(c
, send_buffer
, strlen(send_buffer
), 0);
2351 if (strstr(buffer
, "/test_cache_control_verb"))
2353 if (!memcmp(buffer
, "GET ", sizeof("GET ")-1) &&
2354 !strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2355 else if (strstr(buffer
, "Cache-Control: no-cache\r\n")) send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2356 else send(c
, notokmsg
, sizeof(notokmsg
)-1, 0);
2358 if (strstr(buffer
, "/test_request_content_length"))
2360 static char msg
[] = "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\n\r\n";
2361 static int seen_content_length
;
2363 if (!seen_content_length
)
2365 if (strstr(buffer
, "Content-Length: 0"))
2367 seen_content_length
= 1;
2368 send(c
, msg
, sizeof msg
-1, 0);
2370 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2371 WaitForSingleObject(hCompleteEvent
, 5000);
2375 if (strstr(buffer
, "Content-Length: 0")) send(c
, msg
, sizeof msg
-1, 0);
2376 else send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2377 WaitForSingleObject(hCompleteEvent
, 5000);
2380 if (strstr(buffer
, "GET /test_premature_disconnect"))
2381 trace("closing connection\n");
2382 if (strstr(buffer
, "HEAD /upload.txt"))
2384 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2385 send(c
, okmsg
, sizeof okmsg
-1, 0);
2387 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2389 if (strstr(buffer
, "PUT /upload2.txt"))
2391 if (strstr(buffer
, "Authorization: Basic dXNlcjpwd2Q="))
2392 send(c
, okmsg
, sizeof okmsg
-1, 0);
2394 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2396 if (strstr(buffer
, "/test_cookie_path1"))
2398 if (strstr(buffer
, "subcookie=data"))
2399 send(c
, okmsg
, sizeof okmsg
-1, 0);
2401 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2403 if (strstr(buffer
, "/test_cookie_path2"))
2405 if (strstr(buffer
, "subcookie2=data"))
2406 send(c
, okmsg
, sizeof okmsg
-1, 0);
2408 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2410 if (strstr(buffer
, "/test_cookie_set_path"))
2412 send(c
, okmsg_cookie_path
, sizeof okmsg_cookie_path
-1, 0);
2414 if (strstr(buffer
, "/test_cookie_merge"))
2416 if (strstr(buffer
, "subcookie=data") &&
2417 !strstr(buffer
, "manual_cookie=test"))
2418 send(c
, okmsg
, sizeof okmsg
-1, 0);
2420 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2422 if (strstr(buffer
, "/test_cookie_set_host_override"))
2424 send(c
, okmsg_cookie
, sizeof okmsg_cookie
-1, 0);
2426 if (strstr(buffer
, "/test_cookie_check_host_override"))
2428 if (strstr(buffer
, "Cookie:") && strstr(buffer
, "testcookie=testvalue"))
2429 send(c
, okmsg
, sizeof okmsg
-1, 0);
2431 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2433 if (strstr(buffer
, "/test_cookie_check_different_host"))
2435 if (!strstr(buffer
, "foo") &&
2436 strstr(buffer
, "cookie=biscuit"))
2437 send(c
, okmsg
, sizeof okmsg
-1, 0);
2439 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2441 if (strstr(buffer
, "/test_host_override"))
2443 if (strstr(buffer
, host_header_override
))
2444 send(c
, okmsg
, sizeof okmsg
-1, 0);
2446 send(c
, notokmsg
, sizeof notokmsg
-1, 0);
2448 if (strstr(buffer
, "/async_read"))
2450 const char *page1_mid
= page1
+ (sizeof page1
- 1)/2;
2451 const char *page1_end
= page1
+ sizeof page1
- 1;
2452 send(c
, okmsg
, sizeof okmsg
-1, 0);
2453 send(c
, page1
, page1_mid
- page1
, 0);
2454 WaitForSingleObject(conn_wait_event
, INFINITE
);
2455 send(c
, page1_mid
, page1_end
- page1_mid
, 0);
2457 if (strstr(buffer
, "/socket"))
2460 SetEvent(server_req_rec_event
);
2461 WaitForSingleObject(conn_wait_event
, INFINITE
);
2463 if (strstr(buffer
, "/echo_request"))
2465 send(c
, okmsg
, sizeof(okmsg
)-1, 0);
2466 send(c
, buffer
, strlen(buffer
), 0);
2468 if (strstr(buffer
, "HEAD /test_auth_host1"))
2470 if (strstr(buffer
, "Authorization: Basic dGVzdDE6cGFzcw=="))
2471 send(c
, okmsg
, sizeof okmsg
-1, 0);
2473 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2475 if (strstr(buffer
, "HEAD /test_auth_host2"))
2477 if (strstr(buffer
, "Authorization: Basic dGVzdDE6cGFzczI="))
2478 send(c
, okmsg
, sizeof okmsg
-1, 0);
2480 send(c
, noauthmsg
, sizeof noauthmsg
-1, 0);
2485 } while (!last_request
);
2488 HeapFree(GetProcessHeap(), 0, buffer
);
2493 static void test_basic_request(int port
, const char *verb
, const char *url
)
2496 DWORD r
, count
, error
;
2499 trace("basic request %s %s\n", verb
, url
);
2501 open_simple_request(&req
, "localhost", port
, verb
, url
);
2503 SetLastError(0xdeadbeef);
2504 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
2505 error
= GetLastError();
2506 ok(error
== ERROR_SUCCESS
|| broken(error
!= ERROR_SUCCESS
), "expected ERROR_SUCCESS, got %u\n", error
);
2507 ok(r
, "HttpSendRequest failed: %u\n", GetLastError());
2510 memset(buffer
, 0, sizeof buffer
);
2511 SetLastError(0xdeadbeef);
2512 r
= InternetReadFile(req
.request
, buffer
, sizeof buffer
, &count
);
2513 ok(r
, "InternetReadFile failed %u\n", GetLastError());
2514 ok(count
== sizeof page1
- 1, "count was wrong\n");
2515 ok(!memcmp(buffer
, page1
, sizeof page1
), "http data wrong, got: %s\n", buffer
);
2517 close_request(&req
);
2520 static void test_proxy_indirect(int port
)
2526 open_simple_request(&req
, "localhost", port
, NULL
, "/test2");
2528 r
= HttpSendRequestA(req
.request
, NULL
, 0, NULL
, 0);
2529 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2532 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_PROXY_AUTHENTICATE
, buffer
, &sz
, NULL
);
2533 ok(r
|| GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo failed: %d\n", GetLastError());
2536 skip("missing proxy header, not testing remaining proxy headers\n");
2539 ok(!strcmp(buffer
, "Basic realm=\"placebo\""), "proxy auth info wrong\n");
2541 test_status_code(req
.request
, 407);
2542 test_request_flags(req
.request
, 0);
2545 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_STATUS_TEXT
, buffer
, &sz
, NULL
);
2546 ok(r
, "HttpQueryInfo failed\n");
2547 ok(!strcmp(buffer
, "Proxy Authentication Required"), "proxy text wrong\n");
2550 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_VERSION
, buffer
, &sz
, NULL
);
2551 ok(r
, "HttpQueryInfo failed\n");
2552 ok(!strcmp(buffer
, "HTTP/1.1"), "http version wrong\n");
2555 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_SERVER
, buffer
, &sz
, NULL
);
2556 ok(r
, "HttpQueryInfo failed\n");
2557 ok(!strcmp(buffer
, "winetest"), "http server wrong\n");
2560 r
= HttpQueryInfoA(req
.request
, HTTP_QUERY_CONTENT_ENCODING
, buffer
, &sz
, NULL
);
2561 ok(GetLastError() == ERROR_HTTP_HEADER_NOT_FOUND
, "HttpQueryInfo should fail\n");
2562 ok(r
== FALSE
, "HttpQueryInfo failed\n");
2565 close_request(&req
);
2568 static void test_proxy_direct(int port
)
2570 HINTERNET hi
, hc
, hr
;
2572 char buffer
[0x40], *url
;
2573 WCHAR bufferW
[0x40];
2574 static const char url_fmt
[] = "http://test.winehq.org:%u/test2";
2575 static CHAR username
[] = "mike",
2576 password
[] = "1101",
2577 useragent
[] = "winetest";
2578 static const WCHAR usernameW
[] = {'m','i','k','e',0},
2579 passwordW
[] = {'1','1','0','1',0},
2580 useragentW
[] = {'w','i','n','e','t','e','s','t',0};
2582 /* specify proxy type without the proxy and bypass */
2583 SetLastError(0xdeadbeef);
2584 hi
= InternetOpenW(NULL
, INTERNET_OPEN_TYPE_PROXY
, NULL
, NULL
, 0);
2585 error
= GetLastError();
2586 ok(error
== ERROR_INVALID_PARAMETER
||
2587 broken(error
== ERROR_SUCCESS
) /* WinXPProSP2 */, "got %u\n", error
);
2588 ok(hi
== NULL
|| broken(!!hi
) /* WinXPProSP2 */, "open should have failed\n");
2590 sprintf(buffer
, "localhost:%d\n", port
);
2591 hi
= InternetOpenA(NULL
, INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2592 ok(hi
!= NULL
, "open failed\n");
2594 /* try connect without authorization */
2595 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2596 ok(hc
!= NULL
, "connect failed\n");
2598 hr
= HttpOpenRequestA(hc
, NULL
, "/test2", NULL
, NULL
, NULL
, 0, 0);
2599 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2602 SetLastError(0xdeadbeef);
2603 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, NULL
, &sz
);
2604 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2605 ok(!r
, "unexpected success\n");
2606 ok(sz
== 1, "got %u\n", sz
);
2609 SetLastError(0xdeadbeef);
2610 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, NULL
, &sz
);
2611 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2612 ok(!r
, "unexpected success\n");
2613 ok(sz
== 1, "got %u\n", sz
);
2615 sz
= sizeof(buffer
);
2616 SetLastError(0xdeadbeef);
2617 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2618 ok(r
, "unexpected failure %u\n", GetLastError());
2619 ok(!sz
, "got %u\n", sz
);
2621 sz
= sizeof(buffer
);
2622 SetLastError(0xdeadbeef);
2623 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2624 ok(r
, "unexpected failure %u\n", GetLastError());
2625 ok(!sz
, "got %u\n", sz
);
2628 SetLastError(0xdeadbeef);
2629 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, NULL
, &sz
);
2630 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2631 ok(!r
, "unexpected success\n");
2632 ok(sz
== 1, "got %u\n", sz
);
2635 SetLastError(0xdeadbeef);
2636 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, NULL
, &sz
);
2637 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2638 ok(!r
, "unexpected success\n");
2639 ok(sz
== 1, "got %u\n", sz
);
2641 sz
= sizeof(buffer
);
2642 SetLastError(0xdeadbeef);
2643 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2644 ok(r
, "unexpected failure %u\n", GetLastError());
2645 ok(!sz
, "got %u\n", sz
);
2647 sz
= sizeof(buffer
);
2648 SetLastError(0xdeadbeef);
2649 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2650 ok(r
, "unexpected failure %u\n", GetLastError());
2651 ok(!sz
, "got %u\n", sz
);
2654 SetLastError(0xdeadbeef);
2655 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, NULL
, &sz
);
2656 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2657 ok(!r
, "unexpected success\n");
2658 ok(sz
== 34, "got %u\n", sz
);
2660 sz
= sizeof(buffer
);
2661 SetLastError(0xdeadbeef);
2662 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2663 ok(r
, "unexpected failure %u\n", GetLastError());
2664 ok(sz
== 33, "got %u\n", sz
);
2666 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2667 ok(r
|| broken(!r
), "HttpSendRequest failed %u\n", GetLastError());
2670 win_skip("skipping proxy tests on broken wininet\n");
2674 test_status_code(hr
, 407);
2676 /* set the user + password then try again */
2677 r
= InternetSetOptionA(hi
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2678 ok(!r
, "unexpected success\n");
2680 r
= InternetSetOptionA(hc
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2681 ok(r
, "failed to set user\n");
2683 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 4);
2684 ok(r
, "failed to set user\n");
2688 SetLastError(0xdeadbeef);
2689 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2690 ok(!r
, "unexpected failure %u\n", GetLastError());
2691 ok(!buffer
[0], "got %s\n", buffer
);
2692 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2696 SetLastError(0xdeadbeef);
2697 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2698 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2699 ok(!r
, "unexpected success\n");
2700 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2704 SetLastError(0xdeadbeef);
2705 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2706 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2707 ok(!r
, "unexpected success\n");
2708 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2711 sz
= sizeof(buffer
);
2712 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2713 ok(r
, "failed to get username\n");
2714 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2715 ok(sz
== strlen(username
), "got %u\n", sz
);
2718 sz
= sizeof(bufferW
);
2719 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_USERNAME
, bufferW
, &sz
);
2720 ok(r
, "failed to get username\n");
2721 ok(!lstrcmpW(bufferW
, usernameW
), "wrong username\n");
2722 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2724 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, username
, 1);
2725 ok(r
, "failed to set user\n");
2728 sz
= sizeof(buffer
);
2729 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_USERNAME
, buffer
, &sz
);
2730 ok(r
, "failed to get username\n");
2731 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2732 ok(sz
== strlen(username
), "got %u\n", sz
);
2734 r
= InternetSetOptionA(hi
, INTERNET_OPTION_USER_AGENT
, useragent
, 1);
2735 ok(r
, "failed to set useragent\n");
2739 SetLastError(0xdeadbeef);
2740 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2741 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2742 ok(!r
, "unexpected success\n");
2743 ok(sz
== strlen(useragent
) + 1, "got %u\n", sz
);
2746 sz
= sizeof(buffer
);
2747 r
= InternetQueryOptionA(hi
, INTERNET_OPTION_USER_AGENT
, buffer
, &sz
);
2748 ok(r
, "failed to get user agent\n");
2749 ok(!strcmp(buffer
, useragent
), "got %s\n", buffer
);
2750 ok(sz
== strlen(useragent
), "got %u\n", sz
);
2754 SetLastError(0xdeadbeef);
2755 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2756 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2757 ok(!r
, "unexpected success\n");
2758 ok(sz
== (lstrlenW(useragentW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2761 sz
= sizeof(bufferW
);
2762 r
= InternetQueryOptionW(hi
, INTERNET_OPTION_USER_AGENT
, bufferW
, &sz
);
2763 ok(r
, "failed to get user agent\n");
2764 ok(!lstrcmpW(bufferW
, useragentW
), "wrong user agent\n");
2765 ok(sz
== lstrlenW(useragentW
), "got %u\n", sz
);
2767 r
= InternetSetOptionA(hr
, INTERNET_OPTION_USERNAME
, username
, 1);
2768 ok(r
, "failed to set user\n");
2772 SetLastError(0xdeadbeef);
2773 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2774 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2775 ok(!r
, "unexpected success\n");
2776 ok(sz
== strlen(username
) + 1, "got %u\n", sz
);
2779 sz
= sizeof(buffer
);
2780 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_USERNAME
, buffer
, &sz
);
2781 ok(r
, "failed to get user\n");
2782 ok(!strcmp(buffer
, username
), "got %s\n", buffer
);
2783 ok(sz
== strlen(username
), "got %u\n", sz
);
2787 SetLastError(0xdeadbeef);
2788 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2789 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2790 ok(!r
, "unexpected success\n");
2791 ok(sz
== (lstrlenW(usernameW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2794 sz
= sizeof(bufferW
);
2795 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_USERNAME
, bufferW
, &sz
);
2796 ok(r
, "failed to get user\n");
2797 ok(!lstrcmpW(bufferW
, usernameW
), "wrong user\n");
2798 ok(sz
== lstrlenW(usernameW
), "got %u\n", sz
);
2800 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PASSWORD
, password
, 1);
2801 ok(r
, "failed to set password\n");
2805 SetLastError(0xdeadbeef);
2806 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2807 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2808 ok(!r
, "unexpected success\n");
2809 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2812 sz
= sizeof(buffer
);
2813 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PASSWORD
, buffer
, &sz
);
2814 ok(r
, "failed to get password\n");
2815 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2816 ok(sz
== strlen(password
), "got %u\n", sz
);
2820 SetLastError(0xdeadbeef);
2821 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2822 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2823 ok(!r
, "unexpected success\n");
2824 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2827 sz
= sizeof(bufferW
);
2828 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PASSWORD
, bufferW
, &sz
);
2829 ok(r
, "failed to get password\n");
2830 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2831 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2833 url
= HeapAlloc(GetProcessHeap(), 0, strlen(url_fmt
) + 11);
2834 sprintf(url
, url_fmt
, port
);
2837 SetLastError(0xdeadbeef);
2838 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2839 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2840 ok(!r
, "unexpected success\n");
2841 ok(sz
== strlen(url
) + 1, "got %u\n", sz
);
2844 sz
= sizeof(buffer
);
2845 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_URL
, buffer
, &sz
);
2846 ok(r
, "failed to get url\n");
2847 ok(!strcmp(buffer
, url
), "got %s\n", buffer
);
2848 ok(sz
== strlen(url
), "got %u\n", sz
);
2852 SetLastError(0xdeadbeef);
2853 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2854 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2855 ok(!r
, "unexpected success\n");
2856 ok(sz
== (strlen(url
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2859 sz
= sizeof(bufferW
);
2860 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_URL
, bufferW
, &sz
);
2861 ok(r
, "failed to get url\n");
2862 ok(!strcmp_wa(bufferW
, url
), "wrong url\n");
2863 ok(sz
== strlen(url
), "got %u\n", sz
);
2864 HeapFree(GetProcessHeap(), 0, url
);
2866 r
= InternetSetOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, password
, 4);
2867 ok(r
, "failed to set password\n");
2871 SetLastError(0xdeadbeef);
2872 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2873 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2874 ok(!r
, "unexpected success\n");
2875 ok(sz
== strlen(password
) + 1, "got %u\n", sz
);
2878 sz
= sizeof(buffer
);
2879 r
= InternetQueryOptionA(hr
, INTERNET_OPTION_PROXY_PASSWORD
, buffer
, &sz
);
2880 ok(r
, "failed to get password\n");
2881 ok(!strcmp(buffer
, password
), "got %s\n", buffer
);
2882 ok(sz
== strlen(password
), "got %u\n", sz
);
2886 SetLastError(0xdeadbeef);
2887 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2888 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER
, "got %u\n", GetLastError());
2889 ok(!r
, "unexpected success\n");
2890 ok(sz
== (lstrlenW(passwordW
) + 1) * sizeof(WCHAR
), "got %u\n", sz
);
2893 sz
= sizeof(bufferW
);
2894 r
= InternetQueryOptionW(hr
, INTERNET_OPTION_PROXY_PASSWORD
, bufferW
, &sz
);
2895 ok(r
, "failed to get password\n");
2896 ok(!lstrcmpW(bufferW
, passwordW
), "wrong password\n");
2897 ok(sz
== lstrlenW(passwordW
), "got %u\n", sz
);
2899 r
= HttpSendRequestW(hr
, NULL
, 0, NULL
, 0);
2902 win_skip("skipping proxy tests on broken wininet\n");
2905 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2907 r
= HttpQueryInfoA(hr
, HTTP_QUERY_STATUS_CODE
, buffer
, &sz
, NULL
);
2908 ok(r
, "HttpQueryInfo failed\n");
2909 ok(!strcmp(buffer
, "200"), "proxy code wrong\n");
2911 InternetCloseHandle(hr
);
2912 InternetCloseHandle(hc
);
2913 InternetCloseHandle(hi
);
2915 sprintf(buffer
, "localhost:%d\n", port
);
2916 hi
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_PROXY
, buffer
, NULL
, 0);
2917 ok(hi
!= NULL
, "InternetOpen failed\n");
2919 hc
= InternetConnectA(hi
, "test.winehq.org", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2920 ok(hc
!= NULL
, "InternetConnect failed\n");
2922 hr
= HttpOpenRequestA(hc
, "POST", "/test2", NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
2923 ok(hr
!= NULL
, "HttpOpenRequest failed\n");
2925 r
= HttpSendRequestA(hr
, NULL
, 0, (char *)"data", sizeof("data"));
2926 ok(r
, "HttpSendRequest failed %u\n", GetLastError());
2928 test_status_code(hr
, 407);
2931 InternetCloseHandle(hr
);
2932 InternetCloseHandle(hc
);
2933 InternetCloseHandle(hi
);
2936 static void test_header_handling_order(int port
)
2938 static const char authorization
[] = "Authorization: Basic dXNlcjpwd2Q=";
2939 static const char connection
[] = "Connection: Close";
2940 static const char *types
[2] = { "*", NULL
};
2942 HINTERNET session
, connect
, request
;
2943 DWORD size
, status
, data_len
;
2946 session
= InternetOpenA("winetest", INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
2947 ok(session
!= NULL
, "InternetOpen failed\n");
2949 connect
= InternetConnectA(session
, "localhost", port
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, 0, 0);
2950 ok(connect
!= NULL
, "InternetConnect failed\n");
2952 request
= HttpOpenRequestA(connect
, NULL
, "/test3", NULL
, NULL
, types
, INTERNET_FLAG_KEEP_CONNECTION
, 0);
2953 ok(request
!= NULL
, "HttpOpenRequest failed\n");
2955 ret
= HttpAddRequestHeadersA(request
, authorization
, ~0u, HTTP_ADDREQ_FLAG_ADD
);
2956 ok(ret
, "HttpAddRequestHeaders failed\n");