1// Copyright (c) 2012 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 CHROME_BROWSER_NET_SPDYPROXY_HTTP_AUTH_HANDLER_SPDYPROXY_H_ 6#define CHROME_BROWSER_NET_SPDYPROXY_HTTP_AUTH_HANDLER_SPDYPROXY_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 15namespace spdyproxy { 16 17// Code for handling http SpdyProxy authentication. 18class HttpAuthHandlerSpdyProxy : public net::HttpAuthHandler { 19 public: 20 class Factory : public net::HttpAuthHandlerFactory { 21 public: 22 // Constructs a new spdyproxy handler factory which mints handlers that 23 // respond to challenges only from the given |authorized_spdyproxy_origins|. 24 explicit Factory(const std::vector<GURL>& authorized_spdyproxy_origins); 25 virtual ~Factory(); 26 27 virtual int CreateAuthHandler( 28 net::HttpAuth::ChallengeTokenizer* challenge, 29 net::HttpAuth::Target target, 30 const GURL& origin, 31 CreateReason reason, 32 int digest_nonce_count, 33 const net::BoundNetLog& net_log, 34 scoped_ptr<HttpAuthHandler>* handler) OVERRIDE; 35 36 private: 37 // The origins for which Chrome will respond to SpdyProxy auth challenges. 38 std::vector<GURL> authorized_spdyproxy_origins_; 39 }; 40 41 // Constructs a new spdyproxy handler. 42 HttpAuthHandlerSpdyProxy() {} 43 44 // Overrides from net::HttpAuthHandler. 45 virtual net::HttpAuth::AuthorizationResult HandleAnotherChallenge( 46 net::HttpAuth::ChallengeTokenizer* challenge) OVERRIDE; 47 virtual bool NeedsIdentity() OVERRIDE; 48 virtual bool AllowsDefaultCredentials() OVERRIDE; 49 virtual bool AllowsExplicitCredentials() OVERRIDE; 50 51 private: 52 FRIEND_TEST_ALL_PREFIXES(HttpAuthHandlerSpdyProxyTest, ParseChallenge); 53 54 virtual ~HttpAuthHandlerSpdyProxy(); 55 56 virtual bool Init(net::HttpAuth::ChallengeTokenizer* challenge) OVERRIDE; 57 58 virtual int GenerateAuthTokenImpl(const net::AuthCredentials* credentials, 59 const net::HttpRequestInfo* request, 60 const net::CompletionCallback& callback, 61 std::string* auth_token) OVERRIDE; 62 63 bool ParseChallenge(net::HttpAuth::ChallengeTokenizer* challenge); 64 65 bool ParseChallengeProperty(const std::string& name, 66 const std::string& value); 67 68 // Proxy server token, encoded as UTF-8. 69 std::string ps_token_; 70 71 DISALLOW_COPY_AND_ASSIGN(HttpAuthHandlerSpdyProxy); 72}; 73 74} // namespace spdyproxy 75 76#endif // CHROME_BROWSER_NET_SPDYPROXY_HTTP_AUTH_HANDLER_SPDYPROXY_H_ 77