protocol: wrapping httpjobfactory with a default protocol handler to intercept
This commit is contained in:
parent
e5380fd671
commit
7fee639edf
5 changed files with 62 additions and 0 deletions
|
@ -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<net::URLRequestJobFactory> top_job_factory = job_factory.Pass();
|
||||
|
|
25
atom/browser/net/http_protocol_handler.cc
Normal file
25
atom/browser/net/http_protocol_handler.cc
Normal file
|
@ -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
|
25
atom/browser/net/http_protocol_handler.h
Normal file
25
atom/browser/net/http_protocol_handler.h
Normal file
|
@ -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_
|
|
@ -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',
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue