3

So Im still trying to find the feature (if it is there) in Cefsharp 3, where one can inspect the headers from the response of a request. In case its not there, is it because it is not there in CEF 3 ? and or, where should i start looking, if Im to implement it ?

Luboš Turek
  • 6,273
  • 9
  • 40
  • 50
Kmtdk
  • 184
  • 2
  • 7

2 Answers2

4

This feature is not in CEF 3 yet. Here's the outstanding issue for it: https://code.google.com/p/chromiumembedded/issues/detail?id=515

There is a workaround noted...

There's no great way to filter response contents with CEF3 currently. You can use CefResourceHandler via CefRequestHandler::GetResourceHandler and execute the request/return the response contents yourself using CefURLRequest.

... however this workaround is not possible in CefSharp 3 because CefURLRequestClient and friends are not implemented.

At this stage, depending on how comfortable you are with C++ you might consider:

  • contributing to the (C++) CEF project and implement the response filtering feature - this will be all C++.
  • contributing C# wrappers of CefURLRequestClient and friends to the CefSharp project - which is a combination of light C++ and C#.

You might also be interested that there is a way to get HTTP headers in JavaScript, as long as you have initiated the request yourself using AJAX: Accessing the web page's HTTP Headers in JavaScript

This type of solution could easily be done with CefSharp 3 by injecting JavaScript into the current page.

Community
  • 1
  • 1
Yoshi
  • 3,325
  • 1
  • 19
  • 24
0

An alternative that provides more control is to use schemehandlers (it's cleaner IMO).

Add a scheme handler that intercepts your resource loading:

CEF.RegisterScheme("ascheme", new HandlerFactory());

then (once you've created a trivial factory or 2) you have this override available:

public bool ProcessRequestAsync(IRequest request, ISchemeHandlerResponse response, OnRequestCompletedHandler requestCompletedCallback)

The Response contains Headers/MimeType and Stream to allow more control. I hope this helps.

penderi
  • 8,673
  • 5
  • 45
  • 62
  • Using a scheme handler intercepts the loading prior to the request being sent, so there is no way to get the original response - you have to submit the request and return the response manually using .NET's `WebClient`/`WebRequest`, but this has drawbacks (cookies not being passed, different user-agent, etc.). – Yoshi Apr 09 '15 at 03:12
  • The request object in the above method allows access to the full request as well as the headers. I thought that's what the question asked. – penderi Apr 09 '15 at 07:25
  • He wants the headers from the response instead. – Yoshi Apr 10 '15 at 07:23