Add some wxLogTrace() calls to wxWebRequestURLSession code

This is helpful when trying to understand what is going on, especially
because CFNETWORK_DIAGNOSTICS, which is supposed to do the same thing at
native level, doesn't seem to work (at least under 10.14).
This commit is contained in:
Vadim Zeitlin 2021-01-13 00:01:21 +01:00
parent 0ccc6d4047
commit d2840d2516
3 changed files with 25 additions and 4 deletions

View File

@ -21,6 +21,9 @@ WX_DECLARE_STRING_HASH_MAP(wxString, wxWebRequestHeaderMap);
// Default buffer size when a fixed-size buffer must be used.
const int wxWEBREQUEST_BUFFER_SIZE = 64 * 1024;
// Trace mask used for the messages in wxWebRequest code.
#define wxTRACE_WEBREQUEST "webrequest"
// ----------------------------------------------------------------------------
// wxWebAuthChallengeImpl
// ----------------------------------------------------------------------------

View File

@ -182,6 +182,8 @@ struct StateEventProcessor
void wxWebRequestImpl::SetState(wxWebRequest::State state, const wxString & failMsg)
{
wxLogTrace(wxTRACE_WEBREQUEST, "Request %p: state => %d", this, state);
m_state = state;
// Trigger the event in the main thread

View File

@ -67,6 +67,9 @@
wxUnusedVar(session);
wxWebRequestURLSession* request = [self requestForTask:dataTask];
wxLogTrace(wxTRACE_WEBREQUEST, "Request %p: didReceiveData", request);
if (request)
request->GetResponseImplPtr()->HandleData(data);
}
@ -77,9 +80,18 @@
wxWebRequestURLSession* request = [self requestForTask:task];
if (error)
{
wxLogTrace(wxTRACE_WEBREQUEST, "Request %p: didCompleteWithError, error=%s",
request, wxCFStringRefFromGet([error description]).AsString());
request->SetState(wxWebRequest::State_Failed, wxCFStringRefFromGet(error.localizedDescription).AsString());
}
else
{
wxLogTrace(wxTRACE_WEBREQUEST, "Request %p: completed successfully", request);
request->HandleCompletion();
}
// After the task is completed it no longer needs to be mapped
[m_requests removeObjectForKey:task];
@ -108,12 +120,13 @@ wxWebRequestURLSession::~wxWebRequestURLSession()
void wxWebRequestURLSession::Start()
{
wxString method = m_method;
if ( method.empty() )
method = m_dataSize ? wxASCII_STR("POST") : wxASCII_STR("GET");
NSMutableURLRequest* req = [NSMutableURLRequest requestWithURL:
[NSURL URLWithString:wxCFStringRef(m_url).AsNSString()]];
if (m_method.empty())
req.HTTPMethod = m_dataSize ? @"POST" : @"GET";
else
req.HTTPMethod = wxCFStringRef(m_method).AsNSString();
req.HTTPMethod = wxCFStringRef(method).AsNSString();
// Set request headers
for (wxWebRequestHeaderMap::const_iterator it = m_headers.begin(); it != m_headers.end(); ++it)
@ -138,6 +151,9 @@ void wxWebRequestURLSession::Start()
m_task = [[m_sessionImpl.GetSession() dataTaskWithRequest:req] retain];
}
wxLogTrace(wxTRACE_WEBREQUEST, "Request %p: start \"%s %s\"",
this, method, m_url);
// The session delegate needs to know which task is wrapped in which request
[m_sessionImpl.GetDelegate() registerRequest:this task:m_task];