Implement WinHTTP authentication

This commit is contained in:
Tobias Taschner
2018-10-25 23:33:05 +02:00
parent 1a34f3dab9
commit 4fd6091513
5 changed files with 145 additions and 20 deletions

View File

@@ -52,6 +52,23 @@ private:
wxDECLARE_NO_COPY_CLASS(wxWebResponseWinHTTP);
};
class WXDLLIMPEXP_NET wxWebAuthChallengeWinHTTP : public wxWebAuthChallenge
{
public:
explicit wxWebAuthChallengeWinHTTP(Source source, wxWebRequestWinHTTP& request);
bool Init();
void SetCredentials(const wxString& user, const wxString& password) wxOVERRIDE;
private:
wxWebRequestWinHTTP& m_request;
DWORD m_target;
DWORD m_selectedScheme;
wxDECLARE_NO_COPY_CLASS(wxWebAuthChallengeWinHTTP);
};
class WXDLLIMPEXP_NET wxWebRequestWinHTTP : public wxWebRequest
{
public:
@@ -65,6 +82,8 @@ public:
wxWebResponse* GetResponse() wxOVERRIDE;
wxWebAuthChallenge* GetAuthChallenge() const wxOVERRIDE { return m_authChallenge.get(); }
void HandleCallback(DWORD dwInternetStatus, LPVOID lpvStatusInformation,
DWORD dwStatusInformationLength);
@@ -76,15 +95,20 @@ private:
HINTERNET m_connect;
HINTERNET m_request;
wxScopedPtr<wxWebResponseWinHTTP> m_response;
wxScopedPtr<wxWebAuthChallengeWinHTTP> m_authChallenge;
wxMemoryBuffer m_dataWriteBuffer;
wxFileOffset m_dataWritten;
void SendRequest();
void WriteData();
void CreateResponse();
void SetFailedWithLastError();
friend class wxWebAuthChallengeWinHTTP;
wxDECLARE_NO_COPY_CLASS(wxWebRequestWinHTTP);
};

View File

@@ -23,6 +23,7 @@
class wxWebResponse;
class wxWebSession;
class wxWebAuthChallenge;
WX_DECLARE_STRING_HASH_MAP(wxString, wxWebRequestHeaderMap);
@@ -33,19 +34,12 @@ public:
{
State_Idle,
State_Unauthorized,
State_UnauthorizedProxy,
State_Active,
State_Completed,
State_Failed,
State_Cancelled
};
enum CredentialTarget
{
CredentialTarget_Server,
CredentialTarget_Proxy
};
virtual ~wxWebRequest() { }
virtual void SetHeader(const wxString& name, const wxString& value)
@@ -57,9 +51,6 @@ public:
void SetData(wxSharedPtr<wxInputStream> dataStream, const wxString& contentType, wxFileOffset dataSize = wxInvalidOffset);
void SetCredentials(const wxString& user, const wxString& password,
CredentialTarget target);
void SetIgnoreServerErrorStatus(bool ignore) { m_ignoreServerErrorStatus = ignore; }
virtual void Start() = 0;
@@ -68,6 +59,8 @@ public:
virtual wxWebResponse* GetResponse() = 0;
virtual wxWebAuthChallenge* GetAuthChallenge() const = 0;
int GetId() const { return m_id; }
State GetState() const { return m_state; }
@@ -125,6 +118,30 @@ private:
wxDECLARE_NO_COPY_CLASS(wxWebResponse);
};
class WXDLLIMPEXP_NET wxWebAuthChallenge
{
public:
enum Source
{
Source_Server,
Source_Proxy
};
virtual ~wxWebAuthChallenge() { }
Source GetSource() const { return m_source; }
virtual void SetCredentials(const wxString& user, const wxString& password) = 0;
protected:
wxWebAuthChallenge(Source source): m_source(source) { }
private:
Source m_source;
wxDECLARE_NO_COPY_CLASS(wxWebAuthChallenge);
};
class WXDLLIMPEXP_NET wxWebSessionFactory
{
public: