Make Accepts: */* default to JSON
There are apparently libraries that use an Accepts header of */*,
instead of simply omitting the Accepts header, or providing a more
correct value for that header.
99351cd856038475cac146029e5db03767a1459c Improve content type
The above commit attempted to refine our handling of this header, and
changed the behavior for */* to default to HTML. While this is arguably
"correct" to the HTTP RFC, and the clients that do this are definitely
wrong in their implementation, we can try to shield them a little from
their incorrectness, and we can certainly avoid compatibility issues
with these clients, without effecting the clients that implement the
spec correctly.
This commit changes the priority order of Accepts header to JSON then
HTML, instead of the other way around.
Tested:
curl --insecure -H "Accept: */*" --user root:0penBmc \
https://192.168.7.2/redfish/v1
Now returns a json payload.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I7850a3afb0b5d635f8d632fb0a9f790e53fe4466
diff --git a/http/http_connection.hpp b/http/http_connection.hpp
index 376eeec..025c143 100644
--- a/http/http_connection.hpp
+++ b/http/http_connection.hpp
@@ -455,8 +455,8 @@
if (res.body().empty() && !res.jsonValue.empty())
{
using http_helpers::ContentType;
- std::array<ContentType, 2> allowed{ContentType::HTML,
- ContentType::JSON};
+ std::array<ContentType, 2> allowed{ContentType::JSON,
+ ContentType::HTML};
ContentType prefered =
getPreferedContentType(req->getHeaderValue("Accept"), allowed);