Skip to content

Commit

Permalink
Add wxWebRequest progress methods
Browse files Browse the repository at this point in the history
  • Loading branch information
TcT2k committed Oct 29, 2018
1 parent 45b76c9 commit 4d4fcff
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
11 changes: 11 additions & 0 deletions include/wx/msw/webrequest_winhttp.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ class WXDLLIMPEXP_NET wxWebRequestWinHTTP : public wxWebRequest

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);

Expand All @@ -98,6 +106,8 @@ class WXDLLIMPEXP_NET wxWebRequestWinHTTP : public wxWebRequest
wxScopedPtr<wxWebAuthChallengeWinHTTP> m_authChallenge;
wxMemoryBuffer m_dataWriteBuffer;
wxFileOffset m_dataWritten;
wxFileOffset m_bytesExpectedToReceive;
wxFileOffset m_bytesReceived;

void SendRequest();

Expand All @@ -108,6 +118,7 @@ class WXDLLIMPEXP_NET wxWebRequestWinHTTP : public wxWebRequest
void SetFailedWithLastError();

friend class wxWebAuthChallengeWinHTTP;
friend class wxWebResponseWinHTTP;

wxDECLARE_NO_COPY_CLASS(wxWebRequestWinHTTP);
};
Expand Down
8 changes: 8 additions & 0 deletions include/wx/webrequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ class WXDLLIMPEXP_NET wxWebRequest : public wxEvtHandler, public wxRefCounter

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;
Expand Down
7 changes: 6 additions & 1 deletion src/msw/webrequest_winhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -415,6 +419,7 @@ bool wxWebResponseWinHTTP::ReadData()
bool wxWebResponseWinHTTP::ReportAvailableData(DWORD dataLen)
{
m_readBuffer.UngetAppendBuf(dataLen);
m_request.m_bytesReceived += dataLen;
return ReadData();
}

Expand Down
2 changes: 2 additions & 0 deletions tests/net/webrequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 4d4fcff

Please sign in to comment.