Implement authentication support for wxWebRequest under Mac

Add wxWebAuthChallengeURLSession and use the appropriate delegate
callback to create it.
This commit is contained in:
Vadim Zeitlin
2021-01-14 23:07:27 +01:00
parent e80b65b132
commit 70e7861a7d
3 changed files with 128 additions and 24 deletions

View File

@@ -14,6 +14,7 @@
#include "wx/private/webrequest.h"
DECLARE_WXCOCOA_OBJC_CLASS(NSURLCredential);
DECLARE_WXCOCOA_OBJC_CLASS(NSURLSession);
DECLARE_WXCOCOA_OBJC_CLASS(NSURLSessionTask);
DECLARE_WXCOCOA_OBJC_CLASS(wxWebSessionDelegate);
@@ -22,6 +23,29 @@ class wxWebSessionURLSession;
class wxWebRequestURLSession;
class wxWebResponseURLSession;
class wxWebAuthChallengeURLSession : public wxWebAuthChallengeImpl
{
public:
wxWebAuthChallengeURLSession(wxWebAuthChallenge::Source source,
wxWebRequestURLSession& request)
: wxWebAuthChallengeImpl(source),
m_request(request)
{
}
~wxWebAuthChallengeURLSession();
void SetCredentials(const wxWebCredentials& cred) wxOVERRIDE;
WX_NSURLCredential GetURLCredential() const { return m_cred; }
private:
wxWebRequestURLSession& m_request;
WX_NSURLCredential m_cred = NULL;
wxDECLARE_NO_COPY_CLASS(wxWebAuthChallengeURLSession);
};
class wxWebResponseURLSession : public wxWebResponseImpl
{
public:
@@ -67,7 +91,8 @@ public:
wxWebResponseImplPtr GetResponse() const wxOVERRIDE
{ return m_response; }
wxWebAuthChallengeImplPtr GetAuthChallenge() const wxOVERRIDE;
wxWebAuthChallengeImplPtr GetAuthChallenge() const wxOVERRIDE
{ return m_authChallenge; }
wxFileOffset GetBytesSent() const wxOVERRIDE;
@@ -79,14 +104,22 @@ public:
void HandleCompletion();
void HandleChallenge(wxWebAuthChallengeURLSession* challenge);
void OnSetCredentials(const wxWebCredentials& cred);
wxWebResponseURLSession* GetResponseImplPtr() const
{ return m_response.get(); }
wxWebAuthChallengeURLSession* GetAuthChallengeImplPtr() const
{ return m_authChallenge.get(); }
private:
wxWebSessionURLSession& m_sessionImpl;
wxString m_url;
WX_NSURLSessionTask m_task;
wxObjectDataPtr<wxWebResponseURLSession> m_response;
wxObjectDataPtr<wxWebAuthChallengeURLSession> m_authChallenge;
wxDECLARE_NO_COPY_CLASS(wxWebRequestURLSession);
};