OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_QUIC_CORE_SPDY_UTILS_H_ | 5 #ifndef NET_QUIC_CORE_SPDY_UTILS_H_ |
6 #define NET_QUIC_CORE_SPDY_UTILS_H_ | 6 #define NET_QUIC_CORE_SPDY_UTILS_H_ |
7 | 7 |
8 #include <cstddef> | 8 #include <cstddef> |
9 #include <cstdint> | 9 #include <cstdint> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "net/quic/core/quic_header_list.h" | 13 #include "net/quic/core/quic_header_list.h" |
14 #include "net/quic/core/quic_packets.h" | 14 #include "net/quic/core/quic_packets.h" |
15 #include "net/quic/platform/api/quic_export.h" | 15 #include "net/quic/platform/api/quic_export.h" |
16 #include "net/spdy/core/spdy_framer.h" | 16 #include "net/spdy/core/spdy_framer.h" |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 | 19 |
20 class QUIC_EXPORT_PRIVATE SpdyUtils { | 20 class QUIC_EXPORT_PRIVATE SpdyUtils { |
21 public: | 21 public: |
22 static std::string SerializeUncompressedHeaders( | 22 static std::string SerializeUncompressedHeaders( |
23 const SpdyHeaderBlock& headers); | 23 const SpdyHeaderBlock& headers); |
24 | 24 |
25 // Parses |data| as a string containing serialized HTTP/2 HEADERS frame, | |
26 // populating |headers| with the key->value pairs found. | |
27 // |content_length| will be populated with the value of the content-length | |
28 // header if one or more are present. | |
29 // Returns true on success, false if parsing fails, or invalid keys are found. | |
30 static bool ParseHeaders(const char* data, | |
31 uint32_t data_len, | |
32 int64_t* content_length, | |
33 SpdyHeaderBlock* headers); | |
34 | |
35 // Populate |content length| with the value of the content-length header. | 25 // Populate |content length| with the value of the content-length header. |
36 // Returns true on success, false if parsing fails or content-length header is | 26 // Returns true on success, false if parsing fails or content-length header is |
37 // missing. | 27 // missing. |
38 static bool ExtractContentLengthFromHeaders(int64_t* content_length, | 28 static bool ExtractContentLengthFromHeaders(int64_t* content_length, |
39 SpdyHeaderBlock* headers); | 29 SpdyHeaderBlock* headers); |
40 | 30 |
41 // Parses |data| as a string containing serialized HTTP/2 HEADERS frame, | 31 // Copies a list of headers to a SpdyHeaderBlock. |
42 // populating |trailers| with the key->value pairs found. | |
43 // The final offset header will be excluded from |trailers|, and instead the | |
44 // value will be copied to |final_byte_offset|. | |
45 // Returns true on success, false if parsing fails, or invalid keys are found. | |
46 static bool ParseTrailers(const char* data, | |
47 uint32_t data_len, | |
48 size_t* final_byte_offset, | |
49 SpdyHeaderBlock* trailers); | |
50 | |
51 // Copies a list of headers to a SpdyHeaderBlock. Performs similar validation | |
52 // to SpdyFramer::ParseHeaderBlockInBuffer and ParseHeaders, above. | |
53 static bool CopyAndValidateHeaders(const QuicHeaderList& header_list, | 32 static bool CopyAndValidateHeaders(const QuicHeaderList& header_list, |
54 int64_t* content_length, | 33 int64_t* content_length, |
55 SpdyHeaderBlock* headers); | 34 SpdyHeaderBlock* headers); |
56 | 35 |
57 // Copies a list of headers to a SpdyHeaderBlock. Performs similar validation | 36 // Copies a list of headers to a SpdyHeaderBlock. |
58 // to SpdyFramer::ParseHeaderBlockInBuffer and ParseTrailers, above. | |
59 static bool CopyAndValidateTrailers(const QuicHeaderList& header_list, | 37 static bool CopyAndValidateTrailers(const QuicHeaderList& header_list, |
60 size_t* final_byte_offset, | 38 size_t* final_byte_offset, |
61 SpdyHeaderBlock* trailers); | 39 SpdyHeaderBlock* trailers); |
62 | 40 |
63 // Returns URL composed from scheme, authority, and path header | 41 // Returns URL composed from scheme, authority, and path header |
64 // values, or empty string if any of those fields are missing. | 42 // values, or empty string if any of those fields are missing. |
65 static std::string GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers); | 43 static std::string GetUrlFromHeaderBlock(const SpdyHeaderBlock& headers); |
66 | 44 |
67 // Returns hostname, or empty string if missing. | 45 // Returns hostname, or empty string if missing. |
68 static std::string GetHostNameFromHeaderBlock(const SpdyHeaderBlock& headers); | 46 static std::string GetHostNameFromHeaderBlock(const SpdyHeaderBlock& headers); |
69 | 47 |
70 // Returns true if result of |GetUrlFromHeaderBlock()| is non-empty | 48 // Returns true if result of |GetUrlFromHeaderBlock()| is non-empty |
71 // and is a well-formed URL. | 49 // and is a well-formed URL. |
72 static bool UrlIsValid(const SpdyHeaderBlock& headers); | 50 static bool UrlIsValid(const SpdyHeaderBlock& headers); |
73 | 51 |
74 // Populates the fields of |headers| to make a GET request of |url|, | 52 // Populates the fields of |headers| to make a GET request of |url|, |
75 // which must be fully-qualified. | 53 // which must be fully-qualified. |
76 static bool PopulateHeaderBlockFromUrl(const std::string url, | 54 static bool PopulateHeaderBlockFromUrl(const std::string url, |
77 SpdyHeaderBlock* headers); | 55 SpdyHeaderBlock* headers); |
78 | 56 |
79 private: | 57 private: |
80 DISALLOW_COPY_AND_ASSIGN(SpdyUtils); | 58 DISALLOW_COPY_AND_ASSIGN(SpdyUtils); |
81 }; | 59 }; |
82 | 60 |
83 } // namespace net | 61 } // namespace net |
84 | 62 |
85 #endif // NET_QUIC_CORE_SPDY_UTILS_H_ | 63 #endif // NET_QUIC_CORE_SPDY_UTILS_H_ |
OLD | NEW |