xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/tools/quic_simple_server_session.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 // A toy server specific QuicSession subclass.
6 
7 #ifndef QUICHE_QUIC_TOOLS_QUIC_SIMPLE_SERVER_SESSION_H_
8 #define QUICHE_QUIC_TOOLS_QUIC_SIMPLE_SERVER_SESSION_H_
9 
10 #include <stdint.h>
11 
12 #include <list>
13 #include <memory>
14 #include <set>
15 #include <string>
16 #include <utility>
17 #include <vector>
18 
19 #include "quiche/quic/core/http/quic_server_session_base.h"
20 #include "quiche/quic/core/http/quic_spdy_session.h"
21 #include "quiche/quic/core/quic_crypto_server_stream_base.h"
22 #include "quiche/quic/core/quic_packets.h"
23 #include "quiche/quic/tools/quic_backend_response.h"
24 #include "quiche/quic/tools/quic_simple_server_backend.h"
25 #include "quiche/quic/tools/quic_simple_server_stream.h"
26 #include "quiche/spdy/core/http2_header_block.h"
27 
28 namespace quic {
29 
30 namespace test {
31 class QuicSimpleServerSessionPeer;
32 }  // namespace test
33 
34 class QuicSimpleServerSession : public QuicServerSessionBase {
35  public:
36   // Takes ownership of |connection|.
37   QuicSimpleServerSession(const QuicConfig& config,
38                           const ParsedQuicVersionVector& supported_versions,
39                           QuicConnection* connection,
40                           QuicSession::Visitor* visitor,
41                           QuicCryptoServerStreamBase::Helper* helper,
42                           const QuicCryptoServerConfig* crypto_config,
43                           QuicCompressedCertsCache* compressed_certs_cache,
44                           QuicSimpleServerBackend* quic_simple_server_backend);
45   QuicSimpleServerSession(const QuicSimpleServerSession&) = delete;
46   QuicSimpleServerSession& operator=(const QuicSimpleServerSession&) = delete;
47 
48   ~QuicSimpleServerSession() override;
49 
50   // Override base class to detact client sending data on server push stream.
51   void OnStreamFrame(const QuicStreamFrame& frame) override;
52 
53  protected:
54   // QuicSession methods:
55   QuicSpdyStream* CreateIncomingStream(QuicStreamId id) override;
56   QuicSpdyStream* CreateIncomingStream(PendingStream* pending) override;
57   QuicSpdyStream* CreateOutgoingBidirectionalStream() override;
58   QuicSimpleServerStream* CreateOutgoingUnidirectionalStream() override;
59 
60   // QuicServerSessionBaseMethod:
61   std::unique_ptr<QuicCryptoServerStreamBase> CreateQuicCryptoServerStream(
62       const QuicCryptoServerConfig* crypto_config,
63       QuicCompressedCertsCache* compressed_certs_cache) override;
64 
65   // Overridden to handle conversion from bidi pending stream.
66   QuicStream* ProcessBidirectionalPendingStream(
67       PendingStream* pending) override;
68 
server_backend()69   QuicSimpleServerBackend* server_backend() {
70     return quic_simple_server_backend_;
71   }
72 
LocallySupportedWebTransportVersions()73   WebTransportHttp3VersionSet LocallySupportedWebTransportVersions()
74       const override {
75     return quic_simple_server_backend_->SupportsWebTransport()
76                ? kDefaultSupportedWebTransportVersions
77                : WebTransportHttp3VersionSet();
78   }
LocalHttpDatagramSupport()79   HttpDatagramSupport LocalHttpDatagramSupport() override {
80     if (ShouldNegotiateWebTransport()) {
81       return HttpDatagramSupport::kRfcAndDraft04;
82     }
83     return QuicServerSessionBase::LocalHttpDatagramSupport();
84   }
85 
86  private:
87   friend class test::QuicSimpleServerSessionPeer;
88 
89   QuicSimpleServerBackend* quic_simple_server_backend_;  // Not owned.
90 };
91 
92 }  // namespace quic
93 
94 #endif  // QUICHE_QUIC_TOOLS_QUIC_SIMPLE_SERVER_SESSION_H_
95