blob: dfa236a0da252e6db78b5efc9f5b52779f827cc5 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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
renjietangd6e461b2020-02-04 16:16:35 -08008#include <memory>
QUICHE teama6ef0a62019-03-07 20:34:33 -05009#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 teama6ef0a62019-03-07 20:34:33 -050012
13namespace quic {
14
15class QuicDataWriter;
16
17// A class for encoding the HTTP frames that are exchanged in an HTTP over QUIC
18// session.
19class QUIC_EXPORT_PRIVATE HttpEncoder {
20 public:
bnc46942722019-10-29 11:56:21 -070021 HttpEncoder() = delete;
QUICHE teama6ef0a62019-03-07 20:34:33 -050022
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.
bnc46942722019-10-29 11:56:21 -070025 static QuicByteCount SerializeDataFrameHeader(
26 QuicByteCount payload_length,
27 std::unique_ptr<char[]>* output);
QUICHE teama6ef0a62019-03-07 20:34:33 -050028
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.
bnc46942722019-10-29 11:56:21 -070031 static QuicByteCount SerializeHeadersFrameHeader(
32 QuicByteCount payload_length,
33 std::unique_ptr<char[]>* output);
QUICHE teama6ef0a62019-03-07 20:34:33 -050034
QUICHE teama6ef0a62019-03-07 20:34:33 -050035 // Serializes a CANCEL_PUSH frame into a new buffer stored in |output|.
36 // Returns the length of the buffer on success, or 0 otherwise.
bnc46942722019-10-29 11:56:21 -070037 static QuicByteCount SerializeCancelPushFrame(
38 const CancelPushFrame& cancel_push,
39 std::unique_ptr<char[]>* output);
QUICHE teama6ef0a62019-03-07 20:34:33 -050040
41 // Serializes a SETTINGS frame into a new buffer stored in |output|.
42 // Returns the length of the buffer on success, or 0 otherwise.
bnc46942722019-10-29 11:56:21 -070043 static QuicByteCount SerializeSettingsFrame(const SettingsFrame& settings,
44 std::unique_ptr<char[]>* output);
QUICHE teama6ef0a62019-03-07 20:34:33 -050045
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.
bnc46942722019-10-29 11:56:21 -070049 static QuicByteCount SerializePushPromiseFrameWithOnlyPushId(
QUICHE teama6ef0a62019-03-07 20:34:33 -050050 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.
bnc46942722019-10-29 11:56:21 -070055 static QuicByteCount SerializeGoAwayFrame(const GoAwayFrame& goaway,
56 std::unique_ptr<char[]>* output);
QUICHE teama6ef0a62019-03-07 20:34:33 -050057
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.
bnc46942722019-10-29 11:56:21 -070060 static QuicByteCount SerializeMaxPushIdFrame(
61 const MaxPushIdFrame& max_push_id,
62 std::unique_ptr<char[]>* output);
QUICHE teama6ef0a62019-03-07 20:34:33 -050063
bnc51e89622020-01-10 10:40:32 -080064 // 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);
renjietangd6e461b2020-02-04 16:16:35 -080069
bnc5d7b0842020-12-03 07:29:10 -080070 // 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
renjietangd6e461b2020-02-04 16:16:35 -080075 // 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 teama6ef0a62019-03-07 20:34:33 -050078};
79
80} // namespace quic
81
82#endif // QUICHE_QUIC_CORE_HTTP_HTTP_ENCODER_H_