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.
5 #ifndef NET_HTTP_PROXY_CLIENT_SOCKET_H_
6 #define NET_HTTP_PROXY_CLIENT_SOCKET_H_
10 #include "net/socket/ssl_client_socket.h"
11 #include "net/socket/stream_socket.h"
18 class HttpAuthController
;
20 class HttpResponseInfo
;
21 class HttpRequestHeaders
;
22 struct HttpRequestInfo
;
23 class HttpAuthController
;
25 class NET_EXPORT_PRIVATE ProxyClientSocket
: public StreamSocket
{
27 ProxyClientSocket() {}
28 ~ProxyClientSocket() override
{}
30 // Returns the HttpResponseInfo (including HTTP Headers) from
31 // the response to the CONNECT request.
32 virtual const HttpResponseInfo
* GetConnectResponseInfo() const = 0;
34 // Transfers ownership of a newly created HttpStream to the caller
35 // which can be used to read the response body.
36 virtual HttpStream
* CreateConnectResponseStream() = 0;
38 // Returns the HttpAuthController which can be used
39 // to interact with an HTTP Proxy Authorization Required (407) request.
40 virtual const scoped_refptr
<HttpAuthController
>& GetAuthController() const
43 // If Connect (or its callback) returns PROXY_AUTH_REQUESTED, then
44 // credentials should be added to the HttpAuthController before calling
45 // RestartWithAuth. Not all ProxyClientSocket implementations will be
46 // restartable. Such implementations should disconnect themselves and
48 virtual int RestartWithAuth(const CompletionCallback
& callback
) = 0;
50 // Returns true of the connection to the proxy is using SPDY.
51 virtual bool IsUsingSpdy() const = 0;
53 // Returns the protocol negotiated with the proxy.
54 virtual NextProto
GetProtocolNegotiated() const = 0;
57 // The HTTP CONNECT method for establishing a tunnel connection is documented
58 // in draft-luotonen-web-proxy-tunneling-01.txt and RFC 2817, Sections 5.2
60 static void BuildTunnelRequest(const HttpRequestInfo
& request_info
,
61 const HttpRequestHeaders
& auth_headers
,
62 const HostPortPair
& endpoint
,
63 std::string
* request_line
,
64 HttpRequestHeaders
* request_headers
);
66 // When an auth challenge (407 response) is received during tunnel
67 // construction/ this method should be called.
68 static int HandleProxyAuthChallenge(HttpAuthController
* auth
,
69 HttpResponseInfo
* response
,
70 const BoundNetLog
& net_log
);
72 // Logs (to the log and in a histogram) a blocked CONNECT response.
73 static void LogBlockedTunnelResponse(int http_response_code
,
77 // When a redirect (e.g. 302 response) is received during tunnel
78 // construction, this method should be called to strip everything
79 // but the Location header from the redirect response. If it returns
80 // false, the response should be discarded and tunnel construction should
81 // fail. |url| is for logging purposes.
82 static bool SanitizeProxyRedirect(HttpResponseInfo
* response
,
86 DISALLOW_COPY_AND_ASSIGN(ProxyClientSocket
);
91 #endif // NET_HTTP_PROXY_CLIENT_SOCKET_H_