xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/http/http_encoder.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2018 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 QUICHE_QUIC_CORE_HTTP_HTTP_ENCODER_H_
6 #define QUICHE_QUIC_CORE_HTTP_HTTP_ENCODER_H_
7 
8 #include <memory>
9 
10 #include "quiche/quic/core/http/http_frames.h"
11 #include "quiche/quic/core/quic_error_codes.h"
12 #include "quiche/quic/core/quic_types.h"
13 #include "quiche/quic/platform/api/quic_export.h"
14 #include "quiche/common/quiche_buffer_allocator.h"
15 
16 namespace quic {
17 
18 class QuicDataWriter;
19 
20 // A class for encoding the HTTP frames that are exchanged in an HTTP over QUIC
21 // session.
22 class QUICHE_EXPORT HttpEncoder {
23  public:
24   HttpEncoder() = delete;
25 
26   // Returns the length of the header for a DATA frame.
27   static QuicByteCount GetDataFrameHeaderLength(QuicByteCount payload_length);
28 
29   // Serializes a DATA frame header into a QuicheBuffer; returns said
30   // QuicheBuffer on success, empty buffer otherwise.
31   static quiche::QuicheBuffer SerializeDataFrameHeader(
32       QuicByteCount payload_length, quiche::QuicheBufferAllocator* allocator);
33 
34   // Serializes a HEADERS frame header.
35   static std::string SerializeHeadersFrameHeader(QuicByteCount payload_length);
36 
37   // Serializes a SETTINGS frame.
38   static std::string SerializeSettingsFrame(const SettingsFrame& settings);
39 
40   // Serializes a GOAWAY frame.
41   static std::string SerializeGoAwayFrame(const GoAwayFrame& goaway);
42 
43   // Serializes a PRIORITY_UPDATE frame.
44   static std::string SerializePriorityUpdateFrame(
45       const PriorityUpdateFrame& priority_update);
46 
47   // Serializes an ACCEPT_CH frame.
48   static std::string SerializeAcceptChFrame(const AcceptChFrame& accept_ch);
49 
50   // Serializes a frame with reserved frame type specified in
51   // https://tools.ietf.org/html/draft-ietf-quic-http-25#section-7.2.9.
52   static std::string SerializeGreasingFrame();
53 
54   // Serializes a WEBTRANSPORT_STREAM frame header as specified in
55   // https://www.ietf.org/archive/id/draft-ietf-webtrans-http3-00.html#name-client-initiated-bidirectio
56   static std::string SerializeWebTransportStreamFrameHeader(
57       WebTransportSessionId session_id);
58 
59   // Serializes a METADATA frame header.
60   static std::string SerializeMetadataFrameHeader(QuicByteCount payload_length);
61 };
62 
63 }  // namespace quic
64 
65 #endif  // QUICHE_QUIC_CORE_HTTP_HTTP_ENCODER_H_
66