Update V8 to version 4.7.47.
[chromium-blink-merge.git] / net / spdy / spdy_alt_svc_wire_format.h
blob85e8d81f096a85f4b4c1c87872ca315e9c1c6769
1 // Copyright (c) 2015 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.
5 // This file contains data structures and utility functions used for serializing
6 // and parsing alternative service header values, common to HTTP/1.1 header
7 // fields and HTTP/2 and QUIC ALTSVC frames. See specification at
8 // https://tools.ietf.org/id/draft-ietf-httpbis-alt-svc-06.html
10 #ifndef NET_SPDY_SPDY_ALT_SVC_WIRE_FORMAT_H_
11 #define NET_SPDY_SPDY_ALT_SVC_WIRE_FORMAT_H_
13 #include <vector>
15 #include "base/basictypes.h"
16 #include "base/strings/string_piece.h"
17 #include "net/base/net_export.h"
19 using base::StringPiece;
21 namespace net {
23 namespace test {
24 class SpdyAltSvcWireFormatPeer;
25 } // namespace test
27 class NET_EXPORT_PRIVATE SpdyAltSvcWireFormat {
28 public:
29 struct AlternativeService {
30 std::string protocol_id;
31 std::string host;
32 uint16 port;
33 uint32 max_age;
34 double p;
36 AlternativeService() = default;
37 AlternativeService(const std::string& protocol_id,
38 const std::string& host,
39 uint16 port,
40 uint32 max_age,
41 double p)
42 : protocol_id(protocol_id),
43 host(host),
44 port(port),
45 max_age(max_age),
46 p(p) {}
48 bool operator==(const AlternativeService& other) const {
49 return protocol_id == other.protocol_id && host == other.host &&
50 port == other.port && max_age == other.max_age && p == other.p;
53 typedef std::vector<AlternativeService> AlternativeServiceVector;
55 friend class test::SpdyAltSvcWireFormatPeer;
56 static bool ParseHeaderFieldValue(StringPiece value,
57 AlternativeServiceVector* altsvc_vector);
58 static std::string SerializeHeaderFieldValue(
59 const AlternativeServiceVector& altsvc_vector);
61 private:
62 static void SkipWhiteSpace(StringPiece::const_iterator* c,
63 StringPiece::const_iterator end);
64 static bool PercentDecode(StringPiece::const_iterator c,
65 StringPiece::const_iterator end,
66 std::string* output);
67 static bool ParseAltAuthority(StringPiece::const_iterator c,
68 StringPiece::const_iterator end,
69 std::string* host,
70 uint16* port);
71 static bool ParsePositiveInteger16(StringPiece::const_iterator c,
72 StringPiece::const_iterator end,
73 uint16* value);
74 static bool ParsePositiveInteger32(StringPiece::const_iterator c,
75 StringPiece::const_iterator end,
76 uint32* value);
77 static bool ParseProbability(StringPiece::const_iterator c,
78 StringPiece::const_iterator end,
79 double* p);
82 } // namespace net
84 #endif // NET_SPDY_SPDY_ALT_SVC_WIRE_FORMAT_H_