Extending the default CefResourceHandler

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.

Extending the default CefResourceHandler

Postby sdiverdi » Wed Mar 17, 2021 3:03 pm

Hi all, like many people I'm running up against the limitations of the file:// protocol when loading local JS files in my CEF app (CORS errors and incorrect mime types). Based on what I've read here and on the wiki, I planned to solve this by making a CefSchemeHandlerFactory that returns my own CefResourceHandler, which I can use to load URLs that look like http://myapp/path/to/local/file, to replace file://path/to/local/file. Now that I'm starting to implement the CefResourceHandler I realize I have to reimplement _everything_, including deducing mime types for whatever files might be opened. I'd rather not duplicate so much logic and would prefer to defer to the default resource handler for most of this functionality -- e.g. I could intercept a request for http://myapp/path/to/local/file, convert it into file://path/to/local/file, use the default resource handler to generate response headers, then amend those response headers with my own (basically I want to add CORS headers and set the mime type for .js files), and return it. Is this possible? Or is there an easier way than re-implementing all of this in a custom CefResourceHandler? Thanks!
sdiverdi
Mentor
 
Posts: 51
Joined: Fri Dec 25, 2020 7:41 pm

Re: Extending the default CefResourceHandler

Postby magreenblatt » Wed Mar 17, 2021 3:09 pm

You can use CefResourceManager. See https://bitbucket.org/chromiumembedded/ ... ce-manager
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm

Re: Extending the default CefResourceHandler

Postby sdiverdi » Wed Mar 17, 2021 4:53 pm

Worked like a charm, thanks!
sdiverdi
Mentor
 
Posts: 51
Joined: Fri Dec 25, 2020 7:41 pm

Re: Extending the default CefResourceHandler

Postby jyelloz » Tue May 16, 2023 2:06 pm

Hi, I was looking into performing a similar task to this topic with CEF, specifically manipulation of response headers. Is it possible with the CefResourceManager -- or anywhere else in CEF -- to have the default resource handler service a request for some scheme, then wrap it in a custom implementation of CefResourceHandler that provides a set of response headers that differs from the default handler?
jyelloz
Newbie
 
Posts: 1
Joined: Tue May 16, 2023 12:54 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 59 guests