diff --git a/src/engine/Server.cpp b/src/engine/Server.cpp index e3511d46e..8d1afd099 100644 --- a/src/engine/Server.cpp +++ b/src/engine/Server.cpp @@ -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(); } diff --git a/src/util/http/MediaTypes.h b/src/util/http/MediaTypes.h index 43a809e33..407473bd2 100644 --- a/src/util/http/MediaTypes.h +++ b/src/util/http/MediaTypes.h @@ -112,6 +112,8 @@ std::vector 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 getMediaTypeFromAcceptHeader( std::string_view acceptHeader); diff --git a/test/ServerTest.cpp b/test/ServerTest.cpp index 23c64f188..3f3235693 100644 --- a/test/ServerTest.cpp +++ b/test/ServerTest.cpp @@ -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.