Fix protocol filtering of net.request
net::URLRequest inherits from base::SupportsUserData, which allows associating arbitrary data with the request. Use this mechanism as a condition for filtering requests from custom protocols. Close #11657
This commit is contained in:
parent
78ccfa0612
commit
bc76f35691
4 changed files with 18 additions and 4 deletions
|
@ -78,10 +78,6 @@ class Protocol : public mate::TrackableObject<Protocol> {
|
||||||
net::URLRequestJob* MaybeCreateJob(
|
net::URLRequestJob* MaybeCreateJob(
|
||||||
net::URLRequest* request,
|
net::URLRequest* request,
|
||||||
net::NetworkDelegate* network_delegate) const override {
|
net::NetworkDelegate* network_delegate) const override {
|
||||||
if (!request->initiator().has_value()) {
|
|
||||||
// Don't intercept this request as it was created by `net.request`.
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
RequestJob* request_job = new RequestJob(request, network_delegate);
|
RequestJob* request_job = new RequestJob(request, network_delegate);
|
||||||
request_job->SetHandlerInfo(isolate_, request_context_.get(), handler_);
|
request_job->SetHandlerInfo(isolate_, request_context_.get(), handler_);
|
||||||
return request_job;
|
return request_job;
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "atom/browser/api/atom_api_url_request.h"
|
#include "atom/browser/api/atom_api_url_request.h"
|
||||||
#include "atom/browser/atom_browser_context.h"
|
#include "atom/browser/atom_browser_context.h"
|
||||||
|
#include "atom/browser/net/atom_url_request_job_factory.h"
|
||||||
#include "base/callback.h"
|
#include "base/callback.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "net/base/elements_upload_data_stream.h"
|
#include "net/base/elements_upload_data_stream.h"
|
||||||
|
@ -121,6 +122,9 @@ void AtomURLRequest::DoInitialize(
|
||||||
request_->set_method(method);
|
request_->set_method(method);
|
||||||
// Do not send cookies from the cookie store.
|
// Do not send cookies from the cookie store.
|
||||||
DoSetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES);
|
DoSetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES);
|
||||||
|
// Set a flag to stop custom protocol from intercepting this request.
|
||||||
|
request_->SetUserData(DisableProtocolInterceptFlagKey(),
|
||||||
|
base::WrapUnique(new base::SupportsUserData::Data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomURLRequest::DoTerminate() {
|
void AtomURLRequest::DoTerminate() {
|
||||||
|
|
|
@ -15,8 +15,18 @@ using content::BrowserThread;
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
int disable_protocol_intercept_flag_key = 0;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
typedef net::URLRequestJobFactory::ProtocolHandler ProtocolHandler;
|
typedef net::URLRequestJobFactory::ProtocolHandler ProtocolHandler;
|
||||||
|
|
||||||
|
const void* DisableProtocolInterceptFlagKey() {
|
||||||
|
return &disable_protocol_intercept_flag_key;
|
||||||
|
}
|
||||||
|
|
||||||
AtomURLRequestJobFactory::AtomURLRequestJobFactory() {}
|
AtomURLRequestJobFactory::AtomURLRequestJobFactory() {}
|
||||||
|
|
||||||
AtomURLRequestJobFactory::~AtomURLRequestJobFactory() {
|
AtomURLRequestJobFactory::~AtomURLRequestJobFactory() {
|
||||||
|
@ -93,6 +103,8 @@ net::URLRequestJob* AtomURLRequestJobFactory::MaybeCreateJobWithProtocolHandler(
|
||||||
auto it = protocol_handler_map_.find(scheme);
|
auto it = protocol_handler_map_.find(scheme);
|
||||||
if (it == protocol_handler_map_.end())
|
if (it == protocol_handler_map_.end())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
if (request->GetUserData(DisableProtocolInterceptFlagKey()))
|
||||||
|
return nullptr;
|
||||||
return it->second->MaybeCreateJob(request, network_delegate);
|
return it->second->MaybeCreateJob(request, network_delegate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
const void* DisableProtocolInterceptFlagKey();
|
||||||
|
|
||||||
class AtomURLRequestJobFactory : public net::URLRequestJobFactory {
|
class AtomURLRequestJobFactory : public net::URLRequestJobFactory {
|
||||||
public:
|
public:
|
||||||
AtomURLRequestJobFactory();
|
AtomURLRequestJobFactory();
|
||||||
|
|
Loading…
Add table
Reference in a new issue