4 * Copyright 2008 Google (Zac Brown)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include <httprequest.h>
33 #include "wine/test.h"
35 static const WCHAR test_useragent[] =
36 {'W','i','n','e',' ','R','e','g','r','e','s','s','i','o','n',' ','T','e','s','t',0};
37 static const WCHAR test_server[] = {'w','i','n','e','h','q','.','o','r','g',0};
38 static const WCHAR localhostW[] = {'l','o','c','a','l','h','o','s','t',0};
40 static BOOL proxy_active(void)
42 WINHTTP_PROXY_INFO proxy_info;
45 if (WinHttpGetDefaultProxyConfiguration(&proxy_info))
47 active = (proxy_info.lpszProxy != NULL);
49 GlobalFree((HGLOBAL) proxy_info.lpszProxy);
50 if (proxy_info.lpszProxyBypass != NULL)
51 GlobalFree((HGLOBAL) proxy_info.lpszProxyBypass);
59 static void test_QueryOption(void)
62 HINTERNET session, request, connection;
65 SetLastError(0xdeadbeef);
66 session = WinHttpOpen(test_useragent, 0, 0, 0, 0);
67 ok(session != NULL, "WinHttpOpen failed to open session, error %u\n", GetLastError());
69 SetLastError(0xdeadbeef);
70 ret = WinHttpQueryOption(session, WINHTTP_OPTION_REDIRECT_POLICY, NULL, NULL);
71 ok(!ret, "should fail to set redirect policy %u\n", GetLastError());
72 ok(GetLastError() == ERROR_INVALID_PARAMETER,
73 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
76 SetLastError(0xdeadbeef);
77 ret = WinHttpQueryOption(session, WINHTTP_OPTION_REDIRECT_POLICY, NULL, &size);
78 ok(!ret, "should fail to query option\n");
79 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
80 "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
81 ok(size == 4, "expected 4, got %u\n", size);
84 size = sizeof(feature) - 1;
85 SetLastError(0xdeadbeef);
86 ret = WinHttpQueryOption(session, WINHTTP_OPTION_REDIRECT_POLICY, &feature, &size);
87 ok(!ret, "should fail to query option\n");
88 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
89 "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
90 ok(size == 4, "expected 4, got %u\n", size);
93 size = sizeof(feature) + 1;
94 SetLastError(0xdeadbeef);
95 ret = WinHttpQueryOption(session, WINHTTP_OPTION_REDIRECT_POLICY, &feature, &size);
96 ok(ret, "failed to query option %u\n", GetLastError());
97 ok(size == sizeof(feature), "WinHttpQueryOption should set the size: %u\n", size);
98 ok(feature == WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP,
99 "expected WINHTTP_OPTION_REDIRECT_POLICY_DISALLOW_HTTPS_TO_HTTP, got %#x\n", feature);
101 SetLastError(0xdeadbeef);
102 ret = WinHttpSetOption(session, WINHTTP_OPTION_REDIRECT_POLICY, NULL, sizeof(feature));
103 ok(!ret, "should fail to set redirect policy %u\n", GetLastError());
104 ok(GetLastError() == ERROR_INVALID_PARAMETER,
105 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
107 feature = WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS;
108 SetLastError(0xdeadbeef);
109 ret = WinHttpSetOption(session, WINHTTP_OPTION_REDIRECT_POLICY, &feature, sizeof(feature) - 1);
110 ok(!ret, "should fail to set redirect policy %u\n", GetLastError());
111 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
112 "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
114 feature = WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS;
115 SetLastError(0xdeadbeef);
116 ret = WinHttpSetOption(session, WINHTTP_OPTION_REDIRECT_POLICY, &feature, sizeof(feature) + 1);
117 ok(!ret, "should fail to set redirect policy %u\n", GetLastError());
118 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
119 "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
121 feature = WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS;
122 SetLastError(0xdeadbeef);
123 ret = WinHttpSetOption(session, WINHTTP_OPTION_REDIRECT_POLICY, &feature, sizeof(feature));
124 ok(ret, "failed to set redirect policy %u\n", GetLastError());
126 feature = 0xdeadbeef;
127 size = sizeof(feature);
128 SetLastError(0xdeadbeef);
129 ret = WinHttpQueryOption(session, WINHTTP_OPTION_REDIRECT_POLICY, &feature, &size);
130 ok(ret, "failed to query option %u\n", GetLastError());
131 ok(feature == WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS,
132 "expected WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS, got %#x\n", feature);
134 feature = WINHTTP_DISABLE_COOKIES;
135 SetLastError(0xdeadbeef);
136 ret = WinHttpSetOption(session, WINHTTP_OPTION_DISABLE_FEATURE, &feature, sizeof(feature));
137 ok(!ret, "should fail to set disable feature for a session\n");
138 ok(GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_TYPE,
139 "expected ERROR_WINHTTP_INCORRECT_HANDLE_TYPE, got %u\n", GetLastError());
141 SetLastError(0xdeadbeef);
142 connection = WinHttpConnect(session, test_server, INTERNET_DEFAULT_HTTP_PORT, 0);
143 ok(connection != NULL, "WinHttpConnect failed to open a connection, error: %u\n", GetLastError());
145 feature = WINHTTP_DISABLE_COOKIES;
146 SetLastError(0xdeadbeef);
147 ret = WinHttpSetOption(connection, WINHTTP_OPTION_DISABLE_FEATURE, &feature, sizeof(feature));
148 ok(!ret, "should fail to set disable feature for a connection\n");
149 ok(GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_TYPE,
150 "expected ERROR_WINHTTP_INCORRECT_HANDLE_TYPE, got %u\n", GetLastError());
152 SetLastError(0xdeadbeef);
153 request = WinHttpOpenRequest(connection, NULL, NULL, NULL, WINHTTP_NO_REFERER,
154 WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
155 if (request == NULL && GetLastError() == ERROR_WINHTTP_NAME_NOT_RESOLVED)
157 skip("Network unreachable, skipping the test\n");
161 feature = 0xdeadbeef;
162 size = sizeof(feature);
163 SetLastError(0xdeadbeef);
164 ret = WinHttpQueryOption(request, WINHTTP_OPTION_DISABLE_FEATURE, &feature, &size);
165 ok(!ret, "should fail to query disable feature for a request\n");
166 ok(GetLastError() == ERROR_INVALID_PARAMETER,
167 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
170 size = sizeof(feature);
171 SetLastError(0xdeadbeef);
172 ret = WinHttpSetOption(request, WINHTTP_OPTION_DISABLE_FEATURE, &feature, sizeof(feature));
173 ok(ret, "failed to set feature %u\n", GetLastError());
175 feature = 0xffffffff;
176 size = sizeof(feature);
177 SetLastError(0xdeadbeef);
178 ret = WinHttpSetOption(request, WINHTTP_OPTION_DISABLE_FEATURE, &feature, sizeof(feature));
179 ok(ret, "failed to set feature %u\n", GetLastError());
181 feature = WINHTTP_DISABLE_COOKIES;
182 size = sizeof(feature);
183 SetLastError(0xdeadbeef);
184 ret = WinHttpSetOption(request, WINHTTP_OPTION_DISABLE_FEATURE, &feature, sizeof(feature));
185 ok(ret, "failed to set feature %u\n", GetLastError());
188 SetLastError(0xdeadbeef);
189 ret = WinHttpQueryOption(request, WINHTTP_OPTION_DISABLE_FEATURE, NULL, &size);
190 ok(!ret, "should fail to query disable feature for a request\n");
191 ok(GetLastError() == ERROR_INVALID_PARAMETER,
192 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
194 SetLastError(0xdeadbeef);
195 ret = WinHttpCloseHandle(request);
196 ok(ret, "WinHttpCloseHandle failed on closing request: %u\n", GetLastError());
199 SetLastError(0xdeadbeef);
200 ret = WinHttpCloseHandle(connection);
201 ok(ret, "WinHttpCloseHandle failed on closing connection: %u\n", GetLastError());
202 SetLastError(0xdeadbeef);
203 ret = WinHttpCloseHandle(session);
204 ok(ret, "WinHttpCloseHandle failed on closing session: %u\n", GetLastError());
207 static void test_OpenRequest (void)
210 HINTERNET session, request, connection;
212 session = WinHttpOpen(test_useragent, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
213 WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
214 ok(session != NULL, "WinHttpOpen failed to open session.\n");
216 /* Test with a bad server name */
217 SetLastError(0xdeadbeef);
218 connection = WinHttpConnect(session, NULL, INTERNET_DEFAULT_HTTP_PORT, 0);
219 ok (connection == NULL, "WinHttpConnect succeeded in opening connection to NULL server argument.\n");
220 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
222 /* Test with a valid server name */
223 connection = WinHttpConnect (session, test_server, INTERNET_DEFAULT_HTTP_PORT, 0);
224 ok(connection != NULL, "WinHttpConnect failed to open a connection, error: %u.\n", GetLastError());
226 request = WinHttpOpenRequest(connection, NULL, NULL, NULL, WINHTTP_NO_REFERER,
227 WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
228 if (request == NULL && GetLastError() == ERROR_WINHTTP_NAME_NOT_RESOLVED)
230 skip("Network unreachable, skipping.\n");
233 ok(request != NULL, "WinHttpOpenrequest failed to open a request, error: %u.\n", GetLastError());
235 ret = WinHttpSendRequest(request, WINHTTP_NO_ADDITIONAL_HEADERS, 0, NULL, 0, 0, 0);
236 if (!ret && GetLastError() == ERROR_WINHTTP_CANNOT_CONNECT)
238 skip("Connection failed, skipping.\n");
241 ok(ret == TRUE, "WinHttpSendRequest failed: %u\n", GetLastError());
242 ret = WinHttpCloseHandle(request);
243 ok(ret == TRUE, "WinHttpCloseHandle failed on closing request, got %d.\n", ret);
246 ret = WinHttpCloseHandle(connection);
247 ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret);
248 ret = WinHttpCloseHandle(session);
249 ok(ret == TRUE, "WinHttpCloseHandle failed on closing session, got %d.\n", ret);
253 static void test_empty_headers_param(void)
255 static const WCHAR winehq[] = {'w','i','n','e','h','q','.','o','r','g',0};
256 static const WCHAR empty[] = {0};
257 HINTERNET ses, con, req;
260 ses = WinHttpOpen(test_useragent, 0, NULL, NULL, 0);
261 ok(ses != NULL, "failed to open session %u\n", GetLastError());
263 con = WinHttpConnect(ses, winehq, 80, 0);
264 ok(con != NULL, "failed to open a connection %u\n", GetLastError());
266 req = WinHttpOpenRequest(con, NULL, NULL, NULL, NULL, NULL, 0);
267 ok(req != NULL, "failed to open a request %u\n", GetLastError());
269 ret = WinHttpSendRequest(req, empty, 0, NULL, 0, 0, 0);
270 ok(ret, "failed to send request %u\n", GetLastError());
272 WinHttpCloseHandle(req);
273 WinHttpCloseHandle(con);
274 WinHttpCloseHandle(ses);
277 static void test_SendRequest (void)
279 HINTERNET session, request, connection;
280 DWORD header_len, optional_len, total_len, bytes_rw, size;
286 static const WCHAR test_site[] = {'c','r','o','s','s','o','v','e','r','.',
287 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0};
288 static const WCHAR content_type[] =
289 {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t','i','o','n',
290 '/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o','d','e','d',0};
291 static const WCHAR test_file[] = {'/','p','o','s','t','t','e','s','t','.','p','h','p',0};
292 static const WCHAR test_verb[] = {'P','O','S','T',0};
293 static CHAR post_data[] = "mode=Test";
294 static CHAR test_post[] = "mode => Test\\0\n";
297 total_len = optional_len = sizeof(post_data);
298 memset(buffer, 0xff, sizeof(buffer));
300 session = WinHttpOpen(test_useragent, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
301 WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
302 ok(session != NULL, "WinHttpOpen failed to open session.\n");
304 connection = WinHttpConnect (session, test_site, INTERNET_DEFAULT_HTTP_PORT, 0);
305 ok(connection != NULL, "WinHttpConnect failed to open a connection, error: %u.\n", GetLastError());
307 request = WinHttpOpenRequest(connection, test_verb, test_file, NULL, WINHTTP_NO_REFERER,
308 WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_BYPASS_PROXY_CACHE);
309 if (request == NULL && GetLastError() == ERROR_WINHTTP_NAME_NOT_RESOLVED)
311 skip("Network unreachable, skipping.\n");
314 ok(request != NULL, "WinHttpOpenrequest failed to open a request, error: %u.\n", GetLastError());
315 if (!request) goto done;
317 context = 0xdeadbeef;
318 ret = WinHttpSetOption(request, WINHTTP_OPTION_CONTEXT_VALUE, &context, sizeof(context));
319 ok(ret, "WinHttpSetOption failed: %u\n", GetLastError());
322 ret = WinHttpSendRequest(request, content_type, header_len, post_data, optional_len, total_len, context);
323 ok(ret == TRUE, "WinHttpSendRequest failed: %u\n", GetLastError());
326 size = sizeof(context);
327 ret = WinHttpQueryOption(request, WINHTTP_OPTION_CONTEXT_VALUE, &context, &size);
328 ok(ret, "WinHttpQueryOption failed: %u\n", GetLastError());
329 ok(context == 0xdeadbef0, "expected 0xdeadbef0, got %lx\n", context);
331 for (i = 3; post_data[i]; i++)
334 ret = WinHttpWriteData(request, &post_data[i], 1, &bytes_rw);
336 ok(bytes_rw == 1, "WinHttpWriteData failed, wrote %u bytes instead of 1 byte.\n", bytes_rw);
337 else /* Since we already passed all optional data in WinHttpSendRequest Win7 fails our WinHttpWriteData call */
339 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER got %u.\n", GetLastError());
340 ok(bytes_rw == -1, "Expected bytes_rw to remain unchanged.\n");
344 ret = WinHttpReceiveResponse(request, NULL);
345 ok(ret == TRUE, "WinHttpReceiveResponse failed: %u.\n", GetLastError());
348 ret = WinHttpReadData(request, buffer, sizeof(buffer) - 1, &bytes_rw);
349 ok(ret == TRUE, "WinHttpReadData failed: %u.\n", GetLastError());
351 ok(bytes_rw == strlen(test_post), "Read %u bytes instead of %d.\n", bytes_rw, lstrlen(test_post));
352 ok(strncmp(buffer, test_post, bytes_rw) == 0, "Data read did not match, got '%s'.\n", buffer);
354 ret = WinHttpCloseHandle(request);
355 ok(ret == TRUE, "WinHttpCloseHandle failed on closing request, got %d.\n", ret);
357 ret = WinHttpCloseHandle(connection);
358 ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret);
359 ret = WinHttpCloseHandle(session);
360 ok(ret == TRUE, "WinHttpCloseHandle failed on closing session, got %d.\n", ret);
363 static void test_WinHttpTimeFromSystemTime(void)
366 static const SYSTEMTIME time = {2008, 7, 1, 28, 10, 5, 52, 0};
367 static const WCHAR expected_string[] =
368 {'M','o','n',',',' ','2','8',' ','J','u','l',' ','2','0','0','8',' ',
369 '1','0',':','0','5',':','5','2',' ','G','M','T',0};
370 WCHAR time_string[WINHTTP_TIME_FORMAT_BUFSIZE+1];
372 ret = WinHttpTimeFromSystemTime(&time, time_string);
373 ok(ret == TRUE, "WinHttpTimeFromSystemTime failed: %u\n", GetLastError());
374 ok(memcmp(time_string, expected_string, sizeof(expected_string)) == 0,
375 "Time string returned did not match expected time string.\n");
378 static void test_WinHttpTimeToSystemTime(void)
382 static const SYSTEMTIME expected_time = {2008, 7, 1, 28, 10, 5, 52, 0};
383 static const WCHAR time_string1[] =
384 {'M','o','n',',',' ','2','8',' ','J','u','l',' ','2','0','0','8',' ',
385 + '1','0',':','0','5',':','5','2',' ','G','M','T','\n',0};
386 static const WCHAR time_string2[] =
387 {' ','m','o','n',' ','2','8',' ','j','u','l',' ','2','0','0','8',' ',
388 '1','0',' ','0','5',' ','5','2','\n',0};
390 ret = WinHttpTimeToSystemTime(time_string1, &time);
391 ok(ret == TRUE, "WinHttpTimeToSystemTime failed: %u\n", GetLastError());
392 ok(memcmp(&time, &expected_time, sizeof(SYSTEMTIME)) == 0,
393 "Returned SYSTEMTIME structure did not match expected SYSTEMTIME structure.\n");
395 ret = WinHttpTimeToSystemTime(time_string2, &time);
396 ok(ret == TRUE, "WinHttpTimeToSystemTime failed: %u\n", GetLastError());
397 ok(memcmp(&time, &expected_time, sizeof(SYSTEMTIME)) == 0,
398 "Returned SYSTEMTIME structure did not match expected SYSTEMTIME structure.\n");
401 static void test_WinHttpAddHeaders(void)
403 HINTERNET session, request, connection;
405 WCHAR buffer[MAX_PATH];
406 WCHAR check_buffer[MAX_PATH];
407 DWORD index, len, oldlen;
409 static const WCHAR test_site[] = {'c','r','o','s','s','o','v','e','r','.',
410 'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0};
411 static const WCHAR test_file[] = {'/','p','o','s','t','t','e','s','t','.','p','h','p',0};
412 static const WCHAR test_verb[] = {'P','O','S','T',0};
414 static const WCHAR test_header_begin[] =
415 {'P','O','S','T',' ','/','p','o','s','t','t','e','s','t','.','p','h','p',' ','H','T','T','P','/','1'};
416 static const WCHAR full_path_test_header_begin[] =
417 {'P','O','S','T',' ','h','t','t','p',':','/','/','c','r','o','s','s','o','v','e','r','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',':','8','0','/','p','o','s','t','t','e','s','t','.','p','h','p',' ','H','T','T','P','/','1'};
418 static const WCHAR test_header_end[] = {'\r','\n','\r','\n',0};
419 static const WCHAR test_header_name[] = {'W','a','r','n','i','n','g',0};
421 static const WCHAR test_flag_coalesce[] = {'t','e','s','t','2',',',' ','t','e','s','t','4',0};
422 static const WCHAR test_flag_coalesce_reverse[] = {'t','e','s','t','3',',',' ','t','e','s','t','4',0};
423 static const WCHAR test_flag_coalesce_comma[] =
424 {'t','e','s','t','2',',',' ','t','e','s','t','4',',',' ','t','e','s','t','5',0};
425 static const WCHAR test_flag_coalesce_comma_reverse[] =
426 {'t','e','s','t','3',',',' ','t','e','s','t','4',',',' ','t','e','s','t','5',0};
427 static const WCHAR test_flag_coalesce_semicolon[] =
428 {'t','e','s','t','2',',',' ','t','e','s','t','4',',',' ','t','e','s','t','5',';',' ','t','e','s','t','6',0};
429 static const WCHAR test_flag_coalesce_semicolon_reverse[] =
430 {'t','e','s','t','3',',',' ','t','e','s','t','4',',',' ','t','e','s','t','5',';',' ','t','e','s','t','6',0};
432 static const WCHAR field[] = {'f','i','e','l','d',0};
433 static const WCHAR value[] = {'v','a','l','u','e',' ',0};
434 static const WCHAR value_nospace[] = {'v','a','l','u','e',0};
436 static const WCHAR test_headers[][14] =
438 {'W','a','r','n','i','n','g',':','t','e','s','t','1',0},
439 {'W','a','r','n','i','n','g',':','t','e','s','t','2',0},
440 {'W','a','r','n','i','n','g',':','t','e','s','t','3',0},
441 {'W','a','r','n','i','n','g',':','t','e','s','t','4',0},
442 {'W','a','r','n','i','n','g',':','t','e','s','t','5',0},
443 {'W','a','r','n','i','n','g',':','t','e','s','t','6',0},
444 {'W','a','r','n','i','n','g',':','t','e','s','t','7',0},
450 {' ','e',' ',':','f',0},
451 {'f','i','e','l','d',':',' ','v','a','l','u','e',' ',0}
453 static const WCHAR test_indices[][6] =
455 {'t','e','s','t','1',0},
456 {'t','e','s','t','2',0},
457 {'t','e','s','t','3',0},
458 {'t','e','s','t','4',0}
461 session = WinHttpOpen(test_useragent, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
462 WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0);
463 ok(session != NULL, "WinHttpOpen failed to open session.\n");
465 connection = WinHttpConnect (session, test_site, INTERNET_DEFAULT_HTTP_PORT, 0);
466 ok(connection != NULL, "WinHttpConnect failed to open a connection, error: %u.\n", GetLastError());
468 request = WinHttpOpenRequest(connection, test_verb, test_file, NULL, WINHTTP_NO_REFERER,
469 WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
470 if (request == NULL && GetLastError() == ERROR_WINHTTP_NAME_NOT_RESOLVED)
472 skip("Network unreachable, skipping.\n");
475 ok(request != NULL, "WinHttpOpenRequest failed to open a request, error: %u.\n", GetLastError());
478 len = sizeof(buffer);
479 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
480 test_header_name, buffer, &len, &index);
481 ok(ret == FALSE, "WinHttpQueryHeaders unexpectedly succeeded, found 'Warning' header.\n");
482 ret = WinHttpAddRequestHeaders(request, test_headers[0], -1L, WINHTTP_ADDREQ_FLAG_ADD);
483 ok(ret == TRUE, "WinHttpAddRequestHeader failed to add new header, got %d with error %u.\n", ret, GetLastError());
486 len = sizeof(buffer);
487 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
488 test_header_name, buffer, &len, &index);
489 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
490 ok(index == 1, "WinHttpQueryHeaders failed: header index not incremented\n");
491 ok(memcmp(buffer, test_indices[0], sizeof(test_indices[0])) == 0, "WinHttpQueryHeaders failed: incorrect string returned\n");
492 ok(len == 5*sizeof(WCHAR), "WinHttpQueryHeaders failed: invalid length returned, expected 5, got %d\n", len);
494 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
495 test_header_name, buffer, &len, &index);
496 ok(ret == FALSE, "WinHttpQueryHeaders unexpectedly succeeded, second index should not exist.\n");
498 /* Try to fetch the header info with a buffer that's big enough to fit the
499 * string but not the NULL terminator.
502 len = 5*sizeof(WCHAR);
503 memset(check_buffer, 0xab, sizeof(check_buffer));
504 memcpy(buffer, check_buffer, sizeof(buffer));
505 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
506 test_header_name, buffer, &len, &index);
507 ok(ret == FALSE, "WinHttpQueryHeaders unexpectedly succeeded with a buffer that's too small.\n");
508 ok(memcmp(buffer, check_buffer, sizeof(buffer)) == 0,
509 "WinHttpQueryHeaders failed, modified the buffer when it should not have.\n");
510 ok(len == 6*sizeof(WCHAR), "WinHttpQueryHeaders returned invalid length, expected 12, got %d\n", len);
512 /* Try with a NULL buffer */
514 len = sizeof(buffer);
515 SetLastError(0xdeadbeef);
516 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_RAW_HEADERS_CRLF | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
517 test_header_name, NULL, &len, &index);
518 ok(ret == FALSE, "WinHttpQueryHeaders unexpectedly succeeded.\n");
519 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
520 ok(len > 40, "WinHttpQueryHeaders returned invalid length: expected greater than 40, got %d\n", len);
521 ok(index == 0, "WinHttpQueryHeaders incorrectly incremented header index.\n");
523 /* Try with a NULL buffer and a length that's too small */
526 SetLastError(0xdeadbeef);
527 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_RAW_HEADERS_CRLF | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
528 test_header_name, NULL, &len, &index);
529 ok(ret == FALSE, "WinHttpQueryHeaders unexpectedly succeeded.\n");
530 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
531 "WinHttpQueryHeaders set incorrect error: expected ERROR_INSUFFICENT_BUFFER, go %u\n", GetLastError());
532 ok(len > 40, "WinHttpQueryHeaders returned invalid length: expected greater than 40, got %d\n", len);
533 ok(index == 0, "WinHttpQueryHeaders incorrectly incremented header index.\n");
537 SetLastError(0xdeadbeef);
538 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_RAW_HEADERS_CRLF | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
539 test_header_name, NULL, &len, &index);
540 ok(ret == FALSE, "WinHttpQueryHeaders unexpectedly succeeded.\n");
541 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
542 "WinHttpQueryHeaders set incorrect error: expected ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
543 ok(len > 40, "WinHttpQueryHeaders returned invalid length: expected greater than 40, got %d\n", len);
544 ok(index == 0, "WinHttpQueryHeaders failed: index was incremented.\n");
549 len = sizeof(buffer);
550 memset(buffer, 0xff, sizeof(buffer));
551 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_RAW_HEADERS_CRLF | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
552 test_header_name, buffer, &len, &index);
553 ok(ret == TRUE, "WinHttpQueryHeaders failed: got %d\n", ret);
554 ok(len + sizeof(WCHAR) <= oldlen, "WinHttpQueryHeaders resulting length longer than advertized.\n");
555 ok((len < sizeof(buffer) - sizeof(WCHAR)) && buffer[len / sizeof(WCHAR)] == 0, "WinHttpQueryHeaders did not append NULL terminator\n");
556 ok(len == lstrlenW(buffer) * sizeof(WCHAR), "WinHttpQueryHeaders returned incorrect length.\n");
557 ok(memcmp(buffer, test_header_begin, sizeof(test_header_begin)) == 0 ||
558 memcmp(buffer, full_path_test_header_begin, sizeof(full_path_test_header_begin)) == 0,
559 "WinHttpQueryHeaders returned invalid beginning of header string.\n");
560 ok(memcmp(buffer + lstrlenW(buffer) - 4, test_header_end, sizeof(test_header_end)) == 0,
561 "WinHttpQueryHeaders returned invalid end of header string.\n");
562 ok(index == 0, "WinHttpQueryHeaders incremented header index.\n");
566 SetLastError(0xdeadbeef);
567 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_RAW_HEADERS | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
568 test_header_name, NULL, &len, &index);
569 ok(ret == FALSE, "WinHttpQueryHeaders unexpectedly succeeded.\n");
570 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
571 "WinHttpQueryHeaders set incorrect error: expected ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
572 ok(len > 40, "WinHttpQueryHeaders returned invalid length: expected greater than 40, got %d\n", len);
573 ok(index == 0, "WinHttpQueryHeaders failed: index was incremented.\n");
577 len = sizeof(buffer);
578 memset(buffer, 0xff, sizeof(buffer));
579 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_RAW_HEADERS | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
580 test_header_name, buffer, &len, &index);
581 ok(ret == TRUE, "WinHttpQueryHeaders failed %u\n", GetLastError());
582 ok(len + sizeof(WCHAR) <= oldlen, "resulting length longer than advertized\n");
583 ok((len < sizeof(buffer) - sizeof(WCHAR)) && !buffer[len / sizeof(WCHAR)] && !buffer[len / sizeof(WCHAR) - 1],
584 "no double NULL terminator\n");
585 ok(memcmp(buffer, test_header_begin, sizeof(test_header_begin)) == 0 ||
586 memcmp(buffer, full_path_test_header_begin, sizeof(full_path_test_header_begin)) == 0,
587 "invalid beginning of header string.\n");
588 ok(index == 0, "header index was incremented\n");
590 /* tests for more indices */
591 ret = WinHttpAddRequestHeaders(request, test_headers[1], -1L, WINHTTP_ADDREQ_FLAG_ADD);
592 ok(ret == TRUE, "WinHttpAddRequestHeaders failed to add duplicate header: %d\n", ret);
595 len = sizeof(buffer);
596 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
597 test_header_name, buffer, &len, &index);
598 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
599 ok(index == 1, "WinHttpQueryHeaders failed to increment index.\n");
600 ok(memcmp(buffer, test_indices[0], sizeof(test_indices[0])) == 0, "WinHttpQueryHeaders returned incorrect string.\n");
602 len = sizeof(buffer);
603 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
604 test_header_name, buffer, &len, &index);
605 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
606 ok(index == 2, "WinHttpQueryHeaders failed to increment index.\n");
607 ok(memcmp(buffer, test_indices[1], sizeof(test_indices[1])) == 0, "WinHttpQueryHeaders returned incorrect string.\n");
609 ret = WinHttpAddRequestHeaders(request, test_headers[2], -1L, WINHTTP_ADDREQ_FLAG_REPLACE);
610 ok(ret == TRUE, "WinHttpAddRequestHeaders failed to add duplicate header.\n");
613 len = sizeof(buffer);
614 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
615 test_header_name, buffer, &len, &index);
616 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
617 ok(index == 1, "WinHttpQueryHeaders failed to increment index.\n");
618 reverse = (memcmp(buffer, test_indices[1], sizeof(test_indices[1])) != 0); /* Win7 returns values in reverse order of adding */
619 ok(memcmp(buffer, test_indices[reverse ? 2 : 1], sizeof(test_indices[reverse ? 2 : 1])) == 0, "WinHttpQueryHeaders returned incorrect string.\n");
621 len = sizeof(buffer);
622 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
623 test_header_name, buffer, &len, &index);
624 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
625 ok(index == 2, "WinHttpQueryHeaders failed to increment index.\n");
626 ok(memcmp(buffer, test_indices[reverse ? 1 : 2], sizeof(test_indices[reverse ? 1 : 2])) == 0, "WinHttpQueryHeaders returned incorrect string.\n");
628 /* add if new flag */
629 ret = WinHttpAddRequestHeaders(request, test_headers[3], -1L, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW);
630 ok(ret == FALSE, "WinHttpAddRequestHeaders incorrectly replaced existing header.\n");
633 len = sizeof(buffer);
634 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
635 test_header_name, buffer, &len, &index);
636 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
637 ok(index == 1, "WinHttpQueryHeaders failed to increment index.\n");
638 ok(memcmp(buffer, test_indices[reverse ? 2 : 1], sizeof(test_indices[reverse ? 2 : 1])) == 0, "WinHttpQueryHeaders returned incorrect string.\n");
640 len = sizeof(buffer);
641 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
642 test_header_name, buffer, &len, &index);
643 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
644 ok(index == 2, "WinHttpQueryHeaders failed to increment index.\n");
645 ok(memcmp(buffer, test_indices[reverse ? 1 : 2], sizeof(test_indices[reverse ? 1 : 2])) == 0, "WinHttpQueryHeaders returned incorrect string.\n");
647 len = sizeof(buffer);
648 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
649 test_header_name, buffer, &len, &index);
650 ok(ret == FALSE, "WinHttpQueryHeaders succeeded unexpectedly, found third header.\n");
653 ret = WinHttpAddRequestHeaders(request, test_headers[3], -1L, WINHTTP_ADDREQ_FLAG_COALESCE);
654 ok(ret == TRUE, "WinHttpAddRequestHeaders failed with flag WINHTTP_ADDREQ_FLAG_COALESCE.\n");
657 len = sizeof(buffer);
658 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
659 test_header_name, buffer, &len, &index);
660 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
661 ok(index == 1, "WinHttpQueryHeaders failed to increment index.\n");
662 ok(memcmp(buffer, reverse ? test_flag_coalesce_reverse : test_flag_coalesce,
663 reverse ? sizeof(test_flag_coalesce_reverse) : sizeof(test_flag_coalesce)) == 0, "WinHttpQueryHeaders returned incorrect string.\n");
665 len = sizeof(buffer);
666 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
667 test_header_name, buffer, &len, &index);
668 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
669 ok(index == 2, "WinHttpQueryHeaders failed to increment index.\n");
670 ok(memcmp(buffer, test_indices[reverse ? 1 : 2], sizeof(test_indices[reverse ? 1 : 2])) == 0, "WinHttpQueryHeaders returned incorrect string.\n");
672 len = sizeof(buffer);
673 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
674 test_header_name, buffer, &len, &index);
675 ok(ret == FALSE, "WinHttpQueryHeaders succeeded unexpectedly, found third header.\n");
677 /* coalesce with comma flag */
678 ret = WinHttpAddRequestHeaders(request, test_headers[4], -1L, WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA);
679 ok(ret == TRUE, "WinHttpAddRequestHeaders failed with flag WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA.\n");
682 len = sizeof(buffer);
683 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
684 test_header_name, buffer, &len, &index);
685 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
686 ok(index == 1, "WinHttpQueryHeaders failed to increment index.\n");
687 ok(memcmp(buffer, reverse ? test_flag_coalesce_comma_reverse : test_flag_coalesce_comma,
688 reverse ? sizeof(test_flag_coalesce_comma_reverse) : sizeof(test_flag_coalesce_comma)) == 0,
689 "WinHttpQueryHeaders returned incorrect string.\n");
691 len = sizeof(buffer);
692 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
693 test_header_name, buffer, &len, &index);
694 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
695 ok(index == 2, "WinHttpQueryHeaders failed to increment index.\n");
696 ok(memcmp(buffer, test_indices[reverse ? 1 : 2], sizeof(test_indices[reverse ? 1 : 2])) == 0, "WinHttpQueryHeaders returned incorrect string.\n");
698 len = sizeof(buffer);
699 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
700 test_header_name, buffer, &len, &index);
701 ok(ret == FALSE, "WinHttpQueryHeaders succeeded unexpectedly, found third header.\n");
704 /* coalesce with semicolon flag */
705 ret = WinHttpAddRequestHeaders(request, test_headers[5], -1L, WINHTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON);
706 ok(ret == TRUE, "WinHttpAddRequestHeaders failed with flag WINHTTP_ADDREQ_FLAG_COALESCE_WITH_SEMICOLON.\n");
709 len = sizeof(buffer);
710 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
711 test_header_name, buffer, &len, &index);
712 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
713 ok(index == 1, "WinHttpQueryHeaders failed to increment index.\n");
714 ok(memcmp(buffer, reverse ? test_flag_coalesce_semicolon_reverse : test_flag_coalesce_semicolon,
715 reverse ? sizeof(test_flag_coalesce_semicolon_reverse) : sizeof(test_flag_coalesce_semicolon)) == 0,
716 "WinHttpQueryHeaders returned incorrect string.\n");
718 len = sizeof(buffer);
719 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
720 test_header_name, buffer, &len, &index);
721 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
722 ok(index == 2, "WinHttpQueryHeaders failed to increment index.\n");
723 ok(memcmp(buffer, test_indices[reverse ? 1 : 2], sizeof(test_indices[reverse ? 1 : 2])) == 0, "WinHttpQueryHeaders returned incorrect string.\n");
725 len = sizeof(buffer);
726 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
727 test_header_name, buffer, &len, &index);
728 ok(ret == FALSE, "WinHttpQueryHeaders succeeded unexpectedly, found third header.\n");
730 /* add and replace flags */
731 ret = WinHttpAddRequestHeaders(request, test_headers[3], -1L, WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE);
732 ok(ret == TRUE, "WinHttpAddRequestHeaders failed with flag WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE.\n");
735 len = sizeof(buffer);
736 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
737 test_header_name, buffer, &len, &index);
738 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
739 ok(index == 1, "WinHttpQueryHeaders failed to increment index.\n");
740 ok(memcmp(buffer, test_indices[reverse ? 3 : 2], sizeof(test_indices[reverse ? 3 : 2])) == 0, "WinHttpQueryHeaders returned incorrect string.\n");
742 len = sizeof(buffer);
743 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
744 test_header_name, buffer, &len, &index);
745 ok(ret == TRUE, "WinHttpQueryHeaders failed: %u\n", GetLastError());
746 ok(index == 2, "WinHttpQueryHeaders failed to increment index.\n");
747 ok(memcmp(buffer, test_indices[reverse ? 1 : 3], sizeof(test_indices[reverse ? 1 : 3])) == 0, "WinHttpQueryHeaders returned incorrect string.\n");
749 len = sizeof(buffer);
750 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
751 test_header_name, buffer, &len, &index);
752 ok(ret == FALSE, "WinHttpQueryHeaders succeeded unexpectedly, found third header.\n");
754 ret = WinHttpAddRequestHeaders(request, test_headers[8], ~0u, WINHTTP_ADDREQ_FLAG_ADD);
755 ok(!ret, "WinHttpAddRequestHeaders failed\n");
757 ret = WinHttpAddRequestHeaders(request, test_headers[9], ~0u, WINHTTP_ADDREQ_FLAG_ADD);
758 ok(ret, "WinHttpAddRequestHeaders failed\n");
760 ret = WinHttpAddRequestHeaders(request, test_headers[10], ~0u, WINHTTP_ADDREQ_FLAG_ADD);
761 ok(!ret, "WinHttpAddRequestHeaders failed\n");
763 ret = WinHttpAddRequestHeaders(request, test_headers[11], ~0u, WINHTTP_ADDREQ_FLAG_ADD);
764 ok(!ret, "WinHttpAddRequestHeaders failed\n");
766 ret = WinHttpAddRequestHeaders(request, test_headers[12], ~0u, WINHTTP_ADDREQ_FLAG_ADD);
767 ok(!ret, "WinHttpAddRequestHeaders failed\n");
769 ret = WinHttpAddRequestHeaders(request, test_headers[13], ~0u, WINHTTP_ADDREQ_FLAG_ADD);
770 ok(ret, "WinHttpAddRequestHeaders failed\n");
774 len = sizeof(buffer);
775 ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_CUSTOM | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
776 field, buffer, &len, &index);
777 ok(ret, "WinHttpQueryHeaders failed: %u\n", GetLastError());
778 ok(!memcmp(buffer, value, sizeof(value)) || ! memcmp(buffer, value_nospace, sizeof(value_nospace)), "unexpected result\n");
780 ret = WinHttpCloseHandle(request);
781 ok(ret == TRUE, "WinHttpCloseHandle failed on closing request, got %d.\n", ret);
783 ret = WinHttpCloseHandle(connection);
784 ok(ret == TRUE, "WinHttpCloseHandle failed on closing connection, got %d.\n", ret);
785 ret = WinHttpCloseHandle(session);
786 ok(ret == TRUE, "WinHttpCloseHandle failed on closing session, got %d.\n", ret);
790 static void test_secure_connection(void)
792 static const WCHAR google[] = {'w','w','w','.','g','o','o','g','l','e','.','c','o','m',0};
794 HINTERNET ses, con, req;
795 DWORD size, status, policy, bitness;
798 WINHTTP_CERTIFICATE_INFO info;
801 ses = WinHttpOpen(test_useragent, 0, NULL, NULL, 0);
802 ok(ses != NULL, "failed to open session %u\n", GetLastError());
804 policy = WINHTTP_OPTION_REDIRECT_POLICY_ALWAYS;
805 ret = WinHttpSetOption(ses, WINHTTP_OPTION_REDIRECT_POLICY, &policy, sizeof(policy));
806 ok(ret, "failed to set redirect policy %u\n", GetLastError());
808 con = WinHttpConnect(ses, google, 443, 0);
809 ok(con != NULL, "failed to open a connection %u\n", GetLastError());
811 /* try without setting WINHTTP_FLAG_SECURE */
812 req = WinHttpOpenRequest(con, NULL, NULL, NULL, NULL, NULL, 0);
813 ok(req != NULL, "failed to open a request %u\n", GetLastError());
815 ret = WinHttpSendRequest(req, NULL, 0, NULL, 0, 0, 0);
816 if (!ret && GetLastError() == ERROR_WINHTTP_CANNOT_CONNECT)
818 skip("Connection failed, skipping.\n");
821 ok(ret, "failed to send request %u\n", GetLastError());
823 ret = WinHttpReceiveResponse(req, NULL);
824 ok(!ret || proxy_active(), "succeeded unexpectedly\n");
827 ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_RAW_HEADERS_CRLF, NULL, NULL, &size, NULL);
828 ok(!ret, "succeeded unexpectedly\n");
830 WinHttpCloseHandle(req);
832 req = WinHttpOpenRequest(con, NULL, NULL, NULL, NULL, NULL, WINHTTP_FLAG_SECURE);
833 ok(req != NULL, "failed to open a request %u\n", GetLastError());
835 ret = WinHttpSendRequest(req, NULL, 0, NULL, 0, 0, 0);
836 ok(ret, "failed to send request %u\n", GetLastError());
839 skip("secure connection failed, skipping remaining secure tests\n");
844 ret = WinHttpQueryOption(req, WINHTTP_OPTION_SERVER_CERT_CONTEXT, &cert, &size );
845 ok(ret, "failed to retrieve certificate context %u\n", GetLastError());
847 CertFreeCertificateContext(cert);
849 size = sizeof(bitness);
850 ret = WinHttpQueryOption(req, WINHTTP_OPTION_SECURITY_KEY_BITNESS, &bitness, &size );
851 ok(ret, "failed to retrieve key bitness %u\n", GetLastError());
854 ret = WinHttpQueryOption(req, WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT, &info, &size );
855 ok(ret, "failed to retrieve certificate info %u\n", GetLastError());
857 trace("lpszSubjectInfo %s\n", wine_dbgstr_w(info.lpszSubjectInfo));
858 trace("lpszIssuerInfo %s\n", wine_dbgstr_w(info.lpszIssuerInfo));
859 trace("lpszProtocolName %s\n", wine_dbgstr_w(info.lpszProtocolName));
860 trace("lpszSignatureAlgName %s\n", wine_dbgstr_w(info.lpszSignatureAlgName));
861 trace("lpszEncryptionAlgName %s\n", wine_dbgstr_w(info.lpszEncryptionAlgName));
862 trace("dwKeySize %u\n", info.dwKeySize);
864 ret = WinHttpReceiveResponse(req, NULL);
865 ok(ret, "failed to receive response %u\n", GetLastError());
867 size = sizeof(status);
868 ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL);
869 ok(ret, "failed unexpectedly %u\n", GetLastError());
870 ok(status == 200, "request failed unexpectedly %u\n", status);
873 ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_RAW_HEADERS_CRLF, NULL, NULL, &size, NULL);
874 ok(!ret, "succeeded unexpectedly\n");
879 ret = WinHttpReadData(req, buffer, sizeof(buffer), &size);
880 ok(ret == TRUE, "WinHttpReadData failed: %u.\n", GetLastError());
885 WinHttpCloseHandle(req);
886 WinHttpCloseHandle(con);
887 WinHttpCloseHandle(ses);
890 static void test_request_parameter_defaults(void)
892 static const WCHAR empty[] = {0};
893 static const WCHAR codeweavers[] = {'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0};
895 HINTERNET ses, con, req;
896 DWORD size, status, error;
900 ses = WinHttpOpen(test_useragent, 0, NULL, NULL, 0);
901 ok(ses != NULL, "failed to open session %u\n", GetLastError());
903 con = WinHttpConnect(ses, codeweavers, 0, 0);
904 ok(con != NULL, "failed to open a connection %u\n", GetLastError());
906 req = WinHttpOpenRequest(con, NULL, NULL, NULL, NULL, NULL, 0);
907 ok(req != NULL, "failed to open a request %u\n", GetLastError());
909 ret = WinHttpSendRequest(req, NULL, 0, NULL, 0, 0, 0);
910 ok(ret, "failed to send request %u\n", GetLastError());
912 ret = WinHttpReceiveResponse(req, NULL);
913 ok(ret, "failed to receive response %u\n", GetLastError());
915 size = sizeof(status);
916 ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL);
917 ok(ret, "failed unexpectedly %u\n", GetLastError());
918 ok(status == 200, "request failed unexpectedly %u\n", status);
920 WinHttpCloseHandle(req);
922 req = WinHttpOpenRequest(con, empty, empty, empty, NULL, NULL, 0);
923 ok(req != NULL, "failed to open a request %u\n", GetLastError());
925 ret = WinHttpSendRequest(req, NULL, 0, NULL, 0, 0, 0);
926 ok(ret, "failed to send request %u\n", GetLastError());
928 ret = WinHttpReceiveResponse(req, NULL);
929 ok(ret, "failed to receive response %u\n", GetLastError());
932 SetLastError(0xdeadbeef);
933 ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_VERSION, NULL, NULL, &size, NULL);
934 error = GetLastError();
935 ok(!ret, "succeeded unexpectedly\n");
936 ok(error == ERROR_INSUFFICIENT_BUFFER, "expected ERROR_INSUFFICIENT_BUFFER, got %u\n", error);
938 version = HeapAlloc(GetProcessHeap(), 0, size);
939 ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_VERSION, NULL, version, &size, NULL);
940 ok(ret, "failed unexpectedly %u\n", GetLastError());
941 ok(lstrlenW(version) == size / sizeof(WCHAR), "unexpected size %u\n", size);
942 HeapFree(GetProcessHeap(), 0, version);
944 size = sizeof(status);
945 ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL);
946 ok(ret, "failed unexpectedly %u\n", GetLastError());
947 ok(status == 200, "request failed unexpectedly %u\n", status);
949 WinHttpCloseHandle(req);
950 WinHttpCloseHandle(con);
951 WinHttpCloseHandle(ses);
954 static const WCHAR Connections[] = {
955 'S','o','f','t','w','a','r','e','\\',
956 'M','i','c','r','o','s','o','f','t','\\',
957 'W','i','n','d','o','w','s','\\',
958 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
959 'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s','\\',
960 'C','o','n','n','e','c','t','i','o','n','s',0 };
961 static const WCHAR WinHttpSettings[] = {
962 'W','i','n','H','t','t','p','S','e','t','t','i','n','g','s',0 };
964 static DWORD get_default_proxy_reg_value( BYTE *buf, DWORD len, DWORD *type )
970 l = RegOpenKeyExW( HKEY_LOCAL_MACHINE, Connections, 0, KEY_READ, &key );
975 l = RegQueryValueExW( key, WinHttpSettings, NULL, type, NULL, &size );
979 l = RegQueryValueExW( key, WinHttpSettings, NULL, type, buf,
989 static void set_default_proxy_reg_value( BYTE *buf, DWORD len, DWORD type )
994 l = RegCreateKeyExW( HKEY_LOCAL_MACHINE, Connections, 0, NULL, 0,
995 KEY_WRITE, NULL, &key, NULL );
999 RegSetValueExW( key, WinHttpSettings, 0, type, buf, len );
1001 RegDeleteValueW( key, WinHttpSettings );
1006 static void test_set_default_proxy_config(void)
1008 static const WCHAR wideString[] = { 0x226f, 0x575b, 0 };
1009 static const WCHAR normalString[] = { 'f','o','o',0 };
1011 BYTE *saved_proxy_settings = NULL;
1012 WINHTTP_PROXY_INFO info;
1015 /* FIXME: it would be simpler to read the current settings using
1016 * WinHttpGetDefaultProxyConfiguration and save them using
1017 * WinHttpSetDefaultProxyConfiguration, but they appear to have a bug.
1019 * If a proxy is configured in the registry, e.g. via 'proxcfg -p "foo"',
1020 * the access type reported by WinHttpGetDefaultProxyConfiguration is 1,
1021 * WINHTTP_ACCESS_TYPE_NO_PROXY, whereas it should be
1022 * WINHTTP_ACCESS_TYPE_NAMED_PROXY.
1023 * If WinHttpSetDefaultProxyConfiguration is called with dwAccessType = 1,
1024 * the lpszProxy and lpszProxyBypass values are ignored.
1025 * Thus, if a proxy is set with proxycfg, then calling
1026 * WinHttpGetDefaultProxyConfiguration followed by
1027 * WinHttpSetDefaultProxyConfiguration results in the proxy settings
1028 * getting deleted from the registry.
1030 * Instead I read the current registry value and restore it directly.
1032 len = get_default_proxy_reg_value( NULL, 0, &type );
1035 saved_proxy_settings = HeapAlloc( GetProcessHeap(), 0, len );
1036 len = get_default_proxy_reg_value( saved_proxy_settings, len, &type );
1041 /* Crashes on Vista and higher */
1042 SetLastError(0xdeadbeef);
1043 ret = WinHttpSetDefaultProxyConfiguration(NULL);
1044 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1045 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1048 /* test with invalid access type */
1049 info.dwAccessType = 0xdeadbeef;
1050 info.lpszProxy = info.lpszProxyBypass = NULL;
1051 SetLastError(0xdeadbeef);
1052 ret = WinHttpSetDefaultProxyConfiguration(&info);
1053 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1054 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1056 /* at a minimum, the proxy server must be set */
1057 info.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
1058 info.lpszProxy = info.lpszProxyBypass = NULL;
1059 SetLastError(0xdeadbeef);
1060 ret = WinHttpSetDefaultProxyConfiguration(&info);
1061 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1062 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1063 info.lpszProxyBypass = normalString;
1064 SetLastError(0xdeadbeef);
1065 ret = WinHttpSetDefaultProxyConfiguration(&info);
1066 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1067 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1069 /* the proxy server can't have wide characters */
1070 info.lpszProxy = wideString;
1071 SetLastError(0xdeadbeef);
1072 ret = WinHttpSetDefaultProxyConfiguration(&info);
1073 ok((!ret && GetLastError() == ERROR_INVALID_PARAMETER) ||
1074 broken(ret), /* Earlier winhttp versions on W2K/XP */
1075 "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
1077 info.lpszProxy = normalString;
1078 SetLastError(0xdeadbeef);
1079 ret = WinHttpSetDefaultProxyConfiguration(&info);
1082 ok(ret, "always true\n");
1083 set_default_proxy_reg_value( saved_proxy_settings, len, type );
1085 else if (GetLastError() == ERROR_ACCESS_DENIED)
1086 skip("couldn't set default proxy configuration: access denied\n");
1088 ok(ret, "WinHttpSetDefaultProxyConfiguration failed: %d\n",
1092 static void test_Timeouts (void)
1096 HINTERNET ses, req, con;
1097 static const WCHAR codeweavers[] = {'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0};
1100 ses = WinHttpOpen(test_useragent, 0, NULL, NULL, 0);
1101 ok(ses != NULL, "failed to open session %u\n", GetLastError());
1103 SetLastError(0xdeadbeef);
1104 ret = WinHttpSetTimeouts(ses, -2, 0, 0, 0);
1105 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1106 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1108 SetLastError(0xdeadbeef);
1109 ret = WinHttpSetTimeouts(ses, 0, -2, 0, 0);
1110 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1111 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1113 SetLastError(0xdeadbeef);
1114 ret = WinHttpSetTimeouts(ses, 0, 0, -2, 0);
1115 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1116 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1118 SetLastError(0xdeadbeef);
1119 ret = WinHttpSetTimeouts(ses, 0, 0, 0, -2);
1120 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1121 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1123 SetLastError(0xdeadbeef);
1124 ret = WinHttpSetTimeouts(ses, -1, -1, -1, -1);
1125 ok(ret, "%u\n", GetLastError());
1127 SetLastError(0xdeadbeef);
1128 ret = WinHttpSetTimeouts(ses, 0, 0, 0, 0);
1129 ok(ret, "%u\n", GetLastError());
1131 SetLastError(0xdeadbeef);
1132 ret = WinHttpSetTimeouts(ses, 0x0123, 0x4567, 0x89ab, 0xcdef);
1133 ok(ret, "%u\n", GetLastError());
1135 SetLastError(0xdeadbeef);
1137 size = sizeof(DWORD);
1138 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, &size);
1139 ok(ret, "%u\n", GetLastError());
1140 ok(value == 0x0123, "Expected 0x0123, got %u\n", value);
1142 SetLastError(0xdeadbeef);
1144 size = sizeof(DWORD);
1145 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, &size);
1146 ok(ret, "%u\n", GetLastError());
1147 ok(value == 0x4567, "Expected 0x4567, got %u\n", value);
1149 SetLastError(0xdeadbeef);
1151 size = sizeof(DWORD);
1152 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_SEND_TIMEOUT, &value, &size);
1153 ok(ret, "%u\n", GetLastError());
1154 ok(value == 0x89ab, "Expected 0x89ab, got %u\n", value);
1156 SetLastError(0xdeadbeef);
1158 size = sizeof(DWORD);
1159 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, &size);
1160 ok(ret, "%u\n", GetLastError());
1161 ok(value == 0xcdef, "Expected 0xcdef, got %u\n", value);
1163 SetLastError(0xdeadbeef);
1165 ret = WinHttpSetOption(ses, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, sizeof(value));
1166 ok(ret, "%u\n", GetLastError());
1168 SetLastError(0xdeadbeef);
1170 size = sizeof(DWORD);
1171 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, &size);
1172 ok(ret, "%u\n", GetLastError());
1173 ok(value == 0, "Expected 0, got %u\n", value);
1175 SetLastError(0xdeadbeef);
1177 ret = WinHttpSetOption(ses, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, sizeof(value));
1178 ok(ret, "%u\n", GetLastError());
1180 SetLastError(0xdeadbeef);
1182 size = sizeof(DWORD);
1183 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, &size);
1184 ok(ret, "%u\n", GetLastError());
1185 ok(value == 0, "Expected 0, got %u\n", value);
1187 SetLastError(0xdeadbeef);
1189 ret = WinHttpSetOption(ses, WINHTTP_OPTION_SEND_TIMEOUT, &value, sizeof(value));
1190 ok(ret, "%u\n", GetLastError());
1192 SetLastError(0xdeadbeef);
1194 size = sizeof(DWORD);
1195 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_SEND_TIMEOUT, &value, &size);
1196 ok(ret, "%u\n", GetLastError());
1197 ok(value == 0, "Expected 0, got %u\n", value);
1199 SetLastError(0xdeadbeef);
1201 ret = WinHttpSetOption(ses, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, sizeof(value));
1202 ok(ret, "%u\n", GetLastError());
1204 SetLastError(0xdeadbeef);
1206 size = sizeof(DWORD);
1207 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, &size);
1208 ok(ret, "%u\n", GetLastError());
1209 ok(value == 0, "Expected 0, got %u\n", value);
1211 SetLastError(0xdeadbeef);
1213 ret = WinHttpSetOption(ses, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, sizeof(value));
1214 ok(ret, "%u\n", GetLastError());
1216 SetLastError(0xdeadbeef);
1218 size = sizeof(DWORD);
1219 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, &size);
1220 ok(ret, "%u\n", GetLastError());
1221 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1223 SetLastError(0xdeadbeef);
1225 ret = WinHttpSetOption(ses, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, sizeof(value));
1226 ok(ret, "%u\n", GetLastError());
1228 SetLastError(0xdeadbeef);
1230 size = sizeof(DWORD);
1231 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, &size);
1232 ok(ret, "%u\n", GetLastError());
1233 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1235 SetLastError(0xdeadbeef);
1237 ret = WinHttpSetOption(ses, WINHTTP_OPTION_SEND_TIMEOUT, &value, sizeof(value));
1238 ok(ret, "%u\n", GetLastError());
1240 SetLastError(0xdeadbeef);
1242 size = sizeof(DWORD);
1243 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_SEND_TIMEOUT, &value, &size);
1244 ok(ret, "%u\n", GetLastError());
1245 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1247 SetLastError(0xdeadbeef);
1249 ret = WinHttpSetOption(ses, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, sizeof(value));
1250 ok(ret, "%u\n", GetLastError());
1252 SetLastError(0xdeadbeef);
1254 size = sizeof(DWORD);
1255 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, &size);
1256 ok(ret, "%u\n", GetLastError());
1257 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1259 con = WinHttpConnect(ses, codeweavers, 0, 0);
1260 ok(con != NULL, "failed to open a connection %u\n", GetLastError());
1262 /* Timeout values should match the last one set for session */
1263 SetLastError(0xdeadbeef);
1265 size = sizeof(DWORD);
1266 ret = WinHttpQueryOption(con, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, &size);
1267 ok(ret, "%u\n", GetLastError());
1268 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1270 SetLastError(0xdeadbeef);
1272 size = sizeof(DWORD);
1273 ret = WinHttpQueryOption(con, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, &size);
1274 ok(ret, "%u\n", GetLastError());
1275 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1277 SetLastError(0xdeadbeef);
1279 size = sizeof(DWORD);
1280 ret = WinHttpQueryOption(con, WINHTTP_OPTION_SEND_TIMEOUT, &value, &size);
1281 ok(ret, "%u\n", GetLastError());
1282 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1284 SetLastError(0xdeadbeef);
1286 size = sizeof(DWORD);
1287 ret = WinHttpQueryOption(con, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, &size);
1288 ok(ret, "%u\n", GetLastError());
1289 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1291 SetLastError(0xdeadbeef);
1292 ret = WinHttpSetTimeouts(con, -2, 0, 0, 0);
1293 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1294 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1296 SetLastError(0xdeadbeef);
1297 ret = WinHttpSetTimeouts(con, 0, -2, 0, 0);
1298 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1299 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1301 SetLastError(0xdeadbeef);
1302 ret = WinHttpSetTimeouts(con, 0, 0, -2, 0);
1303 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1304 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1306 SetLastError(0xdeadbeef);
1307 ret = WinHttpSetTimeouts(con, 0, 0, 0, -2);
1308 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1309 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1311 SetLastError(0xdeadbeef);
1312 ret = WinHttpSetTimeouts(con, -1, -1, -1, -1);
1313 ok(!ret && GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_TYPE,
1314 "expected ERROR_WINHTTP_INVALID_TYPE, got %u\n", GetLastError());
1316 SetLastError(0xdeadbeef);
1317 ret = WinHttpSetTimeouts(con, 0, 0, 0, 0);
1318 ok(!ret && GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_TYPE,
1319 "expected ERROR_WINHTTP_INVALID_TYPE, got %u\n", GetLastError());
1321 SetLastError(0xdeadbeef);
1323 ret = WinHttpSetOption(con, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, sizeof(value));
1324 ok(!ret && GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_TYPE,
1325 "expected ERROR_WINHTTP_INVALID_TYPE, got %u\n", GetLastError());
1327 SetLastError(0xdeadbeef);
1329 ret = WinHttpSetOption(con, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, sizeof(value));
1330 ok(!ret && GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_TYPE,
1331 "expected ERROR_WINHTTP_INVALID_TYPE, got %u\n", GetLastError());
1333 SetLastError(0xdeadbeef);
1335 ret = WinHttpSetOption(con, WINHTTP_OPTION_SEND_TIMEOUT, &value, sizeof(value));
1336 ok(!ret && GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_TYPE,
1337 "expected ERROR_WINHTTP_INVALID_TYPE, got %u\n", GetLastError());
1339 SetLastError(0xdeadbeef);
1341 ret = WinHttpSetOption(con, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, sizeof(value));
1342 ok(!ret && GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_TYPE,
1343 "expected ERROR_WINHTTP_INVALID_TYPE, got %u\n", GetLastError());
1345 /* Changing timeout values for session should affect the values for connection */
1346 SetLastError(0xdeadbeef);
1348 ret = WinHttpSetOption(ses, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, sizeof(value));
1349 ok(ret, "%u\n", GetLastError());
1351 SetLastError(0xdeadbeef);
1353 size = sizeof(DWORD);
1354 ret = WinHttpQueryOption(con, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, &size);
1355 ok(ret, "%u\n", GetLastError());
1356 ok(value == 0xdead, "Expected 0xdead, got %u\n", value);
1358 SetLastError(0xdeadbeef);
1360 ret = WinHttpSetOption(ses, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, sizeof(value));
1361 ok(ret, "%u\n", GetLastError());
1363 SetLastError(0xdeadbeef);
1365 size = sizeof(DWORD);
1366 ret = WinHttpQueryOption(con, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, &size);
1367 ok(ret, "%u\n", GetLastError());
1368 ok(value == 0xdead, "Expected 0xdead, got %u\n", value);
1370 SetLastError(0xdeadbeef);
1372 ret = WinHttpSetOption(ses, WINHTTP_OPTION_SEND_TIMEOUT, &value, sizeof(value));
1373 ok(ret, "%u\n", GetLastError());
1375 SetLastError(0xdeadbeef);
1377 size = sizeof(DWORD);
1378 ret = WinHttpQueryOption(con, WINHTTP_OPTION_SEND_TIMEOUT, &value, &size);
1379 ok(ret, "%u\n", GetLastError());
1380 ok(value == 0xdead, "Expected 0xdead, got %u\n", value);
1382 SetLastError(0xdeadbeef);
1384 ret = WinHttpSetOption(ses, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, sizeof(value));
1385 ok(ret, "%u\n", GetLastError());
1387 SetLastError(0xdeadbeef);
1389 size = sizeof(DWORD);
1390 ret = WinHttpQueryOption(con, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, &size);
1391 ok(ret, "%u\n", GetLastError());
1392 ok(value == 0xdead, "Expected 0xdead, got %u\n", value);
1394 req = WinHttpOpenRequest(con, NULL, NULL, NULL, NULL, NULL, 0);
1395 ok(req != NULL, "failed to open a request %u\n", GetLastError());
1397 /* Timeout values should match the last one set for session */
1398 SetLastError(0xdeadbeef);
1400 size = sizeof(DWORD);
1401 ret = WinHttpQueryOption(req, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, &size);
1402 ok(ret, "%u\n", GetLastError());
1403 ok(value == 0xdead, "Expected 0xdead, got %u\n", value);
1405 SetLastError(0xdeadbeef);
1407 size = sizeof(DWORD);
1408 ret = WinHttpQueryOption(req, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, &size);
1409 ok(ret, "%u\n", GetLastError());
1410 ok(value == 0xdead, "Expected 0xdead, got %u\n", value);
1412 SetLastError(0xdeadbeef);
1414 size = sizeof(DWORD);
1415 ret = WinHttpQueryOption(req, WINHTTP_OPTION_SEND_TIMEOUT, &value, &size);
1416 ok(ret, "%u\n", GetLastError());
1417 ok(value == 0xdead, "Expected 0xdead, got %u\n", value);
1419 SetLastError(0xdeadbeef);
1421 size = sizeof(DWORD);
1422 ret = WinHttpQueryOption(req, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, &size);
1423 ok(ret, "%u\n", GetLastError());
1424 ok(value == 0xdead, "Expected 0xdead, got %u\n", value);
1426 SetLastError(0xdeadbeef);
1427 ret = WinHttpSetTimeouts(req, -2, 0, 0, 0);
1428 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1429 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1431 SetLastError(0xdeadbeef);
1432 ret = WinHttpSetTimeouts(req, 0, -2, 0, 0);
1433 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1434 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1436 SetLastError(0xdeadbeef);
1437 ret = WinHttpSetTimeouts(req, 0, 0, -2, 0);
1438 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1439 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1441 SetLastError(0xdeadbeef);
1442 ret = WinHttpSetTimeouts(req, 0, 0, 0, -2);
1443 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
1444 "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError());
1446 SetLastError(0xdeadbeef);
1447 ret = WinHttpSetTimeouts(req, -1, -1, -1, -1);
1448 ok(ret, "%u\n", GetLastError());
1450 SetLastError(0xdeadbeef);
1451 ret = WinHttpSetTimeouts(req, 0, 0, 0, 0);
1452 ok(ret, "%u\n", GetLastError());
1454 SetLastError(0xdeadbeef);
1455 ret = WinHttpSetTimeouts(req, 0xcdef, 0x89ab, 0x4567, 0x0123);
1456 ok(ret, "%u\n", GetLastError());
1458 SetLastError(0xdeadbeef);
1460 size = sizeof(DWORD);
1461 ret = WinHttpQueryOption(req, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, &size);
1462 ok(ret, "%u\n", GetLastError());
1463 ok(value == 0xcdef, "Expected 0xcdef, got %u\n", value);
1465 SetLastError(0xdeadbeef);
1467 size = sizeof(DWORD);
1468 ret = WinHttpQueryOption(req, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, &size);
1469 ok(ret, "%u\n", GetLastError());
1470 ok(value == 0x89ab, "Expected 0x89ab, got %u\n", value);
1472 SetLastError(0xdeadbeef);
1474 size = sizeof(DWORD);
1475 ret = WinHttpQueryOption(req, WINHTTP_OPTION_SEND_TIMEOUT, &value, &size);
1476 ok(ret, "%u\n", GetLastError());
1477 ok(value == 0x4567, "Expected 0x4567, got %u\n", value);
1479 SetLastError(0xdeadbeef);
1481 size = sizeof(DWORD);
1482 ret = WinHttpQueryOption(req, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, &size);
1483 ok(ret, "%u\n", GetLastError());
1484 ok(value == 0x0123, "Expected 0x0123, got %u\n", value);
1486 SetLastError(0xdeadbeef);
1488 ret = WinHttpSetOption(req, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, sizeof(value));
1489 ok(ret, "%u\n", GetLastError());
1491 SetLastError(0xdeadbeef);
1493 size = sizeof(DWORD);
1494 ret = WinHttpQueryOption(req, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, &size);
1495 ok(ret, "%u\n", GetLastError());
1496 ok(value == 0, "Expected 0, got %u\n", value);
1498 SetLastError(0xdeadbeef);
1500 ret = WinHttpSetOption(req, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, sizeof(value));
1501 ok(ret, "%u\n", GetLastError());
1503 SetLastError(0xdeadbeef);
1505 size = sizeof(DWORD);
1506 ret = WinHttpQueryOption(req, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, &size);
1507 ok(ret, "%u\n", GetLastError());
1508 ok(value == 0, "Expected 0, got %u\n", value);
1510 SetLastError(0xdeadbeef);
1512 ret = WinHttpSetOption(req, WINHTTP_OPTION_SEND_TIMEOUT, &value, sizeof(value));
1513 ok(ret, "%u\n", GetLastError());
1515 SetLastError(0xdeadbeef);
1517 size = sizeof(DWORD);
1518 ret = WinHttpQueryOption(req, WINHTTP_OPTION_SEND_TIMEOUT, &value, &size);
1519 ok(ret, "%u\n", GetLastError());
1520 ok(value == 0, "Expected 0, got %u\n", value);
1522 SetLastError(0xdeadbeef);
1524 ret = WinHttpSetOption(req, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, sizeof(value));
1525 ok(ret, "%u\n", GetLastError());
1527 SetLastError(0xdeadbeef);
1529 size = sizeof(DWORD);
1530 ret = WinHttpQueryOption(req, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, &size);
1531 ok(ret, "%u\n", GetLastError());
1532 ok(value == 0, "Expected 0, got %u\n", value);
1534 SetLastError(0xdeadbeef);
1536 ret = WinHttpSetOption(req, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, sizeof(value));
1537 ok(ret, "%u\n", GetLastError());
1539 SetLastError(0xdeadbeef);
1541 size = sizeof(DWORD);
1542 ret = WinHttpQueryOption(req, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, &size);
1543 ok(ret, "%u\n", GetLastError());
1544 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1546 SetLastError(0xdeadbeef);
1548 ret = WinHttpSetOption(req, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, sizeof(value));
1549 ok(ret, "%u\n", GetLastError());
1551 SetLastError(0xdeadbeef);
1553 size = sizeof(DWORD);
1554 ret = WinHttpQueryOption(req, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, &size);
1555 ok(ret, "%u\n", GetLastError());
1556 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1558 SetLastError(0xdeadbeef);
1560 ret = WinHttpSetOption(req, WINHTTP_OPTION_SEND_TIMEOUT, &value, sizeof(value));
1561 ok(ret, "%u\n", GetLastError());
1563 SetLastError(0xdeadbeef);
1565 size = sizeof(DWORD);
1566 ret = WinHttpQueryOption(req, WINHTTP_OPTION_SEND_TIMEOUT, &value, &size);
1567 ok(ret, "%u\n", GetLastError());
1568 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1570 SetLastError(0xdeadbeef);
1572 ret = WinHttpSetOption(req, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, sizeof(value));
1573 ok(ret, "%u\n", GetLastError());
1575 SetLastError(0xdeadbeef);
1577 size = sizeof(DWORD);
1578 ret = WinHttpQueryOption(req, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, &size);
1579 ok(ret, "%u\n", GetLastError());
1580 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1582 /* Changing timeout values for session should not affect the values for a request,
1583 * neither should the other way around.
1585 SetLastError(0xdeadbeef);
1587 ret = WinHttpSetOption(req, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, sizeof(value));
1588 ok(ret, "%u\n", GetLastError());
1590 SetLastError(0xdeadbeef);
1592 size = sizeof(DWORD);
1593 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, &size);
1594 ok(ret, "%u\n", GetLastError());
1595 ok(value == 0xdead, "Expected 0xdead, got %u\n", value);
1597 SetLastError(0xdeadbeef);
1599 ret = WinHttpSetOption(req, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, sizeof(value));
1600 ok(ret, "%u\n", GetLastError());
1602 SetLastError(0xdeadbeef);
1604 size = sizeof(DWORD);
1605 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, &size);
1606 ok(ret, "%u\n", GetLastError());
1607 ok(value == 0xdead, "Expected 0xdead, got %u\n", value);
1609 SetLastError(0xdeadbeef);
1611 ret = WinHttpSetOption(req, WINHTTP_OPTION_SEND_TIMEOUT, &value, sizeof(value));
1612 ok(ret, "%u\n", GetLastError());
1614 SetLastError(0xdeadbeef);
1616 size = sizeof(DWORD);
1617 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_SEND_TIMEOUT, &value, &size);
1618 ok(ret, "%u\n", GetLastError());
1619 ok(value == 0xdead, "Expected 0xdead, got %u\n", value);
1621 SetLastError(0xdeadbeef);
1623 ret = WinHttpSetOption(req, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, sizeof(value));
1624 ok(ret, "%u\n", GetLastError());
1626 SetLastError(0xdeadbeef);
1628 size = sizeof(DWORD);
1629 ret = WinHttpQueryOption(ses, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, &size);
1630 ok(ret, "%u\n", GetLastError());
1631 ok(value == 0xdead, "Expected 0xdead, got %u\n", value);
1633 SetLastError(0xdeadbeef);
1635 ret = WinHttpSetOption(ses, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, sizeof(value));
1636 ok(ret, "%u\n", GetLastError());
1638 SetLastError(0xdeadbeef);
1640 size = sizeof(DWORD);
1641 ret = WinHttpQueryOption(req, WINHTTP_OPTION_RESOLVE_TIMEOUT, &value, &size);
1642 ok(ret, "%u\n", GetLastError());
1643 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1645 SetLastError(0xdeadbeef);
1647 ret = WinHttpSetOption(ses, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, sizeof(value));
1648 ok(ret, "%u\n", GetLastError());
1650 SetLastError(0xdeadbeef);
1652 size = sizeof(DWORD);
1653 ret = WinHttpQueryOption(req, WINHTTP_OPTION_CONNECT_TIMEOUT, &value, &size);
1654 ok(ret, "%u\n", GetLastError());
1655 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1657 SetLastError(0xdeadbeef);
1659 ret = WinHttpSetOption(ses, WINHTTP_OPTION_SEND_TIMEOUT, &value, sizeof(value));
1660 ok(ret, "%u\n", GetLastError());
1662 SetLastError(0xdeadbeef);
1664 size = sizeof(DWORD);
1665 ret = WinHttpQueryOption(req, WINHTTP_OPTION_SEND_TIMEOUT, &value, &size);
1666 ok(ret, "%u\n", GetLastError());
1667 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1669 SetLastError(0xdeadbeef);
1671 ret = WinHttpSetOption(ses, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, sizeof(value));
1672 ok(ret, "%u\n", GetLastError());
1674 SetLastError(0xdeadbeef);
1676 size = sizeof(DWORD);
1677 ret = WinHttpQueryOption(req, WINHTTP_OPTION_RECEIVE_TIMEOUT, &value, &size);
1678 ok(ret, "%u\n", GetLastError());
1679 ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value);
1681 WinHttpCloseHandle(req);
1682 WinHttpCloseHandle(con);
1683 WinHttpCloseHandle(ses);
1686 static void test_resolve_timeout(void)
1688 static const WCHAR codeweavers[] =
1689 {'c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0};
1690 static const WCHAR nxdomain[] =
1691 {'n','x','d','o','m','a','i','n','.','c','o','d','e','w','e','a','v','e','r','s','.','c','o','m',0};
1693 HINTERNET ses, con, req;
1697 if (! proxy_active())
1699 ses = WinHttpOpen(test_useragent, 0, NULL, NULL, 0);
1700 ok(ses != NULL, "failed to open session %u\n", GetLastError());
1703 ret = WinHttpSetOption(ses, WINHTTP_OPTION_RESOLVE_TIMEOUT, &timeout, sizeof(timeout));
1704 ok(ret, "failed to set resolve timeout %u\n", GetLastError());
1706 con = WinHttpConnect(ses, nxdomain, 0, 0);
1707 ok(con != NULL, "failed to open a connection %u\n", GetLastError());
1709 req = WinHttpOpenRequest(con, NULL, NULL, NULL, NULL, NULL, 0);
1710 ok(req != NULL, "failed to open a request %u\n", GetLastError());
1712 SetLastError(0xdeadbeef);
1713 ret = WinHttpSendRequest(req, NULL, 0, NULL, 0, 0, 0);
1714 ok(!ret, "sent request\n");
1715 ok(GetLastError() == ERROR_WINHTTP_NAME_NOT_RESOLVED,
1716 "expected ERROR_WINHTTP_NAME_NOT_RESOLVED got %u\n", GetLastError());
1718 WinHttpCloseHandle(req);
1719 WinHttpCloseHandle(con);
1720 WinHttpCloseHandle(ses);
1723 skip("Skipping host resolution tests, host resolution preformed by proxy\n");
1725 ses = WinHttpOpen(test_useragent, 0, NULL, NULL, 0);
1726 ok(ses != NULL, "failed to open session %u\n", GetLastError());
1729 ret = WinHttpSetOption(ses, WINHTTP_OPTION_RESOLVE_TIMEOUT, &timeout, sizeof(timeout));
1730 ok(ret, "failed to set resolve timeout %u\n", GetLastError());
1732 con = WinHttpConnect(ses, codeweavers, 0, 0);
1733 ok(con != NULL, "failed to open a connection %u\n", GetLastError());
1735 req = WinHttpOpenRequest(con, NULL, NULL, NULL, NULL, NULL, 0);
1736 ok(req != NULL, "failed to open a request %u\n", GetLastError());
1738 ret = WinHttpSendRequest(req, NULL, 0, NULL, 0, 0, 0);
1739 ok(ret, "failed to send request\n");
1741 WinHttpCloseHandle(req);
1742 WinHttpCloseHandle(con);
1743 WinHttpCloseHandle(ses);
1746 static const char page1[] =
1748 "<HEAD><TITLE>winhttp test page</TITLE></HEAD>\r\n"
1749 "<BODY>The quick brown fox jumped over the lazy dog<P></BODY>\r\n"
1752 static const char okmsg[] =
1753 "HTTP/1.1 200 OK\r\n"
1754 "Server: winetest\r\n"
1757 static const char notokmsg[] =
1758 "HTTP/1.1 400 Bad Request\r\n"
1759 "Server: winetest\r\n"
1762 static const char noauthmsg[] =
1763 "HTTP/1.1 401 Unauthorized\r\n"
1764 "Server: winetest\r\n"
1765 "Connection: close\r\n"
1766 "WWW-Authenticate: Basic realm=\"placebo\"\r\n"
1769 static const char proxymsg[] =
1770 "HTTP/1.1 407 Proxy Authentication Required\r\n"
1771 "Server: winetest\r\n"
1772 "Proxy-Connection: close\r\n"
1773 "Proxy-Authenticate: Basic realm=\"placebo\"\r\n"
1782 static DWORD CALLBACK server_thread(LPVOID param)
1784 struct server_info *si = param;
1787 struct sockaddr_in sa;
1790 int last_request = 0;
1792 WSAStartup(MAKEWORD(1,1), &wsaData);
1794 s = socket(AF_INET, SOCK_STREAM, 0);
1795 if (s == INVALID_SOCKET)
1799 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof on);
1801 memset(&sa, 0, sizeof sa);
1802 sa.sin_family = AF_INET;
1803 sa.sin_port = htons(si->port);
1804 sa.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
1806 r = bind(s, (struct sockaddr *)&sa, sizeof(sa));
1811 SetEvent(si->event);
1814 c = accept(s, NULL, NULL);
1816 memset(buffer, 0, sizeof buffer);
1817 for(i = 0; i < sizeof buffer - 1; i++)
1819 r = recv(c, &buffer[i], 1, 0);
1822 if (i < 4) continue;
1823 if (buffer[i - 2] == '\n' && buffer[i] == '\n' &&
1824 buffer[i - 3] == '\r' && buffer[i - 1] == '\r')
1827 if (strstr(buffer, "GET /basic"))
1829 send(c, okmsg, sizeof okmsg - 1, 0);
1830 send(c, page1, sizeof page1 - 1, 0);
1832 if (strstr(buffer, "/auth"))
1834 if (strstr(buffer, "Authorization: Basic dXNlcjpwd2Q="))
1835 send(c, okmsg, sizeof okmsg - 1, 0);
1837 send(c, noauthmsg, sizeof noauthmsg - 1, 0);
1839 if (strstr(buffer, "/no_headers"))
1841 send(c, page1, sizeof page1 - 1, 0);
1843 if (strstr(buffer, "GET /quit"))
1845 send(c, okmsg, sizeof okmsg - 1, 0);
1846 send(c, page1, sizeof page1 - 1, 0);
1852 } while (!last_request);
1858 static void test_basic_request(int port, const WCHAR *verb, const WCHAR *path)
1860 HINTERNET ses, con, req;
1862 DWORD count, status, size;
1865 ses = WinHttpOpen(test_useragent, 0, NULL, NULL, 0);
1866 ok(ses != NULL, "failed to open session %u\n", GetLastError());
1868 con = WinHttpConnect(ses, localhostW, port, 0);
1869 ok(con != NULL, "failed to open a connection %u\n", GetLastError());
1871 req = WinHttpOpenRequest(con, verb, path, NULL, NULL, NULL, 0);
1872 ok(req != NULL, "failed to open a request %u\n", GetLastError());
1874 ret = WinHttpSendRequest(req, NULL, 0, NULL, 0, 0, 0);
1875 ok(ret, "failed to send request %u\n", GetLastError());
1877 ret = WinHttpReceiveResponse(req, NULL);
1878 ok(ret, "failed to receive response %u\n", GetLastError());
1880 size = sizeof(status);
1881 ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_STATUS_CODE|WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL);
1882 ok(ret, "failed to query status code %u\n", GetLastError());
1883 ok(status == 200, "request failed unexpectedly %u\n", status);
1886 memset(buffer, 0, sizeof(buffer));
1887 ret = WinHttpReadData(req, buffer, sizeof buffer, &count);
1888 ok(ret, "failed to read data %u\n", GetLastError());
1889 ok(count == sizeof page1 - 1, "count was wrong\n");
1890 ok(!memcmp(buffer, page1, sizeof page1), "http data wrong\n");
1892 WinHttpCloseHandle(req);
1893 WinHttpCloseHandle(con);
1894 WinHttpCloseHandle(ses);
1897 static void test_basic_authentication(int port)
1899 static const WCHAR authW[] = {'/','a','u','t','h',0};
1900 static const WCHAR userW[] = {'u','s','e','r',0};
1901 static const WCHAR passW[] = {'p','w','d',0};
1902 HINTERNET ses, con, req;
1903 DWORD status, size, error;
1906 ses = WinHttpOpen(test_useragent, 0, NULL, NULL, 0);
1907 ok(ses != NULL, "failed to open session %u\n", GetLastError());
1909 con = WinHttpConnect(ses, localhostW, port, 0);
1910 ok(con != NULL, "failed to open a connection %u\n", GetLastError());
1912 req = WinHttpOpenRequest(con, NULL, authW, NULL, NULL, NULL, 0);
1913 ok(req != NULL, "failed to open a request %u\n", GetLastError());
1915 ret = WinHttpSendRequest(req, NULL, 0, NULL, 0, 0, 0);
1916 ok(ret, "failed to send request %u\n", GetLastError());
1918 ret = WinHttpReceiveResponse(req, NULL);
1919 ok(ret, "failed to receive response %u\n", GetLastError());
1921 size = sizeof(status);
1922 ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_STATUS_CODE|WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL);
1923 ok(ret, "failed to query status code %u\n", GetLastError());
1924 ok(status == 401, "request failed unexpectedly %u\n", status);
1926 SetLastError(0xdeadbeef);
1927 ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_BASIC, userW, NULL, NULL);
1928 error = GetLastError();
1929 ok(!ret, "expected failure\n");
1930 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
1932 SetLastError(0xdeadbeef);
1933 ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_BASIC, NULL, passW, NULL);
1934 error = GetLastError();
1935 ok(!ret, "expected failure\n");
1936 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
1938 ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_BASIC, userW, passW, NULL);
1939 ok(ret, "failed to set credentials %u\n", GetLastError());
1941 ret = WinHttpSendRequest(req, NULL, 0, NULL, 0, 0, 0);
1942 ok(ret, "failed to send request %u\n", GetLastError());
1944 ret = WinHttpReceiveResponse(req, NULL);
1945 ok(ret, "failed to receive response %u\n", GetLastError());
1947 size = sizeof(status);
1948 ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_STATUS_CODE|WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL);
1949 ok(ret, "failed to query status code %u\n", GetLastError());
1950 ok(status == 200, "request failed unexpectedly %u\n", status);
1952 WinHttpCloseHandle(req);
1953 WinHttpCloseHandle(con);
1954 WinHttpCloseHandle(ses);
1957 static void test_no_headers(int port)
1959 static const WCHAR no_headersW[] = {'/','n','o','_','h','e','a','d','e','r','s',0};
1960 HINTERNET ses, con, req;
1964 ses = WinHttpOpen(test_useragent, 0, NULL, NULL, 0);
1965 ok(ses != NULL, "failed to open session %u\n", GetLastError());
1967 con = WinHttpConnect(ses, localhostW, port, 0);
1968 ok(con != NULL, "failed to open a connection %u\n", GetLastError());
1970 req = WinHttpOpenRequest(con, NULL, no_headersW, NULL, NULL, NULL, 0);
1971 ok(req != NULL, "failed to open a request %u\n", GetLastError());
1973 ret = WinHttpSendRequest(req, NULL, 0, NULL, 0, 0, 0);
1974 ok(ret, "failed to send request %u\n", GetLastError());
1976 SetLastError(0xdeadbeef);
1977 ret = WinHttpReceiveResponse(req, NULL);
1978 error = GetLastError();
1979 ok(!ret, "expected failure\n");
1980 ok(error == ERROR_WINHTTP_INVALID_SERVER_RESPONSE, "got %u\n", error);
1982 WinHttpCloseHandle(req);
1983 WinHttpCloseHandle(con);
1984 WinHttpCloseHandle(ses);
1987 static void test_credentials(void)
1989 static WCHAR userW[] = {'u','s','e','r',0};
1990 static WCHAR passW[] = {'p','a','s','s',0};
1991 static WCHAR proxy_userW[] = {'p','r','o','x','y','u','s','e','r',0};
1992 static WCHAR proxy_passW[] = {'p','r','o','x','y','p','a','s','s',0};
1993 HINTERNET ses, con, req;
1998 ses = WinHttpOpen(test_useragent, 0, proxy_userW, proxy_passW, 0);
1999 ok(ses != NULL, "failed to open session %u\n", GetLastError());
2001 con = WinHttpConnect(ses, localhostW, 0, 0);
2002 ok(con != NULL, "failed to open a connection %u\n", GetLastError());
2004 req = WinHttpOpenRequest(con, NULL, NULL, NULL, NULL, NULL, 0);
2005 ok(req != NULL, "failed to open a request %u\n", GetLastError());
2007 size = sizeof(buffer)/sizeof(WCHAR);
2008 ret = WinHttpQueryOption(req, WINHTTP_OPTION_PROXY_USERNAME, &buffer, &size);
2009 ok(ret, "failed to query proxy username %u\n", GetLastError());
2010 ok(!buffer[0], "unexpected result %s\n", wine_dbgstr_w(buffer));
2011 ok(!size, "expected 0, got %u\n", size);
2013 size = sizeof(buffer)/sizeof(WCHAR);
2014 ret = WinHttpQueryOption(req, WINHTTP_OPTION_PROXY_PASSWORD, &buffer, &size);
2015 ok(ret, "failed to query proxy password %u\n", GetLastError());
2016 ok(!buffer[0], "unexpected result %s\n", wine_dbgstr_w(buffer));
2017 ok(!size, "expected 0, got %u\n", size);
2019 ret = WinHttpSetOption(req, WINHTTP_OPTION_PROXY_USERNAME, proxy_userW, lstrlenW(proxy_userW));
2020 ok(ret, "failed to set username %u\n", GetLastError());
2022 size = sizeof(buffer)/sizeof(WCHAR);
2023 ret = WinHttpQueryOption(req, WINHTTP_OPTION_PROXY_USERNAME, &buffer, &size);
2024 ok(ret, "failed to query proxy username %u\n", GetLastError());
2025 ok(!winetest_strcmpW(buffer, proxy_userW), "unexpected result %s\n", wine_dbgstr_w(buffer));
2026 ok(size == lstrlenW(proxy_userW) * sizeof(WCHAR), "unexpected result %u\n", size);
2028 size = sizeof(buffer)/sizeof(WCHAR);
2029 ret = WinHttpQueryOption(req, WINHTTP_OPTION_USERNAME, &buffer, &size);
2030 ok(ret, "failed to query username %u\n", GetLastError());
2031 ok(!buffer[0], "unexpected result %s\n", wine_dbgstr_w(buffer));
2032 ok(!size, "expected 0, got %u\n", size);
2034 size = sizeof(buffer)/sizeof(WCHAR);
2035 ret = WinHttpQueryOption(req, WINHTTP_OPTION_PASSWORD, &buffer, &size);
2036 ok(ret, "failed to query password %u\n", GetLastError());
2037 ok(!buffer[0], "unexpected result %s\n", wine_dbgstr_w(buffer));
2038 ok(!size, "expected 0, got %u\n", size);
2040 ret = WinHttpSetOption(req, WINHTTP_OPTION_PROXY_PASSWORD, proxy_passW, lstrlenW(proxy_passW));
2041 ok(ret, "failed to set proxy password %u\n", GetLastError());
2043 size = sizeof(buffer)/sizeof(WCHAR);
2044 ret = WinHttpQueryOption(req, WINHTTP_OPTION_PROXY_PASSWORD, &buffer, &size);
2045 ok(ret, "failed to query proxy password %u\n", GetLastError());
2046 ok(!winetest_strcmpW(buffer, proxy_passW), "unexpected result %s\n", wine_dbgstr_w(buffer));
2047 ok(size == lstrlenW(proxy_passW) * sizeof(WCHAR), "unexpected result %u\n", size);
2049 ret = WinHttpSetOption(req, WINHTTP_OPTION_USERNAME, userW, lstrlenW(userW));
2050 ok(ret, "failed to set username %u\n", GetLastError());
2052 size = sizeof(buffer)/sizeof(WCHAR);
2053 ret = WinHttpQueryOption(req, WINHTTP_OPTION_USERNAME, &buffer, &size);
2054 ok(ret, "failed to query username %u\n", GetLastError());
2055 ok(!winetest_strcmpW(buffer, userW), "unexpected result %s\n", wine_dbgstr_w(buffer));
2056 ok(size == lstrlenW(userW) * sizeof(WCHAR), "unexpected result %u\n", size);
2058 ret = WinHttpSetOption(req, WINHTTP_OPTION_PASSWORD, passW, lstrlenW(passW));
2059 ok(ret, "failed to set password %u\n", GetLastError());
2061 size = sizeof(buffer)/sizeof(WCHAR);
2062 ret = WinHttpQueryOption(req, WINHTTP_OPTION_PASSWORD, &buffer, &size);
2063 ok(ret, "failed to query password %u\n", GetLastError());
2064 ok(!winetest_strcmpW(buffer, passW), "unexpected result %s\n", wine_dbgstr_w(buffer));
2065 ok(size == lstrlenW(passW) * sizeof(WCHAR), "unexpected result %u\n", size);
2067 WinHttpCloseHandle(req);
2069 req = WinHttpOpenRequest(con, NULL, NULL, NULL, NULL, NULL, 0);
2070 ok(req != NULL, "failed to open a request %u\n", GetLastError());
2072 SetLastError(0xdeadbeef);
2073 ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_BASIC, userW, NULL, NULL);
2074 error = GetLastError();
2075 ok(!ret, "expected failure\n");
2076 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2078 SetLastError(0xdeadbeef);
2079 ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_BASIC, NULL, passW, NULL);
2080 error = GetLastError();
2081 ok(!ret, "expected failure\n");
2082 ok(error == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", error);
2084 ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_BASIC, userW, passW, NULL);
2085 ok(ret, "failed to set credentials %u\n", GetLastError());
2087 size = sizeof(buffer)/sizeof(WCHAR);
2088 ret = WinHttpQueryOption(req, WINHTTP_OPTION_USERNAME, &buffer, &size);
2089 ok(ret, "failed to query username %u\n", GetLastError());
2091 ok(!buffer[0], "unexpected result %s\n", wine_dbgstr_w(buffer));
2092 ok(!size, "expected 0, got %u\n", size);
2095 size = sizeof(buffer)/sizeof(WCHAR);
2096 ret = WinHttpQueryOption(req, WINHTTP_OPTION_PASSWORD, &buffer, &size);
2097 ok(ret, "failed to query password %u\n", GetLastError());
2099 ok(!buffer[0], "unexpected result %s\n", wine_dbgstr_w(buffer));
2100 ok(!size, "expected 0, got %u\n", size);
2103 WinHttpCloseHandle(req);
2104 WinHttpCloseHandle(con);
2105 WinHttpCloseHandle(ses);
2108 static void test_IWinHttpRequest(void)
2110 static const WCHAR usernameW[] = {'u','s','e','r','n','a','m','e',0};
2111 static const WCHAR passwordW[] = {'p','a','s','s','w','o','r','d',0};
2112 static const WCHAR url1W[] = {'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g',0};
2113 static const WCHAR url2W[] = {'w','i','n','e','h','q','.','o','r','g',0};
2114 static const WCHAR method1W[] = {'G','E','T',0};
2115 static const WCHAR method2W[] = {'I','N','V','A','L','I','D',0};
2116 static const WCHAR proxy_serverW[] = {'p','r','o','x','y','s','e','r','v','e','r',0};
2117 static const WCHAR bypas_listW[] = {'b','y','p','a','s','s','l','i','s','t',0};
2118 static const WCHAR connectionW[] = {'C','o','n','n','e','c','t','i','o','n',0};
2119 static const WCHAR dateW[] = {'D','a','t','e',0};
2121 IWinHttpRequest *req;
2122 BSTR method, url, username, password, response = NULL, status_text = NULL, headers = NULL;
2123 BSTR date, today, connection, value = NULL;
2124 VARIANT async, empty, timeout, body, proxy_server, bypass_list;
2125 VARIANT_BOOL succeeded;
2127 WCHAR todayW[WINHTTP_TIME_FORMAT_BUFSIZE];
2130 GetSystemTime( &st );
2131 WinHttpTimeFromSystemTime( &st, todayW );
2133 CoInitialize( NULL );
2134 hr = CoCreateInstance( &CLSID_WinHttpRequest, NULL, CLSCTX_INPROC_SERVER, &IID_IWinHttpRequest, (void **)&req );
2135 ok( hr == S_OK, "got %08x\n", hr );
2137 V_VT( &empty ) = VT_ERROR;
2138 V_ERROR( &empty ) = 0xdeadbeef;
2140 V_VT( &async ) = VT_BOOL;
2141 V_BOOL( &async ) = VARIANT_FALSE;
2143 hr = IWinHttpRequest_Open( req, NULL, NULL, empty );
2144 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2146 method = SysAllocString( method1W );
2147 hr = IWinHttpRequest_Open( req, method, NULL, empty );
2148 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2150 hr = IWinHttpRequest_Open( req, method, NULL, async );
2151 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2153 url = SysAllocString( url1W );
2154 hr = IWinHttpRequest_Open( req, NULL, url, empty );
2155 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2157 hr = IWinHttpRequest_Abort( req );
2158 ok( hr == S_OK, "got %08x\n", hr );
2160 hr = IWinHttpRequest_Open( req, method, url, empty );
2161 ok( hr == S_OK, "got %08x\n", hr );
2163 hr = IWinHttpRequest_Abort( req );
2164 ok( hr == S_OK, "got %08x\n", hr );
2166 hr = IWinHttpRequest_Release( req );
2167 ok( hr == S_OK, "got %08x\n", hr );
2169 hr = CoCreateInstance( &CLSID_WinHttpRequest, NULL, CLSCTX_INPROC_SERVER, &IID_IWinHttpRequest, (void **)&req );
2170 ok( hr == S_OK, "got %08x\n", hr );
2172 SysFreeString( url );
2173 url = SysAllocString( url2W );
2174 hr = IWinHttpRequest_Open( req, method, url, async );
2175 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_UNRECOGNIZED_SCHEME ), "got %08x\n", hr );
2177 SysFreeString( method );
2178 method = SysAllocString( method2W );
2179 hr = IWinHttpRequest_Open( req, method, url, async );
2180 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_UNRECOGNIZED_SCHEME ), "got %08x\n", hr );
2182 SysFreeString( method );
2183 method = SysAllocString( method1W );
2184 SysFreeString( url );
2185 url = SysAllocString( url1W );
2186 hr = IWinHttpRequest_Open( req, method, url, async );
2187 ok( hr == S_OK, "got %08x\n", hr );
2189 hr = IWinHttpRequest_Abort( req );
2190 ok( hr == S_OK, "got %08x\n", hr );
2192 hr = IWinHttpRequest_Send( req, empty );
2193 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN ), "got %08x\n", hr );
2195 hr = IWinHttpRequest_Abort( req );
2196 ok( hr == S_OK, "got %08x\n", hr );
2198 hr = IWinHttpRequest_Release( req );
2199 ok( hr == S_OK, "got %08x\n", hr );
2201 hr = CoCreateInstance( &CLSID_WinHttpRequest, NULL, CLSCTX_INPROC_SERVER, &IID_IWinHttpRequest, (void **)&req );
2202 ok( hr == S_OK, "got %08x\n", hr );
2204 hr = IWinHttpRequest_get_ResponseText( req, NULL );
2205 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2207 hr = IWinHttpRequest_get_ResponseText( req, &response );
2208 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
2210 hr = IWinHttpRequest_get_Status( req, NULL );
2211 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2213 hr = IWinHttpRequest_get_Status( req, &status );
2214 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
2216 hr = IWinHttpRequest_get_StatusText( req, NULL );
2217 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2219 hr = IWinHttpRequest_get_StatusText( req, &status_text );
2220 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
2222 hr = IWinHttpRequest_get_ResponseBody( req, NULL );
2223 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2225 hr = IWinHttpRequest_SetTimeouts( req, 10000, 10000, 10000, 10000 );
2226 ok( hr == S_OK, "got %08x\n", hr );
2228 hr = IWinHttpRequest_SetCredentials( req, NULL, NULL, 0xdeadbeef );
2229 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN ), "got %08x\n", hr );
2231 VariantInit( &proxy_server );
2232 V_VT( &proxy_server ) = VT_ERROR;
2233 VariantInit( &bypass_list );
2234 V_VT( &bypass_list ) = VT_ERROR;
2235 hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list );
2236 ok( hr == S_OK, "got %08x\n", hr );
2238 hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_PROXY, proxy_server, bypass_list );
2239 ok( hr == S_OK, "got %08x\n", hr );
2241 hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list );
2242 ok( hr == S_OK, "got %08x\n", hr );
2244 hr = IWinHttpRequest_GetAllResponseHeaders( req, NULL );
2245 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2247 hr = IWinHttpRequest_GetAllResponseHeaders( req, &headers );
2248 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
2250 hr = IWinHttpRequest_GetResponseHeader( req, NULL, NULL );
2251 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
2253 connection = SysAllocString( connectionW );
2254 hr = IWinHttpRequest_GetResponseHeader( req, connection, NULL );
2255 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
2257 hr = IWinHttpRequest_GetResponseHeader( req, connection, &value );
2258 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
2260 hr = IWinHttpRequest_SetRequestHeader( req, NULL, NULL );
2261 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2263 date = SysAllocString( dateW );
2264 hr = IWinHttpRequest_SetRequestHeader( req, date, NULL );
2265 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN ), "got %08x\n", hr );
2267 today = SysAllocString( todayW );
2268 hr = IWinHttpRequest_SetRequestHeader( req, date, today );
2269 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_OPEN ), "got %08x\n", hr );
2271 hr = IWinHttpRequest_SetAutoLogonPolicy( req, 0xdeadbeef );
2272 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2274 hr = IWinHttpRequest_SetAutoLogonPolicy( req, AutoLogonPolicy_OnlyIfBypassProxy );
2275 ok( hr == S_OK, "got %08x\n", hr );
2277 SysFreeString( method );
2278 method = SysAllocString( method1W );
2279 SysFreeString( url );
2280 url = SysAllocString( url1W );
2281 hr = IWinHttpRequest_Open( req, method, url, async );
2282 ok( hr == S_OK, "got %08x\n", hr );
2284 hr = IWinHttpRequest_get_ResponseText( req, NULL );
2285 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2287 hr = IWinHttpRequest_get_ResponseText( req, &response );
2288 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
2290 hr = IWinHttpRequest_get_Status( req, &status );
2291 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
2293 hr = IWinHttpRequest_get_StatusText( req, &status_text );
2294 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
2296 hr = IWinHttpRequest_get_ResponseBody( req, NULL );
2297 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2299 hr = IWinHttpRequest_SetTimeouts( req, 10000, 10000, 10000, 10000 );
2300 ok( hr == S_OK, "got %08x\n", hr );
2302 hr = IWinHttpRequest_SetCredentials( req, NULL, NULL, 0xdeadbeef );
2303 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2305 username = SysAllocString( usernameW );
2306 hr = IWinHttpRequest_SetCredentials( req, username, NULL, 0xdeadbeef );
2307 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2309 password = SysAllocString( passwordW );
2310 hr = IWinHttpRequest_SetCredentials( req, NULL, password, 0xdeadbeef );
2311 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2313 hr = IWinHttpRequest_SetCredentials( req, username, password, 0xdeadbeef );
2314 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2316 hr = IWinHttpRequest_SetCredentials( req, NULL, password, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER );
2317 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2319 hr = IWinHttpRequest_SetCredentials( req, username, password, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER );
2320 ok( hr == S_OK, "got %08x\n", hr );
2322 V_VT( &proxy_server ) = VT_BSTR;
2323 V_BSTR( &proxy_server ) = SysAllocString( proxy_serverW );
2324 V_VT( &bypass_list ) = VT_BSTR;
2325 V_BSTR( &bypass_list ) = SysAllocString( bypas_listW );
2326 hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_PROXY, proxy_server, bypass_list );
2327 ok( hr == S_OK, "got %08x\n", hr );
2329 hr = IWinHttpRequest_SetProxy( req, 0xdeadbeef, proxy_server, bypass_list );
2330 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2332 hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list );
2333 ok( hr == S_OK, "got %08x\n", hr );
2335 hr = IWinHttpRequest_GetAllResponseHeaders( req, &headers );
2336 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
2338 hr = IWinHttpRequest_GetResponseHeader( req, connection, &value );
2339 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_BEFORE_SEND ), "got %08x\n", hr );
2341 hr = IWinHttpRequest_SetRequestHeader( req, date, today );
2342 ok( hr == S_OK, "got %08x\n", hr );
2344 hr = IWinHttpRequest_SetRequestHeader( req, date, NULL );
2345 ok( hr == S_OK, "got %08x\n", hr );
2347 hr = IWinHttpRequest_SetAutoLogonPolicy( req, AutoLogonPolicy_OnlyIfBypassProxy );
2348 ok( hr == S_OK, "got %08x\n", hr );
2350 hr = IWinHttpRequest_Send( req, empty );
2351 ok( hr == S_OK, "got %08x\n", hr );
2353 hr = IWinHttpRequest_Send( req, empty );
2354 ok( hr == S_OK, "got %08x\n", hr );
2356 hr = IWinHttpRequest_get_ResponseText( req, NULL );
2357 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2359 hr = IWinHttpRequest_get_ResponseText( req, &response );
2360 ok( hr == S_OK, "got %08x\n", hr );
2361 SysFreeString( response );
2363 hr = IWinHttpRequest_get_Status( req, NULL );
2364 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2367 hr = IWinHttpRequest_get_Status( req, &status );
2368 ok( hr == S_OK, "got %08x\n", hr );
2369 trace("%d\n", status);
2371 hr = IWinHttpRequest_get_StatusText( req, NULL );
2372 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2374 hr = IWinHttpRequest_get_StatusText( req, &status_text );
2375 ok( hr == S_OK, "got %08x\n", hr );
2376 trace("%s\n", wine_dbgstr_w(status_text));
2377 SysFreeString( status_text );
2379 hr = IWinHttpRequest_get_ResponseBody( req, NULL );
2380 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2382 hr = IWinHttpRequest_SetCredentials( req, username, password, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER );
2383 ok( hr == S_OK, "got %08x\n", hr );
2385 hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_PROXY, proxy_server, bypass_list );
2386 ok( hr == S_OK, "got %08x\n", hr );
2388 hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list );
2389 ok( hr == S_OK, "got %08x\n", hr );
2391 hr = IWinHttpRequest_GetAllResponseHeaders( req, NULL );
2392 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2394 hr = IWinHttpRequest_GetAllResponseHeaders( req, &headers );
2395 ok( hr == S_OK, "got %08x\n", hr );
2396 SysFreeString( headers );
2398 hr = IWinHttpRequest_GetResponseHeader( req, NULL, NULL );
2399 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2401 hr = IWinHttpRequest_GetResponseHeader( req, connection, NULL );
2402 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2404 hr = IWinHttpRequest_GetResponseHeader( req, connection, &value );
2405 ok( hr == S_OK, "got %08x\n", hr );
2406 SysFreeString( value );
2408 hr = IWinHttpRequest_SetRequestHeader( req, date, today );
2409 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_AFTER_SEND ), "got %08x\n", hr );
2411 hr = IWinHttpRequest_SetAutoLogonPolicy( req, AutoLogonPolicy_OnlyIfBypassProxy );
2412 ok( hr == S_OK, "got %08x\n", hr );
2414 VariantInit( &timeout );
2415 V_VT( &timeout ) = VT_I4;
2416 V_I4( &timeout ) = 10;
2417 hr = IWinHttpRequest_WaitForResponse( req, timeout, &succeeded );
2418 ok( hr == S_OK, "got %08x\n", hr );
2420 hr = IWinHttpRequest_get_Status( req, &status );
2421 ok( hr == S_OK, "got %08x\n", hr );
2423 hr = IWinHttpRequest_get_StatusText( req, &status_text );
2424 ok( hr == S_OK, "got %08x\n", hr );
2425 SysFreeString( status_text );
2427 hr = IWinHttpRequest_SetCredentials( req, username, password, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER );
2428 ok( hr == S_OK, "got %08x\n", hr );
2430 hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_PROXY, proxy_server, bypass_list );
2431 ok( hr == S_OK, "got %08x\n", hr );
2433 hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list );
2434 ok( hr == S_OK, "got %08x\n", hr );
2436 hr = IWinHttpRequest_Send( req, empty );
2437 ok( hr == S_OK, "got %08x\n", hr );
2439 hr = IWinHttpRequest_get_ResponseText( req, NULL );
2440 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2442 hr = IWinHttpRequest_get_ResponseText( req, &response );
2443 ok( hr == S_OK, "got %08x\n", hr );
2444 SysFreeString( response );
2446 hr = IWinHttpRequest_get_ResponseBody( req, NULL );
2447 ok( hr == E_INVALIDARG, "got %08x\n", hr );
2449 VariantInit( &body );
2450 V_VT( &body ) = VT_ERROR;
2451 hr = IWinHttpRequest_get_ResponseBody( req, &body );
2452 ok( hr == S_OK, "got %08x\n", hr );
2453 ok( V_VT( &body ) == (VT_ARRAY|VT_UI1), "got %08x\n", V_VT( &body ) );
2455 hr = VariantClear( &body );
2456 ok( hr == S_OK, "got %08x\n", hr );
2458 hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_PROXY, proxy_server, bypass_list );
2459 ok( hr == S_OK, "got %08x\n", hr );
2461 hr = IWinHttpRequest_SetProxy( req, HTTPREQUEST_PROXYSETTING_DIRECT, proxy_server, bypass_list );
2462 ok( hr == S_OK, "got %08x\n", hr );
2464 hr = IWinHttpRequest_GetAllResponseHeaders( req, &headers );
2465 ok( hr == S_OK, "got %08x\n", hr );
2466 SysFreeString( headers );
2468 hr = IWinHttpRequest_GetResponseHeader( req, connection, &value );
2469 ok( hr == S_OK, "got %08x\n", hr );
2470 SysFreeString( value );
2472 hr = IWinHttpRequest_SetRequestHeader( req, date, today );
2473 ok( hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_CANNOT_CALL_AFTER_SEND ), "got %08x\n", hr );
2475 hr = IWinHttpRequest_SetAutoLogonPolicy( req, AutoLogonPolicy_OnlyIfBypassProxy );
2476 ok( hr == S_OK, "got %08x\n", hr );
2478 hr = IWinHttpRequest_Send( req, empty );
2479 ok( hr == S_OK, "got %08x\n", hr );
2481 hr = IWinHttpRequest_Abort( req );
2482 ok( hr == S_OK, "got %08x\n", hr );
2484 hr = IWinHttpRequest_Abort( req );
2485 ok( hr == S_OK, "got %08x\n", hr );
2487 hr = IWinHttpRequest_Release( req );
2488 ok( hr == S_OK, "got %08x\n", hr );
2490 SysFreeString( method );
2491 SysFreeString( url );
2492 SysFreeString( username );
2493 SysFreeString( password );
2494 SysFreeString( connection );
2495 SysFreeString( date );
2496 SysFreeString( today );
2497 VariantClear( &proxy_server );
2498 VariantClear( &bypass_list );
2502 START_TEST (winhttp)
2504 static const WCHAR basicW[] = {'/','b','a','s','i','c',0};
2505 static const WCHAR quitW[] = {'/','q','u','i','t',0};
2506 struct server_info si;
2512 test_WinHttpTimeFromSystemTime();
2513 test_WinHttpTimeToSystemTime();
2514 test_WinHttpAddHeaders();
2515 test_secure_connection();
2516 test_request_parameter_defaults();
2518 test_set_default_proxy_config();
2519 test_empty_headers_param();
2521 test_resolve_timeout();
2523 test_IWinHttpRequest();
2525 si.event = CreateEvent(NULL, 0, 0, NULL);
2528 thread = CreateThread(NULL, 0, server_thread, (LPVOID)&si, 0, NULL);
2529 ok(thread != NULL, "failed to create thread %u\n", GetLastError());
2531 ret = WaitForSingleObject(si.event, 10000);
2532 ok(ret == WAIT_OBJECT_0, "failed to start winhttp test server %u\n", GetLastError());
2533 if (ret != WAIT_OBJECT_0)
2536 test_basic_request(si.port, NULL, basicW);
2537 test_no_headers(si.port);
2538 test_basic_authentication(si.port);
2540 /* send the basic request again to shutdown the server thread */
2541 test_basic_request(si.port, NULL, quitW);
2543 WaitForSingleObject(thread, 3000);