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