Home | History | Annotate | Download | only in browser
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_HTTP_AUTH_HANDLER_DATA_REDUCTION_PROXY_H_
      6 #define COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_HTTP_AUTH_HANDLER_DATA_REDUCTION_PROXY_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/gtest_prod_util.h"
     12 #include "net/http/http_auth_handler.h"
     13 #include "net/http/http_auth_handler_factory.h"
     14 
     15 namespace data_reduction_proxy {
     16 
     17 // Code for handling http SpdyProxy authentication.
     18 class HttpAuthHandlerDataReductionProxy : public net::HttpAuthHandler {
     19  public:
     20   // Returns the data reduction proxy auth scheme.
     21   static std::string Scheme();
     22 
     23   class Factory : public net::HttpAuthHandlerFactory {
     24    public:
     25     // Constructs a new spdyproxy handler factory which mints handlers that
     26     // respond to challenges only from the given |authorized_spdyproxy_origins|.
     27     explicit Factory(const std::vector<GURL>& authorized_spdyproxy_origins);
     28     virtual ~Factory();
     29 
     30     virtual int CreateAuthHandler(
     31         net::HttpAuthChallengeTokenizer* challenge,
     32         net::HttpAuth::Target target,
     33         const GURL& origin,
     34         CreateReason reason,
     35         int digest_nonce_count,
     36         const net::BoundNetLog& net_log,
     37         scoped_ptr<HttpAuthHandler>* handler) OVERRIDE;
     38 
     39    private:
     40     // The origins for which Chrome will respond to SpdyProxy auth challenges.
     41     std::vector<GURL> authorized_spdyproxy_origins_;
     42   };
     43 
     44   // Constructs a new spdyproxy handler.
     45   HttpAuthHandlerDataReductionProxy() {}
     46 
     47   // Overrides from net::HttpAuthHandler.
     48   virtual net::HttpAuth::AuthorizationResult HandleAnotherChallenge(
     49       net::HttpAuthChallengeTokenizer* challenge) OVERRIDE;
     50   virtual bool NeedsIdentity() OVERRIDE;
     51   virtual bool AllowsDefaultCredentials() OVERRIDE;
     52   virtual bool AllowsExplicitCredentials() OVERRIDE;
     53 
     54  private:
     55   FRIEND_TEST_ALL_PREFIXES(HttpAuthHandlerDataReductionProxyTest,
     56                            ParseChallenge);
     57 
     58   virtual ~HttpAuthHandlerDataReductionProxy();
     59 
     60   virtual bool Init(net::HttpAuthChallengeTokenizer* challenge) OVERRIDE;
     61 
     62   virtual int GenerateAuthTokenImpl(const net::AuthCredentials* credentials,
     63                                     const net::HttpRequestInfo* request,
     64                                     const net::CompletionCallback& callback,
     65                                     std::string* auth_token) OVERRIDE;
     66 
     67   bool ParseChallenge(net::HttpAuthChallengeTokenizer* challenge);
     68 
     69   bool ParseChallengeProperty(const std::string& name,
     70                               const std::string& value);
     71 
     72   // Proxy server token, encoded as UTF-8.
     73   std::string ps_token_;
     74 
     75   DISALLOW_COPY_AND_ASSIGN(HttpAuthHandlerDataReductionProxy);
     76 };
     77 
     78 }  // namespace data_reduction_proxy
     79 
     80 #endif  // COMPONENTS_DATA_REDUCTION_PROXY_BROWSER_HTTP_AUTH_HANDLER_DATA_REDUCTION_PROXY_H_
     81