Origin header set to null when using custom scheme handler

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.

Origin header set to null when using custom scheme handler

Postby Czarek » Mon Aug 06, 2018 8:04 am

I've modified the "scheme_test.cc" file [1] and changed form action to http://xhaus.com/headers , so that I can see the headers sent. However I can see that "Origin" header is set to "null". In scheme_test_common.cc [2] I can see that the "is_cors_enabled" parameter is set to true, so according to docs [3] this should enable the Origin header. Is this a bug or am I doing something wrong?

In Electron project, in this comment [4], I can see that Origin is set to "app://" when using app:// scheme handler.

Ref:
[1] https://github.com/chromiumembedded/cef ... est.cc#L54
[2] https://github.com/chromiumembedded/cef ... mon.cc#L14
[3] https://github.com/chromiumembedded/cef ... eme.h#L126
[4] https://github.com/electron/electron/is ... -246335171
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: Origin header set to null when using custom scheme handl

Postby ndesktop » Mon Aug 06, 2018 4:33 pm

Maybe CORS does not apply to non-http schemes (and you are using a http:// one)?
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: Origin header set to null when using custom scheme handl

Postby Czarek » Tue Aug 07, 2018 6:15 am

I've set the "is_cors_enabled" option when registering scheme. Link to docs in my previous post. It works in Electron, so I guess it should work in CEF as well.
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: Origin header set to null when using custom scheme handl

Postby ndesktop » Tue Aug 07, 2018 7:22 am

Electron guys seems to overcome this by removing the (null?) Origin in onBeforeSendHeaders.
I'm not sure what will be the equivalent in libcef, perhaps OnBeforeResourceLoad + CefBeforeResourceLoadCallback or by patching GetRequestHandler and call a patch overridden method in CefRequestImpl::Set.
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: Origin header set to null when using custom scheme handl

Postby Czarek » Tue Aug 07, 2018 7:31 am

Thanks! Good to know. I've set Origin header in OnBeforeResourceLoad when sending a POST request to a http:// from a file:// protocol and it works fine.
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: Origin header set to null when using custom scheme handl

Postby ndesktop » Tue Aug 07, 2018 9:41 am

I've noticed sometimes (yes, I know...) that setting a header DCHECKs because the request object has been SetReadOnly.
I could not find the time to investigate deeper - only use IsReadOnly() to verify if the CefRequest::SetReadOnly underlying object has been called.
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am

Re: Origin header set to null when using custom scheme handl

Postby Czarek » Tue Aug 07, 2018 10:06 am

Do you recall in which method of request handler did that happen? Setting header doesn't e.g. work in OnBeforeBrowse. Docs for OnBeforeResourceLoad state that request object can be modified.
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: Origin header set to null when using custom scheme handl

Postby Czarek » Tue Aug 07, 2018 10:14 am

The issue you referenced earlier in Electron was about making a POST request to a http:// from file:// protocol. I only noticed this now. In this case it is expected for Origin header to be null, because it is a 'local' scheme. The issue I report here is different. It is about a custom scheme handler that is standard, not local and with cors enabled. In such case the Origin header should be set automatically according to WHATWG specification and CEF docs. In Electron Origin header is set properly when using a custom scheme.
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: Origin header set to null when using custom scheme handl

Postby ndesktop » Tue Aug 07, 2018 11:11 am

Czarek wrote:Do you recall in which method of request handler did that happen? Setting header doesn't e.g. work in OnBeforeBrowse. Docs for OnBeforeResourceLoad state that request object can be modified.

I'm not 100% sure, but yes, I think OnBeforeBrowse.
ndesktop
Master
 
Posts: 756
Joined: Thu Dec 03, 2015 10:10 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 107 guests