public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Nickle Wang via groups.io" <nicklew=nvidia.com@groups.io>
To: <devel@edk2.groups.io>
Cc: Abner Chang <abner.chang@amd.com>,
	Igor Kulchytskyy <igork@ami.com>,
	"Nick Ramirez" <nramirez@nvidia.com>,
	Mike Maslenkin <mike.maslenkin@gmail.com>
Subject: [edk2-devel] [PATCH v2] RedfishPkg/RedfishRestExDxe: return HTTP status code to caller.
Date: Mon, 18 Sep 2023 21:13:22 +0800	[thread overview]
Message-ID: <20230918131322.7761-1-nicklew@nvidia.com> (raw)

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 <nicklew@nvidia.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Igor Kulchytskyy <igork@ami.com>
Cc: Nick Ramirez <nramirez@nvidia.com>
Cc: Mike Maslenkin <mike.maslenkin@gmail.com>
---
 MdePkg/Include/Protocol/RestEx.h              |  3 ++-
 .../RedfishRestExDxe/RedfishRestExProtocol.c  | 27 ++++++++++---------
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/MdePkg/Include/Protocol/RestEx.h b/MdePkg/Include/Protocol/RestEx.h
index e9bc7be94f2c..da9f1c3f87ef 100644
--- a/MdePkg/Include/Protocol/RestEx.h
+++ b/MdePkg/Include/Protocol/RestEx.h
@@ -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.
diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c b/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c
index 90973619f2bc..5bcdade4b18c 100644
--- a/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c
+++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c
@@ -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.
@@ -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;
   }
 
@@ -443,18 +456,6 @@ ON_EXIT:
     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;
 }
 
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#108778): https://edk2.groups.io/g/devel/message/108778
Mute This Topic: https://groups.io/mt/101432753/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



             reply	other threads:[~2023-09-18 13:13 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-18 13:13 Nickle Wang via groups.io [this message]
2023-09-18 13:42 ` [edk2-devel] [PATCH v2] RedfishPkg/RedfishRestExDxe: return HTTP status code to caller Igor Kulchytskyy via groups.io
2023-09-18 15:41 ` Chang, Abner via groups.io
     [not found] <1786007649F51CE2.9824@groups.io>
2023-09-18 13:17 ` Nickle Wang via groups.io

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230918131322.7761-1-nicklew@nvidia.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox