Skip to content

Commit

Permalink
NetworkStorageSession: use netservices default URL context
Browse files Browse the repository at this point in the history
There is no clean API to access it directly, but it can be done by
creating an URL request without a context and getting its context.

Fixes a problem with deleting the context on exit while it is still
referenced, and also possibly fixes usage of the two different contexts
in different places.
  • Loading branch information
pulkomandy committed Nov 29, 2022
1 parent f0f77ce commit fe216a3
Showing 1 changed file with 15 additions and 2 deletions.
Expand Up @@ -29,6 +29,8 @@

#include <support/Locker.h>
#include <UrlContext.h>
#include <UrlProtocolRoster.h>
#include <UrlRequest.h>

#include "Cookie.h"
#include "CookieRequestHeaderFieldProxy.h"
Expand Down Expand Up @@ -234,8 +236,19 @@ std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(

BPrivate::Network::BUrlContext& NetworkStorageSession::platformSession() const
{
static BPrivate::Network::BUrlContext sDefaultContext;
return m_context ? *m_context : sDefaultContext;
if (m_context)
return *m_context;

// This is the only way to access the default context in the netservces lib
static BPrivate::Network::BUrlContext* sDefaultContext = nullptr;

if (sDefaultContext == nullptr) {
BPrivate::Network::BUrlRequest* fakeRequest
= BPrivate::Network::BUrlProtocolRoster::MakeRequest(BUrl("data:"), NULL, NULL);
sDefaultContext = fakeRequest->Context();
delete fakeRequest;
}
return *sDefaultContext;
}

void NetworkStorageSession::setPlatformSession(BPrivate::Network::BUrlContext* context)
Expand Down

0 comments on commit fe216a3

Please sign in to comment.