]> git.proxmox.com Git - mirror_edk2.git/commitdiff
NetworkPkg: Display HTTP redirection info to the screen if need.
authorFu Siyuan <siyuan.fu@intel.com>
Wed, 26 Jul 2017 07:57:38 +0000 (15:57 +0800)
committerFu Siyuan <siyuan.fu@intel.com>
Thu, 3 Aug 2017 06:12:43 +0000 (14:12 +0800)
HTTP defines a set of status code for redirecting a request to a different URI
in Section 6.4 of RFC7231 and also RFC7583. This patch updates the HTTP boot
driver to display the redirection info to the screen so the user would have
chance to know new URI address of the HTTP boot image.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Fu Siyuan <siyuan.fu@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
NetworkPkg/HttpBootDxe/HttpBootDxe.h
NetworkPkg/HttpBootDxe/HttpBootImpl.c
NetworkPkg/HttpBootDxe/HttpBootSupport.c
NetworkPkg/HttpBootDxe/HttpBootSupport.h

index 8d89b3e95c7bcf211a2bc03902dcab40b5fe6897..4632ee2c8dd30b3957ec1548c52331e6b249f022 100644 (file)
@@ -179,6 +179,10 @@ struct _HTTP_BOOT_PRIVATE_DATA {
   UINT32                                    Id;\r
   EFI_HTTP_BOOT_CALLBACK_PROTOCOL           *HttpBootCallback;\r
   EFI_HTTP_BOOT_CALLBACK_PROTOCOL           LoadFileCallback;\r
+\r
+  //\r
+  // Data for the default HTTP Boot callback protocol\r
+  //\r
   UINT64                                    FileSize;\r
   UINT64                                    ReceivedSize;\r
   UINT32                                    Percentage;\r
index 63cf3960a9c5e2ca9f63bfc5728f2f86fabc67da..dfd0e23db02d2f41fad348c53a86a8b08117690f 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The implementation of EFI_LOAD_FILE_PROTOCOL for UEFI HTTP boot.\r
 \r
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 This program and the accompanying materials are licensed and made available under \r
 the terms and conditions of the BSD License that accompanies this distribution.  \r
@@ -665,6 +665,25 @@ HttpBootCallback (
   case HttpBootHttpResponse:\r
     if (Data != NULL) {\r
       HttpMessage = (EFI_HTTP_MESSAGE *) Data;\r
+      \r
+      if (HttpMessage->Data.Response != NULL) {\r
+        if (HttpBootIsHttpRedirectStatusCode (HttpMessage->Data.Response->StatusCode)) {\r
+          //\r
+          // Server indicates the resource has been redirected to a different URL\r
+          // according to the section 6.4 of RFC7231 and the RFC 7538.\r
+          // Display the redirect information on the screen.\r
+          //\r
+          HttpHeader = HttpFindHeader (\r
+                 HttpMessage->HeaderCount,\r
+                 HttpMessage->Headers,\r
+                 HTTP_HEADER_LOCATION\r
+                 );\r
+          if (HttpHeader != NULL) {\r
+            Print (L"\n  HTTP ERROR: Resource Redirected.\n  New Location: %a\n", HttpHeader->FieldValue);\r
+          }\r
+        }\r
+      }\r
+      \r
       HttpHeader = HttpFindHeader (\r
                      HttpMessage->HeaderCount,\r
                      HttpMessage->Headers,\r
@@ -685,7 +704,7 @@ HttpBootCallback (
         // We already know the file size, print in percentage format.\r
         //\r
         if (Private->ReceivedSize == 0) {\r
-          Print (L"  File Size: %lu\n", Private->FileSize);\r
+          Print (L"  File Size: %lu Bytes\n", Private->FileSize);\r
         }\r
         Private->ReceivedSize += DataLength;\r
         Percentage = (UINT32) DivU64x64Remainder (MultU64x32 (Private->ReceivedSize, 100), Private->FileSize, NULL);\r
index a19fe6cdbfe5c6e3d1dc86bc9c625220801861b4..4e78cf3b962d1aac9fdc46cf3dfc51232b84daec 100644 (file)
@@ -1034,7 +1034,8 @@ HttpIoRecvResponse (
     HttpIo->IsRxDone = FALSE;\r
   }\r
 \r
-  if (!EFI_ERROR (HttpIo->RspToken.Status) && HttpIo->Callback != NULL) {\r
+  if ((HttpIo->Callback != NULL) && \r
+      (HttpIo->RspToken.Status == EFI_SUCCESS || HttpIo->RspToken.Status == EFI_HTTP_ERROR)) {\r
     Status = HttpIo->Callback (\r
                HttpIoResponse,\r
                HttpIo->RspToken.Message,\r
@@ -1319,3 +1320,25 @@ HttpBootRegisterRamDisk (
   return Status;\r
 }\r
 \r
+/**\r
+  Indicate if the HTTP status code indicates a redirection.\r
+  \r
+  @param[in]  StatusCode      HTTP status code from server.\r
+\r
+  @return                     TRUE if it's redirection.\r
+\r
+**/\r
+BOOLEAN\r
+HttpBootIsHttpRedirectStatusCode (\r
+  IN   EFI_HTTP_STATUS_CODE        StatusCode\r
+ )\r
+{\r
+  if (StatusCode == HTTP_STATUS_301_MOVED_PERMANENTLY ||\r
+      StatusCode == HTTP_STATUS_302_FOUND ||\r
+      StatusCode == HTTP_STATUS_307_TEMPORARY_REDIRECT ||\r
+      StatusCode == HTTP_STATUS_308_PERMANENT_REDIRECT) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
index f2b1846c056c250c3b56ac27479ebdc12c97d55c..c10b2cf5221b9c9db3d2a6ac7071c5f608cceca9 100644 (file)
@@ -445,4 +445,17 @@ HttpBootRegisterRamDisk (
   IN  VOID                         *Buffer,\r
   IN  HTTP_BOOT_IMAGE_TYPE         ImageType\r
   );\r
+\r
+/**\r
+  Indicate if the HTTP status code indicates a redirection.\r
+  \r
+  @param[in]  StatusCode      HTTP status code from server.\r
+\r
+  @return                     TRUE if it's redirection.\r
+\r
+**/\r
+BOOLEAN\r
+HttpBootIsHttpRedirectStatusCode (\r
+  IN   EFI_HTTP_STATUS_CODE        StatusCode\r
+ );\r
 #endif\r