support https, ws, wss builtin schemes to be intercepted
This commit is contained in:
parent
7fee639edf
commit
707503ac40
4 changed files with 37 additions and 4 deletions
|
@ -61,7 +61,13 @@ net::URLRequestJobFactory* AtomBrowserContext::CreateURLRequestJobFactory(
|
|||
BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
|
||||
base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kHttpScheme, new HttpProtocolHandler());
|
||||
url::kHttpScheme, new HttpProtocolHandler(url::kHttpScheme));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kHttpsScheme, new HttpProtocolHandler(url::kHttpsScheme));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kWsScheme, new HttpProtocolHandler(url::kWsScheme));
|
||||
job_factory->SetProtocolHandler(
|
||||
url::kWssScheme, new HttpProtocolHandler(url::kWssScheme));
|
||||
|
||||
// Set up interceptors in the reverse order.
|
||||
scoped_ptr<net::URLRequestJobFactory> top_job_factory = job_factory.Pass();
|
||||
|
|
|
@ -8,7 +8,8 @@
|
|||
|
||||
namespace atom {
|
||||
|
||||
HttpProtocolHandler::HttpProtocolHandler() {
|
||||
HttpProtocolHandler::HttpProtocolHandler(const std::string& scheme)
|
||||
: scheme_(scheme) {
|
||||
}
|
||||
|
||||
HttpProtocolHandler::~HttpProtocolHandler() {
|
||||
|
@ -19,7 +20,7 @@ net::URLRequestJob* HttpProtocolHandler::MaybeCreateJob(
|
|||
net::NetworkDelegate* network_delegate) const {
|
||||
return net::URLRequestHttpJob::Factory(request,
|
||||
network_delegate,
|
||||
"http");
|
||||
scheme_);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -5,19 +5,24 @@
|
|||
#ifndef ATOM_BROWSER_NET_HTTP_PROTOCOL_HANDLER_H_
|
||||
#define ATOM_BROWSER_NET_HTTP_PROTOCOL_HANDLER_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "net/url_request/url_request_job_factory.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
class HttpProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler {
|
||||
public:
|
||||
HttpProtocolHandler();
|
||||
explicit HttpProtocolHandler(const std::string&);
|
||||
virtual ~HttpProtocolHandler();
|
||||
|
||||
// net::URLRequestJobFactory::ProtocolHandler:
|
||||
net::URLRequestJob* MaybeCreateJob(
|
||||
net::URLRequest* request,
|
||||
net::NetworkDelegate* network_delegate) const override;
|
||||
|
||||
private:
|
||||
std::string scheme_;
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -197,3 +197,24 @@ describe 'protocol module', ->
|
|||
protocol.uninterceptProtocol 'http'
|
||||
done()
|
||||
protocol.interceptProtocol 'http', handler
|
||||
|
||||
it 'can override https protocol handler', (done) ->
|
||||
handler = remote.createFunctionWithReturnValue 'valar morghulis'
|
||||
protocol.once 'intercepted', ->
|
||||
protocol.uninterceptProtocol 'https'
|
||||
done()
|
||||
protocol.interceptProtocol 'https', handler
|
||||
|
||||
it 'can override ws protocol handler', (done) ->
|
||||
handler = remote.createFunctionWithReturnValue 'valar morghulis'
|
||||
protocol.once 'intercepted', ->
|
||||
protocol.uninterceptProtocol 'ws'
|
||||
done()
|
||||
protocol.interceptProtocol 'ws', handler
|
||||
|
||||
it 'can override wss protocol handler', (done) ->
|
||||
handler = remote.createFunctionWithReturnValue 'valar morghulis'
|
||||
protocol.once 'intercepted', ->
|
||||
protocol.uninterceptProtocol 'wss'
|
||||
done()
|
||||
protocol.interceptProtocol 'wss', handler
|
||||
|
|
Loading…
Add table
Reference in a new issue