Add support for WXWEBREQUEST_BACKEND environment variable
Defining this variable overrides the default backend choice. Document the variable itself and also extend wxWebSession::New() documentation.
This commit is contained in:
@@ -26,5 +26,11 @@ wxWidgets programs.
|
|||||||
@c /usr/local or @c /usr). You can set WXPREFIX if you are for example
|
@c /usr/local or @c /usr). You can set WXPREFIX if you are for example
|
||||||
distributing a binary version of an application and you don't know in advance
|
distributing a binary version of an application and you don't know in advance
|
||||||
where it will be installed.}
|
where it will be installed.}
|
||||||
|
@itemdef{WXWEBREQUEST_BACKEND,
|
||||||
|
This variable can be set to override the choice of the default backend
|
||||||
|
used by wxWebRequest, see wxWebSession::New(). Most common use is to
|
||||||
|
set it to @c "CURL" to force using libcurl-based implementation under
|
||||||
|
MSW or macOS platforms where the native implementation would be chosed
|
||||||
|
by default.}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@@ -610,15 +610,28 @@ public:
|
|||||||
/**
|
/**
|
||||||
Creates a new wxWebSession object.
|
Creates a new wxWebSession object.
|
||||||
|
|
||||||
|
@a backend may be specified explicitly by using of the predefined @c
|
||||||
|
wxWebSessionBackendWinHTTP, @c wxWebSessionBackendURLSession or @c
|
||||||
|
wxWebSessionBackendCURL constants to select the corresponding backend
|
||||||
|
or left empty to select the default backend. The default depends on the
|
||||||
|
the current platform: WinHTTP-based implementation is used under MSW,
|
||||||
|
NSURLSession-based one under macOS and libcurl-based otherwise.
|
||||||
|
|
||||||
|
Further, if @c WXWEBREQUEST_BACKEND environment variable is defined, it
|
||||||
|
overrides the default backend selection, allowing to force the use of
|
||||||
|
libcurl-based implementation by default under MSW or macOS platforms,
|
||||||
|
for example.
|
||||||
|
|
||||||
Use IsOpened() to check if the session creation succeeded.
|
Use IsOpened() to check if the session creation succeeded.
|
||||||
|
|
||||||
@param backend
|
@param backend
|
||||||
The backend web session implementation to use.
|
The backend web session implementation to use or empty to use the
|
||||||
|
default implementation as described above.
|
||||||
|
|
||||||
@return
|
@return
|
||||||
The created wxWebSession
|
The created wxWebSession
|
||||||
*/
|
*/
|
||||||
static wxWebSession New(const wxString& backend = wxWebSessionBackendDefault);
|
static wxWebSession New(const wxString& backend = wxString());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Allows to check if the specified backend is available at runtime.
|
Allows to check if the specified backend is available at runtime.
|
||||||
|
@@ -39,9 +39,9 @@
|
|||||||
#include "wx/private/webrequest_curl.h"
|
#include "wx/private/webrequest_curl.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern WXDLLIMPEXP_DATA_NET(const char) wxWebSessionBackendWinHTTP[] = "wxWebSessionBackendWinHTTP";
|
extern WXDLLIMPEXP_DATA_NET(const char) wxWebSessionBackendWinHTTP[] = "WinHTTP";
|
||||||
extern WXDLLIMPEXP_DATA_NET(const char) wxWebSessionBackendURLSession[] = "wxWebSessionBackendURLSession";
|
extern WXDLLIMPEXP_DATA_NET(const char) wxWebSessionBackendURLSession[] = "URLSession";
|
||||||
extern WXDLLIMPEXP_DATA_NET(const char) wxWebSessionBackendCURL[] = "wxWebSessionBackendCURL";
|
extern WXDLLIMPEXP_DATA_NET(const char) wxWebSessionBackendCURL[] = "CURL";
|
||||||
|
|
||||||
wxDEFINE_EVENT(wxEVT_WEBREQUEST_STATE, wxWebRequestEvent);
|
wxDEFINE_EVENT(wxEVT_WEBREQUEST_STATE, wxWebRequestEvent);
|
||||||
wxDEFINE_EVENT(wxEVT_WEBREQUEST_DATA, wxWebRequestEvent);
|
wxDEFINE_EVENT(wxEVT_WEBREQUEST_DATA, wxWebRequestEvent);
|
||||||
@@ -824,6 +824,8 @@ wxWebSession wxWebSession::New(const wxString& backendOrig)
|
|||||||
wxString backend = backendOrig;
|
wxString backend = backendOrig;
|
||||||
if ( backend.empty() )
|
if ( backend.empty() )
|
||||||
{
|
{
|
||||||
|
if ( !wxGetEnv("WXWEBREQUEST_BACKEND", &backend) )
|
||||||
|
{
|
||||||
#if wxUSE_WEBREQUEST_WINHTTP
|
#if wxUSE_WEBREQUEST_WINHTTP
|
||||||
backend = wxWebSessionBackendWinHTTP;
|
backend = wxWebSessionBackendWinHTTP;
|
||||||
#elif wxUSE_WEBREQUEST_URLSESSION
|
#elif wxUSE_WEBREQUEST_URLSESSION
|
||||||
@@ -832,6 +834,7 @@ wxWebSession wxWebSession::New(const wxString& backendOrig)
|
|||||||
backend = wxWebSessionBackendCURL;
|
backend = wxWebSessionBackendCURL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wxStringWebSessionFactoryMap::iterator factory = gs_factoryMap.find(backend);
|
wxStringWebSessionFactoryMap::iterator factory = gs_factoryMap.find(backend);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user