Skip to content

Commit

Permalink
RedfishPkg/RedfishRestExDxe: return HTTP status code to caller.
Browse files Browse the repository at this point in the history
Return unsupported HTTP status code to caller so caller can handle
HTTP error status code. Current implementation only return EFI error
to caller. Without knowing the HTTP status code, caller has trouble
to handle HTTP request failure.

Signed-off-by: Nickle Wang <[email protected]>
Cc: Abner Chang <[email protected]>
Cc: Igor Kulchytskyy <[email protected]>
Cc: Nick Ramirez <[email protected]>
Cc: Mike Maslenkin <[email protected]>
Reviewed-by: Igor Kulchytskyy <[email protected]>
Reviewed-by: Abner Chang <[email protected]>
Acked-by: Mike Maslenkin <[email protected]>
  • Loading branch information
nicklela authored and mergify[bot] committed Sep 19, 2023
1 parent cbcf042 commit 7275993
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
3 changes: 2 additions & 1 deletion MdePkg/Include/Protocol/RestEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ typedef struct {
response when the data is retrieved from the service. RequestMessage contains the HTTP
request to the REST resource identified by RequestMessage.Request.Url. The
ResponseMessage is the returned HTTP response for that request, including any HTTP
status.
status. It's caller's responsibility to free this ResponseMessage using FreePool().
RestConfigFreeHttpMessage() in RedfishLib is an example to release ResponseMessage structure.
@param[in] This Pointer to EFI_REST_EX_PROTOCOL instance for a particular
REST service.
Expand Down
27 changes: 14 additions & 13 deletions RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ EFI_REST_EX_PROTOCOL mRedfishRestExProtocol = {
response when the data is retrieved from the service. RequestMessage contains the HTTP
request to the REST resource identified by RequestMessage.Request.Url. The
ResponseMessage is the returned HTTP response for that request, including any HTTP
status.
status. It's caller's responsibility to free this ResponseMessage using FreePool().
RestConfigFreeHttpMessage() in RedfishLib is an example to release ResponseMessage structure.
@param[in] This Pointer to EFI_REST_EX_PROTOCOL instance for a particular
REST service.
Expand Down Expand Up @@ -320,6 +321,18 @@ ReSendRequest:;
DEBUG ((DEBUG_ERROR, "This HTTP Status is not handled!\n"));
DumpHttpStatusCode (DEBUG_REDFISH_NETWORK, ResponseData->Response.StatusCode);
Status = EFI_UNSUPPORTED;

//
// Deliver status code back to caller so caller can handle it.
//
ResponseMessage->Data.Response = AllocateZeroPool (sizeof (EFI_HTTP_RESPONSE_DATA));
if (ResponseMessage->Data.Response == NULL) {
Status = EFI_OUT_OF_RESOURCES;
goto ON_EXIT;
}

ResponseMessage->Data.Response->StatusCode = ResponseData->Response.StatusCode;

goto ON_EXIT;
}

Expand Down Expand Up @@ -443,18 +456,6 @@ ReSendRequest:;
FreePool (ResponseData);
}

if (EFI_ERROR (Status)) {
if (ResponseMessage->Data.Response != NULL) {
FreePool (ResponseMessage->Data.Response);
ResponseMessage->Data.Response = NULL;
}

if (ResponseMessage->Body != NULL) {
FreePool (ResponseMessage->Body);
ResponseMessage->Body = NULL;
}
}

return Status;
}

Expand Down

0 comments on commit 7275993

Please sign in to comment.