]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: Add codes to support trailer parse in HttpLib.
authorZhang Lubo <lubo.zhang@intel.com>
Wed, 12 Aug 2015 12:44:31 +0000 (12:44 +0000)
committerluobozhang <luobozhang@Edk2>
Wed, 12 Aug 2015 12:44:31 +0000 (12:44 +0000)
In HttpLib, the Event BodyParseComplete should return to the
callback function when the whole message body has been parsed
including the trailer if it has.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Zhang Lubo <lubo.zhang@intel.com>
Reviewed-by: Ye Ting <ting.ye@intel.com>
Reviewed-by: Wu Jiaxin <jiaxin.wu@intel.com>
Reviewed-by: Fu Siyuan <siyuan.fu@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18213 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Library/DxeHttpLib/DxeHttpLib.c

index 3b0d9c96045bfc061bfc71ba7b47aad27f5553bf..4a76bff7801f01ca724febb087f3ceb1f27b5af1 100644 (file)
@@ -818,6 +818,9 @@ typedef enum {
   BodyParserChunkDataStart,
   BodyParserChunkDataEnd,
   BodyParserChunkDataEndCR,
+  BodyParserTrailer,
+  BodyParserLastCRLF,
+  BodyParserLastCRLFEnd,
   BodyParserComplete,
   BodyParserStateMax
 } HTTP_BODY_PARSE_STATE;
@@ -1212,21 +1215,52 @@ HttpParseMessageBody (
         Parser->State = BodyParserStateMax;
         break;
       }
-      Parser->State = BodyParserChunkDataStart;
-      Parser->CurrentChunkParsedSize = 0;
       Char++;
-      break;
-
-    case BodyParserChunkDataStart:
       if (Parser->CurrentChunkSize == 0) {
         //
-        // This is the last chunk, the trailer header is unsupported.
+        // The last chunk has been parsed and now assumed the state 
+        // of HttpBodyParse is ParserLastCRLF. So it need to decide
+        // whether the rest message is trailer or last CRLF in the next round.
         //
         Parser->ContentLengthIsValid = TRUE;
+        Parser->State = BodyParserLastCRLF;
+        break;
+      }
+      Parser->State = BodyParserChunkDataStart;
+      Parser->CurrentChunkParsedSize = 0;
+      break;
+      
+    case BodyParserLastCRLF:
+      //
+      // Judge the byte is belong to the Last CRLF or trailer, and then 
+      // configure the state of HttpBodyParse to corresponding state.
+      //
+      if (*Char == '\r') {
+        Char++;
+        Parser->State = BodyParserLastCRLFEnd;
+        break;
+      } else {
+        Parser->State = BodyParserTrailer;
+        break;
+      }
+      
+    case BodyParserLastCRLFEnd:
+      if (*Char == '\n') {
         Parser->State = BodyParserComplete;
         break;
+      } else {
+        Parser->State = BodyParserStateMax;
+        break;
       }
       
+    case BodyParserTrailer:
+      if (*Char == '\r') {
+        Parser->State = BodyParserChunkSizeEndCR;
+      }
+      Char++;
+      break;      
+
+    case BodyParserChunkDataStart:
       //
       // First byte of chunk-data, the chunk data also might be truncated.
       //