forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspdy_alt_svc_wire_format.h
93 lines (77 loc) · 3.57 KB
/
spdy_alt_svc_wire_format.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This file contains data structures and utility functions used for serializing
// and parsing alternative service header values, common to HTTP/1.1 header
// fields and HTTP/2 and QUIC ALTSVC frames. See specification at
// https://httpwg.github.io/http-extensions/alt-svc.html.
#ifndef NET_SPDY_SPDY_ALT_SVC_WIRE_FORMAT_H_
#define NET_SPDY_SPDY_ALT_SVC_WIRE_FORMAT_H_
#include <stdint.h>
#include <vector>
#include "base/strings/string_piece.h"
#include "net/base/net_export.h"
namespace net {
namespace test {
class SpdyAltSvcWireFormatPeer;
} // namespace test
class NET_EXPORT_PRIVATE SpdyAltSvcWireFormat {
public:
using VersionVector = std::vector<uint16_t>;
struct NET_EXPORT_PRIVATE AlternativeService {
std::string protocol_id;
std::string host;
// Default is 0: invalid port.
uint16_t port = 0;
// Default is one day.
uint32_t max_age = 86400;
// Default is always use.
double probability = 1.0;
// Default is empty: unspecified version.
VersionVector version;
AlternativeService();
AlternativeService(const std::string& protocol_id,
const std::string& host,
uint16_t port,
uint32_t max_age,
double probability,
VersionVector version);
AlternativeService(const AlternativeService& other);
~AlternativeService();
bool operator==(const AlternativeService& other) const {
return protocol_id == other.protocol_id && host == other.host &&
port == other.port && version == other.version &&
max_age == other.max_age && probability == other.probability;
}
};
// An empty vector means alternative services should be cleared for given
// origin. Note that the wire format for this is the string "clear", not an
// empty value (which is invalid).
typedef std::vector<AlternativeService> AlternativeServiceVector;
friend class test::SpdyAltSvcWireFormatPeer;
static bool ParseHeaderFieldValue(base::StringPiece value,
AlternativeServiceVector* altsvc_vector);
static std::string SerializeHeaderFieldValue(
const AlternativeServiceVector& altsvc_vector);
private:
static void SkipWhiteSpace(base::StringPiece::const_iterator* c,
base::StringPiece::const_iterator end);
static bool PercentDecode(base::StringPiece::const_iterator c,
base::StringPiece::const_iterator end,
std::string* output);
static bool ParseAltAuthority(base::StringPiece::const_iterator c,
base::StringPiece::const_iterator end,
std::string* host,
uint16_t* port);
static bool ParsePositiveInteger16(base::StringPiece::const_iterator c,
base::StringPiece::const_iterator end,
uint16_t* value);
static bool ParsePositiveInteger32(base::StringPiece::const_iterator c,
base::StringPiece::const_iterator end,
uint32_t* value);
static bool ParseProbability(base::StringPiece::const_iterator c,
base::StringPiece::const_iterator end,
double* probability);
};
} // namespace net
#endif // NET_SPDY_SPDY_ALT_SVC_WIRE_FORMAT_H_