| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 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://httpwg.github.io/http-extensions/alt-svc.html. | |
| 9 | |
| 10 #ifndef NET_SPDY_SPDY_ALT_SVC_WIRE_FORMAT_H_ | |
| 11 #define NET_SPDY_SPDY_ALT_SVC_WIRE_FORMAT_H_ | |
| 12 | |
| 13 #include <cstdint> | |
| 14 #include <vector> | |
| 15 | |
| 16 #include "net/base/net_export.h" | |
| 17 #include "net/spdy/platform/api/spdy_string.h" | |
| 18 #include "net/spdy/platform/api/spdy_string_piece.h" | |
| 19 | |
| 20 namespace net { | |
| 21 | |
| 22 namespace test { | |
| 23 class SpdyAltSvcWireFormatPeer; | |
| 24 } // namespace test | |
| 25 | |
| 26 class NET_EXPORT_PRIVATE SpdyAltSvcWireFormat { | |
| 27 public: | |
| 28 using VersionVector = std::vector<uint16_t>; | |
| 29 | |
| 30 struct NET_EXPORT_PRIVATE AlternativeService { | |
| 31 SpdyString protocol_id; | |
| 32 SpdyString host; | |
| 33 | |
| 34 // Default is 0: invalid port. | |
| 35 uint16_t port = 0; | |
| 36 // Default is one day. | |
| 37 uint32_t max_age = 86400; | |
| 38 // Default is empty: unspecified version. | |
| 39 VersionVector version; | |
| 40 | |
| 41 AlternativeService(); | |
| 42 AlternativeService(const SpdyString& protocol_id, | |
| 43 const SpdyString& host, | |
| 44 uint16_t port, | |
| 45 uint32_t max_age, | |
| 46 VersionVector version); | |
| 47 AlternativeService(const AlternativeService& other); | |
| 48 ~AlternativeService(); | |
| 49 | |
| 50 bool operator==(const AlternativeService& other) const { | |
| 51 return protocol_id == other.protocol_id && host == other.host && | |
| 52 port == other.port && version == other.version && | |
| 53 max_age == other.max_age; | |
| 54 } | |
| 55 }; | |
| 56 // An empty vector means alternative services should be cleared for given | |
| 57 // origin. Note that the wire format for this is the string "clear", not an | |
| 58 // empty value (which is invalid). | |
| 59 typedef std::vector<AlternativeService> AlternativeServiceVector; | |
| 60 | |
| 61 friend class test::SpdyAltSvcWireFormatPeer; | |
| 62 static bool ParseHeaderFieldValue(SpdyStringPiece value, | |
| 63 AlternativeServiceVector* altsvc_vector); | |
| 64 static SpdyString SerializeHeaderFieldValue( | |
| 65 const AlternativeServiceVector& altsvc_vector); | |
| 66 | |
| 67 private: | |
| 68 static void SkipWhiteSpace(SpdyStringPiece::const_iterator* c, | |
| 69 SpdyStringPiece::const_iterator end); | |
| 70 static bool PercentDecode(SpdyStringPiece::const_iterator c, | |
| 71 SpdyStringPiece::const_iterator end, | |
| 72 SpdyString* output); | |
| 73 static bool ParseAltAuthority(SpdyStringPiece::const_iterator c, | |
| 74 SpdyStringPiece::const_iterator end, | |
| 75 SpdyString* host, | |
| 76 uint16_t* port); | |
| 77 static bool ParsePositiveInteger16(SpdyStringPiece::const_iterator c, | |
| 78 SpdyStringPiece::const_iterator end, | |
| 79 uint16_t* value); | |
| 80 static bool ParsePositiveInteger32(SpdyStringPiece::const_iterator c, | |
| 81 SpdyStringPiece::const_iterator end, | |
| 82 uint32_t* value); | |
| 83 }; | |
| 84 | |
| 85 } // namespace net | |
| 86 | |
| 87 #endif // NET_SPDY_SPDY_ALT_SVC_WIRE_FORMAT_H_ | |
| OLD | NEW |