summaryrefslogtreecommitdiffstats
path: root/NetworkPkg/HttpBootDxe
diff options
context:
space:
mode:
authorFu Siyuan <siyuan.fu@intel.com>2017-07-26 15:57:38 +0800
committerFu Siyuan <siyuan.fu@intel.com>2017-08-03 14:12:43 +0800
commitbb4831c03dd15ff8528dcdbc7d2ad1835f55563e (patch)
tree343482b29459ea663d2f29c526531b9fadaac964 /NetworkPkg/HttpBootDxe
parentf11a7a555269f469b609ceb77221b59ec9b93ba9 (diff)
downloadedk2-bb4831c03dd15ff8528dcdbc7d2ad1835f55563e.tar.gz
edk2-bb4831c03dd15ff8528dcdbc7d2ad1835f55563e.tar.bz2
edk2-bb4831c03dd15ff8528dcdbc7d2ad1835f55563e.zip
NetworkPkg: Display HTTP redirection info to the screen if need.
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>
Diffstat (limited to 'NetworkPkg/HttpBootDxe')
-rw-r--r--NetworkPkg/HttpBootDxe/HttpBootDxe.h4
-rw-r--r--NetworkPkg/HttpBootDxe/HttpBootImpl.c23
-rw-r--r--NetworkPkg/HttpBootDxe/HttpBootSupport.c25
-rw-r--r--NetworkPkg/HttpBootDxe/HttpBootSupport.h13
4 files changed, 62 insertions, 3 deletions
diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
index 8d89b3e95c..4632ee2c8d 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootDxe.h
+++ b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
@@ -179,6 +179,10 @@ struct _HTTP_BOOT_PRIVATE_DATA {
UINT32 Id;
EFI_HTTP_BOOT_CALLBACK_PROTOCOL *HttpBootCallback;
EFI_HTTP_BOOT_CALLBACK_PROTOCOL LoadFileCallback;
+
+ //
+ // Data for the default HTTP Boot callback protocol
+ //
UINT64 FileSize;
UINT64 ReceivedSize;
UINT32 Percentage;
diff --git a/NetworkPkg/HttpBootDxe/HttpBootImpl.c b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
index 63cf3960a9..dfd0e23db0 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootImpl.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootImpl.c
@@ -1,7 +1,7 @@
/** @file
The implementation of EFI_LOAD_FILE_PROTOCOL for UEFI HTTP boot.
-Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
@@ -665,6 +665,25 @@ HttpBootCallback (
case HttpBootHttpResponse:
if (Data != NULL) {
HttpMessage = (EFI_HTTP_MESSAGE *) Data;
+
+ if (HttpMessage->Data.Response != NULL) {
+ if (HttpBootIsHttpRedirectStatusCode (HttpMessage->Data.Response->StatusCode)) {
+ //
+ // Server indicates the resource has been redirected to a different URL
+ // according to the section 6.4 of RFC7231 and the RFC 7538.
+ // Display the redirect information on the screen.
+ //
+ HttpHeader = HttpFindHeader (
+ HttpMessage->HeaderCount,
+ HttpMessage->Headers,
+ HTTP_HEADER_LOCATION
+ );
+ if (HttpHeader != NULL) {
+ Print (L"\n HTTP ERROR: Resource Redirected.\n New Location: %a\n", HttpHeader->FieldValue);
+ }
+ }
+ }
+
HttpHeader = HttpFindHeader (
HttpMessage->HeaderCount,
HttpMessage->Headers,
@@ -685,7 +704,7 @@ HttpBootCallback (
// We already know the file size, print in percentage format.
//
if (Private->ReceivedSize == 0) {
- Print (L" File Size: %lu\n", Private->FileSize);
+ Print (L" File Size: %lu Bytes\n", Private->FileSize);
}
Private->ReceivedSize += DataLength;
Percentage = (UINT32) DivU64x64Remainder (MultU64x32 (Private->ReceivedSize, 100), Private->FileSize, NULL);
diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
index a19fe6cdbf..4e78cf3b96 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootSupport.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
@@ -1034,7 +1034,8 @@ HttpIoRecvResponse (
HttpIo->IsRxDone = FALSE;
}
- if (!EFI_ERROR (HttpIo->RspToken.Status) && HttpIo->Callback != NULL) {
+ if ((HttpIo->Callback != NULL) &&
+ (HttpIo->RspToken.Status == EFI_SUCCESS || HttpIo->RspToken.Status == EFI_HTTP_ERROR)) {
Status = HttpIo->Callback (
HttpIoResponse,
HttpIo->RspToken.Message,
@@ -1319,3 +1320,25 @@ HttpBootRegisterRamDisk (
return Status;
}
+/**
+ Indicate if the HTTP status code indicates a redirection.
+
+ @param[in] StatusCode HTTP status code from server.
+
+ @return TRUE if it's redirection.
+
+**/
+BOOLEAN
+HttpBootIsHttpRedirectStatusCode (
+ IN EFI_HTTP_STATUS_CODE StatusCode
+ )
+{
+ if (StatusCode == HTTP_STATUS_301_MOVED_PERMANENTLY ||
+ StatusCode == HTTP_STATUS_302_FOUND ||
+ StatusCode == HTTP_STATUS_307_TEMPORARY_REDIRECT ||
+ StatusCode == HTTP_STATUS_308_PERMANENT_REDIRECT) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.h b/NetworkPkg/HttpBootDxe/HttpBootSupport.h
index f2b1846c05..c10b2cf522 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootSupport.h
+++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.h
@@ -445,4 +445,17 @@ HttpBootRegisterRamDisk (
IN VOID *Buffer,
IN HTTP_BOOT_IMAGE_TYPE ImageType
);
+
+/**
+ Indicate if the HTTP status code indicates a redirection.
+
+ @param[in] StatusCode HTTP status code from server.
+
+ @return TRUE if it's redirection.
+
+**/
+BOOLEAN
+HttpBootIsHttpRedirectStatusCode (
+ IN EFI_HTTP_STATUS_CODE StatusCode
+ );
#endif