diff options
author | Nickle Wang <nicklew@nvidia.com> | 2024-08-07 15:48:37 +0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-08-29 05:19:58 +0000 |
commit | 31f022500549f1d862af531da704a9b3c6568ff5 (patch) | |
tree | 7ec8c7c4c9baeb80af4b7dbff5a9a9c0c1718823 /RedfishPkg | |
parent | 14e6c48103d7bff65226a063c263a405c4de426e (diff) | |
download | edk2-31f022500549f1d862af531da704a9b3c6568ff5.tar.gz edk2-31f022500549f1d862af531da704a9b3c6568ff5.tar.bz2 edk2-31f022500549f1d862af531da704a9b3c6568ff5.zip |
RedfishPkg/RedfishHttpDxe: check response content type.
Check HTTP response content type to see if it is application/json
type or not. In Redfish, we expect to see response data in JSON
format. If it is not, show warning message to developer.
Signed-off-by: Nickle Wang <nicklew@nvidia.com>
Diffstat (limited to 'RedfishPkg')
-rw-r--r-- | RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c b/RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c index 8110985add..8ae1d2d7a3 100644 --- a/RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c +++ b/RedfishPkg/RedfishHttpDxe/RedfishHttpOperation.c @@ -493,6 +493,7 @@ ParseResponseMessage ( EFI_STATUS Status;
EDKII_JSON_VALUE JsonData;
EFI_HTTP_HEADER *ContentEncodedHeader;
+ EFI_HTTP_HEADER *ContentTypeHeader;
VOID *DecodedBody;
UINTN DecodedLength;
@@ -545,6 +546,17 @@ ParseResponseMessage ( //
if ((ResponseMsg->BodyLength != 0) && (ResponseMsg->Body != NULL)) {
DEBUG ((REDFISH_HTTP_CACHE_DEBUG_REQUEST, "%a: body length: %d\n", __func__, ResponseMsg->BodyLength));
+
+ //
+ // We expect to see JSON body
+ //
+ ContentTypeHeader = HttpFindHeader (RedfishResponse->HeaderCount, RedfishResponse->Headers, HTTP_HEADER_CONTENT_TYPE);
+ if (ContentTypeHeader != NULL) {
+ if (AsciiStrCmp (ContentTypeHeader->FieldValue, HTTP_CONTENT_TYPE_APP_JSON) != 0) {
+ DEBUG ((DEBUG_WARN, "%a: body is not in %a format\n", __func__, HTTP_CONTENT_TYPE_APP_JSON));
+ }
+ }
+
//
// Check if data is encoded.
//
|