]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c
BaseTools:Change the path of the file that Binary Cache
[mirror_edk2.git] / MdeModulePkg / Library / DxeHttpLib / DxeHttpLib.c
index 774bf7d7e56a39fd3b9e4226b16c264f8e4ef2eb..8b74554cd96157b2cb788b1c32f9c50a6664ef9f 100644 (file)
@@ -2,15 +2,9 @@
   This library is used to share code between UEFI network stack modules.\r
   It provides the helper routines to parse the HTTP message byte stream.\r
 \r
   This library is used to share code between UEFI network stack modules.\r
   It provides the helper routines to parse the HTTP message byte stream.\r
 \r
-Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at<BR>\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 \r
 **/\r
 \r
@@ -20,10 +14,10 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 /**\r
   Decode a percent-encoded URI component to the ASCII character.\r
 \r
 /**\r
   Decode a percent-encoded URI component to the ASCII character.\r
-  \r
-  Decode the input component in Buffer according to RFC 3986. The caller is responsible to make \r
+\r
+  Decode the input component in Buffer according to RFC 3986. The caller is responsible to make\r
   sure ResultBuffer points to a buffer with size equal or greater than ((AsciiStrSize (Buffer))\r
   sure ResultBuffer points to a buffer with size equal or greater than ((AsciiStrSize (Buffer))\r
-  in bytes. \r
+  in bytes.\r
 \r
   @param[in]    Buffer           The pointer to a percent-encoded URI component.\r
   @param[in]    BufferLength     Length of Buffer in bytes.\r
 \r
   @param[in]    Buffer           The pointer to a percent-encoded URI component.\r
   @param[in]    BufferLength     Length of Buffer in bytes.\r
@@ -32,7 +26,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
   @retval EFI_SUCCESS            Successfully decoded the URI.\r
   @retval EFI_INVALID_PARAMETER  Buffer is not a valid percent-encoded string.\r
 \r
   @retval EFI_SUCCESS            Successfully decoded the URI.\r
   @retval EFI_INVALID_PARAMETER  Buffer is not a valid percent-encoded string.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -50,13 +44,14 @@ UriPercentDecode (
   if (Buffer == NULL || BufferLength == 0 || ResultBuffer == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   if (Buffer == NULL || BufferLength == 0 || ResultBuffer == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   Index = 0;\r
   Offset = 0;\r
   HexStr[2] = '\0';\r
   while (Index < BufferLength) {\r
     if (Buffer[Index] == '%') {\r
   Index = 0;\r
   Offset = 0;\r
   HexStr[2] = '\0';\r
   while (Index < BufferLength) {\r
     if (Buffer[Index] == '%') {\r
-      if (Index + 1 >= BufferLength || Index + 2 >= BufferLength || !NET_IS_HEX_CHAR (Buffer[Index+1]) || !NET_IS_HEX_CHAR (Buffer[Index+2])) {\r
+      if (Index + 1 >= BufferLength || Index + 2 >= BufferLength ||\r
+          !NET_IS_HEX_CHAR (Buffer[Index+1]) || !NET_IS_HEX_CHAR (Buffer[Index+2])) {\r
         return EFI_INVALID_PARAMETER;\r
       }\r
       HexStr[0] = Buffer[Index+1];\r
         return EFI_INVALID_PARAMETER;\r
       }\r
       HexStr[0] = Buffer[Index+1];\r
@@ -71,7 +66,7 @@ UriPercentDecode (
   }\r
 \r
   *ResultLength = (UINT32) Offset;\r
   }\r
 \r
   *ResultLength = (UINT32) Offset;\r
-    \r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -81,8 +76,8 @@ UriPercentDecode (
 \r
   @param[in]       Char           Next character.\r
   @param[in]       State          Current value of the parser state machine.\r
 \r
   @param[in]       Char           Next character.\r
   @param[in]       State          Current value of the parser state machine.\r
-  @param[in]       IsRightBracket TRUE if there is an sign ']' in the authority component and \r
-                                  indicates the next part is ':' before Port.                                \r
+  @param[in]       IsRightBracket TRUE if there is an sign ']' in the authority component and\r
+                                  indicates the next part is ':' before Port.\r
 \r
   @return          Updated state value.\r
 **/\r
 \r
   @return          Updated state value.\r
 **/\r
@@ -115,27 +110,27 @@ NetHttpParseAuthorityChar (
     break;\r
 \r
   case UrlParserHost:\r
     break;\r
 \r
   case UrlParserHost:\r
-  case UrlParserHostStart:  \r
+  case UrlParserHostStart:\r
     if (Char == '[') {\r
       return UrlParserHostIpv6;\r
     }\r
     if (Char == '[') {\r
       return UrlParserHostIpv6;\r
     }\r
-    \r
+\r
     if (Char == ':') {\r
       return UrlParserPortStart;\r
     }\r
     if (Char == ':') {\r
       return UrlParserPortStart;\r
     }\r
-    \r
+\r
     return UrlParserHost;\r
     return UrlParserHost;\r
-    \r
-  case UrlParserHostIpv6:  \r
+\r
+  case UrlParserHostIpv6:\r
     if (Char == ']') {\r
       *IsRightBracket = TRUE;\r
     }\r
     if (Char == ']') {\r
       *IsRightBracket = TRUE;\r
     }\r
-    \r
+\r
     if (Char == ':' && *IsRightBracket) {\r
       return UrlParserPortStart;\r
     }\r
     return UrlParserHostIpv6;\r
     if (Char == ':' && *IsRightBracket) {\r
       return UrlParserPortStart;\r
     }\r
     return UrlParserHostIpv6;\r
-    \r
+\r
   case UrlParserPort:\r
   case UrlParserPortStart:\r
     return UrlParserPort;\r
   case UrlParserPort:\r
   case UrlParserPortStart:\r
     return UrlParserPort;\r
@@ -155,7 +150,7 @@ NetHttpParseAuthorityChar (
   @param[in, out]  UrlParser      Pointer to the buffer of the parse result.\r
 \r
   @retval EFI_SUCCESS             Successfully parse the authority.\r
   @param[in, out]  UrlParser      Pointer to the buffer of the parse result.\r
 \r
   @retval EFI_SUCCESS             Successfully parse the authority.\r
-  @retval Other                   Error happened.\r
+  @retval EFI_INVALID_PARAMETER   The Url is invalid to parse the authority component.\r
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
@@ -172,7 +167,7 @@ NetHttpParseAuthority (
   UINT32                Field;\r
   UINT32                OldField;\r
   BOOLEAN               IsrightBracket;\r
   UINT32                Field;\r
   UINT32                OldField;\r
   BOOLEAN               IsrightBracket;\r
-  \r
+\r
   ASSERT ((UrlParser->FieldBitMap & BIT (HTTP_URI_FIELD_AUTHORITY)) != 0);\r
 \r
   //\r
   ASSERT ((UrlParser->FieldBitMap & BIT (HTTP_URI_FIELD_AUTHORITY)) != 0);\r
 \r
   //\r
@@ -202,7 +197,7 @@ NetHttpParseAuthority (
     case UrlParserUserInfo:\r
       Field = HTTP_URI_FIELD_USERINFO;\r
       break;\r
     case UrlParserUserInfo:\r
       Field = HTTP_URI_FIELD_USERINFO;\r
       break;\r
-      \r
+\r
     case UrlParserHost:\r
       Field = HTTP_URI_FIELD_HOST;\r
       break;\r
     case UrlParserHost:\r
       Field = HTTP_URI_FIELD_HOST;\r
       break;\r
@@ -210,7 +205,7 @@ NetHttpParseAuthority (
     case UrlParserHostIpv6:\r
       Field = HTTP_URI_FIELD_HOST;\r
       break;\r
     case UrlParserHostIpv6:\r
       Field = HTTP_URI_FIELD_HOST;\r
       break;\r
-      \r
+\r
     case UrlParserPort:\r
       Field = HTTP_URI_FIELD_PORT;\r
       break;\r
     case UrlParserPort:\r
       Field = HTTP_URI_FIELD_PORT;\r
       break;\r
@@ -258,12 +253,12 @@ NetHttpParseUrlChar (
   if (Char == ' ' || Char == '\r' || Char == '\n') {\r
     return UrlParserStateMax;\r
   }\r
   if (Char == ' ' || Char == '\r' || Char == '\n') {\r
     return UrlParserStateMax;\r
   }\r
-  \r
+\r
   //\r
   // http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]\r
   //\r
   // http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]\r
-  // \r
+  //\r
   // Request-URI    = "*" | absolute-URI | path-absolute | authority\r
   // Request-URI    = "*" | absolute-URI | path-absolute | authority\r
-  // \r
+  //\r
   // absolute-URI  = scheme ":" hier-part [ "?" query ]\r
   // path-absolute = "/" [ segment-nz *( "/" segment ) ]\r
   // authority   = [ userinfo "@" ] host [ ":" port ]\r
   // absolute-URI  = scheme ":" hier-part [ "?" query ]\r
   // path-absolute = "/" [ segment-nz *( "/" segment ) ]\r
   // authority   = [ userinfo "@" ] host [ ":" port ]\r
@@ -332,7 +327,7 @@ NetHttpParseUrlChar (
 \r
   case UrlParserFragmentStart:\r
     return UrlParserFragment;\r
 \r
   case UrlParserFragmentStart:\r
     return UrlParserFragment;\r
-    \r
+\r
   default:\r
     break;\r
   }\r
   default:\r
     break;\r
   }\r
@@ -374,7 +369,7 @@ HttpParseUrl (
   HTTP_URL_PARSER       *Parser;\r
 \r
   Parser = NULL;\r
   HTTP_URL_PARSER       *Parser;\r
 \r
   Parser = NULL;\r
-  \r
+\r
   if (Url == NULL || Length == 0 || UrlParser == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   if (Url == NULL || Length == 0 || UrlParser == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -383,7 +378,7 @@ HttpParseUrl (
   if (Parser == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   if (Parser == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  \r
+\r
   if (IsConnectMethod) {\r
     //\r
     // According to RFC 2616, the authority form is only used by the CONNECT method.\r
   if (IsConnectMethod) {\r
     //\r
     // According to RFC 2616, the authority form is only used by the CONNECT method.\r
@@ -406,7 +401,7 @@ HttpParseUrl (
     case UrlParserStateMax:\r
       FreePool (Parser);\r
       return EFI_INVALID_PARAMETER;\r
     case UrlParserStateMax:\r
       FreePool (Parser);\r
       return EFI_INVALID_PARAMETER;\r
-      \r
+\r
     case UrlParserSchemeColon:\r
     case UrlParserSchemeColonSlash:\r
     case UrlParserSchemeColonSlashSlash:\r
     case UrlParserSchemeColon:\r
     case UrlParserSchemeColonSlash:\r
     case UrlParserSchemeColonSlashSlash:\r
@@ -416,7 +411,7 @@ HttpParseUrl (
       // Skip all the delimiting char: "://" "?" "@"\r
       //\r
       continue;\r
       // Skip all the delimiting char: "://" "?" "@"\r
       //\r
       continue;\r
-    \r
+\r
     case UrlParserScheme:\r
       Field = HTTP_URI_FIELD_SCHEME;\r
       break;\r
     case UrlParserScheme:\r
       Field = HTTP_URI_FIELD_SCHEME;\r
       break;\r
@@ -473,7 +468,7 @@ HttpParseUrl (
   }\r
 \r
   *UrlParser = Parser;\r
   }\r
 \r
   *UrlParser = Parser;\r
-  return EFI_SUCCESS;  \r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -490,7 +485,7 @@ HttpParseUrl (
   @retval EFI_INVALID_PARAMETER    Uri is NULL or HostName is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No hostName component in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
   @retval EFI_INVALID_PARAMETER    Uri is NULL or HostName is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No hostName component in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -509,7 +504,7 @@ HttpUrlGetHostName (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Parser = (HTTP_URL_PARSER*) UrlParser;\r
+  Parser = (HTTP_URL_PARSER *) UrlParser;\r
 \r
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) == 0) {\r
     return EFI_NOT_FOUND;\r
 \r
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) == 0) {\r
     return EFI_NOT_FOUND;\r
@@ -519,7 +514,7 @@ HttpUrlGetHostName (
   if (Name == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   if (Name == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  \r
+\r
   Status = UriPercentDecode (\r
              Url + Parser->FieldData[HTTP_URI_FIELD_HOST].Offset,\r
              Parser->FieldData[HTTP_URI_FIELD_HOST].Length,\r
   Status = UriPercentDecode (\r
              Url + Parser->FieldData[HTTP_URI_FIELD_HOST].Offset,\r
              Parser->FieldData[HTTP_URI_FIELD_HOST].Length,\r
@@ -550,7 +545,7 @@ HttpUrlGetHostName (
   @retval EFI_INVALID_PARAMETER    Uri is NULL or Ip4Address is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No IPv4 address component in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
   @retval EFI_INVALID_PARAMETER    Uri is NULL or Ip4Address is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No IPv4 address component in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -564,22 +559,22 @@ HttpUrlGetIp4 (
   EFI_STATUS           Status;\r
   UINT32               ResultLength;\r
   HTTP_URL_PARSER      *Parser;\r
   EFI_STATUS           Status;\r
   UINT32               ResultLength;\r
   HTTP_URL_PARSER      *Parser;\r
-  \r
+\r
   if (Url == NULL || UrlParser == NULL || Ip4Address == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   if (Url == NULL || UrlParser == NULL || Ip4Address == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Parser = (HTTP_URL_PARSER*) UrlParser;\r
+  Parser = (HTTP_URL_PARSER *) UrlParser;\r
 \r
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) == 0) {\r
 \r
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) == 0) {\r
-    return EFI_INVALID_PARAMETER;\r
+    return EFI_NOT_FOUND;\r
   }\r
 \r
   Ip4String = AllocatePool (Parser->FieldData[HTTP_URI_FIELD_HOST].Length + 1);\r
   if (Ip4String == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   }\r
 \r
   Ip4String = AllocatePool (Parser->FieldData[HTTP_URI_FIELD_HOST].Length + 1);\r
   if (Ip4String == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  \r
+\r
   Status = UriPercentDecode (\r
              Url + Parser->FieldData[HTTP_URI_FIELD_HOST].Offset,\r
              Parser->FieldData[HTTP_URI_FIELD_HOST].Length,\r
   Status = UriPercentDecode (\r
              Url + Parser->FieldData[HTTP_URI_FIELD_HOST].Offset,\r
              Parser->FieldData[HTTP_URI_FIELD_HOST].Length,\r
@@ -611,7 +606,7 @@ HttpUrlGetIp4 (
   @retval EFI_INVALID_PARAMETER    Uri is NULL or Ip6Address is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No IPv6 address component in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
   @retval EFI_INVALID_PARAMETER    Uri is NULL or Ip6Address is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No IPv6 address component in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -627,15 +622,15 @@ HttpUrlGetIp6 (
   EFI_STATUS           Status;\r
   UINT32               ResultLength;\r
   HTTP_URL_PARSER      *Parser;\r
   EFI_STATUS           Status;\r
   UINT32               ResultLength;\r
   HTTP_URL_PARSER      *Parser;\r
-  \r
+\r
   if (Url == NULL || UrlParser == NULL || Ip6Address == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
   if (Url == NULL || UrlParser == NULL || Ip6Address == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Parser = (HTTP_URL_PARSER*) UrlParser;\r
+  Parser = (HTTP_URL_PARSER *) UrlParser;\r
 \r
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) == 0) {\r
 \r
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_HOST)) == 0) {\r
-    return EFI_INVALID_PARAMETER;\r
+    return EFI_NOT_FOUND;\r
   }\r
 \r
   //\r
   }\r
 \r
   //\r
@@ -655,7 +650,7 @@ HttpUrlGetIp6 (
   if (Ip6String == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   if (Ip6String == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  \r
+\r
   Status = UriPercentDecode (\r
              Ptr + 1,\r
              Length - 2,\r
   Status = UriPercentDecode (\r
              Ptr + 1,\r
              Length - 2,\r
@@ -666,7 +661,7 @@ HttpUrlGetIp6 (
     FreePool (Ip6String);\r
     return Status;\r
   }\r
     FreePool (Ip6String);\r
     return Status;\r
   }\r
-  \r
+\r
   Ip6String[ResultLength] = '\0';\r
   Status = NetLibAsciiStrToIp6 (Ip6String, Ip6Address);\r
   FreePool (Ip6String);\r
   Ip6String[ResultLength] = '\0';\r
   Status = NetLibAsciiStrToIp6 (Ip6String, Ip6Address);\r
   FreePool (Ip6String);\r
@@ -687,7 +682,7 @@ HttpUrlGetIp6 (
   @retval EFI_INVALID_PARAMETER    Uri is NULL or Port is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No port number in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
   @retval EFI_INVALID_PARAMETER    Uri is NULL or Port is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No port number in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -697,11 +692,11 @@ HttpUrlGetPort (
      OUT  UINT16             *Port\r
   )\r
 {\r
      OUT  UINT16             *Port\r
   )\r
 {\r
-  CHAR8         *PortString;\r
-  EFI_STATUS    Status;\r
-  UINTN         Index;\r
-  UINTN         Data;\r
-  UINT32        ResultLength;\r
+  CHAR8                *PortString;\r
+  EFI_STATUS           Status;\r
+  UINTN                Index;\r
+  UINTN                Data;\r
+  UINT32               ResultLength;\r
   HTTP_URL_PARSER      *Parser;\r
 \r
   if (Url == NULL || UrlParser == NULL || Port == NULL) {\r
   HTTP_URL_PARSER      *Parser;\r
 \r
   if (Url == NULL || UrlParser == NULL || Port == NULL) {\r
@@ -711,10 +706,10 @@ HttpUrlGetPort (
   *Port = 0;\r
   Index = 0;\r
 \r
   *Port = 0;\r
   Index = 0;\r
 \r
-  Parser = (HTTP_URL_PARSER*) UrlParser;\r
+  Parser = (HTTP_URL_PARSER *) UrlParser;\r
 \r
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PORT)) == 0) {\r
 \r
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PORT)) == 0) {\r
-    return EFI_INVALID_PARAMETER;\r
+    return EFI_NOT_FOUND;\r
   }\r
 \r
   PortString = AllocatePool (Parser->FieldData[HTTP_URI_FIELD_PORT].Length + 1);\r
   }\r
 \r
   PortString = AllocatePool (Parser->FieldData[HTTP_URI_FIELD_PORT].Length + 1);\r
@@ -770,7 +765,7 @@ ON_EXIT:
   @retval EFI_INVALID_PARAMETER    Uri is NULL or HostName is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No hostName component in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
   @retval EFI_INVALID_PARAMETER    Uri is NULL or HostName is NULL or UrlParser is invalid.\r
   @retval EFI_NOT_FOUND            No hostName component in the URL.\r
   @retval EFI_OUT_OF_RESOURCES     Could not allocate needed resources.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -789,7 +784,7 @@ HttpUrlGetPath (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Parser = (HTTP_URL_PARSER*) UrlParser;\r
+  Parser = (HTTP_URL_PARSER *) UrlParser;\r
 \r
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PATH)) == 0) {\r
     return EFI_NOT_FOUND;\r
 \r
   if ((Parser->FieldBitMap & BIT (HTTP_URI_FIELD_PATH)) == 0) {\r
     return EFI_NOT_FOUND;\r
@@ -799,7 +794,7 @@ HttpUrlGetPath (
   if (PathStr == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
   if (PathStr == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  \r
+\r
   Status = UriPercentDecode (\r
              Url + Parser->FieldData[HTTP_URI_FIELD_PATH].Offset,\r
              Parser->FieldData[HTTP_URI_FIELD_PATH].Length,\r
   Status = UriPercentDecode (\r
              Url + Parser->FieldData[HTTP_URI_FIELD_PATH].Offset,\r
              Parser->FieldData[HTTP_URI_FIELD_PATH].Length,\r
@@ -820,7 +815,7 @@ HttpUrlGetPath (
   Release the resource of the URL parser.\r
 \r
   @param[in]    UrlParser            Pointer to the parser.\r
   Release the resource of the URL parser.\r
 \r
   @param[in]    UrlParser            Pointer to the parser.\r
-  \r
+\r
 **/\r
 VOID\r
 EFIAPI\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -834,9 +829,9 @@ HttpUrlFreeParser (
 /**\r
   Find a specified header field according to the field name.\r
 \r
 /**\r
   Find a specified header field according to the field name.\r
 \r
-  @param[in]   HeaderCount      Number of HTTP header structures in Headers list. \r
+  @param[in]   HeaderCount      Number of HTTP header structures in Headers list.\r
   @param[in]   Headers          Array containing list of HTTP headers.\r
   @param[in]   Headers          Array containing list of HTTP headers.\r
-  @param[in]   FieldName        Null terminated string which describes a field name. \r
+  @param[in]   FieldName        Null terminated string which describes a field name.\r
 \r
   @return    Pointer to the found header or NULL.\r
 \r
 \r
   @return    Pointer to the found header or NULL.\r
 \r
@@ -897,27 +892,6 @@ typedef struct {
   UINTN                         CurrentChunkParsedSize;\r
 } HTTP_BODY_PARSER;\r
 \r
   UINTN                         CurrentChunkParsedSize;\r
 } HTTP_BODY_PARSER;\r
 \r
-/**\r
-\r
-  Convert an Ascii char to its uppercase.\r
-\r
-  @param[in]       Char           Ascii character.\r
-\r
-  @return          Uppercase value of the input Char.\r
-\r
-**/\r
-CHAR8\r
-HttpIoCharToUpper (\r
-  IN      CHAR8                    Char\r
-  )\r
-{\r
-  if (Char >= 'a' && Char <= 'z') {\r
-    return  Char - ('a' - 'A');\r
-  }\r
-\r
-  return Char;\r
-}\r
-\r
 /**\r
   Convert an hexadecimal char to a value of type UINTN.\r
 \r
 /**\r
   Convert an hexadecimal char to a value of type UINTN.\r
 \r
@@ -935,7 +909,7 @@ HttpIoHexCharToUintn (
     return Char - '0';\r
   }\r
 \r
     return Char - '0';\r
   }\r
 \r
-  return (10 + HttpIoCharToUpper (Char) - 'A');\r
+  return (10 + AsciiCharToUpper (Char) - 'A');\r
 }\r
 \r
 /**\r
 }\r
 \r
 /**\r
@@ -974,7 +948,7 @@ HttpIoParseContentLengthHeader (
   @param[in]    Headers            Array containing list of HTTP headers.\r
 \r
   @return       The message is "chunked" transfer-coding (TRUE) or not (FALSE).\r
   @param[in]    Headers            Array containing list of HTTP headers.\r
 \r
   @return       The message is "chunked" transfer-coding (TRUE) or not (FALSE).\r
\r
+\r
 **/\r
 BOOLEAN\r
 HttpIoIsChunked (\r
 **/\r
 BOOLEAN\r
 HttpIoIsChunked (\r
@@ -1071,7 +1045,7 @@ HttpInitMsgParser (
 {\r
   EFI_STATUS            Status;\r
   HTTP_BODY_PARSER      *Parser;\r
 {\r
   EFI_STATUS            Status;\r
   HTTP_BODY_PARSER      *Parser;\r
-  \r
+\r
   if (HeaderCount != 0 && Headers == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   if (HeaderCount != 0 && Headers == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -1086,7 +1060,7 @@ HttpInitMsgParser (
   }\r
 \r
   Parser->State = BodyParserBodyStart;\r
   }\r
 \r
   Parser->State = BodyParserBodyStart;\r
-  \r
+\r
   //\r
   // Determine the message length according to RFC 2616.\r
   // 1. Check whether the message "MUST NOT" have a message-body.\r
   //\r
   // Determine the message length according to RFC 2616.\r
   // 1. Check whether the message "MUST NOT" have a message-body.\r
@@ -1107,7 +1081,7 @@ HttpInitMsgParser (
   // 4. Range header is not supported now, so we won't meet media type "multipart/byteranges".\r
   // 5. By server closing the connection\r
   //\r
   // 4. Range header is not supported now, so we won't meet media type "multipart/byteranges".\r
   // 5. By server closing the connection\r
   //\r
-  \r
+\r
   //\r
   // Set state to skip body parser if the message shouldn't have a message body.\r
   //\r
   //\r
   // Set state to skip body parser if the message shouldn't have a message body.\r
   //\r
@@ -1133,7 +1107,8 @@ HttpInitMsgParser (
 \r
   @retval EFI_SUCCESS                Successfully parse the message-body.\r
   @retval EFI_INVALID_PARAMETER      MsgParser is NULL or Body is NULL or BodyLength is 0.\r
 \r
   @retval EFI_SUCCESS                Successfully parse the message-body.\r
   @retval EFI_INVALID_PARAMETER      MsgParser is NULL or Body is NULL or BodyLength is 0.\r
-  @retval Others                     Operation aborted.\r
+  @retval EFI_ABORTED                Operation aborted.\r
+  @retval Other                      Error happened while parsing message body.\r
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1149,7 +1124,7 @@ HttpParseMessageBody (
   UINTN                 LengthForCallback;\r
   EFI_STATUS            Status;\r
   HTTP_BODY_PARSER      *Parser;\r
   UINTN                 LengthForCallback;\r
   EFI_STATUS            Status;\r
   HTTP_BODY_PARSER      *Parser;\r
-  \r
+\r
   if (BodyLength == 0 || Body == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
   if (BodyLength == 0 || Body == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -1158,17 +1133,17 @@ HttpParseMessageBody (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Parser = (HTTP_BODY_PARSER*) MsgParser;\r
+  Parser = (HTTP_BODY_PARSER *) MsgParser;\r
 \r
   if (Parser->IgnoreBody) {\r
     Parser->State = BodyParserComplete;\r
     if (Parser->Callback != NULL) {\r
       Status = Parser->Callback (\r
 \r
   if (Parser->IgnoreBody) {\r
     Parser->State = BodyParserComplete;\r
     if (Parser->Callback != NULL) {\r
       Status = Parser->Callback (\r
-                 BodyParseEventOnComplete,\r
-                 Body,\r
-                 0,\r
-                 Parser->Context\r
-                 );\r
+                         BodyParseEventOnComplete,\r
+                         Body,\r
+                         0,\r
+                         Parser->Context\r
+                         );\r
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
@@ -1193,18 +1168,18 @@ HttpParseMessageBody (
     switch (Parser->State) {\r
     case BodyParserStateMax:\r
       return EFI_ABORTED;\r
     switch (Parser->State) {\r
     case BodyParserStateMax:\r
       return EFI_ABORTED;\r
\r
+\r
     case BodyParserBodyIdentity:\r
       //\r
       // Identity transfer-coding, just notify user to save the body data.\r
       //\r
       if (Parser->Callback != NULL) {\r
         Status = Parser->Callback (\r
     case BodyParserBodyIdentity:\r
       //\r
       // Identity transfer-coding, just notify user to save the body data.\r
       //\r
       if (Parser->Callback != NULL) {\r
         Status = Parser->Callback (\r
-                   BodyParseEventOnData,\r
-                   Char,\r
-                   MIN (BodyLength, Parser->ContentLength - Parser->ParsedBodyLength),\r
-                   Parser->Context\r
-                   );\r
+                           BodyParseEventOnData,\r
+                           Char,\r
+                           MIN (BodyLength, Parser->ContentLength - Parser->ParsedBodyLength),\r
+                           Parser->Context\r
+                           );\r
         if (EFI_ERROR (Status)) {\r
           return Status;\r
         }\r
         if (EFI_ERROR (Status)) {\r
           return Status;\r
         }\r
@@ -1215,11 +1190,11 @@ HttpParseMessageBody (
         Parser->State = BodyParserComplete;\r
         if (Parser->Callback != NULL) {\r
           Status = Parser->Callback (\r
         Parser->State = BodyParserComplete;\r
         if (Parser->Callback != NULL) {\r
           Status = Parser->Callback (\r
-                     BodyParseEventOnComplete,\r
-                     Char,\r
-                     0,\r
-                     Parser->Context\r
-                     );\r
+                             BodyParseEventOnComplete,\r
+                             Char,\r
+                             0,\r
+                             Parser->Context\r
+                             );\r
           if (EFI_ERROR (Status)) {\r
             return Status;\r
           }\r
           if (EFI_ERROR (Status)) {\r
             return Status;\r
           }\r
@@ -1263,7 +1238,7 @@ HttpParseMessageBody (
        }\r
       Char++;\r
       break;\r
        }\r
       Char++;\r
       break;\r
-      \r
+\r
     case BodyParserChunkSizeEndCR:\r
       if (*Char != '\n') {\r
         Parser->State = BodyParserStateMax;\r
     case BodyParserChunkSizeEndCR:\r
       if (*Char != '\n') {\r
         Parser->State = BodyParserStateMax;\r
@@ -1272,7 +1247,7 @@ HttpParseMessageBody (
       Char++;\r
       if (Parser->CurrentChunkSize == 0) {\r
         //\r
       Char++;\r
       if (Parser->CurrentChunkSize == 0) {\r
         //\r
-        // The last chunk has been parsed and now assumed the state \r
+        // The last chunk has been parsed and now assumed the state\r
         // of HttpBodyParse is ParserLastCRLF. So it need to decide\r
         // whether the rest message is trailer or last CRLF in the next round.\r
         //\r
         // of HttpBodyParse is ParserLastCRLF. So it need to decide\r
         // whether the rest message is trailer or last CRLF in the next round.\r
         //\r
@@ -1283,10 +1258,10 @@ HttpParseMessageBody (
       Parser->State = BodyParserChunkDataStart;\r
       Parser->CurrentChunkParsedSize = 0;\r
       break;\r
       Parser->State = BodyParserChunkDataStart;\r
       Parser->CurrentChunkParsedSize = 0;\r
       break;\r
-      \r
+\r
     case BodyParserLastCRLF:\r
       //\r
     case BodyParserLastCRLF:\r
       //\r
-      // Judge the byte is belong to the Last CRLF or trailer, and then \r
+      // Judge the byte is belong to the Last CRLF or trailer, and then\r
       // configure the state of HttpBodyParse to corresponding state.\r
       //\r
       if (*Char == '\r') {\r
       // configure the state of HttpBodyParse to corresponding state.\r
       //\r
       if (*Char == '\r') {\r
@@ -1297,18 +1272,18 @@ HttpParseMessageBody (
         Parser->State = BodyParserTrailer;\r
         break;\r
       }\r
         Parser->State = BodyParserTrailer;\r
         break;\r
       }\r
-      \r
+\r
     case BodyParserLastCRLFEnd:\r
       if (*Char == '\n') {\r
         Parser->State = BodyParserComplete;\r
         Char++;\r
         if (Parser->Callback != NULL) {\r
           Status = Parser->Callback (\r
     case BodyParserLastCRLFEnd:\r
       if (*Char == '\n') {\r
         Parser->State = BodyParserComplete;\r
         Char++;\r
         if (Parser->Callback != NULL) {\r
           Status = Parser->Callback (\r
-                     BodyParseEventOnComplete,\r
-                     Char,\r
-                     0,\r
-                     Parser->Context\r
-                     );\r
+                             BodyParseEventOnComplete,\r
+                             Char,\r
+                             0,\r
+                             Parser->Context\r
+                             );\r
           if (EFI_ERROR (Status)) {\r
             return Status;\r
           }\r
           if (EFI_ERROR (Status)) {\r
             return Status;\r
           }\r
@@ -1318,13 +1293,13 @@ HttpParseMessageBody (
         Parser->State = BodyParserStateMax;\r
         break;\r
       }\r
         Parser->State = BodyParserStateMax;\r
         break;\r
       }\r
-      \r
+\r
     case BodyParserTrailer:\r
       if (*Char == '\r') {\r
         Parser->State = BodyParserChunkSizeEndCR;\r
       }\r
       Char++;\r
     case BodyParserTrailer:\r
       if (*Char == '\r') {\r
         Parser->State = BodyParserChunkSizeEndCR;\r
       }\r
       Char++;\r
-      break;      \r
+      break;\r
 \r
     case BodyParserChunkDataStart:\r
       //\r
 \r
     case BodyParserChunkDataStart:\r
       //\r
@@ -1334,11 +1309,11 @@ HttpParseMessageBody (
       LengthForCallback = MIN (Parser->CurrentChunkSize - Parser->CurrentChunkParsedSize, RemainderLengthInThis);\r
       if (Parser->Callback != NULL) {\r
         Status = Parser->Callback (\r
       LengthForCallback = MIN (Parser->CurrentChunkSize - Parser->CurrentChunkParsedSize, RemainderLengthInThis);\r
       if (Parser->Callback != NULL) {\r
         Status = Parser->Callback (\r
-                   BodyParseEventOnData,\r
-                   Char,\r
-                   LengthForCallback,\r
-                   Parser->Context\r
-                   );\r
+                           BodyParseEventOnData,\r
+                           Char,\r
+                           LengthForCallback,\r
+                           Parser->Context\r
+                           );\r
         if (EFI_ERROR (Status)) {\r
           return Status;\r
         }\r
         if (EFI_ERROR (Status)) {\r
           return Status;\r
         }\r
@@ -1348,7 +1323,7 @@ HttpParseMessageBody (
       Parser->CurrentChunkParsedSize += LengthForCallback;\r
       if (Parser->CurrentChunkParsedSize == Parser->CurrentChunkSize) {\r
         Parser->State = BodyParserChunkDataEnd;\r
       Parser->CurrentChunkParsedSize += LengthForCallback;\r
       if (Parser->CurrentChunkParsedSize == Parser->CurrentChunkSize) {\r
         Parser->State = BodyParserChunkDataEnd;\r
-      }           \r
+      }\r
       break;\r
 \r
     case BodyParserChunkDataEnd:\r
       break;\r
 \r
     case BodyParserChunkDataEnd:\r
@@ -1367,7 +1342,7 @@ HttpParseMessageBody (
       }\r
       Char++;\r
       Parser->State = BodyParserChunkSizeStart;\r
       }\r
       Char++;\r
       Parser->State = BodyParserChunkSizeStart;\r
-      break;     \r
+      break;\r
 \r
     default:\r
       break;\r
 \r
     default:\r
       break;\r
@@ -1399,7 +1374,11 @@ HttpIsMessageComplete (
 {\r
   HTTP_BODY_PARSER      *Parser;\r
 \r
 {\r
   HTTP_BODY_PARSER      *Parser;\r
 \r
-  Parser = (HTTP_BODY_PARSER*) MsgParser;\r
+  if (MsgParser == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
+  Parser = (HTTP_BODY_PARSER *) MsgParser;\r
 \r
   if (Parser->State == BodyParserComplete) {\r
     return TRUE;\r
 \r
   if (Parser->State == BodyParserComplete) {\r
     return TRUE;\r
@@ -1418,7 +1397,7 @@ HttpIsMessageComplete (
   @retval EFI_SUCCESS                Successfully to get the entity length.\r
   @retval EFI_NOT_READY              Entity length is not valid yet.\r
   @retval EFI_INVALID_PARAMETER      MsgParser is NULL or ContentLength is NULL.\r
   @retval EFI_SUCCESS                Successfully to get the entity length.\r
   @retval EFI_NOT_READY              Entity length is not valid yet.\r
   @retval EFI_INVALID_PARAMETER      MsgParser is NULL or ContentLength is NULL.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -1433,7 +1412,7 @@ HttpGetEntityLength (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  Parser = (HTTP_BODY_PARSER*) MsgParser;\r
+  Parser = (HTTP_BODY_PARSER *) MsgParser;\r
 \r
   if (!Parser->ContentLengthIsValid) {\r
     return EFI_NOT_READY;\r
 \r
   if (!Parser->ContentLengthIsValid) {\r
     return EFI_NOT_READY;\r
@@ -1447,7 +1426,7 @@ HttpGetEntityLength (
   Release the resource of the message parser.\r
 \r
   @param[in]    MsgParser            Pointer to the message parser.\r
   Release the resource of the message parser.\r
 \r
   @param[in]    MsgParser            Pointer to the message parser.\r
-  \r
+\r
 **/\r
 VOID\r
 EFIAPI\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -1471,7 +1450,6 @@ HttpFreeMsgParser (
 \r
 **/\r
 CHAR8 *\r
 \r
 **/\r
 CHAR8 *\r
-EFIAPI\r
 AsciiStrGetNextToken (\r
   IN CONST CHAR8 *String,\r
   IN       CHAR8 Separator\r
 AsciiStrGetNextToken (\r
   IN CONST CHAR8 *String,\r
   IN       CHAR8 Separator\r
@@ -1500,6 +1478,7 @@ AsciiStrGetNextToken (
 \r
 \r
   @retval EFI_SUCCESS             The FieldName and FieldValue are set into HttpHeader successfully.\r
 \r
 \r
   @retval EFI_SUCCESS             The FieldName and FieldValue are set into HttpHeader successfully.\r
+  @retval EFI_INVALID_PARAMETER   The parameter is invalid.\r
   @retval EFI_OUT_OF_RESOURCES    Failed to allocate resources.\r
 \r
 **/\r
   @retval EFI_OUT_OF_RESOURCES    Failed to allocate resources.\r
 \r
 **/\r
@@ -1514,6 +1493,10 @@ HttpSetFieldNameAndValue (
   UINTN                       FieldNameSize;\r
   UINTN                       FieldValueSize;\r
 \r
   UINTN                       FieldNameSize;\r
   UINTN                       FieldValueSize;\r
 \r
+  if (HttpHeader == NULL || FieldName == NULL || FieldValue == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
   if (HttpHeader->FieldName != NULL) {\r
     FreePool (HttpHeader->FieldName);\r
   }\r
   if (HttpHeader->FieldName != NULL) {\r
     FreePool (HttpHeader->FieldName);\r
   }\r
@@ -1587,6 +1570,18 @@ HttpGetFieldNameAndValue (
 \r
   //\r
   // Each header field consists of a name followed by a colon (":") and the field value.\r
 \r
   //\r
   // Each header field consists of a name followed by a colon (":") and the field value.\r
+  // The field value MAY be preceded by any amount of LWS, though a single SP is preferred.\r
+  //\r
+  // message-header = field-name ":" [ field-value ]\r
+  // field-name = token\r
+  // field-value = *( field-content | LWS )\r
+  //\r
+  // Note: "*(element)" allows any number element, including zero; "1*(element)" requires at least one element.\r
+  //       [element] means element is optional.\r
+  //       LWS  = [CRLF] 1*(SP|HT), it can be ' ' or '\t' or '\r\n ' or '\r\n\t'.\r
+  //       CRLF = '\r\n'.\r
+  //       SP   = ' '.\r
+  //       HT   = '\t' (Tab).\r
   //\r
   FieldNameStr = String;\r
   FieldValueStr = AsciiStrGetNextToken (FieldNameStr, ':');\r
   //\r
   FieldNameStr = String;\r
   FieldValueStr = AsciiStrGetNextToken (FieldNameStr, ':');\r
@@ -1595,51 +1590,70 @@ HttpGetFieldNameAndValue (
   }\r
 \r
   //\r
   }\r
 \r
   //\r
-  // Replace ':' with 0\r
+  // Replace ':' with 0, then FieldName has been retrived from String.\r
   //\r
   *(FieldValueStr - 1) = 0;\r
 \r
   //\r
   //\r
   *(FieldValueStr - 1) = 0;\r
 \r
   //\r
-  // The field value MAY be preceded by any amount of LWS, though a single SP is preferred.\r
-  // Note: LWS  = [CRLF] 1*(SP|HT), it can be '\r\n ' or '\r\n\t' or ' ' or '\t'.\r
-  //       CRLF = '\r\n'.\r
-  //       SP   = ' '.\r
-  //       HT   = '\t' (Tab).\r
+  // Handle FieldValueStr, skip all the preceded LWS.\r
   //\r
   while (TRUE) {\r
     if (*FieldValueStr == ' ' || *FieldValueStr == '\t') {\r
       //\r
   //\r
   while (TRUE) {\r
     if (*FieldValueStr == ' ' || *FieldValueStr == '\t') {\r
       //\r
-      // Boundary condition check. \r
+      // Boundary condition check.\r
       //\r
       //\r
-      if ((UINTN)EndofHeader - (UINTN)(FieldValueStr) < 1) {\r
-        return NULL;  \r
+      if ((UINTN) EndofHeader - (UINTN) FieldValueStr < 1) {\r
+        //\r
+        // Wrong String format!\r
+        //\r
+        return NULL;\r
       }\r
       }\r
-      \r
+\r
       FieldValueStr ++;\r
     } else if (*FieldValueStr == '\r') {\r
       //\r
       FieldValueStr ++;\r
     } else if (*FieldValueStr == '\r') {\r
       //\r
-      // Boundary condition check. \r
+      // Boundary condition check.\r
       //\r
       //\r
-      if ((UINTN)EndofHeader - (UINTN)(FieldValueStr) < 3) {\r
-        return NULL;  \r
+      if ((UINTN) EndofHeader - (UINTN) FieldValueStr < 3) {\r
+        //\r
+        // No more preceded LWS, so break here.\r
+        //\r
+        break;\r
       }\r
 \r
       }\r
 \r
-      if (*(FieldValueStr + 1) == '\n' && (*(FieldValueStr + 2) == ' ' || *(FieldValueStr + 2) == '\t')) {\r
-        FieldValueStr = FieldValueStr + 3;\r
+      if (*(FieldValueStr + 1) == '\n' ) {\r
+        if (*(FieldValueStr + 2) == ' ' || *(FieldValueStr + 2) == '\t') {\r
+          FieldValueStr = FieldValueStr + 3;\r
+        } else {\r
+          //\r
+          // No more preceded LWS, so break here.\r
+          //\r
+          break;\r
+        }\r
+      } else {\r
+        //\r
+        // Wrong String format!\r
+        //\r
+        return NULL;\r
       }\r
     } else {\r
       }\r
     } else {\r
+      //\r
+      // No more preceded LWS, so break here.\r
+      //\r
       break;\r
     }\r
   }\r
 \r
       break;\r
     }\r
   }\r
 \r
-  //\r
-  // Header fields can be extended over multiple lines by preceding each extra\r
-  // line with at least one SP or HT.\r
-  //\r
   StrPtr = FieldValueStr;\r
   do {\r
   StrPtr = FieldValueStr;\r
   do {\r
+    //\r
+    // Handle the LWS within the field value.\r
+    //\r
     StrPtr = AsciiStrGetNextToken (StrPtr, '\r');\r
     if (StrPtr == NULL || *StrPtr != '\n') {\r
     StrPtr = AsciiStrGetNextToken (StrPtr, '\r');\r
     if (StrPtr == NULL || *StrPtr != '\n') {\r
+      //\r
+      // Wrong String format!\r
+      //\r
       return NULL;\r
     }\r
 \r
       return NULL;\r
     }\r
 \r
@@ -1706,9 +1720,9 @@ HttpFreeHeaderFields (
                                   NULL if any error occured.\r
   @param[out]  RequestMsgSize     Size of the RequestMsg (in bytes).\r
 \r
                                   NULL if any error occured.\r
   @param[out]  RequestMsgSize     Size of the RequestMsg (in bytes).\r
 \r
-  @return EFI_SUCCESS             If HTTP request string was created successfully\r
+  @retval EFI_SUCCESS             If HTTP request string was created successfully.\r
   @retval EFI_OUT_OF_RESOURCES    Failed to allocate resources.\r
   @retval EFI_OUT_OF_RESOURCES    Failed to allocate resources.\r
-  @retval EFI_INVALID_PARAMETER   The input arguments are invalid\r
+  @retval EFI_INVALID_PARAMETER   The input arguments are invalid.\r
 \r
 **/\r
 EFI_STATUS\r
 \r
 **/\r
 EFI_STATUS\r
@@ -1731,10 +1745,6 @@ HttpGenRequestMessage (
   UINTN                            Index;\r
   EFI_HTTP_UTILITIES_PROTOCOL      *HttpUtilitiesProtocol;\r
 \r
   UINTN                            Index;\r
   EFI_HTTP_UTILITIES_PROTOCOL      *HttpUtilitiesProtocol;\r
 \r
-\r
-  ASSERT (Message != NULL);\r
-\r
-  *RequestMsg           = NULL;\r
   Status                = EFI_SUCCESS;\r
   HttpHdrSize           = 0;\r
   MsgSize               = 0;\r
   Status                = EFI_SUCCESS;\r
   HttpHdrSize           = 0;\r
   MsgSize               = 0;\r
@@ -1749,7 +1759,8 @@ HttpGenRequestMessage (
   // 3. If we do not have a Request, HeaderCount should be zero\r
   // 4. If we do not have Request and Headers, we need at least a message-body\r
   //\r
   // 3. If we do not have a Request, HeaderCount should be zero\r
   // 4. If we do not have Request and Headers, we need at least a message-body\r
   //\r
-  if ((Message->Data.Request != NULL && Url == NULL) ||\r
+  if ((Message == NULL || RequestMsg == NULL || RequestMsgSize == NULL) ||\r
+      (Message->Data.Request != NULL && Url == NULL) ||\r
       (Message->Data.Request != NULL && Message->HeaderCount == 0) ||\r
       (Message->Data.Request == NULL && Message->HeaderCount != 0) ||\r
       (Message->Data.Request == NULL && Message->HeaderCount == 0 && Message->BodyLength == 0)) {\r
       (Message->Data.Request != NULL && Message->HeaderCount == 0) ||\r
       (Message->Data.Request == NULL && Message->HeaderCount != 0) ||\r
       (Message->Data.Request == NULL && Message->HeaderCount == 0 && Message->BodyLength == 0)) {\r
@@ -1763,7 +1774,7 @@ HttpGenRequestMessage (
     Status = gBS->LocateProtocol (\r
                     &gEfiHttpUtilitiesProtocolGuid,\r
                     NULL,\r
     Status = gBS->LocateProtocol (\r
                     &gEfiHttpUtilitiesProtocolGuid,\r
                     NULL,\r
-                    (VOID **)&HttpUtilitiesProtocol\r
+                    (VOID **) &HttpUtilitiesProtocol\r
                     );\r
 \r
     if (EFI_ERROR (Status)) {\r
                     );\r
 \r
     if (EFI_ERROR (Status)) {\r
@@ -1787,20 +1798,18 @@ HttpGenRequestMessage (
     // Build raw HTTP Headers\r
     //\r
     Status = HttpUtilitiesProtocol->Build (\r
     // Build raw HTTP Headers\r
     //\r
     Status = HttpUtilitiesProtocol->Build (\r
-                HttpUtilitiesProtocol,\r
-                0,\r
-                NULL,\r
-                0,\r
-                NULL,\r
-                Message->HeaderCount,\r
-                AppendList,\r
-                &HttpHdrSize,\r
-                &HttpHdr\r
-                );\r
-\r
-    if (AppendList != NULL) {\r
-      FreePool (AppendList);\r
-    }\r
+                                      HttpUtilitiesProtocol,\r
+                                      0,\r
+                                      NULL,\r
+                                      0,\r
+                                      NULL,\r
+                                      Message->HeaderCount,\r
+                                      AppendList,\r
+                                      &HttpHdrSize,\r
+                                      &HttpHdr\r
+                                      );\r
+\r
+    FreePool (AppendList);\r
 \r
     if (EFI_ERROR (Status) || HttpHdr == NULL){\r
       return Status;\r
 \r
     if (EFI_ERROR (Status) || HttpHdr == NULL){\r
       return Status;\r
@@ -1830,6 +1839,7 @@ HttpGenRequestMessage (
   //\r
   // memory for the string that needs to be sent to TCP\r
   //\r
   //\r
   // memory for the string that needs to be sent to TCP\r
   //\r
+  *RequestMsg = NULL;\r
   *RequestMsg = AllocateZeroPool (MsgSize);\r
   if (*RequestMsg == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
   *RequestMsg = AllocateZeroPool (MsgSize);\r
   if (*RequestMsg == NULL) {\r
     Status = EFI_OUT_OF_RESOURCES;\r
@@ -2055,7 +2065,15 @@ HttpIsValidHttpHeader (
 {\r
   UINTN                       Index;\r
 \r
 {\r
   UINTN                       Index;\r
 \r
+  if (FieldName == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
   for (Index = 0; Index < DeleteCount; Index++) {\r
   for (Index = 0; Index < DeleteCount; Index++) {\r
+    if (DeleteList[Index] == NULL) {\r
+      continue;\r
+    }\r
+\r
     if (AsciiStrCmp (FieldName, DeleteList[Index]) == 0) {\r
       return FALSE;\r
     }\r
     if (AsciiStrCmp (FieldName, DeleteList[Index]) == 0) {\r
       return FALSE;\r
     }\r