SetHeaderMap cannot set Accept header

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

SetHeaderMap cannot set Accept header

Postby rado » Sun Feb 17, 2019 9:49 am

I need to send request with custom "Accept" header, but it does not work.
I've also tried this in cefclient / file test_runner.cc method RunRequestTest by adding code to modify headers:
Code: Select all
// Add a custom header
  CefRequest::HeaderMap headerMap;
  headerMap.insert(std::make_pair("X-My-Header", "My Header Value"));

   // added
     headerMap.erase("Accept");
     headerMap.insert(std::make_pair("Accept", "application/test"));
   
   headerMap.erase("User-Agent");
   headerMap.insert(std::make_pair("User-Agent", "test agent"));
    // end
   
  request->SetHeaderMap(headerMap);


Result is:
Code: Select all
URL: http://tests/request
Method: POST
Headers:
   Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
   Content-Type: application/x-www-form-urlencoded
   Origin: null
   Upgrade-Insecure-Requests: 1
   User-Agent: test agent
   X-My-Header: My Header Value
Post Data:
   Bytes: arg1=val1&arg2=val2


the User-Agent was correctly modified, also X-My-Header is added, but change of Accept is ignored.
Is it known problem? (I could not find this mentioned anywhere) Is it possible to fix this or some workaround?
Thank you
rado
Expert
 
Posts: 145
Joined: Wed Oct 05, 2011 3:32 am

Re: SetHeaderMap cannot set Accept header

Postby Czarek » Thu Feb 21, 2019 10:22 am

Can you tell more of what you are trying to do? Are you using CefURLRequest?
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: SetHeaderMap cannot set Accept header

Postby rado » Thu Feb 21, 2019 11:21 am

Czarek wrote:Can you tell more of what you are trying to do? Are you using CefURLRequest?

It is not using CefURLRequest, this is how my cefclient application makes the request:
Code: Select all
browser->GetMainFrame()->LoadRequest(request);

BTW setting the Accept header works correctly with CefURLRequest. Currently I'm using CefURLRequest as workaround solution - in CefResourceHandler::ProcessRequest I handle the request using CefURLRequest but still I'd like avoid that because CefURLRequest has other problems.
rado
Expert
 
Posts: 145
Joined: Wed Oct 05, 2011 3:32 am

Re: SetHeaderMap cannot set Accept header

Postby magreenblatt » Thu Feb 21, 2019 5:15 pm

Some values are overridden in the Chromium network stack. You can use https://cs.chromium.org to try and find where.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: SetHeaderMap cannot set Accept header

Postby rado » Fri Feb 22, 2019 7:21 am

I've found it here: https://cs.chromium.org/chromium/src/content/browser/loader/navigation_url_loader_impl.cc?l=233
If I've found correct place, it does not look good, it sets the header unconditionally unless there would be another place where it can be later overridden.
rado
Expert
 
Posts: 145
Joined: Wed Oct 05, 2011 3:32 am

Re: SetHeaderMap cannot set Accept header

Postby magreenblatt » Fri Feb 22, 2019 11:20 am

rado wrote:I've found it here: https://cs.chromium.org/chromium/src/content/browser/loader/navigation_url_loader_impl.cc?l=233
If I've found correct place, it does not look good, it sets the header unconditionally unless there would be another place where it can be later overridden.

That looks like the correct place to me. It's probably best to use CefURLRequest or CefBrowserHost::StartDownload if you're looking to download/process the response contents instead of loading them in the browser.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 20 guests