diff --git a/src/kits/network/libnetservices2/HttpFields.cpp b/src/kits/network/libnetservices2/HttpFields.cpp index 5cc9770e94..a0bce8146c 100755 --- a/src/kits/network/libnetservices2/HttpFields.cpp +++ b/src/kits/network/libnetservices2/HttpFields.cpp @@ -12,34 +12,14 @@ #include #include +#include "HttpPrivate.h" + using namespace BPrivate::Network; // #pragma mark -- utilities -/*! - \brief Validate whether the string conforms to a HTTP token value - - RFC 7230 section 3.2.6 determines that valid tokens for the header name are: - !#$%&'*+=.^_`|~, any digits or alpha. - - \returns \c true if the string is valid, or \c false if it is not. -*/ -static inline bool -validate_token_string(const std::string_view& string) -{ - for (auto it = string.cbegin(); it < string.cend(); it++) { - if (*it <= 31 || *it == 127 || *it == '(' || *it == ')' || *it == '<' || *it == '>' - || *it == '@' || *it == ',' || *it == ';' || *it == '\\' || *it == '"' - || *it == '/' || *it == '[' || *it == ']' || *it == '?' || *it == '=' - || *it == '{' || *it == '}' || *it == ' ') - return false; - } - return true; -} - - /*! \brief Validate whether the string is a valid HTTP header value @@ -269,7 +249,7 @@ BHttpFields::Field::Field(const std::string_view& name, const std::string_view& BHttpFields::Field::Field(const std::string_view& name, const std::string_view& value, bool borrowed) : fName(name), fValue(value) { - if (name.length() == 0 || !validate_token_string(name)) + if (name.length() == 0 || !validate_http_token_string(name)) throw BHttpFields::InvalidInput(__PRETTY_FUNCTION__, fName); if (value.length() == 0 || !validate_value_string(value)) throw BHttpFields::InvalidInput(__PRETTY_FUNCTION__, BString(value.data(), value.length())); diff --git a/src/kits/network/libnetservices2/HttpPrivate.h b/src/kits/network/libnetservices2/HttpPrivate.h new file mode 100644 index 0000000000..7d8335f0f9 --- /dev/null +++ b/src/kits/network/libnetservices2/HttpPrivate.h @@ -0,0 +1,42 @@ +/* + * Copyright 2022 Haiku Inc. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#ifndef _B_HTTP_PRIVATE_H_ +#define _B_HTTP_PRIVATE_H_ + +#include + + +namespace BPrivate { + +namespace Network { + +/*! + \brief Validate whether the string conforms to a HTTP token value + + RFC 7230 section 3.2.6 determines that valid tokens for the header name are: + !#$%&'*+=.^_`|~, any digits or alpha. + + \returns \c true if the string is valid, or \c false if it is not. +*/ +static inline bool +validate_http_token_string(const std::string_view& string) +{ + for (auto it = string.cbegin(); it < string.cend(); it++) { + if (*it <= 31 || *it == 127 || *it == '(' || *it == ')' || *it == '<' || *it == '>' + || *it == '@' || *it == ',' || *it == ';' || *it == '\\' || *it == '"' + || *it == '/' || *it == '[' || *it == ']' || *it == '?' || *it == '=' + || *it == '{' || *it == '}' || *it == ' ') + return false; + } + return true; +} + + +} // namespace Network + +} // namespace BPrivate + +#endif // _B_HTTP_PRIVATE_H_