You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Upstream CEF has now exposed new API, when you only need to alter request you can do it easily using GetResourceResponseFilter. The complexity of the wxpython-response.py example that implements ResourceHandler would be no more required for such case. The new callback available in upstream:
+ ///
+ // Called on the IO thread to optionally filter resource response content.
+ // |request| and |response| represent the request and response respectively
+ // and cannot be modified in this callback.
+ ///
+ /*--cef()--*/
+ virtual CefRefPtr<CefResponseFilter> GetResourceResponseFilter(
+ CefRefPtr<CefBrowser> browser,
+ CefRefPtr<CefFrame> frame,
+ CefRefPtr<CefRequest> request,
+ CefRefPtr<CefResponse> response) {
+ return NULL;
+ }
Filter response body with CefResponseFilter::Filter:
///
// Called to filter a chunk of data. |data_in| is the input buffer containing
// |data_in_size| bytes of pre-filter data (|data_in| will be NULL if
// |data_in_size| is zero). |data_out| is the output buffer that can accept up
// to |data_out_size| bytes of filtered output data. Set |data_in_read| to the
// number of bytes that were read from |data_in|. Set |data_out_written| to
// the number of bytes that were written into |data_out|. If some or all of
// the pre-filter data was read successfully but more data is needed in order
// to continue filtering (filtered output is pending) return
// RESPONSE_FILTER_NEED_MORE_DATA. If some or all of the pre-filter data was
// read successfully and all available filtered output has been written return
// RESPONSE_FILTER_DONE. If an error occurs during filtering return
// RESPONSE_FILTER_ERROR. This method will be called repeatedly until there is
// no more data to filter (resource response is complete), |data_in_read|
// matches |data_in_size| (all available pre-filter bytes have been read), and
// the method returns RESPONSE_FILTER_DONE or RESPONSE_FILTER_ERROR. Do not
// keep a reference to the buffers passed to this method.
///
/*--cef(optional_param=data_in,default_retval=RESPONSE_FILTER_ERROR)--*/
virtual FilterStatus Filter(void* data_in,
size_t data_in_size,
size_t& data_in_read,
void* data_out,
size_t data_out_size,
size_t& data_out_written) =0;
There was also added OnResourceResponse, but it doesn't allow altering response:
+ // Called on the IO thread when a resource response is received. To allow the
+ // resource to load normally return false. To redirect or retry the resource
+ // modify |request| (url, headers or post body) and return true. The
+ // |response| object cannot be modified in this callback.
+ ///
+ /*--cef()--*/
+ virtual bool OnResourceResponse(CefRefPtr<CefBrowser> browser,
+ CefRefPtr<CefFrame> frame,
+ CefRefPtr<CefRequest> request,
+ CefRefPtr<CefResponse> response) {
+ return false;
+ }
Also a bit related, new OnResourceLoadComplete callback:
+ ///
+ // Called on the IO thread when a resource load has completed. |request| and
+ // |response| represent the request and response respectively and cannot be
+ // modified in this callback. |status| indicates the load completion status.
+ // |received_content_length| is the number of response bytes actually read.
+ ///
+ /*--cef()--*/
+ virtual void OnResourceLoadComplete(CefRefPtr<CefBrowser> browser,
+ CefRefPtr<CefFrame> frame,
+ CefRefPtr<CefRequest> request,
+ CefRefPtr<CefResponse> response,
+ URLRequestStatus status,
+ int64 received_content_length) {}
The text was updated successfully, but these errors were encountered:
cztomczak
changed the title
wxpython-response.py and OnResourceResponse availability in upstream
wxpython-response.py and GetResourceResponseFilter availability in upstream
Jun 24, 2016
cztomczak
changed the title
wxpython-response.py and GetResourceResponseFilter availability in upstream
Read web response contents using GetResourceResponseFilter callback
May 26, 2017
how to use the new api of the GetResourceResponseFilter or the OnResourceResponse callback ?
cefpython version is 57.1;
platform is Windows 10;
wxpython-response.py is too complexity for me and 'image/*' data render incorrect.
cztomczak
changed the title
Read web response contents using GetResourceResponseFilter callback
Read and modify web response using GetResourceResponseFilter callback
Aug 4, 2018
Currently to read web response you have to implement ResourceHandler with the use of WebRequest object and WebRequestClient interface that allows reading/modifying web requests: see the wxpython-response.py example in the cefpython31 branch.
Upstream CEF has now exposed new API, when you only need to alter request you can do it easily using GetResourceResponseFilter. The complexity of the wxpython-response.py example that implements ResourceHandler would be no more required for such case. The new callback available in upstream:
Filter response body with CefResponseFilter::Filter:
There was also added OnResourceResponse, but it doesn't allow altering response:
Also a bit related, new OnResourceLoadComplete callback:
The text was updated successfully, but these errors were encountered: