Skip to content

Commit

Permalink
Remove superfluous checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Qup42 committed Oct 27, 2024
1 parent dadc2df commit ff9be3a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
9 changes: 1 addition & 8 deletions src/engine/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,15 +747,8 @@ MediaType Server::determineMediaType(
if (!mediaType.has_value()) {
mediaType = ad_utility::getMediaTypeFromAcceptHeader(acceptHeader);
}
AD_CORRECTNESS_CHECK(mediaType.has_value());

if (!mediaType.has_value()) {
throw NoSupportedMediatypeError(
absl::StrCat("Did not find any supported media type "
"in this \'Accept:\' header field: \"",
acceptHeader, "\". ",
ad_utility::getErrorMessageForSupportedMediaTypes()));
}
AD_CONTRACT_CHECK(mediaType.has_value());
return mediaType.value();
}

Expand Down
2 changes: 2 additions & 0 deletions src/util/http/MediaTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ std::vector<MediaTypeWithQuality> parseAcceptHeader(
/// media types that appear earlier in the `SUPPORTED_MEDIA_TYPES`. If none of
/// the `SUPPORTED_MEDIA_TYPES` is accepted by `acceptHeader`, then
/// `std::nullopt` is returned.
// TODO: An exception is thrown if no supported media type is found. Update the
// docstring and signature to reflect this.
std::optional<MediaType> getMediaTypeFromAcceptHeader(
std::string_view acceptHeader);

Expand Down
4 changes: 3 additions & 1 deletion test/ServerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ TEST(ServerTest, determineMediaType) {
EXPECT_THAT(Server::determineMediaType(
{}, MakeRequest("application/sparql-results+json")),
testing::Eq(ad_utility::MediaType::sparqlJson));
// No supported media type.
// No supported media type in the `Accept` header. (Contrary to it's docstring
// and interface) `ad_utility::getMediaTypeFromAcceptHeader` throws an
// exception if no supported media type is found.
EXPECT_THROW(Server::determineMediaType({}, MakeRequest("text/css")),
std::runtime_error);
// No `Accept` header means that any content type is allowed.
Expand Down

0 comments on commit ff9be3a

Please sign in to comment.