From 050058c5bfa668e28bd6f53043126025943ee0a2 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Tue, 26 Jul 2011 09:26:07 +0200 Subject: [PATCH] winhttp: Add accept types to the request headers. --- dlls/winhttp/request.c | 11 ++++++++-- dlls/winhttp/session.c | 38 +++++++++++++++++++++++++++++++++- dlls/winhttp/winhttp_private.h | 2 ++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c index 15979c30de9..00f5caf840b 100644 --- a/dlls/winhttp/request.c +++ b/dlls/winhttp/request.c @@ -1031,8 +1031,13 @@ static BOOL send_request( request_t *request, LPCWSTR headers, DWORD headers_len WCHAR *req = NULL; char *req_ascii; int bytes_sent; - DWORD len; + DWORD len, i, flags; + flags = WINHTTP_ADDREQ_FLAG_ADD|WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA; + for (i = 0; i < request->num_accept_types; i++) + { + process_header( request, attr_accept, request->accept_types[i], flags, TRUE ); + } if (session->agent) process_header( request, attr_user_agent, session->agent, WINHTTP_ADDREQ_FLAG_ADD_IF_NEW, TRUE ); @@ -2422,6 +2427,8 @@ static HRESULT WINAPI winhttp_request_Open( BSTR url, VARIANT async ) { + static const WCHAR typeW[] = {'*','/','*',0}; + static const WCHAR *acceptW[] = {typeW, NULL}; struct winhttp_request *request = impl_from_IWinHttpRequest( iface ); HINTERNET hsession = NULL, hconnect = NULL, hrequest; URL_COMPONENTS uc; @@ -2461,7 +2468,7 @@ static HRESULT WINAPI winhttp_request_Open( err = get_last_error(); goto error; } - if (!(hrequest = WinHttpOpenRequest( hconnect, method, path, NULL, NULL, NULL, 0 ))) + if (!(hrequest = WinHttpOpenRequest( hconnect, method, path, NULL, NULL, acceptW, 0 ))) { err = get_last_error(); goto error; diff --git a/dlls/winhttp/session.c b/dlls/winhttp/session.c index 14f3940fef3..1fe18892724 100644 --- a/dlls/winhttp/session.c +++ b/dlls/winhttp/session.c @@ -527,7 +527,7 @@ end: static void request_destroy( object_header_t *hdr ) { request_t *request = (request_t *)hdr; - DWORD i; + unsigned int i; TRACE("%p\n", request); @@ -544,6 +544,8 @@ static void request_destroy( object_header_t *hdr ) heap_free( request->headers[i].value ); } heap_free( request->headers ); + for (i = 0; i < request->num_accept_types; i++) heap_free( request->accept_types[i] ); + heap_free( request->accept_types ); heap_free( request ); } @@ -859,6 +861,39 @@ static const object_vtbl_t request_vtbl = request_set_option }; +static BOOL store_accept_types( request_t *request, const WCHAR **accept_types ) +{ + const WCHAR **types = accept_types; + int i; + + if (!types) return TRUE; + while (*types) + { + request->num_accept_types++; + types++; + } + if (!request->num_accept_types) return TRUE; + if (!(request->accept_types = heap_alloc( request->num_accept_types * sizeof(WCHAR *)))) + { + request->num_accept_types = 0; + return FALSE; + } + types = accept_types; + for (i = 0; i < request->num_accept_types; i++) + { + if (!(request->accept_types[i] = strdupW( *types ))) + { + for (; i >= 0; i--) heap_free( request->accept_types[i] ); + heap_free( request->accept_types ); + request->accept_types = NULL; + request->num_accept_types = 0; + return FALSE; + } + types++; + } + return TRUE; +} + /*********************************************************************** * WinHttpOpenRequest (winhttp.@) */ @@ -926,6 +961,7 @@ HINTERNET WINAPI WinHttpOpenRequest( HINTERNET hconnect, LPCWSTR verb, LPCWSTR o if (!version || !version[0]) version = http1_1; if (!(request->version = strdupW( version ))) goto end; + if (!(store_accept_types( request, types ))) goto end; if (!(hrequest = alloc_handle( &request->hdr ))) goto end; request->hdr.handle = hrequest; diff --git a/dlls/winhttp/winhttp_private.h b/dlls/winhttp/winhttp_private.h index 4bac24f148f..fbd5032e174 100644 --- a/dlls/winhttp/winhttp_private.h +++ b/dlls/winhttp/winhttp_private.h @@ -157,6 +157,8 @@ typedef struct DWORD content_read; /* bytes read so far */ header_t *headers; DWORD num_headers; + WCHAR **accept_types; + DWORD num_accept_types; } request_t; typedef struct _task_header_t task_header_t;