Add wxWebRequest progress methods

This commit is contained in:
Tobias Taschner
2018-10-26 23:38:40 +02:00
parent 871049f1a1
commit cf85c04d25
4 changed files with 27 additions and 1 deletions

View File

@@ -84,6 +84,14 @@ public:
wxWebAuthChallenge* GetAuthChallenge() const wxOVERRIDE { return m_authChallenge.get(); } wxWebAuthChallenge* GetAuthChallenge() const wxOVERRIDE { return m_authChallenge.get(); }
wxFileOffset GetBytesSent() const wxOVERRIDE { return m_dataWritten; }
wxFileOffset GetBytesExpectedToSend() const wxOVERRIDE { return m_dataSize; }
wxFileOffset GetBytesReceived() const wxOVERRIDE { return m_bytesReceived; }
wxFileOffset GetBytesExpectedToReceive() const wxOVERRIDE { return m_bytesExpectedToReceive; }
void HandleCallback(DWORD dwInternetStatus, LPVOID lpvStatusInformation, void HandleCallback(DWORD dwInternetStatus, LPVOID lpvStatusInformation,
DWORD dwStatusInformationLength); DWORD dwStatusInformationLength);
@@ -98,6 +106,8 @@ private:
wxScopedPtr<wxWebAuthChallengeWinHTTP> m_authChallenge; wxScopedPtr<wxWebAuthChallengeWinHTTP> m_authChallenge;
wxMemoryBuffer m_dataWriteBuffer; wxMemoryBuffer m_dataWriteBuffer;
wxFileOffset m_dataWritten; wxFileOffset m_dataWritten;
wxFileOffset m_bytesExpectedToReceive;
wxFileOffset m_bytesReceived;
void SendRequest(); void SendRequest();
@@ -108,6 +118,7 @@ private:
void SetFailedWithLastError(); void SetFailedWithLastError();
friend class wxWebAuthChallengeWinHTTP; friend class wxWebAuthChallengeWinHTTP;
friend class wxWebResponseWinHTTP;
wxDECLARE_NO_COPY_CLASS(wxWebRequestWinHTTP); wxDECLARE_NO_COPY_CLASS(wxWebRequestWinHTTP);
}; };

View File

@@ -65,6 +65,14 @@ public:
State GetState() const { return m_state; } State GetState() const { return m_state; }
virtual wxFileOffset GetBytesSent() const = 0;
virtual wxFileOffset GetBytesExpectedToSend() const = 0;
virtual wxFileOffset GetBytesReceived() const = 0;
virtual wxFileOffset GetBytesExpectedToReceive() const = 0;
protected: protected:
wxString m_method; wxString m_method;
wxWebRequestHeaderMap m_headers; wxWebRequestHeaderMap m_headers;

View File

@@ -147,7 +147,10 @@ wxWebRequestWinHTTP::wxWebRequestWinHTTP(int id, wxWebSessionWinHTTP& session, c
m_session(session), m_session(session),
m_url(url), m_url(url),
m_connect(NULL), m_connect(NULL),
m_request(NULL) m_request(NULL),
m_dataWritten(0),
m_bytesExpectedToReceive(0),
m_bytesReceived(0)
{ {
m_headers = session.GetHeaders(); m_headers = session.GetHeaders();
} }
@@ -219,6 +222,7 @@ void wxWebRequestWinHTTP::CreateResponse()
if (::WinHttpReceiveResponse(m_request, NULL)) if (::WinHttpReceiveResponse(m_request, NULL))
{ {
m_response.reset(new wxWebResponseWinHTTP(*this)); m_response.reset(new wxWebResponseWinHTTP(*this));
m_bytesExpectedToReceive = m_response->GetContentLength();
int status = m_response->GetStatus(); int status = m_response->GetStatus();
if ( status == 401 || status == 407) if ( status == 401 || status == 407)
{ {
@@ -415,6 +419,7 @@ bool wxWebResponseWinHTTP::ReadData()
bool wxWebResponseWinHTTP::ReportAvailableData(DWORD dataLen) bool wxWebResponseWinHTTP::ReportAvailableData(DWORD dataLen)
{ {
m_readBuffer.UngetAppendBuf(dataLen); m_readBuffer.UngetAppendBuf(dataLen);
m_request.m_bytesReceived += dataLen;
return ReadData(); return ReadData();
} }

View File

@@ -96,6 +96,8 @@ TEST_CASE_METHOD(RequestFixture, "WebRequest", "[net][.]")
Create("/bytes/65536"); Create("/bytes/65536");
Run(); Run();
REQUIRE( request->GetResponse()->GetContentLength() == 65536 ); REQUIRE( request->GetResponse()->GetContentLength() == 65536 );
REQUIRE( request->GetBytesExpectedToReceive() == 65536 );
REQUIRE( request->GetBytesReceived() == 65536 );
} }
SECTION("GET 404 error") SECTION("GET 404 error")