From 2f752970360977597cdd450d7793b7d0e2a53b51 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Mon, 26 Nov 2018 12:08:57 +0100 Subject: [PATCH] winhttp: Store Accept headers like the other headers. Based on a patch by Sebastian Lackner. Signed-off-by: Hans Leidekker Signed-off-by: Alexandre Julliard --- dlls/winhttp/request.c | 10 ++-------- dlls/winhttp/session.c | 31 +++++-------------------------- dlls/winhttp/winhttp_private.h | 5 ++--- 3 files changed, 9 insertions(+), 37 deletions(-) diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c index a081b608ab9..5525c1c0bbe 100644 --- a/dlls/winhttp/request.c +++ b/dlls/winhttp/request.c @@ -398,8 +398,7 @@ static BOOL delete_header( struct request *request, DWORD index ) return TRUE; } -static BOOL process_header( struct request *request, const WCHAR *field, const WCHAR *value, DWORD flags, - BOOL request_only ) +BOOL process_header( struct request *request, const WCHAR *field, const WCHAR *value, DWORD flags, BOOL request_only ) { int index; struct header hdr; @@ -2180,16 +2179,11 @@ static BOOL send_request( struct request *request, const WCHAR *headers, DWORD h struct session *session = connect->session; char *wire_req; int bytes_sent; - DWORD len, i, flags; + DWORD len; clear_response_headers( request ); drain_content( request ); - 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 ); diff --git a/dlls/winhttp/session.c b/dlls/winhttp/session.c index f8d98d0c860..39e8d8233f4 100644 --- a/dlls/winhttp/session.c +++ b/dlls/winhttp/session.c @@ -626,8 +626,6 @@ static void request_destroy( struct object_header *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 ); for (i = 0; i < TARGET_MAX; i++) { for (j = 0; j < SCHEME_MAX; j++) @@ -1042,34 +1040,15 @@ static const struct object_vtbl request_vtbl = request_set_option }; -static BOOL store_accept_types( struct request *request, const WCHAR **accept_types ) +static BOOL add_accept_types_header( struct request *request, const WCHAR **types ) { - const WCHAR **types = accept_types; - DWORD i; + static const WCHAR acceptW[] = {'A','c','c','e','p','t',0}; + static const DWORD flags = WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA; 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 - 1] ); - heap_free( request->accept_types ); - request->accept_types = NULL; - request->num_accept_types = 0; - return FALSE; - } + if (!process_header( request, acceptW, *types, flags, TRUE )) return FALSE; types++; } return TRUE; @@ -1151,7 +1130,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 (!(add_accept_types_header( 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 14cee4403b2..b46f7087d89 100644 --- a/dlls/winhttp/winhttp_private.h +++ b/dlls/winhttp/winhttp_private.h @@ -198,8 +198,6 @@ struct request char read_buf[8192]; /* buffer for already read but not returned data */ struct header *headers; DWORD num_headers; - WCHAR **accept_types; - DWORD num_accept_types; struct authinfo *authinfo; struct authinfo *proxy_authinfo; HANDLE task_wait; @@ -288,7 +286,8 @@ void destroy_cookies( struct session * ) DECLSPEC_HIDDEN; BOOL set_server_for_hostname( struct connect *, const WCHAR *, INTERNET_PORT ) DECLSPEC_HIDDEN; void destroy_authinfo( struct authinfo * ) DECLSPEC_HIDDEN; -void release_host( struct hostdata *host ) DECLSPEC_HIDDEN; +void release_host( struct hostdata * ) DECLSPEC_HIDDEN; +BOOL process_header( struct request *, const WCHAR *, const WCHAR *, DWORD, BOOL ) DECLSPEC_HIDDEN; extern HRESULT WinHttpRequest_create( void ** ) DECLSPEC_HIDDEN; void release_typelib( void ) DECLSPEC_HIDDEN;