public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH V2] RedfishPkg: RedfishRestExDxe: PCD introduced to control "Expect" header
@ 2023-02-08  2:36 Igor Kulchytskyy
  0 siblings, 0 replies; only message in thread
From: Igor Kulchytskyy @ 2023-02-08  2:36 UTC (permalink / raw)
  To: devel@edk2.groups.io; +Cc: Igor Kulchytskyy, Abner Chang, Nickle Wang

"Expect" header for POST, PATCH, PUT requests should be optional
in order to work with different BMC implementation

Cc: Abner Chang <abner.chang@amd.com>
Cc: Nickle Wang <nicklew@nvidia.com>
Signed-off-by: Igor Kulchytskyy <igork@ami.com>
---
 RedfishPkg/RedfishPkg.dec                           |   6 +-
 RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf    |   1 +
 RedfishPkg/RedfishRestExDxe/RedfishRestExImpl.c     |  23 ++--
 RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c | 136 +++++++++++---------
 4 files changed, 95 insertions(+), 71 deletions(-)

diff --git a/RedfishPkg/RedfishPkg.dec b/RedfishPkg/RedfishPkg.dec
index 4b4706b..bf48fdd 100644
--- a/RedfishPkg/RedfishPkg.dec
+++ b/RedfishPkg/RedfishPkg.dec
@@ -102,4 +102,8 @@
   # Default is set to non chunk mode.
   #
   gEfiRedfishPkgTokenSpaceGuid.PcdRedfishRestExChunkRequestMode|FALSE|BOOLEAN|0x00001003
-
\ No newline at end of file
+  #
+  # This PCD indicates if the EFI REST EX adds Expect header to the POST, PATCH, PUT requests to Redfish service.
+  # Default is set to not add.
+  #
+  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishRestExAddingExpect|FALSE|BOOLEAN|0x00001004
diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf b/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf
index 26ce167..29003ae 100644
--- a/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf
+++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExDxe.inf
@@ -58,6 +58,7 @@
 [Pcd]
   gEfiRedfishPkgTokenSpaceGuid.PcdRedfishRestExServiceAccessModeInBand   ## CONSUMES
   gEfiRedfishPkgTokenSpaceGuid.PcdRedfishRestExChunkRequestMode   ## CONSUMES
+  gEfiRedfishPkgTokenSpaceGuid.PcdRedfishRestExAddingExpect   ## CONSUMES

 [UserExtensions.TianoCore."ExtraFiles"]
   RedfishRestExDxeExtra.uni
diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExImpl.c b/RedfishPkg/RedfishRestExDxe/RedfishRestExImpl.c
index 952e9d1..0da0d10 100644
--- a/RedfishPkg/RedfishRestExDxe/RedfishRestExImpl.c
+++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExImpl.c
@@ -140,9 +140,6 @@ RedfishHttpAddExpectation (
   }

   *ItsWrite = FALSE;
-  if (PreservedRequestHeaders != NULL) {
-    *PreservedRequestHeaders = RequestMessage->Headers;
-  }

   if ((RequestMessage->Data.Request->Method != HttpMethodPut) && (RequestMessage->Data.Request->Method != HttpMethodPost) &&
       (RequestMessage->Data.Request->Method != HttpMethodPatch))
@@ -152,10 +149,20 @@ RedfishHttpAddExpectation (

   *ItsWrite = TRUE;

-  NewHeaders = AllocateZeroPool ((RequestMessage->HeaderCount + 1) * sizeof (EFI_HTTP_HEADER));
-  CopyMem ((VOID *)NewHeaders, (VOID *)RequestMessage->Headers, RequestMessage->HeaderCount * sizeof (EFI_HTTP_HEADER));
-  HttpSetFieldNameAndValue (NewHeaders + RequestMessage->HeaderCount, HTTP_HEADER_EXPECT, HTTP_EXPECT_100_CONTINUE);
-  RequestMessage->HeaderCount++;
-  RequestMessage->Headers = NewHeaders;
+  //
+  // Check PCD before adding Expect header
+  //
+  if(FixedPcdGetBool(PcdRedfishRestExAddingExpect)) {
+    if (PreservedRequestHeaders != NULL) {
+      *PreservedRequestHeaders = RequestMessage->Headers;
+    }
+
+    NewHeaders = AllocateZeroPool ((RequestMessage->HeaderCount + 1) * sizeof (EFI_HTTP_HEADER));
+    CopyMem ((VOID *)NewHeaders, (VOID *)RequestMessage->Headers, RequestMessage->HeaderCount * sizeof (EFI_HTTP_HEADER));
+    HttpSetFieldNameAndValue (NewHeaders + RequestMessage->HeaderCount, HTTP_HEADER_EXPECT, HTTP_EXPECT_100_CONTINUE);
+    RequestMessage->HeaderCount++;
+    RequestMessage->Headers = NewHeaders;
+  }
+
   return EFI_SUCCESS;
 }
diff --git a/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c b/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c
index 22dc5e1..fbd5e46 100644
--- a/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c
+++ b/RedfishPkg/RedfishRestExDxe/RedfishRestExProtocol.c
@@ -97,84 +97,70 @@ RedfishRestExSendReceive (
   DEBUG ((DEBUG_INFO, "*** Perform HTTP Request Method - %d, URL: %s\n", RequestMessage->Data.Request->Method, RequestMessage->Data.Request->Url));

   if(FixedPcdGetBool(PcdRedfishRestExChunkRequestMode)){
-      //
-      // Add header "Expect" to server, only for URL write.
-      //
-      Status = RedfishHttpAddExpectation (This, RequestMessage, &PreservedRequestHeaders, &ItsWrite);
-      if (EFI_ERROR (Status)) {
-        return Status;
-      }
-
-      if (ItsWrite == TRUE) {
-        if (RequestMessage->BodyLength > HTTP_IO_MAX_SEND_PAYLOAD) {
-          //
-          // Send chunked transfer.
-          //
-          SendChunkProcess++;
-          CopyMem ((VOID *)&ChunkTransferRequestMessage, (VOID *)RequestMessage, sizeof (EFI_HTTP_MESSAGE));
-        } else {
-          SendNonChunkProcess++;
-        }
+    //
+    // Add header "Expect" to server, only for URL write.
+    //
+    Status = RedfishHttpAddExpectation (This, RequestMessage, &PreservedRequestHeaders, &ItsWrite);
+    if (EFI_ERROR (Status)) {
+      return Status;
+    }
+
+    if (ItsWrite == TRUE) {
+      if (RequestMessage->BodyLength > HTTP_IO_MAX_SEND_PAYLOAD) {
+        //
+        // Send chunked transfer.
+        //
+        SendChunkProcess++;
+        CopyMem ((VOID *)&ChunkTransferRequestMessage, (VOID *)RequestMessage, sizeof (EFI_HTTP_MESSAGE));
+      } else {
+        SendNonChunkProcess++;
       }
+    }
   }
-
+
 ReSendRequest:;

   if(FixedPcdGetBool(PcdRedfishRestExChunkRequestMode)){
+    //
+    // Send the chunked request to REST service.
+    //
+    if (ItsWrite == TRUE) {
       //
-      // Send the chunked request to REST service.
+      // This is write to URI
       //
-      if (ItsWrite == TRUE) {
+      if (SendChunkProcess > HttpIoSendChunkNone) {
         //
-        // This is write to URI
+        // This is chunk transfer for writing large payload.
+        // Send request header first and then handle the
+        // following request message body using chunk transfer.
         //
-        if (SendChunkProcess > HttpIoSendChunkNone) {
-          //
-          // This is chunk transfer for writing large payload.
-          // Send request header first and then handle the
-          // following request message body using chunk transfer.
-          //
-          do {
-            Status = HttpIoSendChunkedTransfer (
-                       &(Instance->HttpIo),
-                       &SendChunkProcess,
-                       &ChunkTransferRequestMessage
-                       );
-            if (EFI_ERROR (Status)) {
-              goto ON_EXIT;
-            }
-          } while (SendChunkProcess == HttpIoSendChunkContent || SendChunkProcess == HttpIoSendChunkEndChunk);
-        } else {
-          //
-          // This is the non-chunk transfer, send request header first and then
-          // handle the following request message body using chunk transfer.
-          //
-          Status = HttpIoSendRequest (
+        do {
+          Status = HttpIoSendChunkedTransfer (
                      &(Instance->HttpIo),
-                     (SendNonChunkProcess == HttpIoSendNonChunkContent) ? NULL : RequestMessage->Data.Request,
-                     (SendNonChunkProcess == HttpIoSendNonChunkContent) ? 0 : RequestMessage->HeaderCount,
-                     (SendNonChunkProcess == HttpIoSendNonChunkContent) ? NULL : RequestMessage->Headers,
-                     (SendNonChunkProcess == HttpIoSendNonChunkHeaderZeroContent) ? 0 : RequestMessage->BodyLength,
-                     (SendNonChunkProcess == HttpIoSendNonChunkHeaderZeroContent) ? NULL : RequestMessage->Body
+                     &SendChunkProcess,
+                     &ChunkTransferRequestMessage
                      );
-        }
+          if (EFI_ERROR (Status)) {
+            goto ON_EXIT;
+          }
+        } while (SendChunkProcess == HttpIoSendChunkContent || SendChunkProcess == HttpIoSendChunkEndChunk);
       } else {
         //
-        // This is read from URI.
+        // This is the non-chunk transfer, send request header first and then
+        // handle the following request message body using chunk transfer.
         //
         Status = HttpIoSendRequest (
                    &(Instance->HttpIo),
-                   RequestMessage->Data.Request,
-                   RequestMessage->HeaderCount,
-                   RequestMessage->Headers,
-                   RequestMessage->BodyLength,
-                   RequestMessage->Body
+                   (SendNonChunkProcess == HttpIoSendNonChunkContent) ? NULL : RequestMessage->Data.Request,
+                   (SendNonChunkProcess == HttpIoSendNonChunkContent) ? 0 : RequestMessage->HeaderCount,
+                   (SendNonChunkProcess == HttpIoSendNonChunkContent) ? NULL : RequestMessage->Headers,
+                   (SendNonChunkProcess == HttpIoSendNonChunkHeaderZeroContent) ? 0 : RequestMessage->BodyLength,
+                   (SendNonChunkProcess == HttpIoSendNonChunkHeaderZeroContent) ? NULL : RequestMessage->Body
                    );
       }
-  }
-  else{
+    } else {
       //
-      // This is normal request to URI.
+      // This is read from URI.
       //
       Status = HttpIoSendRequest (
                  &(Instance->HttpIo),
@@ -184,8 +170,22 @@ ReSendRequest:;
                  RequestMessage->BodyLength,
                  RequestMessage->Body
                  );
+    }
   }
-
+  else{
+    //
+    // This is normal request to URI.
+    //
+    Status = HttpIoSendRequest (
+               &(Instance->HttpIo),
+               RequestMessage->Data.Request,
+               RequestMessage->HeaderCount,
+               RequestMessage->Headers,
+               RequestMessage->BodyLength,
+               RequestMessage->Body
+               );
+  }
+
   if (EFI_ERROR (Status)) {
     goto ON_EXIT;
   }
@@ -233,7 +233,7 @@ ReSendRequest:;
   //
   // Restore the headers if it ever changed in RedfishHttpAddExpectation().
   //
-  if (FixedPcdGetBool(PcdRedfishRestExChunkRequestMode) && RequestMessage->Headers != PreservedRequestHeaders) {
+  if (FixedPcdGetBool(PcdRedfishRestExAddingExpect) && RequestMessage->Headers != PreservedRequestHeaders) {
     FreePool (RequestMessage->Headers);
     RequestMessage->Headers = PreservedRequestHeaders; // Restore headers before we adding "Expect".
     RequestMessage->HeaderCount--;                     // Minus one header count for "Expect".
@@ -248,6 +248,18 @@ ReSendRequest:;
       SendChunkProcess++;
       goto ReSendRequest;
     }
+  } else if (ResponseData->Response.StatusCode == HTTP_STATUS_204_NO_CONTENT) {
+    DEBUG ((DEBUG_INFO, "HTTP_STATUS_204_NO_CONTENT\n"));
+
+    if (FixedPcdGetBool(PcdRedfishRestExChunkRequestMode) && SendChunkProcess == HttpIoSendChunkHeaderZeroContent) {
+      DEBUG ((DEBUG_INFO, "This is chunk transfer, start to send all chunks.", ResponseData->Response.StatusCode));
+      SendChunkProcess ++;
+      goto ReSendRequest;
+    }
+  } else if (ResponseData->Response.StatusCode == HTTP_STATUS_201_CREATED) {
+    DEBUG ((DEBUG_INFO, "HTTP_STATUS_201_CREATED\n"));
+  } else if (ResponseData->Response.StatusCode == HTTP_STATUS_202_ACCEPTED) {
+    DEBUG ((DEBUG_INFO, "HTTP_STATUS_202_ACCEPTED\n"));
   } else if (ResponseData->Response.StatusCode == HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE) {
     DEBUG ((DEBUG_INFO, "HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE\n"));

@@ -414,7 +426,7 @@ ReSendRequest:;
       TotalReceivedSize += ResponseData->BodyLength;
     }

-    DEBUG ((DEBUG_INFO, "Total of lengh of Response :%d\n", TotalReceivedSize));
+    DEBUG ((DEBUG_INFO, "Total of length of Response :%d\n", TotalReceivedSize));
   }

   DEBUG ((DEBUG_INFO, "RedfishRestExSendReceive()- EFI_STATUS: %r\n", Status));
--
2.6.1.windows.1
-The information contained in this message may be confidential and proprietary to American Megatrends (AMI). This communication is intended to be read only by the individual or entity to whom it is addressed or by their designee. If the reader of this message is not the intended recipient, you are on notice that any distribution of this message, in any form, is strictly prohibited. Please promptly notify the sender by reply e-mail or by telephone at 770-246-8600, and then delete or destroy all copies of the transmission.

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-08  2:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-08  2:36 [PATCH V2] RedfishPkg: RedfishRestExDxe: PCD introduced to control "Expect" header Igor Kulchytskyy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox