Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2021 Vinnie Falco (vinnie dot falco at gmail dot com) | ||
3 | // | ||
4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
6 | // | ||
7 | // Official repository: https://github.com/CPPAlliance/http_proto | ||
8 | // | ||
9 | |||
10 | #ifndef BOOST_HTTP_PROTO_IMPL_METHOD_IPP | ||
11 | #define BOOST_HTTP_PROTO_IMPL_METHOD_IPP | ||
12 | |||
13 | #include <boost/http_proto/method.hpp> | ||
14 | #include <boost/http_proto/detail/sv.hpp> | ||
15 | #include <boost/throw_exception.hpp> | ||
16 | #include <stdexcept> | ||
17 | |||
18 | namespace boost { | ||
19 | namespace http_proto { | ||
20 | |||
21 | string_view | ||
22 | 69 | to_string(method v) | |
23 | { | ||
24 | using namespace detail::string_literals; | ||
25 |
35/35✓ Branch 0 taken 3 times.
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 8 taken 1 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 11 taken 1 times.
✓ Branch 12 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 14 taken 1 times.
✓ Branch 15 taken 1 times.
✓ Branch 16 taken 1 times.
✓ Branch 17 taken 1 times.
✓ Branch 18 taken 1 times.
✓ Branch 19 taken 1 times.
✓ Branch 20 taken 1 times.
✓ Branch 21 taken 1 times.
✓ Branch 22 taken 1 times.
✓ Branch 23 taken 1 times.
✓ Branch 24 taken 1 times.
✓ Branch 25 taken 1 times.
✓ Branch 26 taken 1 times.
✓ Branch 27 taken 1 times.
✓ Branch 28 taken 1 times.
✓ Branch 29 taken 1 times.
✓ Branch 30 taken 1 times.
✓ Branch 31 taken 1 times.
✓ Branch 32 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 34 taken 1 times.
|
69 | switch(v) |
26 | { | ||
27 | 3 | case method::delete_: return "DELETE"_sv; | |
28 | 32 | case method::get: return "GET"_sv; | |
29 | 1 | case method::head: return "HEAD"_sv; | |
30 | 1 | case method::post: return "POST"_sv; | |
31 | 1 | case method::put: return "PUT"_sv; | |
32 | 2 | case method::connect: return "CONNECT"_sv; | |
33 | 1 | case method::options: return "OPTIONS"_sv; | |
34 | 1 | case method::trace: return "TRACE"_sv; | |
35 | |||
36 | 1 | case method::copy: return "COPY"_sv; | |
37 | 1 | case method::lock: return "LOCK"_sv; | |
38 | 1 | case method::mkcol: return "MKCOL"_sv; | |
39 | 1 | case method::move: return "MOVE"_sv; | |
40 | 1 | case method::propfind: return "PROPFIND"_sv; | |
41 | 1 | case method::proppatch: return "PROPPATCH"_sv; | |
42 | 1 | case method::search: return "SEARCH"_sv; | |
43 | 1 | case method::unlock: return "UNLOCK"_sv; | |
44 | 1 | case method::bind: return "BIND"_sv; | |
45 | 1 | case method::rebind: return "REBIND"_sv; | |
46 | 1 | case method::unbind: return "UNBIND"_sv; | |
47 | 1 | case method::acl: return "ACL"_sv; | |
48 | |||
49 | 1 | case method::report: return "REPORT"_sv; | |
50 | 1 | case method::mkactivity: return "MKACTIVITY"_sv; | |
51 | 1 | case method::checkout: return "CHECKOUT"_sv; | |
52 | 1 | case method::merge: return "MERGE"_sv; | |
53 | |||
54 | 1 | case method::msearch: return "M-SEARCH"_sv; | |
55 | 1 | case method::notify: return "NOTIFY"_sv; | |
56 | 1 | case method::subscribe: return "SUBSCRIBE"_sv; | |
57 | 1 | case method::unsubscribe: return "UNSUBSCRIBE"_sv; | |
58 | |||
59 | 1 | case method::patch: return "PATCH"_sv; | |
60 | 1 | case method::purge: return "PURGE"_sv; | |
61 | |||
62 | 1 | case method::mkcalendar: return "MKCALENDAR"_sv; | |
63 | |||
64 | 1 | case method::link: return "LINK"_sv; | |
65 | 1 | case method::unlink: return "UNLINK"_sv; | |
66 | |||
67 | 1 | case method::unknown: | |
68 | 1 | return "<unknown>"_sv; | |
69 | } | ||
70 | |||
71 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | BOOST_THROW_EXCEPTION( |
72 | std::invalid_argument("unknown method")); | ||
73 | } | ||
74 | |||
75 | method | ||
76 | 1137 | string_to_method(string_view v) | |
77 | { | ||
78 | /* | ||
79 | ACL | ||
80 | BIND | ||
81 | CHECKOUT | ||
82 | CONNECT | ||
83 | COPY | ||
84 | DELETE | ||
85 | GET | ||
86 | HEAD | ||
87 | LINK | ||
88 | LOCK | ||
89 | M-SEARCH | ||
90 | MERGE | ||
91 | MKACTIVITY | ||
92 | MKCALENDAR | ||
93 | MKCOL | ||
94 | MOVE | ||
95 | NOTIFY | ||
96 | OPTIONS | ||
97 | PATCH | ||
98 | POST | ||
99 | PROPFIND | ||
100 | PROPPATCH | ||
101 | PURGE | ||
102 | PUT | ||
103 | REBIND | ||
104 | REPORT | ||
105 | SEARCH | ||
106 | SUBSCRIBE | ||
107 | TRACE | ||
108 | UNBIND | ||
109 | UNLINK | ||
110 | UNLOCK | ||
111 | UNSUBSCRIBE | ||
112 | */ | ||
113 | using namespace detail::string_literals; | ||
114 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1137 times.
|
1137 | if(v.size() < 3) |
115 | ✗ | return method::unknown; | |
116 | 1137 | auto c = v[0]; | |
117 | 1137 | v.remove_prefix(1); | |
118 |
16/16✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 993 times.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 12 times.
✓ Branch 8 taken 2 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 84 times.
✓ Branch 11 taken 4 times.
✓ Branch 12 taken 4 times.
✓ Branch 13 taken 2 times.
✓ Branch 14 taken 8 times.
✓ Branch 15 taken 1 times.
|
1137 | switch(c) |
119 | { | ||
120 | 2 | case 'A': | |
121 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | if(v == "CL"_sv) |
122 | 1 | return method::acl; | |
123 | 1 | break; | |
124 | |||
125 | 5 | case 'B': | |
126 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4 times.
|
5 | if(v == "IND"_sv) |
127 | 1 | return method::bind; | |
128 | 4 | break; | |
129 | |||
130 | 8 | case 'C': | |
131 | 8 | c = v[0]; | |
132 | 8 | v.remove_prefix(1); | |
133 |
2/3✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
8 | switch(c) |
134 | { | ||
135 | 2 | case 'H': | |
136 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | if(v == "ECKOUT"_sv) |
137 | 1 | return method::checkout; | |
138 | 1 | break; | |
139 | |||
140 | 6 | case 'O': | |
141 |
2/2✓ Branch 2 taken 3 times.
✓ Branch 3 taken 3 times.
|
6 | if(v == "NNECT"_sv) |
142 | 3 | return method::connect; | |
143 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
|
3 | if(v == "PY"_sv) |
144 | 1 | return method::copy; | |
145 | BOOST_FALLTHROUGH; | ||
146 | |||
147 | default: | ||
148 | 2 | break; | |
149 | } | ||
150 | 3 | break; | |
151 | |||
152 | 4 | case 'D': | |
153 |
2/2✓ Branch 2 taken 3 times.
✓ Branch 3 taken 1 times.
|
4 | if(v == "ELETE"_sv) |
154 | 3 | return method::delete_; | |
155 | 1 | break; | |
156 | |||
157 | 993 | case 'G': | |
158 |
2/2✓ Branch 2 taken 992 times.
✓ Branch 3 taken 1 times.
|
993 | if(v == "ET"_sv) |
159 | 992 | return method::get; | |
160 | 1 | break; | |
161 | |||
162 | 2 | case 'H': | |
163 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | if(v == "EAD"_sv) |
164 | 1 | return method::head; | |
165 | 1 | break; | |
166 | |||
167 | 4 | case 'L': | |
168 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
|
4 | if(v == "INK"_sv) |
169 | 1 | return method::link; | |
170 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
|
3 | if(v == "OCK"_sv) |
171 | 1 | return method::lock; | |
172 | 2 | break; | |
173 | |||
174 | 12 | case 'M': | |
175 | 12 | c = v[0]; | |
176 | 12 | v.remove_prefix(1); | |
177 |
4/5✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 6 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
12 | switch(c) |
178 | { | ||
179 | 2 | case '-': | |
180 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | if(v == "SEARCH"_sv) |
181 | 1 | return method::msearch; | |
182 | 1 | break; | |
183 | |||
184 | 2 | case 'E': | |
185 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | if(v == "RGE"_sv) |
186 | 1 | return method::merge; | |
187 | 1 | break; | |
188 | |||
189 | 6 | case 'K': | |
190 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5 times.
|
6 | if(v == "ACTIVITY"_sv) |
191 | 1 | return method::mkactivity; | |
192 |
2/2✓ Branch 1 taken 4 times.
✓ Branch 2 taken 1 times.
|
5 | if(v[0] == 'C') |
193 | { | ||
194 | 4 | v.remove_prefix(1); | |
195 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
|
4 | if(v == "ALENDAR"_sv) |
196 | 1 | return method::mkcalendar; | |
197 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
|
3 | if(v == "OL"_sv) |
198 | 1 | return method::mkcol; | |
199 | 2 | break; | |
200 | } | ||
201 | 1 | break; | |
202 | |||
203 | 2 | case 'O': | |
204 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | if(v == "VE"_sv) |
205 | 1 | return method::move; | |
206 | BOOST_FALLTHROUGH; | ||
207 | |||
208 | default: | ||
209 | 1 | break; | |
210 | } | ||
211 | 6 | break; | |
212 | |||
213 | 2 | case 'N': | |
214 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | if(v == "OTIFY"_sv) |
215 | 1 | return method::notify; | |
216 | 1 | break; | |
217 | |||
218 | 2 | case 'O': | |
219 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | if(v == "PTIONS"_sv) |
220 | 1 | return method::options; | |
221 | 1 | break; | |
222 | |||
223 | 84 | case 'P': | |
224 | 84 | c = v[0]; | |
225 | 84 | v.remove_prefix(1); | |
226 |
4/5✓ Branch 0 taken 2 times.
✓ Branch 1 taken 74 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
|
84 | switch(c) |
227 | { | ||
228 | 2 | case 'A': | |
229 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | if(v == "TCH"_sv) |
230 | 1 | return method::patch; | |
231 | 1 | break; | |
232 | |||
233 | 74 | case 'O': | |
234 |
2/2✓ Branch 2 taken 73 times.
✓ Branch 3 taken 1 times.
|
74 | if(v == "ST"_sv) |
235 | 73 | return method::post; | |
236 | 1 | break; | |
237 | |||
238 | 4 | case 'R': | |
239 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
|
4 | if(v == "OPFIND"_sv) |
240 | 1 | return method::propfind; | |
241 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
|
3 | if(v == "OPPATCH"_sv) |
242 | 1 | return method::proppatch; | |
243 | 2 | break; | |
244 | |||
245 | 4 | case 'U': | |
246 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
|
4 | if(v == "RGE"_sv) |
247 | 1 | return method::purge; | |
248 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
|
3 | if(v == "T"_sv) |
249 | 1 | return method::put; | |
250 | BOOST_FALLTHROUGH; | ||
251 | |||
252 | default: | ||
253 | 2 | break; | |
254 | } | ||
255 | 6 | break; | |
256 | |||
257 | 4 | case 'R': | |
258 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if(v[0] != 'E') |
259 | ✗ | break; | |
260 | 4 | v.remove_prefix(1); | |
261 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
|
4 | if(v == "BIND"_sv) |
262 | 1 | return method::rebind; | |
263 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
|
3 | if(v == "PORT"_sv) |
264 | 1 | return method::report; | |
265 | 2 | break; | |
266 | |||
267 | 4 | case 'S': | |
268 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 3 times.
|
4 | if(v == "EARCH"_sv) |
269 | 1 | return method::search; | |
270 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 2 times.
|
3 | if(v == "UBSCRIBE"_sv) |
271 | 1 | return method::subscribe; | |
272 | 2 | break; | |
273 | |||
274 | 2 | case 'T': | |
275 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 1 times.
|
2 | if(v == "RACE"_sv) |
276 | 1 | return method::trace; | |
277 | 1 | break; | |
278 | |||
279 | 8 | case 'U': | |
280 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
|
8 | if(v[0] != 'N') |
281 | ✗ | break; | |
282 | 8 | v.remove_prefix(1); | |
283 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 7 times.
|
8 | if(v == "BIND"_sv) |
284 | 1 | return method::unbind; | |
285 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 6 times.
|
7 | if(v == "LINK"_sv) |
286 | 1 | return method::unlink; | |
287 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 5 times.
|
6 | if(v == "LOCK"_sv) |
288 | 1 | return method::unlock; | |
289 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 3 taken 4 times.
|
5 | if(v == "SUBSCRIBE"_sv) |
290 | 1 | return method::unsubscribe; | |
291 | 4 | break; | |
292 | |||
293 | 1 | default: | |
294 | 1 | break; | |
295 | } | ||
296 | |||
297 | 37 | return method::unknown; | |
298 | } | ||
299 | |||
300 | } // http_proto | ||
301 | } // boost | ||
302 | |||
303 | #endif | ||
304 |