diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index f0a92af9a3f0..835a5c50ae0a 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -7,6 +7,7 @@ #include "atom/browser/atom_browser_main_parts.h" #include "atom/browser/net/atom_url_request_job_factory.h" #include "atom/browser/net/asar/asar_protocol_handler.h" +#include "atom/browser/net/http_protocol_handler.h" #include "atom/browser/web_view_manager.h" #include "atom/common/options_switches.h" #include "base/command_line.h" @@ -59,6 +60,8 @@ net::URLRequestJobFactory* AtomBrowserContext::CreateURLRequestJobFactory( url::kFileScheme, new asar::AsarProtocolHandler( BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( base::SequencedWorkerPool::SKIP_ON_SHUTDOWN))); + job_factory->SetProtocolHandler( + url::kHttpScheme, new HttpProtocolHandler()); // Set up interceptors in the reverse order. scoped_ptr top_job_factory = job_factory.Pass(); diff --git a/atom/browser/net/http_protocol_handler.cc b/atom/browser/net/http_protocol_handler.cc new file mode 100644 index 000000000000..9cc3d2d2675e --- /dev/null +++ b/atom/browser/net/http_protocol_handler.cc @@ -0,0 +1,25 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/browser/net/http_protocol_handler.h" + +#include "net/url_request/url_request_http_job.h" + +namespace atom { + +HttpProtocolHandler::HttpProtocolHandler() { +} + +HttpProtocolHandler::~HttpProtocolHandler() { +} + +net::URLRequestJob* HttpProtocolHandler::MaybeCreateJob( + net::URLRequest* request, + net::NetworkDelegate* network_delegate) const { + return net::URLRequestHttpJob::Factory(request, + network_delegate, + "http"); +} + +} // namespace atom diff --git a/atom/browser/net/http_protocol_handler.h b/atom/browser/net/http_protocol_handler.h new file mode 100644 index 000000000000..ad66fa75e054 --- /dev/null +++ b/atom/browser/net/http_protocol_handler.h @@ -0,0 +1,25 @@ +// Copyright (c) 2015 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ATOM_BROWSER_NET_HTTP_PROTOCOL_HANDLER_H_ +#define ATOM_BROWSER_NET_HTTP_PROTOCOL_HANDLER_H_ + +#include "net/url_request/url_request_job_factory.h" + +namespace atom { + +class HttpProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { + public: + HttpProtocolHandler(); + virtual ~HttpProtocolHandler(); + + // net::URLRequestJobFactory::ProtocolHandler: + net::URLRequestJob* MaybeCreateJob( + net::URLRequest* request, + net::NetworkDelegate* network_delegate) const override; +}; + +} // namespace atom + +#endif // ATOM_BROWSER_NET_HTTP_PROTOCOL_HANDLER_H_ diff --git a/filenames.gypi b/filenames.gypi index ebd1fb41aaf2..1aa038c0c339 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -145,6 +145,8 @@ 'atom/browser/net/asar/url_request_asar_job.h', 'atom/browser/net/atom_url_request_job_factory.cc', 'atom/browser/net/atom_url_request_job_factory.h', + 'atom/browser/net/http_protocol_handler.cc', + 'atom/browser/net/http_protocol_handler.h', 'atom/browser/net/url_request_string_job.cc', 'atom/browser/net/url_request_string_job.h', 'atom/browser/net/url_request_buffer_job.cc', diff --git a/spec/api-protocol-spec.coffee b/spec/api-protocol-spec.coffee index 0b6c62c02754..060f035037d1 100644 --- a/spec/api-protocol-spec.coffee +++ b/spec/api-protocol-spec.coffee @@ -190,3 +190,10 @@ describe 'protocol module', -> assert false, 'Got error: ' + errorType + ' ' + error free() protocol.interceptProtocol 'file', handler + + it 'can override http protocol handler', (done) -> + handler = remote.createFunctionWithReturnValue 'valar morghulis' + protocol.once 'intercepted', -> + protocol.uninterceptProtocol 'http' + done() + protocol.interceptProtocol 'http', handler