blob: 43bca5ea52e7b1e26d34733f9057fa83d3a3c60d [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright (c) 2013 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_SPDY_UTILS_H_
6#define QUICHE_QUIC_CORE_HTTP_SPDY_UTILS_H_
7
8#include <cstddef>
9#include <cstdint>
vasilvv872e7a32019-03-12 16:42:44 -070010#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050011
renjietang2db302b2019-09-23 12:40:17 -070012#include "net/third_party/quiche/src/quic/core/http/http_constants.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050013#include "net/third_party/quiche/src/quic/core/http/quic_header_list.h"
14#include "net/third_party/quiche/src/quic/core/quic_packets.h"
15#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
danzh2a930462019-07-03 07:28:06 -070016#include "net/third_party/quiche/src/spdy/core/spdy_header_block.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050017
18namespace quic {
19
20class QUIC_EXPORT_PRIVATE SpdyUtils {
21 public:
22 SpdyUtils() = delete;
23
24 // Populate |content length| with the value of the content-length header.
25 // Returns true on success, false if parsing fails or content-length header is
26 // missing.
27 static bool ExtractContentLengthFromHeaders(int64_t* content_length,
28 spdy::SpdyHeaderBlock* headers);
29
30 // Copies a list of headers to a SpdyHeaderBlock.
31 static bool CopyAndValidateHeaders(const QuicHeaderList& header_list,
32 int64_t* content_length,
33 spdy::SpdyHeaderBlock* headers);
34
35 // Copies a list of headers to a SpdyHeaderBlock.
bnc5231ee22019-04-15 19:02:13 -070036 // If |expect_final_byte_offset| is true, requires exactly one header field
37 // with key kFinalOffsetHeaderKey and an integer value.
38 // If |expect_final_byte_offset| is false, no kFinalOffsetHeaderKey may be
39 // present.
40 // Returns true if parsing is successful. Returns false if the presence of
41 // kFinalOffsetHeaderKey does not match the value of
42 // |expect_final_byte_offset|, the kFinalOffsetHeaderKey value cannot be
43 // parsed, any other pseudo-header is present, an empty header key is present,
44 // or a header key contains an uppercase character.
QUICHE teama6ef0a62019-03-07 20:34:33 -050045 static bool CopyAndValidateTrailers(const QuicHeaderList& header_list,
bnc5231ee22019-04-15 19:02:13 -070046 bool expect_final_byte_offset,
QUICHE teama6ef0a62019-03-07 20:34:33 -050047 size_t* final_byte_offset,
48 spdy::SpdyHeaderBlock* trailers);
49
QUICHE teama6ef0a62019-03-07 20:34:33 -050050 // Populates the fields of |headers| to make a GET request of |url|,
51 // which must be fully-qualified.
vasilvvc48c8712019-03-11 13:38:16 -070052 static bool PopulateHeaderBlockFromUrl(const std::string url,
QUICHE teama6ef0a62019-03-07 20:34:33 -050053 spdy::SpdyHeaderBlock* headers);
renjietang2db302b2019-09-23 12:40:17 -070054
55 // Returns HTTP/3 SETTINGS identifier as a string.
56 static std::string H3SettingsToString(
57 Http3AndQpackSettingsIdentifiers identifier);
QUICHE teama6ef0a62019-03-07 20:34:33 -050058};
59
60} // namespace quic
61
62#endif // QUICHE_QUIC_CORE_HTTP_SPDY_UTILS_H_