Click or drag to resize

IResourceHandler Interface

Version 108.4.130
Class used to implement a custom resource handler. The methods of this class will always be called on the CEF IO thread. Blocking the CEF IO thread will adversely affect browser performance. We suggest you execute your code in a Task (or similar). To implement async handling, spawn a new Task (or similar), keep a reference to the callback. When you have a fully populated stream, execute the callback. Once the callback Executes, GetResponseHeaders will be called where you can modify the response including headers, or even redirect to a new Url. Set your responseLength and headers Populate the dataOut stream in ReadResponse. For those looking for a sample implementation or upgrading from a previous version ResourceHandler. For those upgrading, inherit from ResourceHandler instead of IResourceHandler add the override keyword to existing methods e.g. ProcessRequestAsync.

Namespace:  CefSharp
Assembly:  CefSharp (in CefSharp.dll) Version: 108.4.130.0 (108.4.130.0)
Syntax
public interface IResourceHandler : IDisposable

The IResourceHandler type exposes the following members.

Methods
  NameDescription
Public methodCancel
Request processing has been canceled.
Public methodDispose
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
(Inherited from IDisposable.)
Public methodGetResponseHeaders
Retrieve response header information. If the response length is not known set responseLength to -1 and ReadResponse() will be called until it returns false. If the response length is known set responseLength to a positive value and ReadResponse() will be called until it returns false or the specified number of bytes have been read. It is also possible to set response to a redirect http status code and pass the new URL via a Location header. Likewise with redirectUrl it is valid to set a relative or fully qualified URL as the Location header value. If an error occured while setting up the request you can call ErrorCode on response to indicate the error condition.
Public methodOpen
Open the response stream. - To handle the request immediately set handleRequest to true and return true. - To decide at a later time set handleRequest to false, return true, and execute callback to continue or cancel the request. - To cancel the request immediately set handleRequest to true and return false. This method will be called in sequence but not from a dedicated thread. For backwards compatibility set handleRequest to false and return false and the ProcessRequest(IRequest, ICallback) method will be called.
Public methodProcessRequest Obsolete.
Begin processing the request.
Public methodRead
Read response data. If data is available immediately copy up to dataOut.Length bytes into dataOut, set bytesRead to the number of bytes copied, and return true. To read the data at a later time keep a pointer to dataOut, set bytesRead to 0, return true and execute callback when the data is available (dataOut will remain valid until the callback is executed). To indicate response completion set bytesRead to 0 and return false. To indicate failure set bytesRead to < 0 (e.g. -2 for ERR_FAILED) and return false. This method will be called in sequence but not from a dedicated thread. For backwards compatibility set bytesRead to -1 and return false and the ReadResponse method will be called.
Public methodReadResponse Obsolete.
Read response data. If data is available immediately copy to dataOut, set bytesRead to the number of bytes copied, and return true. To read the data at a later time set bytesRead to 0, return true and call ICallback.Continue() when the data is available. To indicate response completion return false.
Public methodSkip
Skip response data when requested by a Range header. Skip over and discard bytesToSkip bytes of response data. - If data is available immediately set bytesSkipped to the number of of bytes skipped and return true. - To read the data at a later time set bytesSkipped to 0, return true and execute callback when the data is available. - To indicate failure set bytesSkipped to < 0 (e.g. -2 for ERR_FAILED) and return false. This method will be called in sequence but not from a dedicated thread.
Top
See Also