public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] NetworkPkg: Display HTTP redirection info to the screen if need.
@ 2017-07-27  3:43 Fu Siyuan
  2017-08-03  2:03 ` Wu, Jiaxin
  2017-08-03  8:30 ` Ye, Ting
  0 siblings, 2 replies; 5+ messages in thread
From: Fu Siyuan @ 2017-07-27  3:43 UTC (permalink / raw)
  To: edk2-devel; +Cc: Ye Ting, Wu Jiaxin

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>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
---
 NetworkPkg/HttpBootDxe/HttpBootDxe.h     |  4 ++++
 NetworkPkg/HttpBootDxe/HttpBootImpl.c    | 21 ++++++++++++++++++++-
 NetworkPkg/HttpBootDxe/HttpBootSupport.c | 25 ++++++++++++++++++++++++-
 NetworkPkg/HttpBootDxe/HttpBootSupport.h | 13 +++++++++++++
 4 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
index 8d89b3e..4632ee2 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 63cf396..5cfb0f4 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,
diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
index 5024f2e..6d4edfc 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 f2b1846..c10b2cf 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
-- 
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Patch] NetworkPkg: Display HTTP redirection info to the screen if need.
  2017-07-27  3:43 [Patch] NetworkPkg: Display HTTP redirection info to the screen if need Fu Siyuan
@ 2017-08-03  2:03 ` Wu, Jiaxin
  2017-08-03  3:28   ` Fu, Siyuan
  2017-08-03  8:30 ` Ye, Ting
  1 sibling, 1 reply; 5+ messages in thread
From: Wu, Jiaxin @ 2017-08-03  2:03 UTC (permalink / raw)
  To: Fu, Siyuan, edk2-devel@lists.01.org; +Cc: Ye, Ting

Hi siyuan,

> +          if (HttpHeader != NULL) {
> +            Print (L"\n  HTTP ERROR: Resource Redirected.\n  New
> Location: %a\n", HttpHeader->FieldValue);
> +          }

How about we use HTTP WARNING instead of HTTP ERROR?

Thanks,
Jiaxin

> -----Original Message-----
> From: Fu, Siyuan
> Sent: Thursday, July 27, 2017 11:44 AM
> To: edk2-devel@lists.01.org
> Cc: Ye, Ting <ting.ye@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
> Subject: [Patch] 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>
> Cc: Ye Ting <ting.ye@intel.com>
> Cc: Wu Jiaxin <jiaxin.wu@intel.com>
> ---
>  NetworkPkg/HttpBootDxe/HttpBootDxe.h     |  4 ++++
>  NetworkPkg/HttpBootDxe/HttpBootImpl.c    | 21 ++++++++++++++++++++-
>  NetworkPkg/HttpBootDxe/HttpBootSupport.c | 25
> ++++++++++++++++++++++++-
>  NetworkPkg/HttpBootDxe/HttpBootSupport.h | 13 +++++++++++++
>  4 files changed, 61 insertions(+), 2 deletions(-)
> 
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h
> b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
> index 8d89b3e..4632ee2 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 63cf396..5cfb0f4 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,
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c
> b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
> index 5024f2e..6d4edfc 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 f2b1846..c10b2cf 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
> --
> 1.9.5.msysgit.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] NetworkPkg: Display HTTP redirection info to the screen if need.
  2017-08-03  2:03 ` Wu, Jiaxin
@ 2017-08-03  3:28   ` Fu, Siyuan
  2017-08-03  3:30     ` Wu, Jiaxin
  0 siblings, 1 reply; 5+ messages in thread
From: Fu, Siyuan @ 2017-08-03  3:28 UTC (permalink / raw)
  To: Wu, Jiaxin, edk2-devel@lists.01.org; +Cc: Ye, Ting

Hi, Jiaxin

We actually don't support HTTP redirect here, which means we won't auto redirect and download the boot image. The HTTP boot process will be aborted, so I think using ERROR makes more sense. 

Thanks, 
Siyuan

-----Original Message-----
From: Wu, Jiaxin 
Sent: Thursday, August 3, 2017 10:03 AM
To: Fu, Siyuan <siyuan.fu@intel.com>; edk2-devel@lists.01.org
Cc: Ye, Ting <ting.ye@intel.com>
Subject: RE: [Patch] NetworkPkg: Display HTTP redirection info to the screen if need.

Hi siyuan,

> +          if (HttpHeader != NULL) {
> +            Print (L"\n  HTTP ERROR: Resource Redirected.\n  New
> Location: %a\n", HttpHeader->FieldValue);
> +          }

How about we use HTTP WARNING instead of HTTP ERROR?

Thanks,
Jiaxin

> -----Original Message-----
> From: Fu, Siyuan
> Sent: Thursday, July 27, 2017 11:44 AM
> To: edk2-devel@lists.01.org
> Cc: Ye, Ting <ting.ye@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
> Subject: [Patch] 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>
> Cc: Ye Ting <ting.ye@intel.com>
> Cc: Wu Jiaxin <jiaxin.wu@intel.com>
> ---
>  NetworkPkg/HttpBootDxe/HttpBootDxe.h     |  4 ++++
>  NetworkPkg/HttpBootDxe/HttpBootImpl.c    | 21 ++++++++++++++++++++-
>  NetworkPkg/HttpBootDxe/HttpBootSupport.c | 25
> ++++++++++++++++++++++++-
>  NetworkPkg/HttpBootDxe/HttpBootSupport.h | 13 +++++++++++++
>  4 files changed, 61 insertions(+), 2 deletions(-)
> 
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h
> b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
> index 8d89b3e..4632ee2 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 63cf396..5cfb0f4 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,
> diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c
> b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
> index 5024f2e..6d4edfc 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 f2b1846..c10b2cf 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
> --
> 1.9.5.msysgit.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] NetworkPkg: Display HTTP redirection info to the screen if need.
  2017-08-03  3:28   ` Fu, Siyuan
@ 2017-08-03  3:30     ` Wu, Jiaxin
  0 siblings, 0 replies; 5+ messages in thread
From: Wu, Jiaxin @ 2017-08-03  3:30 UTC (permalink / raw)
  To: Fu, Siyuan, edk2-devel@lists.01.org; +Cc: Ye, Ting

Ok, that's make sense.

Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>



> -----Original Message-----
> From: Fu, Siyuan
> Sent: Thursday, August 3, 2017 11:28 AM
> To: Wu, Jiaxin <jiaxin.wu@intel.com>; edk2-devel@lists.01.org
> Cc: Ye, Ting <ting.ye@intel.com>
> Subject: RE: [Patch] NetworkPkg: Display HTTP redirection info to the screen
> if need.
> 
> Hi, Jiaxin
> 
> We actually don't support HTTP redirect here, which means we won't auto
> redirect and download the boot image. The HTTP boot process will be
> aborted, so I think using ERROR makes more sense.
> 
> Thanks,
> Siyuan
> 
> -----Original Message-----
> From: Wu, Jiaxin
> Sent: Thursday, August 3, 2017 10:03 AM
> To: Fu, Siyuan <siyuan.fu@intel.com>; edk2-devel@lists.01.org
> Cc: Ye, Ting <ting.ye@intel.com>
> Subject: RE: [Patch] NetworkPkg: Display HTTP redirection info to the screen
> if need.
> 
> Hi siyuan,
> 
> > +          if (HttpHeader != NULL) {
> > +            Print (L"\n  HTTP ERROR: Resource Redirected.\n  New
> > Location: %a\n", HttpHeader->FieldValue);
> > +          }
> 
> How about we use HTTP WARNING instead of HTTP ERROR?
> 
> Thanks,
> Jiaxin
> 
> > -----Original Message-----
> > From: Fu, Siyuan
> > Sent: Thursday, July 27, 2017 11:44 AM
> > To: edk2-devel@lists.01.org
> > Cc: Ye, Ting <ting.ye@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
> > Subject: [Patch] 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>
> > Cc: Ye Ting <ting.ye@intel.com>
> > Cc: Wu Jiaxin <jiaxin.wu@intel.com>
> > ---
> >  NetworkPkg/HttpBootDxe/HttpBootDxe.h     |  4 ++++
> >  NetworkPkg/HttpBootDxe/HttpBootImpl.c    | 21
> ++++++++++++++++++++-
> >  NetworkPkg/HttpBootDxe/HttpBootSupport.c | 25
> > ++++++++++++++++++++++++-
> >  NetworkPkg/HttpBootDxe/HttpBootSupport.h | 13 +++++++++++++
> >  4 files changed, 61 insertions(+), 2 deletions(-)
> >
> > diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h
> > b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
> > index 8d89b3e..4632ee2 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 63cf396..5cfb0f4 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,
> > diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c
> > b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
> > index 5024f2e..6d4edfc 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 f2b1846..c10b2cf 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
> > --
> > 1.9.5.msysgit.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] NetworkPkg: Display HTTP redirection info to the screen if need.
  2017-07-27  3:43 [Patch] NetworkPkg: Display HTTP redirection info to the screen if need Fu Siyuan
  2017-08-03  2:03 ` Wu, Jiaxin
@ 2017-08-03  8:30 ` Ye, Ting
  1 sibling, 0 replies; 5+ messages in thread
From: Ye, Ting @ 2017-08-03  8:30 UTC (permalink / raw)
  To: Fu, Siyuan, edk2-devel@lists.01.org; +Cc: Wu, Jiaxin

Reviewed-by: Ye Ting <ting.ye@intel.com> 

-----Original Message-----
From: Fu, Siyuan 
Sent: Thursday, July 27, 2017 11:44 AM
To: edk2-devel@lists.01.org
Cc: Ye, Ting <ting.ye@intel.com>; Wu, Jiaxin <jiaxin.wu@intel.com>
Subject: [Patch] 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>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Wu Jiaxin <jiaxin.wu@intel.com>
---
 NetworkPkg/HttpBootDxe/HttpBootDxe.h     |  4 ++++
 NetworkPkg/HttpBootDxe/HttpBootImpl.c    | 21 ++++++++++++++++++++-
 NetworkPkg/HttpBootDxe/HttpBootSupport.c | 25 ++++++++++++++++++++++++-  NetworkPkg/HttpBootDxe/HttpBootSupport.h | 13 +++++++++++++
 4 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/NetworkPkg/HttpBootDxe/HttpBootDxe.h b/NetworkPkg/HttpBootDxe/HttpBootDxe.h
index 8d89b3e..4632ee2 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 63cf396..5cfb0f4 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, diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
index 5024f2e..6d4edfc 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 f2b1846..c10b2cf 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
--
1.9.5.msysgit.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-08-03  8:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-27  3:43 [Patch] NetworkPkg: Display HTTP redirection info to the screen if need Fu Siyuan
2017-08-03  2:03 ` Wu, Jiaxin
2017-08-03  3:28   ` Fu, Siyuan
2017-08-03  3:30     ` Wu, Jiaxin
2017-08-03  8:30 ` Ye, Ting

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