]> git.proxmox.com Git - mirror_edk2.git/blobdiff - NetworkPkg/HttpBootDxe/HttpBootClient.c
NetworkPkg/HttpBootDxe: Add HTTP Boot Callback protocol support.
[mirror_edk2.git] / NetworkPkg / HttpBootDxe / HttpBootClient.c
index dd835c4f833a75e64dfe860c070e0fffa50f099c..68f5a49bad9ab609a3b6f34209b5cfd940c46ff3 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Implementation of the boot file download function.\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
 The full text of the license may be found at\r
@@ -167,18 +168,44 @@ HttpBootDhcp4ExtractUriInfo (
   // HttpOffer contains the boot file URL.\r
   //\r
   SelectOffer = &Private->OfferBuffer[SelectIndex].Dhcp4;\r
-  if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) || (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) {\r
-    HttpOffer = SelectOffer;\r
+  if (Private->FilePathUri == NULL) {\r
+    //\r
+    // In Corporate environment, we need a HttpOffer.\r
+    //\r
+    if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) || \r
+        (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns) ||\r
+        (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) {\r
+      HttpOffer = SelectOffer;\r
+    } else {\r
+      ASSERT (Private->SelectProxyType != HttpOfferTypeMax);\r
+      ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0];\r
+      HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp4;\r
+    }\r
+    Private->BootFileUriParser = HttpOffer->UriParser;\r
+    Private->BootFileUri = (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data;\r
   } else {\r
-    ASSERT (Private->SelectProxyType != HttpOfferTypeMax);\r
-    ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0];\r
-    HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp4;\r
+    //\r
+    // In Home environment the BootFileUri comes from the FilePath.\r
+    //\r
+    Private->BootFileUriParser = Private->FilePathUriParser;\r
+    Private->BootFileUri = Private->FilePathUri;\r
+  }\r
+\r
+  //\r
+  // Check the URI scheme.\r
+  //\r
+  Status = HttpBootCheckUriScheme (Private->BootFileUri);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "HttpBootDhcp4ExtractUriInfo: %r.\n", Status));\r
+    return Status;\r
   }\r
 \r
   //\r
   // Configure the default DNS server if server assigned.\r
   //\r
-  if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || (SelectOffer->OfferType == HttpOfferTypeDhcpDns)) {\r
+  if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || \r
+      (SelectOffer->OfferType == HttpOfferTypeDhcpDns) ||\r
+      (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) {\r
     Option = SelectOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_DNS_SERVER];\r
     ASSERT (Option != NULL);\r
     Status = HttpBootRegisterIp4Dns (\r
@@ -195,25 +222,17 @@ HttpBootDhcp4ExtractUriInfo (
   // Extract the port from URL, and use default HTTP port 80 if not provided.\r
   //\r
   Status = HttpUrlGetPort (\r
-             (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data,\r
-             HttpOffer->UriParser,\r
+             Private->BootFileUri,\r
+             Private->BootFileUriParser,\r
              &Private->Port\r
              );\r
   if (EFI_ERROR (Status) || Private->Port == 0) {\r
     Private->Port = 80;\r
   }\r
   \r
-  //\r
-  // Record the URI of boot file from the selected HTTP offer.\r
-  //\r
-  Private->BootFileUriParser = HttpOffer->UriParser;\r
-  Private->BootFileUri = (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP4_TAG_INDEX_BOOTFILE]->Data;\r
-\r
-  \r
   //\r
   // All boot informations are valid here.\r
   //\r
-  AsciiPrint ("\n  URI: %a", Private->BootFileUri);\r
 \r
   //\r
   // Update the device path to include the IP and boot URI information.\r
@@ -244,6 +263,7 @@ HttpBootDhcp6ExtractUriInfo (
   EFI_DHCP6_PACKET_OPTION         *Option;\r
   EFI_IPv6_ADDRESS                IpAddr;\r
   CHAR8                           *HostName;\r
+  UINTN                           HostNameSize;\r
   CHAR16                          *HostNameStr;\r
   EFI_STATUS                      Status;\r
 \r
@@ -259,12 +279,36 @@ HttpBootDhcp6ExtractUriInfo (
   // HttpOffer contains the boot file URL.\r
   //\r
   SelectOffer = &Private->OfferBuffer[SelectIndex].Dhcp6;\r
-  if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) || (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) {\r
-    HttpOffer = SelectOffer;\r
+  if (Private->FilePathUri == NULL) {\r
+    //\r
+    // In Corporate environment, we need a HttpOffer.\r
+    //\r
+    if ((SelectOffer->OfferType == HttpOfferTypeDhcpIpUri) ||\r
+        (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns) ||\r
+        (SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns)) {\r
+      HttpOffer = SelectOffer;\r
+    } else {\r
+      ASSERT (Private->SelectProxyType != HttpOfferTypeMax);\r
+      ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0];\r
+      HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp6;\r
+    }\r
+    Private->BootFileUriParser = HttpOffer->UriParser;\r
+    Private->BootFileUri = (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data;\r
   } else {\r
-    ASSERT (Private->SelectProxyType != HttpOfferTypeMax);\r
-    ProxyIndex = Private->OfferIndex[Private->SelectProxyType][0];\r
-    HttpOffer = &Private->OfferBuffer[ProxyIndex].Dhcp6;\r
+    //\r
+    // In Home environment the BootFileUri comes from the FilePath.\r
+    //\r
+    Private->BootFileUriParser = Private->FilePathUriParser;\r
+    Private->BootFileUri = Private->FilePathUri;\r
+  }\r
+\r
+  //\r
+  // Check the URI scheme.\r
+  //\r
+  Status = HttpBootCheckUriScheme (Private->BootFileUri);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_ERROR, "HttpBootDhcp6ExtractUriInfo: %r.\n", Status));\r
+    return Status;\r
   }\r
 \r
   //\r
@@ -274,11 +318,21 @@ HttpBootDhcp6ExtractUriInfo (
   if (EFI_ERROR (Status)) {\r
     return Status;\r
   }\r
+\r
+  //\r
+  // Register the IPv6 gateway address to the network device.\r
+  //\r
+  Status = HttpBootSetIp6Gateway (Private);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
   \r
   //\r
   // Configure the default DNS server if server assigned.\r
   //\r
-  if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || (SelectOffer->OfferType == HttpOfferTypeDhcpDns)) {\r
+  if ((SelectOffer->OfferType == HttpOfferTypeDhcpNameUriDns) || \r
+      (SelectOffer->OfferType == HttpOfferTypeDhcpDns) ||\r
+      (SelectOffer->OfferType == HttpOfferTypeDhcpIpUriDns)) {\r
     Option = SelectOffer->OptList[HTTP_BOOT_DHCP6_IDX_DNS_SERVER];\r
     ASSERT (Option != NULL);\r
     Status = HttpBootSetIp6Dns (\r
@@ -296,8 +350,8 @@ HttpBootDhcp6ExtractUriInfo (
   // whether can send message to HTTP Server Ip through the GateWay.\r
   //\r
   Status = HttpUrlGetIp6 (\r
-             (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data,\r
-             HttpOffer->UriParser,\r
+             Private->BootFileUri,\r
+             Private->BootFileUriParser,\r
              &IpAddr\r
              );\r
   \r
@@ -306,21 +360,22 @@ HttpBootDhcp6ExtractUriInfo (
     // The Http server address is expressed by Name Ip, so perform DNS resolution\r
     //\r
     Status = HttpUrlGetHostName (\r
-               (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data,\r
-               HttpOffer->UriParser,\r
+               Private->BootFileUri,\r
+               Private->BootFileUriParser,\r
                &HostName\r
                );\r
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
-    \r
-    HostNameStr = AllocateZeroPool ((AsciiStrLen (HostName) + 1) * sizeof (CHAR16));\r
+\r
+    HostNameSize = AsciiStrSize (HostName);\r
+    HostNameStr = AllocateZeroPool (HostNameSize * sizeof (CHAR16));\r
     if (HostNameStr == NULL) {\r
       Status = EFI_OUT_OF_RESOURCES;\r
       goto Error;\r
     }\r
     \r
-    AsciiStrToUnicodeStr (HostName, HostNameStr);\r
+    AsciiStrToUnicodeStrS (HostName, HostNameStr, HostNameSize);\r
     Status = HttpBootDns (Private, HostNameStr, &IpAddr);\r
     FreePool (HostNameStr);\r
     if (EFI_ERROR (Status)) {\r
@@ -328,39 +383,24 @@ HttpBootDhcp6ExtractUriInfo (
     }  \r
   } \r
   \r
-  CopyMem (&Private->ServerIp.v6, &IpAddr, sizeof (EFI_IPv6_ADDRESS));  \r
-    \r
-  //\r
-  // register the IPv6 gateway address to the network device.\r
-  //\r
-  Status = HttpBootSetIp6Gateway (Private);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
+  CopyMem (&Private->ServerIp.v6, &IpAddr, sizeof (EFI_IPv6_ADDRESS));\r
   \r
   //\r
   // Extract the port from URL, and use default HTTP port 80 if not provided.\r
   //\r
   Status = HttpUrlGetPort (\r
-             (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data,\r
-             HttpOffer->UriParser,\r
+             Private->BootFileUri,\r
+             Private->BootFileUriParser,\r
              &Private->Port\r
              );\r
   if (EFI_ERROR (Status) || Private->Port == 0) {\r
     Private->Port = 80;\r
   }\r
   \r
-  //\r
-  // Record the URI of boot file from the selected HTTP offer.\r
-  //\r
-  Private->BootFileUriParser = HttpOffer->UriParser;\r
-  Private->BootFileUri = (CHAR8*) HttpOffer->OptList[HTTP_BOOT_DHCP6_IDX_BOOT_FILE_URL]->Data;\r
-\r
-  \r
   //\r
   // All boot informations are valid here.\r
   //\r
-  AsciiPrint ("\n  URI: %a", Private->BootFileUri);\r
+\r
   //\r
   // Update the device path to include the IP and boot URI information.\r
   //\r
@@ -410,6 +450,40 @@ HttpBootDiscoverBootInfo (
   return Status;\r
 }\r
 \r
+/**\r
+  HttpIo Callback function which will be invoked when specified HTTP_IO_CALLBACK_EVENT happened.\r
+\r
+  @param[in]    EventType      Indicate the Event type that occurs in the current callback.\r
+  @param[in]    Message        HTTP message which will be send to, or just received from HTTP server.\r
+  @param[in]    Context        The Callback Context pointer.\r
+  \r
+  @retval EFI_SUCCESS          Tells the HttpIo to continue the HTTP process.\r
+  @retval Others               Tells the HttpIo to abort the current HTTP process.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+HttpBootHttpIoCallback (\r
+  IN  HTTP_IO_CALLBACK_EVENT    EventType,\r
+  IN  EFI_HTTP_MESSAGE          *Message,\r
+  IN  VOID                      *Context\r
+  )\r
+{\r
+  HTTP_BOOT_PRIVATE_DATA       *Private;\r
+  EFI_STATUS                   Status;\r
+  Private = (HTTP_BOOT_PRIVATE_DATA *) Context;\r
+  if (Private->HttpBootCallback != NULL) {\r
+    Status = Private->HttpBootCallback->Callback (\r
+               Private->HttpBootCallback,\r
+               EventType == HttpIoRequest ? HttpBootHttpRequest : HttpBootHttpResponse,\r
+               EventType == HttpIoRequest ? FALSE : TRUE,\r
+               sizeof (EFI_HTTP_MESSAGE),\r
+               (VOID *) Message\r
+               );\r
+    return Status;\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   Create a HttpIo instance for the file download.\r
 \r
@@ -426,6 +500,7 @@ HttpBootCreateHttpIo (
 {\r
   HTTP_IO_CONFIG_DATA          ConfigData;\r
   EFI_STATUS                   Status;\r
+  EFI_HANDLE                   ImageHandle;\r
 \r
   ASSERT (Private != NULL);\r
 \r
@@ -435,17 +510,21 @@ HttpBootCreateHttpIo (
     ConfigData.Config4.RequestTimeOut = HTTP_BOOT_REQUEST_TIMEOUT;\r
     IP4_COPY_ADDRESS (&ConfigData.Config4.LocalIp, &Private->StationIp.v4);\r
     IP4_COPY_ADDRESS (&ConfigData.Config4.SubnetMask, &Private->SubnetMask.v4);\r
+    ImageHandle = Private->Ip4Nic->ImageHandle;\r
   } else {\r
     ConfigData.Config6.HttpVersion    = HttpVersion11;\r
     ConfigData.Config6.RequestTimeOut = HTTP_BOOT_REQUEST_TIMEOUT;\r
     IP6_COPY_ADDRESS (&ConfigData.Config6.LocalIp, &Private->StationIp.v6);\r
+    ImageHandle = Private->Ip6Nic->ImageHandle;\r
   }\r
 \r
   Status = HttpIoCreateIo (\r
-             Private->Image,\r
+             ImageHandle,\r
              Private->Controller,\r
              Private->UsingIpv6 ? IP_VERSION_6 : IP_VERSION_4,\r
              &ConfigData,\r
+             HttpBootHttpIoCallback,\r
+             (VOID *) Private,\r
              &Private->HttpIo\r
              );\r
   if (EFI_ERROR (Status)) {\r
@@ -546,6 +625,7 @@ HttpBootFreeCacheList (
   @param[out]         Buffer          The memory buffer to transfer the file to. IF Buffer is NULL,\r
                                       then the size of the requested file is returned in\r
                                       BufferSize.\r
+  @param[out]         ImageType       The image type of the downloaded file.\r
 \r
   @retval EFI_SUCCESS          Successfully created.\r
   @retval Others               Failed to create HttpIo.\r
@@ -556,7 +636,8 @@ HttpBootGetFileFromCache (
   IN     HTTP_BOOT_PRIVATE_DATA   *Private,\r
   IN     CHAR16                   *Uri,\r
   IN OUT UINTN                    *BufferSize,\r
-     OUT UINT8                    *Buffer\r
+     OUT UINT8                    *Buffer,\r
+     OUT HTTP_BOOT_IMAGE_TYPE     *ImageType\r
   )\r
 {\r
   LIST_ENTRY                  *Entry;\r
@@ -565,14 +646,10 @@ HttpBootGetFileFromCache (
   HTTP_BOOT_ENTITY_DATA       *EntityData;\r
   UINTN                       CopyedSize;\r
   \r
-  if (Uri == NULL || BufferSize == 0 || Buffer == NULL) {\r
+  if (Uri == NULL || BufferSize == 0 || Buffer == NULL || ImageType == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  //\r
-  // Search file in the cache list, the cache entry will be released upon a successful\r
-  // match.\r
-  //\r
   NET_LIST_FOR_EACH (Entry, &Private->CacheList) {\r
     Cache = NET_LIST_USER_STRUCT (Entry, HTTP_BOOT_CACHE_CONTENT, Link);\r
     //\r
@@ -583,7 +660,12 @@ HttpBootGetFileFromCache (
         (StrCmp (Uri, Cache->RequestData->Url) == 0)) \r
     {\r
       //\r
-      // Hit cache, check buffer size.\r
+      // Hit in cache, record image type.\r
+      //\r
+      *ImageType  = Cache->ImageType;\r
+\r
+      //\r
+      // Check buffer size.\r
       //\r
       if (*BufferSize < Cache->EntityLength) {\r
         *BufferSize = Cache->EntityLength;\r
@@ -606,12 +688,6 @@ HttpBootGetFileFromCache (
         }\r
       }\r
       *BufferSize = CopyedSize;\r
-\r
-      //\r
-      // On success, free the cached data to release the memory resource.\r
-      //\r
-      RemoveEntryList (&Cache->Link);\r
-      HttpBootFreeCache (Cache);\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -645,6 +721,8 @@ HttpBootGetBootFileCallback (
 {\r
   HTTP_BOOT_CALLBACK_DATA      *CallbackData;\r
   HTTP_BOOT_ENTITY_DATA        *NewEntityData;\r
+  EFI_STATUS                   Status;\r
+  EFI_HTTP_BOOT_CALLBACK_PROTOCOL   *HttpBootCallback;\r
 \r
   //\r
   // We only care about the entity data.\r
@@ -654,6 +732,19 @@ HttpBootGetBootFileCallback (
   }\r
 \r
   CallbackData = (HTTP_BOOT_CALLBACK_DATA *) Context;\r
+  HttpBootCallback = CallbackData->Private->HttpBootCallback;\r
+  if (HttpBootCallback != NULL) {\r
+    Status = HttpBootCallback->Callback (\r
+               HttpBootCallback,\r
+               HttpBootHttpEntityBody,\r
+               TRUE,\r
+               (UINT32)Length,\r
+               Data\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
   //\r
   // Copy data if caller has provided a buffer.\r
   //\r
@@ -698,6 +789,7 @@ HttpBootGetBootFileCallback (
   @param[out]      Buffer          The memory buffer to transfer the file to. IF Buffer is NULL,\r
                                    then the size of the requested file is returned in\r
                                    BufferSize.\r
+  @param[out]      ImageType       The image type of the downloaded file.\r
 \r
   @retval EFI_SUCCESS              The file was loaded.\r
   @retval EFI_INVALID_PARAMETER    BufferSize is NULL or Buffer Size is not NULL but Buffer is NULL.\r
@@ -713,7 +805,8 @@ HttpBootGetBootFile (
   IN     HTTP_BOOT_PRIVATE_DATA   *Private,\r
   IN     BOOLEAN                  HeaderOnly,\r
   IN OUT UINTN                    *BufferSize,\r
-     OUT UINT8                    *Buffer\r
+     OUT UINT8                    *Buffer,\r
+     OUT HTTP_BOOT_IMAGE_TYPE     *ImageType\r
   )\r
 {\r
   EFI_STATUS                 Status;\r
@@ -729,6 +822,7 @@ HttpBootGetBootFile (
   UINTN                      ContentLength;\r
   HTTP_BOOT_CACHE_CONTENT    *Cache;\r
   UINT8                      *Block;\r
+  UINTN                      UrlSize;\r
   CHAR16                     *Url;\r
   BOOLEAN                    IdentityMode;\r
   UINTN                      ReceivedSize;\r
@@ -736,7 +830,7 @@ HttpBootGetBootFile (
   ASSERT (Private != NULL);\r
   ASSERT (Private->HttpCreated);\r
 \r
-  if (BufferSize == NULL) {\r
+  if (BufferSize == NULL || ImageType == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -747,13 +841,14 @@ HttpBootGetBootFile (
   //\r
   // First, check whether we already cached the requested Uri.\r
   //\r
-  Url = AllocatePool ((AsciiStrLen (Private->BootFileUri) + 1) * sizeof (CHAR16));\r
+  UrlSize = AsciiStrSize (Private->BootFileUri);\r
+  Url = AllocatePool (UrlSize * sizeof (CHAR16));\r
   if (Url == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-  AsciiStrToUnicodeStr (Private->BootFileUri, Url);\r
+  AsciiStrToUnicodeStrS (Private->BootFileUri, Url, UrlSize);\r
   if (!HeaderOnly) {\r
-    Status = HttpBootGetFileFromCache (Private, Url, BufferSize, Buffer);\r
+    Status = HttpBootGetFileFromCache (Private, Url, BufferSize, Buffer, ImageType);\r
     if (Status != EFI_NOT_FOUND) {\r
       FreePool (Url);\r
       return Status;\r
@@ -774,6 +869,7 @@ HttpBootGetBootFile (
       Status = EFI_OUT_OF_RESOURCES;\r
       goto ERROR_1;\r
     }\r
+    Cache->ImageType = ImageTypeMax;\r
     InitializeListHead (&Cache->EntityDataList);\r
   }\r
 \r
@@ -807,7 +903,7 @@ HttpBootGetBootFile (
   }\r
   Status = HttpBootSetHeader (\r
              HttpIoHeader,\r
-             HTTP_FIELD_NAME_HOST,\r
+             HTTP_HEADER_HOST,\r
              HostName\r
              );\r
   FreePool (HostName);\r
@@ -820,7 +916,7 @@ HttpBootGetBootFile (
   //\r
   Status = HttpBootSetHeader (\r
              HttpIoHeader,\r
-             HTTP_FIELD_NAME_ACCEPT,\r
+             HTTP_HEADER_ACCEPT,\r
              "*/*"\r
              );\r
   if (EFI_ERROR (Status)) {\r
@@ -832,7 +928,7 @@ HttpBootGetBootFile (
   //\r
   Status = HttpBootSetHeader (\r
              HttpIoHeader,\r
-             HTTP_FIELD_NAME_USER_AGENT,\r
+             HTTP_HEADER_USER_AGENT,\r
              HTTP_USER_AGENT_EFI_HTTP_BOOT\r
              );\r
   if (EFI_ERROR (Status)) {\r
@@ -849,11 +945,6 @@ HttpBootGetBootFile (
   }\r
   RequestData->Method = HeaderOnly ? HttpMethodHead : HttpMethodGet;\r
   RequestData->Url = Url;\r
-  if (RequestData->Url == NULL) {\r
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto ERROR_4;\r
-  }\r
-  AsciiStrToUnicodeStr (Private->BootFileUri, RequestData->Url);\r
 \r
   //\r
   // 2.3 Record the request info in a temp cache item.\r
@@ -904,11 +995,26 @@ HttpBootGetBootFile (
     goto ERROR_5;\r
   }\r
 \r
+  //\r
+  // Check the image type according to server's response.\r
+  //\r
+  Status = HttpBootCheckImageType (\r
+             Private->BootFileUri,\r
+             Private->BootFileUriParser,\r
+             ResponseData->HeaderCount,\r
+             ResponseData->Headers,\r
+             ImageType\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    goto ERROR_5;\r
+  }\r
+\r
   //\r
   // 3.2 Cache the response header.\r
   //\r
   if (Cache != NULL) {\r
     Cache->ResponseData = ResponseData;\r
+    Cache->ImageType = *ImageType;\r
   }\r
   \r
   //\r
@@ -921,6 +1027,7 @@ HttpBootGetBootFile (
   Context.Buffer     = Buffer;\r
   Context.BufferSize = *BufferSize;\r
   Context.Cache      = Cache;\r
+  Context.Private    = Private;\r
   Status = HttpInitMsgParser (\r
              HeaderOnly? HttpMethodHead : HttpMethodGet,\r
              ResponseData->Response.StatusCode,\r
@@ -969,10 +1076,25 @@ HttpBootGetBootFile (
                    FALSE,\r
                    &ResponseBody\r
                    );\r
-        if (EFI_ERROR (Status)) {\r
+        if (EFI_ERROR (Status) || EFI_ERROR (ResponseBody.Status)) {\r
+          if (EFI_ERROR (ResponseBody.Status)) {\r
+            Status = ResponseBody.Status;\r
+          }\r
           goto ERROR_6;\r
         }\r
         ReceivedSize += ResponseBody.BodyLength;\r
+        if (Private->HttpBootCallback != NULL) {\r
+          Status = Private->HttpBootCallback->Callback (\r
+                     Private->HttpBootCallback,\r
+                     HttpBootHttpEntityBody,\r
+                     TRUE,\r
+                     (UINT32)ResponseBody.BodyLength,\r
+                     ResponseBody.Body\r
+                     );\r
+          if (EFI_ERROR (Status)) {\r
+            goto ERROR_6;\r
+          }\r
+        }\r
       }\r
     } else {\r
       //\r
@@ -1006,7 +1128,10 @@ HttpBootGetBootFile (
                    FALSE,\r
                    &ResponseBody\r
                    );\r
-        if (EFI_ERROR (Status)) {\r
+        if (EFI_ERROR (Status) || EFI_ERROR (ResponseBody.Status)) {\r
+          if (EFI_ERROR (ResponseBody.Status)) {\r
+            Status = ResponseBody.Status;\r
+          }\r
           goto ERROR_6;\r
         }\r
 \r
@@ -1035,6 +1160,8 @@ HttpBootGetBootFile (
 \r
   if (*BufferSize < ContentLength) {\r
     Status = EFI_BUFFER_TOO_SMALL;\r
+  } else {\r
+    Status = EFI_SUCCESS;\r
   }\r
   *BufferSize = ContentLength;\r
 \r
@@ -1050,7 +1177,7 @@ HttpBootGetBootFile (
     HttpFreeMsgParser (Parser);\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
   \r
 ERROR_6:\r
   if (Parser != NULL) {\r
@@ -1082,3 +1209,4 @@ ERROR_1:
 \r
   return Status;\r
 }\r
+\r