Don't make wxWebRequest::SplitParameters() public

They're not necessary to use this class and we may consider exporting
them later, possibly with a better API and more tests, if really needed.

Also do change their API slightly by leaving only a single function and
returning the value instead of using an out parameter for it to make it
simpler to use.
This commit is contained in:
Vadim Zeitlin
2020-12-13 02:41:01 +01:00
parent be3eb334f6
commit b37c7417f6
4 changed files with 21 additions and 49 deletions

View File

@@ -93,12 +93,6 @@ public:
void ReportDataReceived(size_t sizeReceived);
static void SplitParameters(const wxString& s, wxString& value,
wxWebRequestHeaderMap& parameters);
static void SplitParameters(const wxString::const_iterator& begin,
const wxString::const_iterator& end, wxWebRequestHeaderMap& parameters);
protected:
wxString m_method;
Storage m_storage;

View File

@@ -328,36 +328,6 @@ public:
*/
wxFileOffset GetBytesExpectedToReceive() const;
///@}
/**
Splits the given string into a value and a collection of parameters.
Parameters are expected to be separated by semicolons.
Enclosing quotes of parameter values are removed.
For example, the string
@code
multipart/mixed; boundary="MIME_boundary_01234567"
@endcode
is split into the value
@code
multipart/mixed
@endcode
and the parameter
@code
boundary -> MIME_boundary_01234567
@endcode
*/
static void SplitParameters(const wxString& s, wxString& value,
wxWebRequestHeaderMap& parameters);
/**
Splits the given string into a collection of parameters.
Parameters are expected to be separated by semicolons.
Enclosing quotes of parameter values are removed.
*/
static void SplitParameters(const wxString::const_iterator& begin,
const wxString::const_iterator& end, wxWebRequestHeaderMap& parameters);
};
/**

View File

@@ -144,11 +144,15 @@ void wxWebRequest::ReportDataReceived(size_t sizeReceived)
// The SplitParamaters implementation is adapted to wxWidgets
// from Poco::Net::MessageHeader::splitParameters
void wxWebRequest::SplitParameters(const wxString& s, wxString& value,
wxWebRequestHeaderMap& parameters)
// This function is used in a unit test, so define it inside wxPrivate
// namespace and an anonymous one.
namespace wxPrivate
{
value.clear();
parameters.clear();
WXDLLIMPEXP_NET wxString
SplitParameters(const wxString& s, wxWebRequestHeaderMap& parameters)
{
wxString value;
wxString::const_iterator it = s.begin();
wxString::const_iterator end = s.end();
while ( it != end && wxIsspace(*it) )
@@ -158,17 +162,12 @@ void wxWebRequest::SplitParameters(const wxString& s, wxString& value,
value.Trim();
if ( it != end )
++it;
SplitParameters(it, end, parameters);
}
void wxWebRequest::SplitParameters(const wxString::const_iterator& begin,
const wxString::const_iterator& end, wxWebRequestHeaderMap& parameters)
{
parameters.clear();
wxString pname;
wxString pvalue;
pname.reserve(32);
pvalue.reserve(64);
wxString::const_iterator it = begin;
while ( it != end )
{
pname.clear();
@@ -216,8 +215,12 @@ void wxWebRequest::SplitParameters(const wxString::const_iterator& begin,
if ( it != end )
++it;
}
return value;
}
} // namespace wxPrivate
void wxWebRequest::ProcessStateEvent(State state, const wxString& failMsg)
{
if ( !IsActiveState(state) && GetResponse() )
@@ -318,9 +321,8 @@ wxString wxWebResponse::GetSuggestedFileName() const
// Try to determine from Content-Disposition header
wxString contentDisp = GetHeader("Content-Disposition");
wxString disp;
wxWebRequestHeaderMap params;
wxWebRequest::SplitParameters(contentDisp, disp, params);
const wxString disp = wxPrivate::SplitParameters(contentDisp, params);
if ( disp == "attachment" )
{
// Parse as filename to filter potential path names

View File

@@ -203,6 +203,12 @@ TEST_CASE_METHOD(RequestFixture, "WebRequest", "[net][.]")
}
}
namespace wxPrivate
{
WXDLLIMPEXP_NET wxString
SplitParameters(const wxString& s, wxWebRequestHeaderMap& parameters);
}
TEST_CASE("WebRequestUtils", "[net]")
{
wxString value;
@@ -210,7 +216,7 @@ TEST_CASE("WebRequestUtils", "[net]")
wxString header = "multipart/mixed; boundary=\"MIME_boundary_01234567\"";
wxWebRequest::SplitParameters(header, value, params);
value = wxPrivate::SplitParameters(header, params);
REQUIRE( value == "multipart/mixed" );
REQUIRE( params.size() == 1 );
REQUIRE( params["boundary"] == "MIME_boundary_01234567" );