/src/trafficserver/include/tscore/HTTPVersion.h
Line | Count | Source |
1 | | /** @file |
2 | | |
3 | | HTTPVersion - class to track the HTTP version |
4 | | |
5 | | @section license License |
6 | | |
7 | | Licensed to the Apache Software Foundation (ASF) under one |
8 | | or more contributor license agreements. See the NOTICE file |
9 | | distributed with this work for additional information |
10 | | regarding copyright ownership. The ASF licenses this file |
11 | | to you under the Apache License, Version 2.0 (the |
12 | | "License"); you may not use this file except in compliance |
13 | | with the License. You may obtain a copy of the License at |
14 | | |
15 | | http://www.apache.org/licenses/LICENSE-2.0 |
16 | | |
17 | | Unless required by applicable law or agreed to in writing, software |
18 | | distributed under the License is distributed on an "AS IS" BASIS, |
19 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
20 | | See the License for the specific language governing permissions and |
21 | | limitations under the License. |
22 | | */ |
23 | | |
24 | | #pragma once |
25 | | |
26 | | class HTTPVersion |
27 | | { |
28 | | public: |
29 | 0 | HTTPVersion() {} |
30 | | HTTPVersion(HTTPVersion const &that) = default; |
31 | | HTTPVersion &operator=(const HTTPVersion &) = default; |
32 | | |
33 | | explicit HTTPVersion(int version); |
34 | | constexpr HTTPVersion(uint8_t ver_major, uint8_t ver_minor); |
35 | | |
36 | | int operator==(const HTTPVersion &hv) const; |
37 | | int operator!=(const HTTPVersion &hv) const; |
38 | | int operator>(const HTTPVersion &hv) const; |
39 | | int operator<(const HTTPVersion &hv) const; |
40 | | int operator>=(const HTTPVersion &hv) const; |
41 | | int operator<=(const HTTPVersion &hv) const; |
42 | | |
43 | | uint8_t get_major() const; |
44 | | uint8_t get_minor() const; |
45 | | uint32_t get_flat_version() const; |
46 | | |
47 | | private: |
48 | | uint8_t vmajor = 0; |
49 | | uint8_t vminor = 0; |
50 | | }; |
51 | | |
52 | | /*------------------------------------------------------------------------- |
53 | | -------------------------------------------------------------------------*/ |
54 | | |
55 | | inline HTTPVersion::HTTPVersion(int version) |
56 | | { |
57 | | vmajor = (version >> 16) & 0xFFFF; |
58 | | vminor = version & 0xFFFF; |
59 | | } |
60 | | |
61 | | /*------------------------------------------------------------------------- |
62 | | -------------------------------------------------------------------------*/ |
63 | | |
64 | 0 | inline constexpr HTTPVersion::HTTPVersion(uint8_t ver_major, uint8_t ver_minor) : vmajor(ver_major), vminor(ver_minor) {} |
65 | | |
66 | | /*------------------------------------------------------------------------- |
67 | | -------------------------------------------------------------------------*/ |
68 | | |
69 | | inline uint8_t |
70 | | HTTPVersion::get_major() const |
71 | 0 | { |
72 | 0 | return vmajor; |
73 | 0 | } |
74 | | |
75 | | /*------------------------------------------------------------------------- |
76 | | -------------------------------------------------------------------------*/ |
77 | | |
78 | | inline uint8_t |
79 | | HTTPVersion::get_minor() const |
80 | 0 | { |
81 | 0 | return vminor; |
82 | 0 | } |
83 | | |
84 | | /*------------------------------------------------------------------------- |
85 | | -------------------------------------------------------------------------*/ |
86 | | |
87 | | inline uint32_t |
88 | | HTTPVersion::get_flat_version() const |
89 | 0 | { |
90 | 0 | return vmajor << 16 | vminor; |
91 | 0 | } |
92 | | |
93 | | /*------------------------------------------------------------------------- |
94 | | -------------------------------------------------------------------------*/ |
95 | | |
96 | | inline int |
97 | | HTTPVersion::operator==(const HTTPVersion &hv) const |
98 | 0 | { |
99 | 0 | return vmajor == hv.get_major() && vminor == hv.get_minor(); |
100 | 0 | } |
101 | | |
102 | | /*------------------------------------------------------------------------- |
103 | | -------------------------------------------------------------------------*/ |
104 | | |
105 | | inline int |
106 | | HTTPVersion::operator!=(const HTTPVersion &hv) const |
107 | 0 | { |
108 | 0 | return !(*this == hv); |
109 | 0 | } |
110 | | |
111 | | /*------------------------------------------------------------------------- |
112 | | -------------------------------------------------------------------------*/ |
113 | | |
114 | | inline int |
115 | | HTTPVersion::operator>(const HTTPVersion &hv) const |
116 | 0 | { |
117 | 0 | return vmajor > hv.get_major() || (vmajor == hv.get_major() && vminor > hv.get_minor()); |
118 | 0 | } |
119 | | |
120 | | /*------------------------------------------------------------------------- |
121 | | -------------------------------------------------------------------------*/ |
122 | | |
123 | | inline int |
124 | | HTTPVersion::operator<(const HTTPVersion &hv) const |
125 | 0 | { |
126 | 0 | return vmajor < hv.get_major() || (vmajor == hv.get_major() && vminor < hv.get_minor()); |
127 | 0 | } |
128 | | |
129 | | /*------------------------------------------------------------------------- |
130 | | -------------------------------------------------------------------------*/ |
131 | | |
132 | | inline int |
133 | | HTTPVersion::operator>=(const HTTPVersion &hv) const |
134 | 0 | { |
135 | 0 | return vmajor > hv.get_major() || (vmajor == hv.get_major() && vminor >= hv.get_minor()); |
136 | 0 | } |
137 | | |
138 | | /*------------------------------------------------------------------------- |
139 | | -------------------------------------------------------------------------*/ |
140 | | |
141 | | inline int |
142 | | HTTPVersion::operator<=(const HTTPVersion &hv) const |
143 | 0 | { |
144 | 0 | return vmajor < hv.get_major() || (vmajor == hv.get_major() && vminor <= hv.get_minor()); |
145 | 0 | } |
146 | | |
147 | | /*------------------------------------------------------------------------- |
148 | | -------------------------------------------------------------------------*/ |
149 | | |
150 | | constexpr HTTPVersion HTTP_INVALID{0, 0}; |
151 | | constexpr HTTPVersion HTTP_0_9{0, 9}; |
152 | | constexpr HTTPVersion HTTP_1_0{1, 0}; |
153 | | constexpr HTTPVersion HTTP_1_1{1, 1}; |
154 | | constexpr HTTPVersion HTTP_2_0{2, 0}; |
155 | | constexpr HTTPVersion HTTP_3_0{3, 0}; |