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_
15 #include "base/basictypes.h"
16 #include "base/strings/string_piece.h"
17 #include "net/base/net_export.h"
19 using base::StringPiece
;
24 class SpdyAltSvcWireFormatPeer
;
27 class NET_EXPORT_PRIVATE SpdyAltSvcWireFormat
{
29 struct AlternativeService
{
30 std::string protocol_id
;
36 AlternativeService() = default;
37 AlternativeService(const std::string
& protocol_id
,
38 const std::string
& host
,
42 : protocol_id(protocol_id
),
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
);
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
,
67 static bool ParseAltAuthority(StringPiece::const_iterator c
,
68 StringPiece::const_iterator end
,
71 static bool ParsePositiveInteger16(StringPiece::const_iterator c
,
72 StringPiece::const_iterator end
,
74 static bool ParsePositiveInteger32(StringPiece::const_iterator c
,
75 StringPiece::const_iterator end
,
77 static bool ParseProbability(StringPiece::const_iterator c
,
78 StringPiece::const_iterator end
,
84 #endif // NET_SPDY_SPDY_ALT_SVC_WIRE_FORMAT_H_