proxy_client_socket.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #ifndef NET_HTTP_PROXY_CLIENT_SOCKET_H_
  5. #define NET_HTTP_PROXY_CLIENT_SOCKET_H_
  6. #include <memory>
  7. #include <string>
  8. #include "net/base/completion_once_callback.h"
  9. #include "net/base/net_export.h"
  10. #include "net/base/request_priority.h"
  11. #include "net/socket/ssl_client_socket.h"
  12. #include "net/socket/stream_socket.h"
  13. namespace net {
  14. class HostPortPair;
  15. class HttpAuthController;
  16. class HttpResponseInfo;
  17. class HttpRequestHeaders;
  18. class HttpAuthController;
  19. class NetLogWithSource;
  20. // A common base class for a stream socket tunneled through a proxy.
  21. class NET_EXPORT_PRIVATE ProxyClientSocket : public StreamSocket {
  22. public:
  23. ProxyClientSocket() = default;
  24. ProxyClientSocket(const ProxyClientSocket&) = delete;
  25. ProxyClientSocket& operator=(const ProxyClientSocket&) = delete;
  26. ~ProxyClientSocket() override = default;
  27. // Returns the HttpResponseInfo (including HTTP Headers) from
  28. // the response to the CONNECT request.
  29. virtual const HttpResponseInfo* GetConnectResponseInfo() const = 0;
  30. // Returns the HttpAuthController which can be used
  31. // to interact with an HTTP Proxy Authorization Required (407) request.
  32. virtual const scoped_refptr<HttpAuthController>& GetAuthController() const
  33. = 0;
  34. // If Connect (or its callback) returns PROXY_AUTH_REQUESTED, then an
  35. // auth challenge was received. If the HttpAuthController's HaveAuth()
  36. // method returns true, then the request just needs to be restarted with
  37. // this method to try with those credentials, and new credentials cannot
  38. // be provided. Otherwise, credentials should be added to the
  39. // HttpAuthController before calling RestartWithAuth. Not all
  40. // ProxyClientSocket implementations will be restartable. Such
  41. // implementations should disconnect themselves and return OK.
  42. virtual int RestartWithAuth(CompletionOnceCallback callback) = 0;
  43. // Set the priority of the underlying stream (for SPDY and QUIC)
  44. virtual void SetStreamPriority(RequestPriority priority);
  45. protected:
  46. // The HTTP CONNECT method for establishing a tunnel connection is documented
  47. // in draft-luotonen-web-proxy-tunneling-01.txt and RFC 2817, Sections 5.2
  48. // and 5.3.
  49. static void BuildTunnelRequest(const HostPortPair& endpoint,
  50. const HttpRequestHeaders& extra_headers,
  51. const std::string& user_agent,
  52. std::string* request_line,
  53. HttpRequestHeaders* request_headers);
  54. // When an auth challenge (407 response) is received during tunnel
  55. // construction/ this method should be called.
  56. static int HandleProxyAuthChallenge(HttpAuthController* auth,
  57. HttpResponseInfo* response,
  58. const NetLogWithSource& net_log);
  59. // When a proxy authentication response is received during tunnel
  60. // construction, this method should be called to strip everything
  61. // but the auth header from the redirect response.
  62. static void SanitizeProxyAuth(HttpResponseInfo& response);
  63. };
  64. } // namespace net
  65. #endif // NET_HTTP_PROXY_CLIENT_SOCKET_H_