diff --git a/include/wx/msw/webrequest_winhttp.h b/include/wx/msw/webrequest_winhttp.h index 5da61c7772..b6e707cdc4 100644 --- a/include/wx/msw/webrequest_winhttp.h +++ b/include/wx/msw/webrequest_winhttp.h @@ -84,6 +84,14 @@ public: 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, DWORD dwStatusInformationLength); @@ -98,6 +106,8 @@ private: wxScopedPtr m_authChallenge; wxMemoryBuffer m_dataWriteBuffer; wxFileOffset m_dataWritten; + wxFileOffset m_bytesExpectedToReceive; + wxFileOffset m_bytesReceived; void SendRequest(); @@ -108,6 +118,7 @@ private: void SetFailedWithLastError(); friend class wxWebAuthChallengeWinHTTP; + friend class wxWebResponseWinHTTP; wxDECLARE_NO_COPY_CLASS(wxWebRequestWinHTTP); }; diff --git a/include/wx/webrequest.h b/include/wx/webrequest.h index 62d5ac4884..d670a6fe56 100644 --- a/include/wx/webrequest.h +++ b/include/wx/webrequest.h @@ -65,6 +65,14 @@ public: 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: wxString m_method; wxWebRequestHeaderMap m_headers; diff --git a/src/msw/webrequest_winhttp.cpp b/src/msw/webrequest_winhttp.cpp index 26aa705ef6..76248d45f2 100644 --- a/src/msw/webrequest_winhttp.cpp +++ b/src/msw/webrequest_winhttp.cpp @@ -147,7 +147,10 @@ wxWebRequestWinHTTP::wxWebRequestWinHTTP(int id, wxWebSessionWinHTTP& session, c m_session(session), m_url(url), m_connect(NULL), - m_request(NULL) + m_request(NULL), + m_dataWritten(0), + m_bytesExpectedToReceive(0), + m_bytesReceived(0) { m_headers = session.GetHeaders(); } @@ -219,6 +222,7 @@ void wxWebRequestWinHTTP::CreateResponse() if (::WinHttpReceiveResponse(m_request, NULL)) { m_response.reset(new wxWebResponseWinHTTP(*this)); + m_bytesExpectedToReceive = m_response->GetContentLength(); int status = m_response->GetStatus(); if ( status == 401 || status == 407) { @@ -415,6 +419,7 @@ bool wxWebResponseWinHTTP::ReadData() bool wxWebResponseWinHTTP::ReportAvailableData(DWORD dataLen) { m_readBuffer.UngetAppendBuf(dataLen); + m_request.m_bytesReceived += dataLen; return ReadData(); } diff --git a/tests/net/webrequest.cpp b/tests/net/webrequest.cpp index 9d40350e01..4092036efa 100644 --- a/tests/net/webrequest.cpp +++ b/tests/net/webrequest.cpp @@ -96,6 +96,8 @@ TEST_CASE_METHOD(RequestFixture, "WebRequest", "[net][.]") Create("/bytes/65536"); Run(); REQUIRE( request->GetResponse()->GetContentLength() == 65536 ); + REQUIRE( request->GetBytesExpectedToReceive() == 65536 ); + REQUIRE( request->GetBytesReceived() == 65536 ); } SECTION("GET 404 error")