winhttp: Implement WinHttpQueryHeaders(WINHTTP_QUERY_RAW_HEADERS).
This commit is contained in:
parent
b34e816f4a
commit
6fe2edb5de
|
@ -526,7 +526,7 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID
|
|||
header_t *header = NULL;
|
||||
BOOL request_only, ret = FALSE;
|
||||
int requested_index, header_index = -1;
|
||||
DWORD attr;
|
||||
DWORD attr, len;
|
||||
|
||||
request_only = level & WINHTTP_QUERY_FLAG_REQUEST_HEADERS;
|
||||
requested_index = index ? *index : 0;
|
||||
|
@ -539,10 +539,45 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID
|
|||
header_index = get_header_index( request, name, requested_index, request_only );
|
||||
break;
|
||||
}
|
||||
case WINHTTP_QUERY_RAW_HEADERS:
|
||||
{
|
||||
WCHAR *headers, *p, *q;
|
||||
|
||||
if (request_only)
|
||||
headers = build_request_string( request );
|
||||
else
|
||||
headers = request->raw_headers;
|
||||
|
||||
if (!(p = headers)) return FALSE;
|
||||
for (len = 0; *p; p++) if (*p != '\r') len++;
|
||||
|
||||
if ((len + 1) * sizeof(WCHAR) > *buflen || !buffer)
|
||||
{
|
||||
len++;
|
||||
set_last_error( ERROR_INSUFFICIENT_BUFFER );
|
||||
}
|
||||
else if (buffer)
|
||||
{
|
||||
for (p = headers, q = (WCHAR *)buffer; *p; p++, q++)
|
||||
{
|
||||
if (*p != '\r') *q = *p;
|
||||
else
|
||||
{
|
||||
*q = 0;
|
||||
p++; /* skip '\n' */
|
||||
}
|
||||
}
|
||||
*q = 0;
|
||||
TRACE("returning data: %s\n", debugstr_wn((WCHAR *)buffer, len));
|
||||
ret = TRUE;
|
||||
}
|
||||
*buflen = len * sizeof(WCHAR);
|
||||
if (request_only) heap_free( headers );
|
||||
return ret;
|
||||
}
|
||||
case WINHTTP_QUERY_RAW_HEADERS_CRLF:
|
||||
{
|
||||
WCHAR *headers;
|
||||
DWORD len;
|
||||
|
||||
if (request_only)
|
||||
headers = build_request_string( request );
|
||||
|
@ -551,7 +586,7 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID
|
|||
|
||||
if (!headers) return FALSE;
|
||||
len = strlenW( headers ) * sizeof(WCHAR);
|
||||
if (len + sizeof(WCHAR) > *buflen)
|
||||
if (len + sizeof(WCHAR) > *buflen || !buffer)
|
||||
{
|
||||
len += sizeof(WCHAR);
|
||||
set_last_error( ERROR_INSUFFICIENT_BUFFER );
|
||||
|
|
|
@ -287,7 +287,7 @@ static void test_WinHttpAddHeaders(void)
|
|||
ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_RAW_HEADERS_CRLF | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
|
||||
test_header_name, NULL, &len, &index);
|
||||
ok(ret == FALSE, "WinHttpQueryHeaders unexpectedly succeeded.\n");
|
||||
todo_wine ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
|
||||
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
|
||||
ok(len > 40, "WinHttpQueryHeaders returned invalid length: expected greater than 40, got %d\n", len);
|
||||
ok(index == 0, "WinHttpQueryHeaders incorrectly incremented header index.\n");
|
||||
|
||||
|
@ -331,6 +331,30 @@ static void test_WinHttpAddHeaders(void)
|
|||
"WinHttpQueryHeaders returned invalid end of header string.\n");
|
||||
ok(index == 0, "WinHttpQueryHeaders incremented header index.\n");
|
||||
|
||||
index = 0;
|
||||
len = 0;
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_RAW_HEADERS | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
|
||||
test_header_name, NULL, &len, &index);
|
||||
ok(ret == FALSE, "WinHttpQueryHeaders unexpectedly succeeded.\n");
|
||||
ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
|
||||
"WinHttpQueryHeaders set incorrect error: expected ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
|
||||
ok(len > 40, "WinHttpQueryHeaders returned invalid length: expected greater than 40, got %d\n", len);
|
||||
ok(index == 0, "WinHttpQueryHeaders failed: index was incremented.\n");
|
||||
|
||||
oldlen = len;
|
||||
index = 0;
|
||||
len = sizeof(buffer);
|
||||
memset(buffer, 0xff, sizeof(buffer));
|
||||
ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_RAW_HEADERS | WINHTTP_QUERY_FLAG_REQUEST_HEADERS,
|
||||
test_header_name, buffer, &len, &index);
|
||||
ok(ret == TRUE, "WinHttpQueryHeaders failed %u\n", GetLastError());
|
||||
ok(len + sizeof(WCHAR) <= oldlen, "resulting length longer than advertized\n");
|
||||
ok((len < sizeof(buffer) - sizeof(WCHAR)) && !buffer[len / sizeof(WCHAR)] && !buffer[len / sizeof(WCHAR) - 1],
|
||||
"no double NULL terminator\n");
|
||||
ok(!memcmp(buffer, test_header_begin, sizeof(test_header_begin)), "invalid beginning of header string\n");
|
||||
ok(index == 0, "header index was incremented\n");
|
||||
|
||||
/* tests for more indices */
|
||||
ret = WinHttpAddRequestHeaders(request, test_headers[1], -1L, WINHTTP_ADDREQ_FLAG_ADD);
|
||||
ok(ret == TRUE, "WinHttpAddRequestHeaders failed to add duplicate header: %d\n", ret);
|
||||
|
|
Loading…
Reference in New Issue