Hi, Lubo

For the printed message I think it's better to use a human-readable string, as 
defined in HTTP RFC, instead of directly print the macro name in UEFI spec.
For example, for 400, we could use
        Client Error: 400 Bad Request
Instead of 
        Http Error Status: HTTP_STATUS_400_BAD_REQUEST

Our current driver doesn't support the redirection status code (3xx), so I 
think we could also treat it as an error statue and print it out.

Siyuan

-----Original Message-----
From: edk2-devel [mailto:edk2-devel-boun...@lists.01.org] On Behalf Of Zhang 
Lubo
Sent: Monday, November 9, 2015 4:23 PM
To: edk2-devel@lists.01.org
Cc: Ye, Ting <ting...@intel.com>; Fu, Siyuan <siyuan...@intel.com>; Wu, Jiaxin 
<jiaxin...@intel.com>
Subject: [edk2] [patch] NetworkPkg: Report Http Errors to screen when http 
layer occurs an error

Http server will return error status in http header when http connection cannot 
be established,so the http boot driver should print the error code code to the 
screen and the users can know what happened.

Cc: Ye Ting <ting...@intel.com>
Cc: Fu Siyuan <siyuan...@intel.com>
CC: Wu Jiaxin <jiaxin...@intel.com>
CC: El-Haj-Mahmoud, Samer <samer.el-haj-mahm...@hpe.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <lubo.zh...@intel.com>
---
 NetworkPkg/HttpBootDxe/HttpBootSupport.c | 121 +++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)

diff --git a/NetworkPkg/HttpBootDxe/HttpBootSupport.c 
b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
index d08111f..825a50e 100644
--- a/NetworkPkg/HttpBootDxe/HttpBootSupport.c
+++ b/NetworkPkg/HttpBootDxe/HttpBootSupport.c
@@ -145,10 +145,125 @@ HttpBootShowIp6Addr (
     }
   }
 }
 
 /**
+  This function is to display the HTTP error status.
+
+  @param[in]      StatusCode      The status code value in HTTP message.
+
+**/
+VOID
+HttpBootPrintErrorMessage (
+  EFI_HTTP_STATUS_CODE            StatusCode
+  )
+{
+  AsciiPrint ("\n");
+
+  switch (StatusCode) {
+  case HTTP_STATUS_400_BAD_REQUEST:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_400_BAD_REQUEST");
+    break;
+    
+  case HTTP_STATUS_401_UNAUTHORIZED:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_401_UNAUTHORIZED");
+    break;
+    
+  case HTTP_STATUS_402_PAYMENT_REQUIRED:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_402_PAYMENT_REQUIRED");
+    break;
+
+  case HTTP_STATUS_403_FORBIDDEN:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_403_FORBIDDEN");
+    break;
+
+  case HTTP_STATUS_404_NOT_FOUND:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_404_NOT_FOUND");
+    break;
+
+  case HTTP_STATUS_405_METHOD_NOT_ALLOWED:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_405_METHOD_NOT_ALLOWED");
+    break;
+
+  case HTTP_STATUS_406_NOT_ACCEPTABLE:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_406_NOT_ACCEPTABLE");
+    break;
+
+  case HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED:
+    AsciiPrint ("\n  Http Error Status: 
HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED");
+    break;
+
+  case HTTP_STATUS_408_REQUEST_TIME_OUT:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_408_REQUEST_TIME_OUT");
+    break;
+
+  case HTTP_STATUS_409_CONFLICT:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_409_CONFLICT");
+    break;
+
+  case HTTP_STATUS_410_GONE:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_410_GONE");
+    break;
+
+  case HTTP_STATUS_411_LENGTH_REQUIRED:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_411_LENGTH_REQUIRED");
+    break;
+
+  case HTTP_STATUS_412_PRECONDITION_FAILED:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_412_PRECONDITION_FAILED");
+    break;
+
+  case HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE:
+    AsciiPrint ("\n  Http Error Status: 
HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE");
+    break;
+
+  case HTTP_STATUS_414_REQUEST_URI_TOO_LARGE:
+    AsciiPrint ("\n  Http Error Status: 
HTTP_STATUS_414_REQUEST_URI_TOO_LARGE");
+    break;
+
+  case HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE:
+    AsciiPrint ("\n  Http Error Status: 
HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE");
+    break;
+
+  case HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED:
+    AsciiPrint ("\n  Http Error Status: 
HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED");
+    break;
+
+  case HTTP_STATUS_417_EXPECTATION_FAILED:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_417_EXPECTATION_FAILED");
+    break;
+
+  case HTTP_STATUS_500_INTERNAL_SERVER_ERROR:
+    AsciiPrint ("\n  Http Error Status: 
HTTP_STATUS_500_INTERNAL_SERVER_ERROR");
+    break;
+
+  case HTTP_STATUS_501_NOT_IMPLEMENTED:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_501_NOT_IMPLEMENTED");
+    break;
+
+  case HTTP_STATUS_502_BAD_GATEWAY:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_502_BAD_GATEWAY");
+    break;
+
+  case HTTP_STATUS_503_SERVICE_UNAVAILABLE:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_503_SERVICE_UNAVAILABLE");
+    break;
+
+  case HTTP_STATUS_504_GATEWAY_TIME_OUT:
+    AsciiPrint ("\n  Http Error Status: HTTP_STATUS_504_GATEWAY_TIME_OUT");
+    break;
+
+  case HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED:
+    AsciiPrint ("\n  Http Error Status: 
HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED");
+    break;
+
+  default: ;
+  
+  }
+}
+
+/**
   Notify the callback function when an event is triggered.
 
   @param[in]  Event           The triggered event.
   @param[in]  Context         The opaque parameter to the function.
 
@@ -785,10 +900,11 @@ HttpIoRecvResponse (
      OUT  HTTP_IO_RESOPNSE_DATA    *ResponseData
   )
 {
   EFI_STATUS                 Status;
   EFI_HTTP_PROTOCOL          *Http;
+  EFI_HTTP_STATUS_CODE       StatusCode;
 
   if (HttpIo == NULL || HttpIo->Http == NULL || ResponseData == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
@@ -831,8 +947,13 @@ HttpIoRecvResponse (
   if (!EFI_ERROR (Status)) {
     ResponseData->HeaderCount = HttpIo->RspToken.Message->HeaderCount;
     ResponseData->Headers     = HttpIo->RspToken.Message->Headers;
     ResponseData->BodyLength  = HttpIo->RspToken.Message->BodyLength;
   }
+  
+  if (RecvMsgHeader) {
+    StatusCode = HttpIo->RspToken.Message->Data.Response->StatusCode;
+    HttpBootPrintErrorMessage (StatusCode);  }
 
   return Status;
 }
--
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to