The base class for handling custom schemes in wxWebView, for example to allow virtual file system support.
A new handler should either implement GetFile() or if a more detailed request handling is required (access to headers, post data) StartRequest() has to be implemented.
- Since
- 2.9.3
- See also
- wxWebView
Implementing this method allows for more control over requests from the backend than GetFile().
More details of the request are available from the request object which allows access to URL, method, postdata and headers.
A response can be send via the response object. The response does not have to be finished from this method and it's possible to be finished asynchronously via wxWebViewHandlerResponse::Finish().
The following pseudo code demonstrates a typical implementation:
wxSharedPtr<wxWebViewHandlerResponse> response) override
{
response->SetHeader("Access-Control-Allow-Origin", "*");
response->SetHeader("Access-Control-Allow-Headers", "*");
if (request.
GetMethod().IsSameAs(
"options",
false))
{
response->Finish("");
return;
}
if (!request.
GetHeader(
"Content-Type").StartsWith(
"application/json"))
{
response->FinishWithError();
return;
}
...
response->SetContentType("application/json");
response->Finish("{ result: true }");
}
virtual void StartRequest(const wxWebViewHandlerRequest &request, wxSharedPtr< wxWebViewHandlerResponse > response)
Implementing this method allows for more control over requests from the backend than GetFile().
A class giving access to various parameters of a webview request.
Definition webview.h:413
virtual wxString GetDataString(const wxMBConv &conv=wxConvUTF8) const
virtual wxString GetHeader(const wxString &name) const =0
Returns a header from the request or an empty string if the header could not be found.
virtual wxString GetMethod() const =0
wxString()
Default constructor.
- Note
- This is only used by macOS, Chromium, and the Edge backend.
- See also
- GetFile()
- Since
- 3.3.0