Tweaks to wxWebRequest::SetData() overload taking stream

Check that the stream is valid, if specified at all, and return false if
it isn't -- or if no size was specified and determining stream size
failed.

Check for SetData() success in the test to provide better diagnostics in
case the file it uses is not found (as is the case when running the test
from another directory, for example).

Also pass wxSharedPtr<> by const reference instead of by value to avoid
unnecessary copies.
This commit is contained in:
Vadim Zeitlin
2020-12-12 18:46:28 +01:00
parent 92e41a7477
commit 64a3801160
4 changed files with 21 additions and 6 deletions

View File

@@ -83,8 +83,11 @@ void wxWebRequest::SetData(const wxString& text, const wxString& contentType, co
SetData(wxSharedPtr<wxInputStream>(new wxMemoryInputStream(m_dataText, m_dataText.length())), contentType);
}
void wxWebRequest::SetData(wxSharedPtr<wxInputStream> dataStream, const wxString& contentType, wxFileOffset dataSize)
bool wxWebRequest::SetData(const wxSharedPtr<wxInputStream>& dataStream, const wxString& contentType, wxFileOffset dataSize)
{
if ( !dataStream->IsOk() )
return false;
m_dataStream = dataStream;
if ( m_dataStream.get() )
{
@@ -92,6 +95,9 @@ void wxWebRequest::SetData(wxSharedPtr<wxInputStream> dataStream, const wxString
{
// Determine data size
m_dataSize = m_dataStream->SeekI(0, wxFromEnd);
if ( m_dataSize == wxInvalidOffset )
return false;
m_dataStream->SeekI(0);
}
else
@@ -101,6 +107,8 @@ void wxWebRequest::SetData(wxSharedPtr<wxInputStream> dataStream, const wxString
m_dataSize = 0;
SetHeader("Content-Type", contentType);
return true;
}
wxFileOffset wxWebRequest::GetBytesReceived() const