blob: f04e6e4070043de68b7d2569081e0c5284e48794 [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
8#include <cstddef>
9
10#include "net/third_party/quiche/src/quic/core/http/http_frames.h"
11#include "net/third_party/quiche/src/quic/core/quic_error_codes.h"
12#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
13#include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h"
14
15namespace quic {
16
17class QuicDataWriter;
18
19// A class for encoding the HTTP frames that are exchanged in an HTTP over QUIC
20// session.
21class QUIC_EXPORT_PRIVATE HttpEncoder {
22 public:
23 HttpEncoder();
24
25 ~HttpEncoder();
26
27 // Serializes a DATA frame header into a new buffer stored in |output|.
28 // Returns the length of the buffer on success, or 0 otherwise.
29 QuicByteCount SerializeDataFrameHeader(QuicByteCount payload_length,
30 std::unique_ptr<char[]>* output);
31
32 // Serializes a HEADERS frame header into a new buffer stored in |output|.
33 // Returns the length of the buffer on success, or 0 otherwise.
34 QuicByteCount SerializeHeadersFrameHeader(QuicByteCount payload_length,
35 std::unique_ptr<char[]>* output);
36
37 // Serializes a PRIORITY frame into a new buffer stored in |output|.
38 // Returns the length of the buffer on success, or 0 otherwise.
39 QuicByteCount SerializePriorityFrame(const PriorityFrame& priority,
40 std::unique_ptr<char[]>* output);
41
42 // Serializes a CANCEL_PUSH frame into a new buffer stored in |output|.
43 // Returns the length of the buffer on success, or 0 otherwise.
44 QuicByteCount SerializeCancelPushFrame(const CancelPushFrame& cancel_push,
45 std::unique_ptr<char[]>* output);
46
47 // Serializes a SETTINGS frame into a new buffer stored in |output|.
48 // Returns the length of the buffer on success, or 0 otherwise.
49 QuicByteCount SerializeSettingsFrame(const SettingsFrame& settings,
50 std::unique_ptr<char[]>* output);
51
52 // Serializes the header and push_id of a PUSH_PROMISE frame into a new buffer
53 // stored in |output|. Returns the length of the buffer on success, or 0
54 // otherwise.
55 QuicByteCount SerializePushPromiseFrameWithOnlyPushId(
56 const PushPromiseFrame& push_promise,
57 std::unique_ptr<char[]>* output);
58
59 // Serializes a GOAWAY frame into a new buffer stored in |output|.
60 // Returns the length of the buffer on success, or 0 otherwise.
61 QuicByteCount SerializeGoAwayFrame(const GoAwayFrame& goaway,
62 std::unique_ptr<char[]>* output);
63
64 // Serializes a MAX_PUSH frame into a new buffer stored in |output|.
65 // Returns the length of the buffer on success, or 0 otherwise.
66 QuicByteCount SerializeMaxPushIdFrame(const MaxPushIdFrame& max_push_id,
67 std::unique_ptr<char[]>* output);
68
69 // Serialize a DUPLICATE_PUSH frame into a new buffer stored in |output|.
70 // Returns the length of the buffer on success, or 0 otherwise.
71 QuicByteCount SerializeDuplicatePushFrame(
72 const DuplicatePushFrame& duplicate_push,
73 std::unique_ptr<char[]>* output);
74
75 private:
76 bool WriteFrameHeader(QuicByteCount length,
77 HttpFrameType type,
78 QuicDataWriter* writer);
79
80 QuicByteCount GetTotalLength(QuicByteCount payload_length);
81};
82
83} // namespace quic
84
85#endif // QUICHE_QUIC_CORE_HTTP_HTTP_ENCODER_H_