Removed Azure::Core::Http::InvalidHeaderException and throw std::invalid_argument if the user provides invalid header arguments. (#1871)

This commit is contained in:
Ahson Khan 2021-03-11 13:42:33 -08:00 committed by GitHub
parent 6a1afb9cbe
commit bd8336f8a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 26 deletions

View File

@ -39,6 +39,7 @@
- Removed `Azure::Core::DateTime::GetRfc3339String()`: `Azure::Core::DateTime::ToString()` was extended to provide the same functionality.
- Changed the constructor of `Azure::IO::FileBodyStream` to accept a file name directly and take ownership of opening/closing the file, instead of accepting a file descriptor, offset, and length.
- Renamed the `Range` type to `HttpRange` within the `Azure::Core::Http` namespace.
- Removed `Azure::Core::Http::InvalidHeaderException` and throw `std::invalid_argument` if the user provides invalid header arguments.
- Moved the `Base64Encode()` and `Base64Decode()` functions to be static members of a `Convert` class within the `Azure::Core` namespace.
- Moved `Azure::Core::Response<T>` to `Azure::Response<T>`.
- Moved `Azure::Core::ETag` to `Azure::ETag`.

View File

@ -58,24 +58,6 @@ namespace Azure { namespace Core { namespace Http {
}
};
/**
* @brief An invalid header key name in #Azure::Core::Http::Request or
* #Azure::Core::Http::RawResponse.
*
*/
class InvalidHeaderException : public Azure::Core::RequestFailedException {
public:
/**
* @brief An invalid header key name detected in the HTTP request or response.
*
* @param message The error description.
*/
explicit InvalidHeaderException(std::string const& message)
: Azure::Core::RequestFailedException(message)
{
}
};
/**
* @brief Defines the possible HTTP status codes.
*/

View File

@ -156,7 +156,7 @@ void Azure::Core::_detail::InsertHeaderWithValidation(
{
if (validChars[static_cast<int>(headerName[index])] == 0)
{
throw InvalidHeaderException("Invalid header: " + headerName);
throw std::invalid_argument("Invalid header: " + headerName);
}
}
// insert (override if duplicated)

View File

@ -26,7 +26,7 @@ void RawResponse::SetHeader(uint8_t const* const first, uint8_t const* const las
if (end == last)
{
throw InvalidHeaderException("Invalid header. No delimiter ':' found.");
throw std::invalid_argument("Invalid header. No delimiter ':' found.");
}
// Always toLower() headers

View File

@ -33,7 +33,7 @@ namespace Azure { namespace Core { namespace Test {
req.GetHeaders(),
expected);
EXPECT_THROW(req.SetHeader("invalid()", "header"), std::runtime_error);
EXPECT_THROW(req.SetHeader("invalid()", "header"), std::invalid_argument);
// same header will just override
std::pair<std::string, std::string> expectedOverride("valid", "override");
@ -78,8 +78,7 @@ namespace Azure { namespace Core { namespace Test {
response.GetHeaders(),
expected);
EXPECT_THROW(
response.SetHeader("invalid()", "header"), Azure::Core::Http::InvalidHeaderException);
EXPECT_THROW(response.SetHeader("invalid()", "header"), std::invalid_argument);
// same header will just override
std::pair<std::string, std::string> expectedOverride("valid", "override");
@ -107,9 +106,8 @@ namespace Azure { namespace Core { namespace Test {
expected2);
// Response SetHeader overload method to add from string
EXPECT_THROW(response.SetHeader("inv(): header"), Azure::Core::Http::InvalidHeaderException);
EXPECT_THROW(
response.SetHeader("no delimiter header"), Azure::Core::Http::InvalidHeaderException);
EXPECT_THROW(response.SetHeader("inv(): header"), std::invalid_argument);
EXPECT_THROW(response.SetHeader("no delimiter header"), std::invalid_argument);
// adding header after previous error just happened on add from string
EXPECT_NO_THROW(response.SetHeader("valid3: header3"));