support https, ws, wss builtin schemes to be intercepted
authordeepak1556 <hop2deep@gmail.com>
Mon, 11 May 2015 07:26:36 +0000 (12:56 +0530)
committerdeepak1556 <hop2deep@gmail.com>
Mon, 11 May 2015 07:26:36 +0000 (12:56 +0530)
atom/browser/atom_browser_context.cc
atom/browser/net/http_protocol_handler.cc
atom/browser/net/http_protocol_handler.h
spec/api-protocol-spec.coffee

index 835a5c5..d69aab2 100644 (file)
@@ -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();
index 9cc3d2d..cf5fc01 100644 (file)
@@ -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
index ad66fa7..9808537 100644 (file)
@@ -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
index 060f035..5b72140 100644 (file)
@@ -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