blob: feb12a3816ec829ffe468439645173d64b59f473 [file] [log] [blame]
[email protected]a9cf2b92013-10-30 12:08:491// Copyright 2013 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 NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_BASE_H_
6#define NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_BASE_H_
7
8// This file is included from net/http files.
9// Since net/http can be built without linking net/websockets code,
10// this file must not introduce any link-time dependencies on websockets.
11
danakj9c5cab52016-04-16 00:54:3312#include <memory>
[email protected]96868202014-01-09 10:38:0413#include <string>
14
tfarinaea94afc232015-10-20 04:23:3615#include "base/macros.h"
[email protected]a9cf2b92013-10-30 12:08:4916#include "base/memory/weak_ptr.h"
[email protected]f4533ba2013-11-28 09:35:4117#include "base/supports_user_data.h"
bnc81c46c1f2016-10-04 16:25:5918#include "net/base/net_export.h"
yhiranoa7e05bb2014-11-06 05:40:3919#include "net/http/http_stream.h"
[email protected]f4533ba2013-11-28 09:35:4120#include "net/url_request/websocket_handshake_userdata_key.h"
[email protected]a9cf2b92013-10-30 12:08:4921#include "net/websockets/websocket_stream.h"
22
23namespace net {
24
25class ClientSocketHandle;
Bence Béky46bfbc12018-02-22 19:28:2026class SpdySession;
[email protected]a9cf2b92013-10-30 12:08:4927
28// WebSocketHandshakeStreamBase is the base class of
29// WebSocketBasicHandshakeStream. net/http code uses this interface to handle
30// WebSocketBasicHandshakeStream when it needs to be treated differently from
31// HttpStreamBase.
yhiranoa7e05bb2014-11-06 05:40:3932class NET_EXPORT WebSocketHandshakeStreamBase : public HttpStream {
[email protected]a9cf2b92013-10-30 12:08:4933 public:
[email protected]efa9e732013-11-29 02:55:0534 // An object that stores data needed for the creation of a
35 // WebSocketBasicHandshakeStream object. A new CreateHelper is used for each
36 // WebSocket connection.
37 class NET_EXPORT_PRIVATE CreateHelper : public base::SupportsUserData::Data {
[email protected]a9cf2b92013-10-30 12:08:4938 public:
[email protected]f4533ba2013-11-28 09:35:4139 // Returns a key to use to lookup this object in a URLRequest object. It is
40 // different from any other key that is supplied to
41 // URLRequest::SetUserData().
42 static const void* DataKey() { return kWebSocketHandshakeUserDataKey; }
43
dchengb03027d2014-10-21 12:00:2044 ~CreateHelper() override {}
[email protected]a9cf2b92013-10-30 12:08:4945
[email protected]7e841a52013-11-22 09:04:2146 // Create a WebSocketBasicHandshakeStream. This is called after the
[email protected]a9cf2b92013-10-30 12:08:4947 // underlying connection has been established but before any handshake data
[email protected]efa9e732013-11-29 02:55:0548 // has been transferred. This can be called more than once in the case that
49 // HTTP authentication is needed.
bnc615cf2f2017-05-19 18:53:2650 virtual std::unique_ptr<WebSocketHandshakeStreamBase> CreateBasicStream(
danakj9c5cab52016-04-16 00:54:3351 std::unique_ptr<ClientSocketHandle> connection,
[email protected]a9cf2b92013-10-30 12:08:4952 bool using_proxy) = 0;
Bence Béky46bfbc12018-02-22 19:28:2053
54 // Create a WebSocketHttp2HandshakeStream. This is called after the
55 // underlying HTTP/2 connection has been established but before the stream
56 // has been opened. This cannot be called more than once.
57 virtual std::unique_ptr<WebSocketHandshakeStreamBase> CreateHttp2Stream(
58 base::WeakPtr<SpdySession> session) = 0;
[email protected]a9cf2b92013-10-30 12:08:4959 };
60
[email protected]f4533ba2013-11-28 09:35:4161 // This has to have an inline implementation so that the net/url_request/
62 // tests do not fail on iOS.
dchengb03027d2014-10-21 12:00:2063 ~WebSocketHandshakeStreamBase() override {}
[email protected]a9cf2b92013-10-30 12:08:4964
65 // After the handshake has completed, this method creates a WebSocketStream
66 // (of the appropriate type) from the WebSocketHandshakeStreamBase object.
67 // The WebSocketHandshakeStreamBase object is unusable after Upgrade() has
68 // been called.
danakj9c5cab52016-04-16 00:54:3369 virtual std::unique_ptr<WebSocketStream> Upgrade() = 0;
[email protected]a9cf2b92013-10-30 12:08:4970
Andrey Kosyakov83a6eee2017-08-14 19:20:0471 void SetRequestHeadersCallback(RequestHeadersCallback callback) override {}
72
[email protected]a9cf2b92013-10-30 12:08:4973 protected:
[email protected]f4533ba2013-11-28 09:35:4174 // As with the destructor, this must be inline.
[email protected]a9cf2b92013-10-30 12:08:4975 WebSocketHandshakeStreamBase() {}
76
77 private:
78 DISALLOW_COPY_AND_ASSIGN(WebSocketHandshakeStreamBase);
79};
80
81} // namespace net
82
83#endif // NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_BASE_H_