I'm looking for a way to modify response headers using CefSharp, on the fly (before they load in browser)
Here's what I've tried so far:
First, I setup the event to modify the response event
_browser.RequestHandler.GetResourceResponseFilter += new CfxGetResourceResponseFilterEventHandler(eh.GetResourceResponseFilter);
And here's the method used as callback
public void GetResourceResponseFilter(object sender, CfxGetResourceResponseFilterEventArgs e)
{
// we're doing modifycations only for example.com
if (!e.Request.Url.Contains("example.com")) return;
var headers = e.Response.GetHeaderMap(); // get header map
var new_headers = new List<string[]>(); // new headers will be stored here
// iterate over original headers
for(int i = 0; i < headers.Count - 1; i++)
{
var header = headers[i];
// if we're on our header, ignore it
if (header[0].Equals("remove-me")) continue;
// otherwise, add it to new headers list
new_headers.Add(header);
}
// set new headers for response
e.Response.SetHeaderMap(new_headers);
}
For some reason, this doesn't seem to make any change inside the browser.
I'm iterating over all headers, checking for my header and if present, ignore it. All other headers are added to new_headers list and set with the SetHeaderMap. The method doesn't seem to have any effect.
Aucun commentaire:
Enregistrer un commentaire