xref: /haiku/src/kits/network/libnetservices2/HttpPrivate.h (revision 52c4471a3024d2eb81fe88e2c3982b9f8daa5e56)
1 /*
2  * Copyright 2022 Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #ifndef _B_HTTP_PRIVATE_H_
7 #define _B_HTTP_PRIVATE_H_
8 
9 #include <string_view>
10 
11 #include <HttpRequest.h>
12 #include <Url.h>
13 
14 
15 namespace BPrivate {
16 
17 namespace Network {
18 
19 /*!
20 	\brief Validate whether the string conforms to a HTTP token value
21 
22 	RFC 7230 section 3.2.6 determines that valid tokens for the header name are:
23 	!#$%&'*+=.^_`|~, any digits or alpha.
24 
25 	\returns \c true if the string is valid, or \c false if it is not.
26 */
27 static inline bool
28 validate_http_token_string(const std::string_view& string)
29 {
30 	for (auto it = string.cbegin(); it < string.cend(); it++) {
31 		if (*it <= 31 || *it == 127 || *it == '(' || *it == ')' || *it == '<' || *it == '>'
32 			|| *it == '@' || *it == ',' || *it == ';' || *it == '\\' || *it == '"' || *it == '/'
33 			|| *it == '[' || *it == ']' || *it == '?' || *it == '=' || *it == '{' || *it == '}'
34 			|| *it == ' ')
35 			return false;
36 	}
37 	return true;
38 }
39 
40 
41 } // namespace Network
42 
43 } // namespace BPrivate
44 
45 #endif // _B_HTTP_PRIVATE_H_
46