QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 | |
renjietang | d6e461b | 2020-02-04 16:16:35 -0800 | [diff] [blame] | 8 | #include <memory> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9 | #include "net/third_party/quiche/src/quic/core/http/http_frames.h" |
| 10 | #include "net/third_party/quiche/src/quic/core/quic_error_codes.h" |
| 11 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12 | |
| 13 | namespace quic { |
| 14 | |
| 15 | class QuicDataWriter; |
| 16 | |
| 17 | // A class for encoding the HTTP frames that are exchanged in an HTTP over QUIC |
| 18 | // session. |
| 19 | class QUIC_EXPORT_PRIVATE HttpEncoder { |
| 20 | public: |
bnc | 4694272 | 2019-10-29 11:56:21 -0700 | [diff] [blame] | 21 | HttpEncoder() = delete; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 22 | |
| 23 | // Serializes a DATA frame header into a new buffer stored in |output|. |
| 24 | // Returns the length of the buffer on success, or 0 otherwise. |
bnc | 4694272 | 2019-10-29 11:56:21 -0700 | [diff] [blame] | 25 | static QuicByteCount SerializeDataFrameHeader( |
| 26 | QuicByteCount payload_length, |
| 27 | std::unique_ptr<char[]>* output); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 28 | |
| 29 | // Serializes a HEADERS frame header into a new buffer stored in |output|. |
| 30 | // Returns the length of the buffer on success, or 0 otherwise. |
bnc | 4694272 | 2019-10-29 11:56:21 -0700 | [diff] [blame] | 31 | static QuicByteCount SerializeHeadersFrameHeader( |
| 32 | QuicByteCount payload_length, |
| 33 | std::unique_ptr<char[]>* output); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 34 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 35 | // Serializes a CANCEL_PUSH frame into a new buffer stored in |output|. |
| 36 | // Returns the length of the buffer on success, or 0 otherwise. |
bnc | 4694272 | 2019-10-29 11:56:21 -0700 | [diff] [blame] | 37 | static QuicByteCount SerializeCancelPushFrame( |
| 38 | const CancelPushFrame& cancel_push, |
| 39 | std::unique_ptr<char[]>* output); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 40 | |
| 41 | // Serializes a SETTINGS frame into a new buffer stored in |output|. |
| 42 | // Returns the length of the buffer on success, or 0 otherwise. |
bnc | 4694272 | 2019-10-29 11:56:21 -0700 | [diff] [blame] | 43 | static QuicByteCount SerializeSettingsFrame(const SettingsFrame& settings, |
| 44 | std::unique_ptr<char[]>* output); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 45 | |
| 46 | // Serializes the header and push_id of a PUSH_PROMISE frame into a new buffer |
| 47 | // stored in |output|. Returns the length of the buffer on success, or 0 |
| 48 | // otherwise. |
bnc | 4694272 | 2019-10-29 11:56:21 -0700 | [diff] [blame] | 49 | static QuicByteCount SerializePushPromiseFrameWithOnlyPushId( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 50 | const PushPromiseFrame& push_promise, |
| 51 | std::unique_ptr<char[]>* output); |
| 52 | |
| 53 | // Serializes a GOAWAY frame into a new buffer stored in |output|. |
| 54 | // Returns the length of the buffer on success, or 0 otherwise. |
bnc | 4694272 | 2019-10-29 11:56:21 -0700 | [diff] [blame] | 55 | static QuicByteCount SerializeGoAwayFrame(const GoAwayFrame& goaway, |
| 56 | std::unique_ptr<char[]>* output); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 57 | |
| 58 | // Serializes a MAX_PUSH frame into a new buffer stored in |output|. |
| 59 | // Returns the length of the buffer on success, or 0 otherwise. |
bnc | 4694272 | 2019-10-29 11:56:21 -0700 | [diff] [blame] | 60 | static QuicByteCount SerializeMaxPushIdFrame( |
| 61 | const MaxPushIdFrame& max_push_id, |
| 62 | std::unique_ptr<char[]>* output); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 63 | |
bnc | 51e8962 | 2020-01-10 10:40:32 -0800 | [diff] [blame] | 64 | // Serializes a PRIORITY_UPDATE frame into a new buffer stored in |output|. |
| 65 | // Returns the length of the buffer on success, or 0 otherwise. |
| 66 | static QuicByteCount SerializePriorityUpdateFrame( |
| 67 | const PriorityUpdateFrame& priority_update, |
| 68 | std::unique_ptr<char[]>* output); |
renjietang | d6e461b | 2020-02-04 16:16:35 -0800 | [diff] [blame] | 69 | |
bnc | 5d7b084 | 2020-12-03 07:29:10 -0800 | [diff] [blame] | 70 | // Serializes an ACCEPT_CH frame into a new buffer stored in |output|. |
| 71 | // Returns the length of the buffer on success, or 0 otherwise. |
| 72 | static QuicByteCount SerializeAcceptChFrame(const AcceptChFrame& accept_ch, |
| 73 | std::unique_ptr<char[]>* output); |
| 74 | |
renjietang | d6e461b | 2020-02-04 16:16:35 -0800 | [diff] [blame] | 75 | // Serializes a frame with reserved frame type specified in |
| 76 | // https://tools.ietf.org/html/draft-ietf-quic-http-25#section-7.2.9. |
| 77 | static QuicByteCount SerializeGreasingFrame(std::unique_ptr<char[]>* output); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // namespace quic |
| 81 | |
| 82 | #endif // QUICHE_QUIC_CORE_HTTP_HTTP_ENCODER_H_ |