From d2840d2516e391b8f26cf5aea888cd40016ecca3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 13 Jan 2021 00:01:21 +0100 Subject: [PATCH] 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). --- include/wx/private/webrequest.h | 3 +++ src/common/webrequest.cpp | 2 ++ src/osx/webrequest_urlsession.mm | 24 ++++++++++++++++++++---- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/wx/private/webrequest.h b/include/wx/private/webrequest.h index 8a7725004a..a2f9299ca2 100644 --- a/include/wx/private/webrequest.h +++ b/include/wx/private/webrequest.h @@ -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 // ---------------------------------------------------------------------------- diff --git a/src/common/webrequest.cpp b/src/common/webrequest.cpp index 7f90e3340c..93e967a896 100644 --- a/src/common/webrequest.cpp +++ b/src/common/webrequest.cpp @@ -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 diff --git a/src/osx/webrequest_urlsession.mm b/src/osx/webrequest_urlsession.mm index 917cb1b862..5d7f517b13 100644 --- a/src/osx/webrequest_urlsession.mm +++ b/src/osx/webrequest_urlsession.mm @@ -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];