2018-10-24 17:55:27 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/net/webrequest.cpp
|
|
|
|
// Purpose: wxWebRequest test
|
|
|
|
// Author: Tobias Taschner
|
|
|
|
// Created: 2018-10-24
|
|
|
|
// Copyright: (c) 2018 wxWidgets development team
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
2020-12-26 10:00:03 -05:00
|
|
|
#if wxUSE_WEBREQUEST
|
|
|
|
|
2018-10-24 17:55:27 -04:00
|
|
|
#include "wx/webrequest.h"
|
2018-10-30 16:54:40 -04:00
|
|
|
#include "wx/filename.h"
|
2018-10-24 17:55:27 -04:00
|
|
|
#include "wx/wfstream.h"
|
|
|
|
|
2021-01-23 10:46:02 -05:00
|
|
|
// This test uses httpbin service and by default uses the mirror at the
|
|
|
|
// location below, which seems to be more reliable than the main site at
|
|
|
|
// https://httpbin.org. Any other mirror, including a local one, which can be
|
|
|
|
// set by running kennethreitz/httpbin Docker container, can be used by setting
|
|
|
|
// WX_TEST_WEBREQUEST_URL environment variable to its URL.
|
|
|
|
//
|
|
|
|
// This variable can also be set to a special value "0" to disable running the
|
|
|
|
// test entirely.
|
|
|
|
static const char* WX_TEST_WEBREQUEST_URL_DEFAULT = "https://nghttp2.org/httpbin";
|
2018-10-24 17:55:27 -04:00
|
|
|
|
2021-01-14 18:44:46 -05:00
|
|
|
class RequestFixture : public wxTimer
|
2018-10-24 17:55:27 -04:00
|
|
|
{
|
|
|
|
public:
|
2018-10-30 16:54:40 -04:00
|
|
|
RequestFixture()
|
|
|
|
{
|
|
|
|
expectedFileSize = 0;
|
|
|
|
dataSize = 0;
|
|
|
|
}
|
2018-10-24 17:55:27 -04:00
|
|
|
|
2021-01-10 15:26:12 -05:00
|
|
|
// All tests should call this function first and skip the test entirely if
|
|
|
|
// it returns false, as this indicates that web requests tests are disabled.
|
2020-12-26 10:43:03 -05:00
|
|
|
bool InitBaseURL()
|
|
|
|
{
|
2021-01-24 18:28:11 -05:00
|
|
|
if ( wxGetEnv("WX_TEST_WEBREQUEST_URL", &baseURL) )
|
|
|
|
{
|
|
|
|
static bool s_shown = false;
|
|
|
|
if ( !s_shown )
|
|
|
|
{
|
|
|
|
s_shown = true;
|
|
|
|
WARN("Using non-default root URL " << baseURL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-26 10:43:03 -05:00
|
|
|
baseURL = WX_TEST_WEBREQUEST_URL_DEFAULT;
|
2021-01-24 18:28:11 -05:00
|
|
|
}
|
2020-12-26 10:43:03 -05:00
|
|
|
|
|
|
|
return baseURL != "0";
|
|
|
|
}
|
|
|
|
|
2018-10-24 17:55:27 -04:00
|
|
|
void Create(const wxString& subURL)
|
|
|
|
{
|
|
|
|
CreateAbs(baseURL + subURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreateAbs(const wxString& url)
|
|
|
|
{
|
2020-12-29 19:10:02 -05:00
|
|
|
request = wxWebSession::GetDefault().CreateRequest(this, url);
|
|
|
|
Bind(wxEVT_WEBREQUEST_STATE, &RequestFixture::OnRequestState, this);
|
|
|
|
Bind(wxEVT_WEBREQUEST_DATA, &RequestFixture::OnData, this);
|
2018-10-24 17:55:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnRequestState(wxWebRequestEvent& evt)
|
|
|
|
{
|
|
|
|
switch (evt.GetState())
|
|
|
|
{
|
2021-01-16 09:07:18 -05:00
|
|
|
case wxWebRequest::State_Idle:
|
|
|
|
FAIL("should never get events with State_Idle");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case wxWebRequest::State_Active:
|
|
|
|
CHECK( request.GetNativeHandle() );
|
|
|
|
break;
|
|
|
|
|
2018-10-24 17:55:27 -04:00
|
|
|
case wxWebRequest::State_Completed:
|
2020-12-29 19:10:02 -05:00
|
|
|
if ( request.GetStorage() == wxWebRequest::Storage_File )
|
2018-10-30 16:54:40 -04:00
|
|
|
{
|
2021-01-11 21:34:40 -05:00
|
|
|
wxFileName fn(evt.GetDataFile());
|
2021-01-15 09:42:12 -05:00
|
|
|
CHECK( fn.GetSize() == expectedFileSize );
|
2018-10-30 16:54:40 -04:00
|
|
|
}
|
|
|
|
wxFALLTHROUGH;
|
2021-01-16 09:07:18 -05:00
|
|
|
|
|
|
|
case wxWebRequest::State_Unauthorized:
|
2018-10-24 17:55:27 -04:00
|
|
|
case wxWebRequest::State_Failed:
|
|
|
|
case wxWebRequest::State_Cancelled:
|
2021-01-16 15:20:10 -05:00
|
|
|
errorDescription = evt.GetErrorDescription();
|
2018-10-24 17:55:27 -04:00
|
|
|
loop.Exit();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-14 18:44:46 -05:00
|
|
|
void Notify() wxOVERRIDE
|
|
|
|
{
|
|
|
|
WARN("Exiting loop on timeout");
|
|
|
|
loop.Exit();
|
|
|
|
}
|
|
|
|
|
2018-10-30 16:54:40 -04:00
|
|
|
void OnData(wxWebRequestEvent& evt)
|
|
|
|
{
|
|
|
|
// Count all bytes recieved via data event for Storage_None
|
|
|
|
dataSize += evt.GetDataSize();
|
|
|
|
}
|
|
|
|
|
2021-01-14 18:44:46 -05:00
|
|
|
void RunLoopWithTimeout()
|
|
|
|
{
|
2021-01-23 10:46:31 -05:00
|
|
|
StartOnce(30000); // Ensure that we exit the loop after 30s.
|
2021-01-14 18:44:46 -05:00
|
|
|
loop.Run();
|
|
|
|
Stop();
|
|
|
|
}
|
|
|
|
|
2018-10-24 17:55:27 -04:00
|
|
|
void Run(wxWebRequest::State requiredState = wxWebRequest::State_Completed,
|
|
|
|
int requiredStatus = 200)
|
|
|
|
{
|
2020-12-29 19:10:02 -05:00
|
|
|
REQUIRE( request.GetState() == wxWebRequest::State_Idle );
|
|
|
|
request.Start();
|
2021-01-14 18:44:46 -05:00
|
|
|
RunLoopWithTimeout();
|
2020-12-29 19:10:02 -05:00
|
|
|
REQUIRE( request.GetState() == requiredState );
|
2018-10-24 17:55:27 -04:00
|
|
|
if (requiredStatus)
|
2021-01-15 09:42:12 -05:00
|
|
|
CHECK( request.GetResponse().GetStatus() == requiredStatus );
|
2018-10-24 17:55:27 -04:00
|
|
|
}
|
|
|
|
|
2021-01-09 19:22:40 -05:00
|
|
|
// Precondition: we must have an auth challenge.
|
|
|
|
void UseCredentials(const wxString& user, const wxString& password)
|
|
|
|
{
|
|
|
|
request.GetAuthChallenge().SetCredentials(
|
|
|
|
wxWebCredentials(user, wxSecretValue(password)));
|
|
|
|
}
|
|
|
|
|
2020-12-26 10:43:03 -05:00
|
|
|
wxString baseURL;
|
2018-10-24 17:55:27 -04:00
|
|
|
wxEventLoop loop;
|
2020-12-29 19:10:02 -05:00
|
|
|
wxWebRequest request;
|
2018-10-30 16:54:40 -04:00
|
|
|
wxInt64 expectedFileSize;
|
|
|
|
wxInt64 dataSize;
|
2021-01-16 15:20:10 -05:00
|
|
|
wxString errorDescription;
|
2018-10-24 17:55:27 -04:00
|
|
|
};
|
|
|
|
|
2021-01-10 15:26:12 -05:00
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
|
|
|
"WebRequest::Get::Bytes", "[net][webrequest][get]")
|
2018-10-24 17:55:27 -04:00
|
|
|
{
|
2020-12-26 10:43:03 -05:00
|
|
|
if ( !InitBaseURL() )
|
2018-10-24 17:55:27 -04:00
|
|
|
return;
|
|
|
|
|
2021-01-10 15:26:12 -05:00
|
|
|
Create("/bytes/65536");
|
|
|
|
Run();
|
2021-01-15 09:42:12 -05:00
|
|
|
CHECK( request.GetResponse().GetContentLength() == 65536 );
|
|
|
|
CHECK( request.GetBytesExpectedToReceive() == 65536 );
|
|
|
|
CHECK( request.GetBytesReceived() == 65536 );
|
2021-01-10 15:26:12 -05:00
|
|
|
}
|
2018-10-24 17:55:27 -04:00
|
|
|
|
2021-01-15 18:21:00 -05:00
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
|
|
|
"WebRequest::Get::Simple", "[net][webrequest][get]")
|
|
|
|
{
|
|
|
|
if ( !InitBaseURL() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Note that the session may be initialized on demand, so don't check the
|
|
|
|
// native handle before actually using it.
|
|
|
|
wxWebSession& session = wxWebSession::GetDefault();
|
|
|
|
REQUIRE( session.IsOpened() );
|
|
|
|
|
|
|
|
// Request is not initialized yet.
|
|
|
|
CHECK( !request.IsOk() );
|
|
|
|
CHECK( !request.GetNativeHandle() );
|
|
|
|
|
|
|
|
Create("/status/200");
|
|
|
|
CHECK( request.IsOk() );
|
|
|
|
CHECK( session.GetNativeHandle() );
|
|
|
|
|
|
|
|
// Note that the request must be started to have a valid native handle.
|
|
|
|
request.Start();
|
|
|
|
CHECK( request.GetNativeHandle() );
|
|
|
|
RunLoopWithTimeout();
|
|
|
|
CHECK( request.GetState() == wxWebRequest::State_Completed );
|
|
|
|
CHECK( request.GetResponse().GetStatus() == 200 );
|
|
|
|
}
|
|
|
|
|
2021-01-10 15:26:12 -05:00
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
|
|
|
"WebRequest::Get::String", "[net][webrequest][get]")
|
|
|
|
{
|
|
|
|
if ( !InitBaseURL() )
|
|
|
|
return;
|
2018-10-24 17:55:27 -04:00
|
|
|
|
2021-01-10 15:26:12 -05:00
|
|
|
Create("/base64/VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==");
|
|
|
|
Run();
|
2021-01-15 09:42:12 -05:00
|
|
|
CHECK( request.GetResponse().AsString() == "The quick brown fox jumps over the lazy dog" );
|
2021-01-10 15:26:12 -05:00
|
|
|
}
|
2018-10-24 17:55:27 -04:00
|
|
|
|
2021-01-10 15:26:12 -05:00
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
|
|
|
"WebRequest::Get::File", "[net][webrequest][get]")
|
|
|
|
{
|
|
|
|
if ( !InitBaseURL() )
|
|
|
|
return;
|
2018-10-24 17:55:27 -04:00
|
|
|
|
2021-01-10 15:26:12 -05:00
|
|
|
expectedFileSize = 99 * 1024;
|
|
|
|
Create(wxString::Format("/bytes/%lld", expectedFileSize));
|
|
|
|
request.SetStorage(wxWebRequest::Storage_File);
|
|
|
|
Run();
|
2021-01-15 09:42:12 -05:00
|
|
|
CHECK( request.GetBytesReceived() == expectedFileSize );
|
2021-01-10 15:26:12 -05:00
|
|
|
}
|
2018-10-29 18:20:47 -04:00
|
|
|
|
2021-01-10 15:26:12 -05:00
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
|
|
|
"WebRequest::Get::None", "[net][webrequest][get]")
|
|
|
|
{
|
|
|
|
if ( !InitBaseURL() )
|
|
|
|
return;
|
2018-10-30 16:54:40 -04:00
|
|
|
|
2021-01-10 15:26:12 -05:00
|
|
|
int processingSize = 99 * 1024;
|
|
|
|
Create(wxString::Format("/bytes/%d", processingSize));
|
|
|
|
request.SetStorage(wxWebRequest::Storage_None);
|
|
|
|
Run();
|
2021-01-15 09:42:12 -05:00
|
|
|
CHECK( request.GetBytesReceived() == processingSize );
|
|
|
|
CHECK( dataSize == processingSize );
|
2021-01-10 15:26:12 -05:00
|
|
|
}
|
2018-10-30 16:54:40 -04:00
|
|
|
|
2021-01-10 15:26:12 -05:00
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
|
|
|
"WebRequest::Error::HTTP", "[net][webrequest][error]")
|
|
|
|
{
|
|
|
|
if ( !InitBaseURL() )
|
|
|
|
return;
|
2020-12-12 12:46:28 -05:00
|
|
|
|
2021-01-10 15:26:12 -05:00
|
|
|
Create("/status/404");
|
|
|
|
Run(wxWebRequest::State_Failed, 404);
|
|
|
|
}
|
|
|
|
|
2021-01-14 20:59:54 -05:00
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
|
|
|
"WebRequest::Error::Body", "[net][webrequest][error]")
|
|
|
|
{
|
|
|
|
if ( !InitBaseURL() )
|
|
|
|
return;
|
|
|
|
|
2021-01-26 16:15:32 -05:00
|
|
|
Create("/status/418");
|
2021-01-15 17:14:14 -05:00
|
|
|
Run(wxWebRequest::State_Failed, 0);
|
2021-01-15 09:40:32 -05:00
|
|
|
|
2021-01-26 16:15:32 -05:00
|
|
|
CHECK( request.GetResponse().GetStatus() == 418 );
|
|
|
|
|
|
|
|
const wxString& response = request.GetResponse().AsString();
|
|
|
|
INFO( "Response: " << response);
|
|
|
|
CHECK( response.Contains("teapot") );
|
2021-01-14 20:59:54 -05:00
|
|
|
}
|
|
|
|
|
2021-01-10 15:26:12 -05:00
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
|
|
|
"WebRequest::Error::Connect", "[net][webrequest][error]")
|
|
|
|
{
|
|
|
|
if ( !InitBaseURL() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
CreateAbs("http://127.0.0.1:51234");
|
|
|
|
Run(wxWebRequest::State_Failed, 0);
|
|
|
|
}
|
|
|
|
|
2021-01-19 06:04:36 -05:00
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
|
|
|
"WebRequest::SSL::Error", "[net][webrequest][error]")
|
|
|
|
{
|
|
|
|
if (!InitBaseURL())
|
|
|
|
return;
|
|
|
|
|
|
|
|
CreateAbs("https://self-signed.badssl.com/");
|
|
|
|
Run(wxWebRequest::State_Failed, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
|
|
|
"WebRequest::SSL::Ignore", "[net][webrequest]")
|
|
|
|
{
|
|
|
|
if (!InitBaseURL())
|
|
|
|
return;
|
|
|
|
|
|
|
|
CreateAbs("https://self-signed.badssl.com/");
|
|
|
|
request.DisablePeerVerify();
|
|
|
|
Run(wxWebRequest::State_Completed, 200);
|
|
|
|
}
|
|
|
|
|
2021-01-10 15:26:12 -05:00
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
|
|
|
"WebRequest::Post", "[net][webrequest]")
|
|
|
|
{
|
|
|
|
if ( !InitBaseURL() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Create("/post");
|
|
|
|
request.SetData("app=WebRequestSample&version=1", "application/x-www-form-urlencoded");
|
|
|
|
Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
|
|
|
"WebRequest::Put", "[net][webrequest]")
|
|
|
|
{
|
|
|
|
if ( !InitBaseURL() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Create("/put");
|
|
|
|
wxScopedPtr<wxInputStream> is(new wxFileInputStream("horse.png"));
|
|
|
|
REQUIRE( is->IsOk() );
|
|
|
|
|
|
|
|
request.SetData(is.release(), "image/png");
|
|
|
|
request.SetMethod("PUT");
|
|
|
|
Run();
|
2021-01-09 19:26:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
2021-01-10 15:26:12 -05:00
|
|
|
"WebRequest::Auth::Basic", "[net][webrequest][auth]")
|
2021-01-09 19:26:17 -05:00
|
|
|
{
|
|
|
|
if ( !InitBaseURL() )
|
|
|
|
return;
|
2018-10-25 17:33:05 -04:00
|
|
|
|
2021-01-09 19:26:17 -05:00
|
|
|
Create("/basic-auth/wxtest/wxwidgets");
|
|
|
|
Run(wxWebRequest::State_Unauthorized, 401);
|
|
|
|
REQUIRE( request.GetAuthChallenge().IsOk() );
|
2021-01-09 18:41:05 -05:00
|
|
|
|
2021-01-09 19:26:17 -05:00
|
|
|
SECTION("Good password")
|
|
|
|
{
|
|
|
|
UseCredentials("wxtest", "wxwidgets");
|
2021-01-14 18:44:46 -05:00
|
|
|
RunLoopWithTimeout();
|
2021-01-09 19:26:17 -05:00
|
|
|
CHECK( request.GetResponse().GetStatus() == 200 );
|
|
|
|
CHECK( request.GetState() == wxWebRequest::State_Completed );
|
|
|
|
}
|
2021-01-09 18:41:05 -05:00
|
|
|
|
2021-01-09 19:26:17 -05:00
|
|
|
SECTION("Bad password")
|
|
|
|
{
|
|
|
|
UseCredentials("wxtest", "foobar");
|
2021-01-14 18:44:46 -05:00
|
|
|
RunLoopWithTimeout();
|
2021-01-09 19:26:17 -05:00
|
|
|
CHECK( request.GetResponse().GetStatus() == 401 );
|
|
|
|
CHECK( request.GetState() == wxWebRequest::State_Unauthorized );
|
2018-10-25 17:33:05 -04:00
|
|
|
}
|
2021-01-09 19:26:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
2021-01-10 15:26:12 -05:00
|
|
|
"WebRequest::Auth::Digest", "[net][webrequest][auth]")
|
2021-01-09 19:26:17 -05:00
|
|
|
{
|
|
|
|
if ( !InitBaseURL() )
|
|
|
|
return;
|
2018-10-25 17:33:05 -04:00
|
|
|
|
2021-01-09 19:26:17 -05:00
|
|
|
Create("/digest-auth/auth/wxtest/wxwidgets");
|
|
|
|
Run(wxWebRequest::State_Unauthorized, 401);
|
|
|
|
REQUIRE( request.GetAuthChallenge().IsOk() );
|
2021-01-09 18:41:05 -05:00
|
|
|
|
2021-01-09 19:26:17 -05:00
|
|
|
SECTION("Good password")
|
|
|
|
{
|
|
|
|
UseCredentials("wxtest", "wxwidgets");
|
2021-01-14 18:44:46 -05:00
|
|
|
RunLoopWithTimeout();
|
2021-01-09 19:26:17 -05:00
|
|
|
CHECK( request.GetResponse().GetStatus() == 200 );
|
|
|
|
CHECK( request.GetState() == wxWebRequest::State_Completed );
|
|
|
|
}
|
2021-01-09 18:41:05 -05:00
|
|
|
|
2021-01-09 19:26:17 -05:00
|
|
|
SECTION("Bad password")
|
|
|
|
{
|
|
|
|
UseCredentials("foo", "bar");
|
2021-01-14 18:44:46 -05:00
|
|
|
RunLoopWithTimeout();
|
2021-01-09 19:26:17 -05:00
|
|
|
CHECK( request.GetResponse().GetStatus() == 401 );
|
|
|
|
CHECK( request.GetState() == wxWebRequest::State_Unauthorized );
|
2018-10-25 17:33:05 -04:00
|
|
|
}
|
2018-10-24 17:55:27 -04:00
|
|
|
}
|
|
|
|
|
2021-01-14 18:53:45 -05:00
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
|
|
|
"WebRequest::Cancel", "[net][webrequest]")
|
|
|
|
{
|
|
|
|
if ( !InitBaseURL() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Create("/delay/10");
|
|
|
|
request.Start();
|
|
|
|
request.Cancel();
|
|
|
|
RunLoopWithTimeout();
|
2021-01-16 15:20:10 -05:00
|
|
|
if ( !errorDescription.empty() )
|
|
|
|
INFO( "Error:" << errorDescription );
|
2021-01-14 18:53:45 -05:00
|
|
|
REQUIRE( request.GetState() == wxWebRequest::State_Cancelled );
|
|
|
|
}
|
|
|
|
|
2021-01-10 20:30:43 -05:00
|
|
|
// This test is not run by default and has to be explicitly selected to run.
|
|
|
|
TEST_CASE_METHOD(RequestFixture,
|
2021-01-14 18:56:49 -05:00
|
|
|
"WebRequest::Manual", "[.]")
|
2021-01-10 20:30:43 -05:00
|
|
|
{
|
|
|
|
// Allow getting 8-bit strings from the environment correctly.
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
|
|
|
wxString url;
|
|
|
|
if ( !wxGetEnv("WX_TEST_WEBREQUEST_URL", &url) )
|
|
|
|
{
|
|
|
|
FAIL("Specify WX_TEST_WEBREQUEST_URL");
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateAbs(url);
|
2021-01-14 20:52:15 -05:00
|
|
|
request.Start();
|
|
|
|
RunLoopWithTimeout();
|
|
|
|
|
|
|
|
WARN("Request state " << request.GetState());
|
|
|
|
wxWebResponse response = request.GetResponse();
|
|
|
|
REQUIRE( response.IsOk() );
|
|
|
|
WARN("Status: " << response.GetStatus()
|
|
|
|
<< " (" << response.GetStatusText() << ")\n" <<
|
|
|
|
"Body length: " << response.GetContentLength() << "\n" <<
|
|
|
|
"Body: " << response.AsString() << "\n");
|
2021-01-10 20:30:43 -05:00
|
|
|
}
|
|
|
|
|
2020-12-29 19:10:02 -05:00
|
|
|
WX_DECLARE_STRING_HASH_MAP(wxString, wxWebRequestHeaderMap);
|
|
|
|
|
2020-12-12 20:41:01 -05:00
|
|
|
namespace wxPrivate
|
|
|
|
{
|
|
|
|
WXDLLIMPEXP_NET wxString
|
|
|
|
SplitParameters(const wxString& s, wxWebRequestHeaderMap& parameters);
|
|
|
|
}
|
|
|
|
|
2020-12-26 10:43:03 -05:00
|
|
|
TEST_CASE("WebRequestUtils", "[net][webrequest]")
|
2018-11-01 12:33:56 -04:00
|
|
|
{
|
|
|
|
wxString value;
|
|
|
|
wxWebRequestHeaderMap params;
|
|
|
|
|
|
|
|
wxString header = "multipart/mixed; boundary=\"MIME_boundary_01234567\"";
|
|
|
|
|
2020-12-12 20:41:01 -05:00
|
|
|
value = wxPrivate::SplitParameters(header, params);
|
2021-01-15 09:42:12 -05:00
|
|
|
CHECK( value == "multipart/mixed" );
|
|
|
|
CHECK( params.size() == 1 );
|
|
|
|
CHECK( params["boundary"] == "MIME_boundary_01234567" );
|
2018-11-01 12:33:56 -04:00
|
|
|
}
|
|
|
|
|
2018-10-24 17:55:27 -04:00
|
|
|
#endif // wxUSE_WEBREQUEST
|