2 This library is used to share code between UEFI network stack modules.
3 It provides the helper routines to parse the HTTP message byte stream.
5 Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>
6 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at<BR>
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "DxeHttpLib.h"
22 Decode a percent-encoded URI component to the ASCII character.
24 Decode the input component in Buffer according to RFC 3986. The caller is responsible to make
25 sure ResultBuffer points to a buffer with size equal or greater than ((AsciiStrSize (Buffer))
28 @param[in] Buffer The pointer to a percent-encoded URI component.
29 @param[in] BufferLength Length of Buffer in bytes.
30 @param[out] ResultBuffer Point to the buffer to store the decode result.
31 @param[out] ResultLength Length of decoded string in ResultBuffer in bytes.
33 @retval EFI_SUCCESS Successfully decoded the URI.
34 @retval EFI_INVALID_PARAMETER Buffer is not a valid percent-encoded string.
41 IN UINT32 BufferLength
,
42 OUT CHAR8
*ResultBuffer
,
43 OUT UINT32
*ResultLength
50 if (Buffer
== NULL
|| BufferLength
== 0 || ResultBuffer
== NULL
) {
51 return EFI_INVALID_PARAMETER
;
57 while (Index
< BufferLength
) {
58 if (Buffer
[Index
] == '%') {
59 if (!NET_IS_HEX_CHAR (Buffer
[Index
+1]) || !NET_IS_HEX_CHAR (Buffer
[Index
+2])) {
60 return EFI_INVALID_PARAMETER
;
62 HexStr
[0] = Buffer
[Index
+1];
63 HexStr
[1] = Buffer
[Index
+2];
64 ResultBuffer
[Offset
] = (CHAR8
) AsciiStrHexToUintn (HexStr
);
67 ResultBuffer
[Offset
] = Buffer
[Index
];
73 *ResultLength
= (UINT32
) Offset
;
79 This function return the updated state according to the input state and next character of
82 @param[in] Char Next character.
83 @param[in] State Current value of the parser state machine.
84 @param[in] IsRightBracket TRUE if there is an sign ']' in the authority component and
85 indicates the next part is ':' before Port.
87 @return Updated state value.
90 NetHttpParseAuthorityChar (
92 IN HTTP_URL_PARSE_STATE State
,
93 IN BOOLEAN
*IsRightBracket
99 // The authority component is preceded by a double slash ("//") and is
100 // terminated by the next slash ("/"), question mark ("?"), or number
101 // sign ("#") character, or by the end of the URI.
103 if (Char
== ' ' || Char
== '\r' || Char
== '\n') {
104 return UrlParserStateMax
;
108 // authority = [ userinfo "@" ] host [ ":" port ]
111 case UrlParserUserInfo
:
113 return UrlParserHostStart
;
118 case UrlParserHostStart
:
120 return UrlParserHostIpv6
;
124 return UrlParserPortStart
;
127 return UrlParserHost
;
129 case UrlParserHostIpv6
:
131 *IsRightBracket
= TRUE
;
134 if (Char
== ':' && *IsRightBracket
) {
135 return UrlParserPortStart
;
137 return UrlParserHostIpv6
;
140 case UrlParserPortStart
:
141 return UrlParserPort
;
151 This function parse the authority component of the input URL and update the parser.
153 @param[in] Url The pointer to a HTTP URL string.
154 @param[in] FoundAt TRUE if there is an at sign ('@') in the authority component.
155 @param[in, out] UrlParser Pointer to the buffer of the parse result.
157 @retval EFI_SUCCESS Successfully parse the authority.
158 @retval Other Error happened.
162 NetHttpParseAuthority (
165 IN OUT HTTP_URL_PARSER
*UrlParser
171 HTTP_URL_PARSE_STATE State
;
174 BOOLEAN IsrightBracket
;
176 ASSERT ((UrlParser
->FieldBitMap
& BIT (HTTP_URI_FIELD_AUTHORITY
)) != 0);
179 // authority = [ userinfo "@" ] host [ ":" port ]
182 State
= UrlParserUserInfo
;
184 State
= UrlParserHost
;
187 IsrightBracket
= FALSE
;
188 Field
= HTTP_URI_FIELD_MAX
;
190 Authority
= Url
+ UrlParser
->FieldData
[HTTP_URI_FIELD_AUTHORITY
].Offset
;
191 Length
= UrlParser
->FieldData
[HTTP_URI_FIELD_AUTHORITY
].Length
;
192 for (Char
= Authority
; Char
< Authority
+ Length
; Char
++) {
193 State
= NetHttpParseAuthorityChar (*Char
, State
, &IsrightBracket
);
195 case UrlParserStateMax
:
196 return EFI_INVALID_PARAMETER
;
198 case UrlParserHostStart
:
199 case UrlParserPortStart
:
202 case UrlParserUserInfo
:
203 Field
= HTTP_URI_FIELD_USERINFO
;
207 Field
= HTTP_URI_FIELD_HOST
;
210 case UrlParserHostIpv6
:
211 Field
= HTTP_URI_FIELD_HOST
;
215 Field
= HTTP_URI_FIELD_PORT
;
223 // Field not changed, count the length.
225 ASSERT (Field
< HTTP_URI_FIELD_MAX
);
226 if (Field
== OldField
) {
227 UrlParser
->FieldData
[Field
].Length
++;
234 UrlParser
->FieldBitMap
|= BIT (Field
);
235 UrlParser
->FieldData
[Field
].Offset
= (UINT32
) (Char
- Url
);
236 UrlParser
->FieldData
[Field
].Length
= 1;
244 This function return the updated state according to the input state and next character of a URL.
246 @param[in] Char Next character.
247 @param[in] State Current value of the parser state machine.
249 @return Updated state value.
253 NetHttpParseUrlChar (
255 IN HTTP_URL_PARSE_STATE State
258 if (Char
== ' ' || Char
== '\r' || Char
== '\n') {
259 return UrlParserStateMax
;
263 // http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]
265 // Request-URI = "*" | absolute-URI | path-absolute | authority
267 // absolute-URI = scheme ":" hier-part [ "?" query ]
268 // path-absolute = "/" [ segment-nz *( "/" segment ) ]
269 // authority = [ userinfo "@" ] host [ ":" port ]
272 case UrlParserUrlStart
:
273 if (Char
== '*' || Char
== '/') {
274 return UrlParserPath
;
276 return UrlParserScheme
;
278 case UrlParserScheme
:
280 return UrlParserSchemeColon
;
284 case UrlParserSchemeColon
:
286 return UrlParserSchemeColonSlash
;
290 case UrlParserSchemeColonSlash
:
292 return UrlParserSchemeColonSlashSlash
;
296 case UrlParserAtInAuthority
:
298 return UrlParserStateMax
;
301 case UrlParserAuthority
:
302 case UrlParserSchemeColonSlashSlash
:
304 return UrlParserAtInAuthority
;
307 return UrlParserPath
;
310 return UrlParserQueryStart
;
313 return UrlParserFragmentStart
;
315 return UrlParserAuthority
;
319 return UrlParserQueryStart
;
322 return UrlParserFragmentStart
;
327 case UrlParserQueryStart
:
329 return UrlParserFragmentStart
;
331 return UrlParserQuery
;
333 case UrlParserFragmentStart
:
334 return UrlParserFragment
;
343 Create a URL parser for the input URL string.
345 This function will parse and dereference the input HTTP URL into it components. The original
346 content of the URL won't be modified and the result will be returned in UrlParser, which can
347 be used in other functions like NetHttpUrlGetHostName().
349 @param[in] Url The pointer to a HTTP URL string.
350 @param[in] Length Length of Url in bytes.
351 @param[in] IsConnectMethod Whether the Url is used in HTTP CONNECT method or not.
352 @param[out] UrlParser Pointer to the returned buffer to store the parse result.
354 @retval EFI_SUCCESS Successfully dereferenced the HTTP URL.
355 @retval EFI_INVALID_PARAMETER UrlParser is NULL or Url is not a valid HTTP URL.
356 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
364 IN BOOLEAN IsConnectMethod
,
368 HTTP_URL_PARSE_STATE State
;
374 HTTP_URL_PARSER
*Parser
;
376 if (Url
== NULL
|| Length
== 0 || UrlParser
== NULL
) {
377 return EFI_INVALID_PARAMETER
;
380 Parser
= AllocateZeroPool (sizeof (HTTP_URL_PARSER
));
381 if (Parser
== NULL
) {
382 return EFI_OUT_OF_RESOURCES
;
385 if (IsConnectMethod
) {
387 // According to RFC 2616, the authority form is only used by the CONNECT method.
389 State
= UrlParserAuthority
;
391 State
= UrlParserUrlStart
;
394 Field
= HTTP_URI_FIELD_MAX
;
397 for (Char
= Url
; Char
< Url
+ Length
; Char
++) {
399 // Update state machine according to next char.
401 State
= NetHttpParseUrlChar (*Char
, State
);
404 case UrlParserStateMax
:
405 return EFI_INVALID_PARAMETER
;
407 case UrlParserSchemeColon
:
408 case UrlParserSchemeColonSlash
:
409 case UrlParserSchemeColonSlashSlash
:
410 case UrlParserQueryStart
:
411 case UrlParserFragmentStart
:
413 // Skip all the delimiting char: "://" "?" "@"
417 case UrlParserScheme
:
418 Field
= HTTP_URI_FIELD_SCHEME
;
421 case UrlParserAtInAuthority
:
423 case UrlParserAuthority
:
424 Field
= HTTP_URI_FIELD_AUTHORITY
;
428 Field
= HTTP_URI_FIELD_PATH
;
432 Field
= HTTP_URI_FIELD_QUERY
;
435 case UrlParserFragment
:
436 Field
= HTTP_URI_FIELD_FRAGMENT
;
444 // Field not changed, count the length.
446 ASSERT (Field
< HTTP_URI_FIELD_MAX
);
447 if (Field
== OldField
) {
448 Parser
->FieldData
[Field
].Length
++;
455 Parser
->FieldBitMap
|= BIT (Field
);
456 Parser
->FieldData
[Field
].Offset
= (UINT32
) (Char
- Url
);
457 Parser
->FieldData
[Field
].Length
= 1;
462 // If has authority component, continue to parse the username, host and port.
464 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_AUTHORITY
)) != 0) {
465 Status
= NetHttpParseAuthority (Url
, FoundAt
, Parser
);
466 if (EFI_ERROR (Status
)) {
476 Get the Hostname from a HTTP URL.
478 This function will return the HostName according to the Url and previous parse result ,and
479 it is the caller's responsibility to free the buffer returned in *HostName.
481 @param[in] Url The pointer to a HTTP URL string.
482 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
483 @param[out] HostName Pointer to a buffer to store the HostName.
485 @retval EFI_SUCCESS Successfully get the required component.
486 @retval EFI_INVALID_PARAMETER Uri is NULL or HostName is NULL or UrlParser is invalid.
487 @retval EFI_NOT_FOUND No hostName component in the URL.
488 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
502 HTTP_URL_PARSER
*Parser
;
504 if (Url
== NULL
|| UrlParser
== NULL
|| HostName
== NULL
) {
505 return EFI_INVALID_PARAMETER
;
508 Parser
= (HTTP_URL_PARSER
*) UrlParser
;
510 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_HOST
)) == 0) {
511 return EFI_NOT_FOUND
;
514 Name
= AllocatePool (Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Length
+ 1);
516 return EFI_OUT_OF_RESOURCES
;
519 Status
= UriPercentDecode (
520 Url
+ Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Offset
,
521 Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Length
,
525 if (EFI_ERROR (Status
)) {
529 Name
[ResultLength
] = '\0';
536 Get the IPv4 address from a HTTP URL.
538 This function will return the IPv4 address according to the Url and previous parse result.
540 @param[in] Url The pointer to a HTTP URL string.
541 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
542 @param[out] Ip4Address Pointer to a buffer to store the IP address.
544 @retval EFI_SUCCESS Successfully get the required component.
545 @retval EFI_INVALID_PARAMETER Uri is NULL or Ip4Address is NULL or UrlParser is invalid.
546 @retval EFI_NOT_FOUND No IPv4 address component in the URL.
547 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
555 OUT EFI_IPv4_ADDRESS
*Ip4Address
561 HTTP_URL_PARSER
*Parser
;
563 if (Url
== NULL
|| UrlParser
== NULL
|| Ip4Address
== NULL
) {
564 return EFI_INVALID_PARAMETER
;
567 Parser
= (HTTP_URL_PARSER
*) UrlParser
;
569 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_HOST
)) == 0) {
570 return EFI_INVALID_PARAMETER
;
573 Ip4String
= AllocatePool (Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Length
+ 1);
574 if (Ip4String
== NULL
) {
575 return EFI_OUT_OF_RESOURCES
;
578 Status
= UriPercentDecode (
579 Url
+ Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Offset
,
580 Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Length
,
584 if (EFI_ERROR (Status
)) {
588 Ip4String
[ResultLength
] = '\0';
589 Status
= NetLibAsciiStrToIp4 (Ip4String
, Ip4Address
);
590 FreePool (Ip4String
);
596 Get the IPv6 address from a HTTP URL.
598 This function will return the IPv6 address according to the Url and previous parse result.
600 @param[in] Url The pointer to a HTTP URL string.
601 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
602 @param[out] Ip6Address Pointer to a buffer to store the IP address.
604 @retval EFI_SUCCESS Successfully get the required component.
605 @retval EFI_INVALID_PARAMETER Uri is NULL or Ip6Address is NULL or UrlParser is invalid.
606 @retval EFI_NOT_FOUND No IPv6 address component in the URL.
607 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
615 OUT EFI_IPv6_ADDRESS
*Ip6Address
623 HTTP_URL_PARSER
*Parser
;
625 if (Url
== NULL
|| UrlParser
== NULL
|| Ip6Address
== NULL
) {
626 return EFI_INVALID_PARAMETER
;
629 Parser
= (HTTP_URL_PARSER
*) UrlParser
;
631 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_HOST
)) == 0) {
632 return EFI_INVALID_PARAMETER
;
636 // IP-literal = "[" ( IPv6address / IPvFuture ) "]"
638 Length
= Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Length
;
640 return EFI_INVALID_PARAMETER
;
643 Ptr
= Url
+ Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Offset
;
644 if ((Ptr
[0] != '[') || (Ptr
[Length
- 1] != ']')) {
645 return EFI_INVALID_PARAMETER
;
648 Ip6String
= AllocatePool (Length
);
649 if (Ip6String
== NULL
) {
650 return EFI_OUT_OF_RESOURCES
;
653 Status
= UriPercentDecode (
659 if (EFI_ERROR (Status
)) {
663 Ip6String
[ResultLength
] = '\0';
664 Status
= NetLibAsciiStrToIp6 (Ip6String
, Ip6Address
);
665 FreePool (Ip6String
);
671 Get the port number from a HTTP URL.
673 This function will return the port number according to the Url and previous parse result.
675 @param[in] Url The pointer to a HTTP URL string.
676 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
677 @param[out] Port Pointer to a buffer to store the port number.
679 @retval EFI_SUCCESS Successfully get the required component.
680 @retval EFI_INVALID_PARAMETER Uri is NULL or Port is NULL or UrlParser is invalid.
681 @retval EFI_NOT_FOUND No port number in the URL.
682 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
696 HTTP_URL_PARSER
*Parser
;
698 if (Url
== NULL
|| UrlParser
== NULL
|| Port
== NULL
) {
699 return EFI_INVALID_PARAMETER
;
702 Parser
= (HTTP_URL_PARSER
*) UrlParser
;
704 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_PORT
)) == 0) {
705 return EFI_INVALID_PARAMETER
;
708 PortString
= AllocatePool (Parser
->FieldData
[HTTP_URI_FIELD_PORT
].Length
+ 1);
709 if (PortString
== NULL
) {
710 return EFI_OUT_OF_RESOURCES
;
713 Status
= UriPercentDecode (
714 Url
+ Parser
->FieldData
[HTTP_URI_FIELD_PORT
].Offset
,
715 Parser
->FieldData
[HTTP_URI_FIELD_PORT
].Length
,
719 if (EFI_ERROR (Status
)) {
723 PortString
[ResultLength
] = '\0';
725 return AsciiStrDecimalToUintnS (Url
+ Parser
->FieldData
[HTTP_URI_FIELD_PORT
].Offset
, (CHAR8
**) NULL
, (UINTN
*) Port
);
729 Get the Path from a HTTP URL.
731 This function will return the Path according to the Url and previous parse result,and
732 it is the caller's responsibility to free the buffer returned in *Path.
734 @param[in] Url The pointer to a HTTP URL string.
735 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
736 @param[out] Path Pointer to a buffer to store the Path.
738 @retval EFI_SUCCESS Successfully get the required component.
739 @retval EFI_INVALID_PARAMETER Uri is NULL or HostName is NULL or UrlParser is invalid.
740 @retval EFI_NOT_FOUND No hostName component in the URL.
741 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
755 HTTP_URL_PARSER
*Parser
;
757 if (Url
== NULL
|| UrlParser
== NULL
|| Path
== NULL
) {
758 return EFI_INVALID_PARAMETER
;
761 Parser
= (HTTP_URL_PARSER
*) UrlParser
;
763 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_PATH
)) == 0) {
764 return EFI_NOT_FOUND
;
767 PathStr
= AllocatePool (Parser
->FieldData
[HTTP_URI_FIELD_PATH
].Length
+ 1);
768 if (PathStr
== NULL
) {
769 return EFI_OUT_OF_RESOURCES
;
772 Status
= UriPercentDecode (
773 Url
+ Parser
->FieldData
[HTTP_URI_FIELD_PATH
].Offset
,
774 Parser
->FieldData
[HTTP_URI_FIELD_PATH
].Length
,
778 if (EFI_ERROR (Status
)) {
782 PathStr
[ResultLength
] = '\0';
788 Release the resource of the URL parser.
790 @param[in] UrlParser Pointer to the parser.
799 FreePool (UrlParser
);
803 Find a specified header field according to the field name.
805 @param[in] HeaderCount Number of HTTP header structures in Headers list.
806 @param[in] Headers Array containing list of HTTP headers.
807 @param[in] FieldName Null terminated string which describes a field name.
809 @return Pointer to the found header or NULL.
815 IN UINTN HeaderCount
,
816 IN EFI_HTTP_HEADER
*Headers
,
822 if (HeaderCount
== 0 || Headers
== NULL
|| FieldName
== NULL
) {
826 for (Index
= 0; Index
< HeaderCount
; Index
++){
828 // Field names are case-insensitive (RFC 2616).
830 if (AsciiStriCmp (Headers
[Index
].FieldName
, FieldName
) == 0) {
831 return &Headers
[Index
];
839 BodyParserBodyIdentity
,
840 BodyParserChunkSizeStart
,
842 BodyParserChunkSizeEndCR
,
843 BodyParserChunkExtStart
,
844 BodyParserChunkDataStart
,
845 BodyParserChunkDataEnd
,
846 BodyParserChunkDataEndCR
,
849 BodyParserLastCRLFEnd
,
852 } HTTP_BODY_PARSE_STATE
;
855 BOOLEAN IgnoreBody
; // "MUST NOT" include a message-body
856 BOOLEAN IsChunked
; // "chunked" transfer-coding.
857 BOOLEAN ContentLengthIsValid
;
858 UINTN ContentLength
; // Entity length (not the message-body length), invalid until ContentLengthIsValid is TRUE
860 HTTP_BODY_PARSER_CALLBACK Callback
;
862 UINTN ParsedBodyLength
;
863 HTTP_BODY_PARSE_STATE State
;
864 UINTN CurrentChunkSize
;
865 UINTN CurrentChunkParsedSize
;
870 Convert an Ascii char to its uppercase.
872 @param[in] Char Ascii character.
874 @return Uppercase value of the input Char.
882 if (Char
>= 'a' && Char
<= 'z') {
883 return Char
- ('a' - 'A');
890 Convert an hexadecimal char to a value of type UINTN.
892 @param[in] Char Ascii character.
894 @return Value translated from Char.
898 HttpIoHexCharToUintn (
902 if (Char
>= '0' && Char
<= '9') {
906 return (10 + HttpIoCharToUpper (Char
) - 'A');
910 Get the value of the content length if there is a "Content-Length" header.
912 @param[in] HeaderCount Number of HTTP header structures in Headers.
913 @param[in] Headers Array containing list of HTTP headers.
914 @param[out] ContentLength Pointer to save the value of the content length.
916 @retval EFI_SUCCESS Successfully get the content length.
917 @retval EFI_NOT_FOUND No "Content-Length" header in the Headers.
921 HttpIoParseContentLengthHeader (
922 IN UINTN HeaderCount
,
923 IN EFI_HTTP_HEADER
*Headers
,
924 OUT UINTN
*ContentLength
927 EFI_HTTP_HEADER
*Header
;
929 Header
= HttpFindHeader (HeaderCount
, Headers
, HTTP_HEADER_CONTENT_LENGTH
);
930 if (Header
== NULL
) {
931 return EFI_NOT_FOUND
;
934 return AsciiStrDecimalToUintnS (Header
->FieldValue
, (CHAR8
**) NULL
, ContentLength
);
939 Check whether the HTTP message is using the "chunked" transfer-coding.
941 @param[in] HeaderCount Number of HTTP header structures in Headers.
942 @param[in] Headers Array containing list of HTTP headers.
944 @return The message is "chunked" transfer-coding (TRUE) or not (FALSE).
949 IN UINTN HeaderCount
,
950 IN EFI_HTTP_HEADER
*Headers
953 EFI_HTTP_HEADER
*Header
;
956 Header
= HttpFindHeader (HeaderCount
, Headers
, HTTP_HEADER_TRANSFER_ENCODING
);
957 if (Header
== NULL
) {
961 if (AsciiStriCmp (Header
->FieldValue
, "identity") != 0) {
969 Check whether the HTTP message should have a message-body.
971 @param[in] Method The HTTP method (e.g. GET, POST) for this HTTP message.
972 @param[in] StatusCode Response status code returned by the remote host.
974 @return The message should have a message-body (FALSE) or not (TRUE).
978 HttpIoNoMessageBody (
979 IN EFI_HTTP_METHOD Method
,
980 IN EFI_HTTP_STATUS_CODE StatusCode
985 // All responses to the HEAD request method
986 // MUST NOT include a message-body, even though the presence of entity-
987 // header fields might lead one to believe they do. All 1xx
988 // (informational), 204 (no content), and 304 (not modified) responses
989 // MUST NOT include a message-body. All other responses do include a
990 // message-body, although it MAY be of zero length.
992 if (Method
== HttpMethodHead
) {
996 if ((StatusCode
== HTTP_STATUS_100_CONTINUE
) ||
997 (StatusCode
== HTTP_STATUS_101_SWITCHING_PROTOCOLS
) ||
998 (StatusCode
== HTTP_STATUS_204_NO_CONTENT
) ||
999 (StatusCode
== HTTP_STATUS_304_NOT_MODIFIED
))
1008 Initialize a HTTP message-body parser.
1010 This function will create and initialize a HTTP message parser according to caller provided HTTP message
1011 header information. It is the caller's responsibility to free the buffer returned in *UrlParser by HttpFreeMsgParser().
1013 @param[in] Method The HTTP method (e.g. GET, POST) for this HTTP message.
1014 @param[in] StatusCode Response status code returned by the remote host.
1015 @param[in] HeaderCount Number of HTTP header structures in Headers.
1016 @param[in] Headers Array containing list of HTTP headers.
1017 @param[in] Callback Callback function that is invoked when parsing the HTTP message-body,
1018 set to NULL to ignore all events.
1019 @param[in] Context Pointer to the context that will be passed to Callback.
1020 @param[out] MsgParser Pointer to the returned buffer to store the message parser.
1022 @retval EFI_SUCCESS Successfully initialized the parser.
1023 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
1024 @retval EFI_INVALID_PARAMETER MsgParser is NULL or HeaderCount is not NULL but Headers is NULL.
1025 @retval Others Failed to initialize the parser.
1031 IN EFI_HTTP_METHOD Method
,
1032 IN EFI_HTTP_STATUS_CODE StatusCode
,
1033 IN UINTN HeaderCount
,
1034 IN EFI_HTTP_HEADER
*Headers
,
1035 IN HTTP_BODY_PARSER_CALLBACK Callback
,
1037 OUT VOID
**MsgParser
1041 HTTP_BODY_PARSER
*Parser
;
1043 if (HeaderCount
!= 0 && Headers
== NULL
) {
1044 return EFI_INVALID_PARAMETER
;
1047 if (MsgParser
== NULL
) {
1048 return EFI_INVALID_PARAMETER
;
1051 Parser
= AllocateZeroPool (sizeof (HTTP_BODY_PARSER
));
1052 if (Parser
== NULL
) {
1053 return EFI_OUT_OF_RESOURCES
;
1056 Parser
->State
= BodyParserBodyStart
;
1059 // Determine the message length according to RFC 2616.
1060 // 1. Check whether the message "MUST NOT" have a message-body.
1062 Parser
->IgnoreBody
= HttpIoNoMessageBody (Method
, StatusCode
);
1064 // 2. Check whether the message using "chunked" transfer-coding.
1066 Parser
->IsChunked
= HttpIoIsChunked (HeaderCount
, Headers
);
1068 // 3. Check whether the message has a Content-Length header field.
1070 Status
= HttpIoParseContentLengthHeader (HeaderCount
, Headers
, &Parser
->ContentLength
);
1071 if (!EFI_ERROR (Status
)) {
1072 Parser
->ContentLengthIsValid
= TRUE
;
1075 // 4. Range header is not supported now, so we won't meet media type "multipart/byteranges".
1076 // 5. By server closing the connection
1080 // Set state to skip body parser if the message shouldn't have a message body.
1082 if (Parser
->IgnoreBody
) {
1083 Parser
->State
= BodyParserComplete
;
1085 Parser
->Callback
= Callback
;
1086 Parser
->Context
= Context
;
1089 *MsgParser
= Parser
;
1096 Parse BodyLength of message-body. This function can be called repeatedly to parse the message-body partially.
1098 @param[in, out] MsgParser Pointer to the message parser.
1099 @param[in] BodyLength Length in bytes of the Body.
1100 @param[in] Body Pointer to the buffer of the message-body to be parsed.
1102 @retval EFI_SUCCESS Successfully parse the message-body.
1103 @retval EFI_INVALID_PARAMETER MsgParser is NULL or Body is NULL or BodyLength is 0.
1104 @retval Others Operation aborted.
1109 HttpParseMessageBody (
1110 IN OUT VOID
*MsgParser
,
1111 IN UINTN BodyLength
,
1116 UINTN RemainderLengthInThis
;
1117 UINTN LengthForCallback
;
1119 HTTP_BODY_PARSER
*Parser
;
1121 if (BodyLength
== 0 || Body
== NULL
) {
1122 return EFI_INVALID_PARAMETER
;
1125 if (MsgParser
== NULL
) {
1126 return EFI_INVALID_PARAMETER
;
1129 Parser
= (HTTP_BODY_PARSER
*) MsgParser
;
1131 if (Parser
->IgnoreBody
) {
1132 Parser
->State
= BodyParserComplete
;
1133 if (Parser
->Callback
!= NULL
) {
1134 Status
= Parser
->Callback (
1135 BodyParseEventOnComplete
,
1140 if (EFI_ERROR (Status
)) {
1147 if (Parser
->State
== BodyParserBodyStart
) {
1148 Parser
->ParsedBodyLength
= 0;
1149 if (Parser
->IsChunked
) {
1150 Parser
->State
= BodyParserChunkSizeStart
;
1152 Parser
->State
= BodyParserBodyIdentity
;
1157 // The message body might be truncated in anywhere, so we need to parse is byte-by-byte.
1159 for (Char
= Body
; Char
< Body
+ BodyLength
; ) {
1161 switch (Parser
->State
) {
1162 case BodyParserStateMax
:
1165 case BodyParserBodyIdentity
:
1167 // Identity transfer-coding, just notify user to save the body data.
1169 if (Parser
->Callback
!= NULL
) {
1170 Status
= Parser
->Callback (
1171 BodyParseEventOnData
,
1173 MIN (BodyLength
, Parser
->ContentLength
- Parser
->ParsedBodyLength
),
1176 if (EFI_ERROR (Status
)) {
1180 Char
+= MIN (BodyLength
, Parser
->ContentLength
- Parser
->ParsedBodyLength
);
1181 Parser
->ParsedBodyLength
+= MIN (BodyLength
, Parser
->ContentLength
- Parser
->ParsedBodyLength
);
1182 if (Parser
->ParsedBodyLength
== Parser
->ContentLength
) {
1183 Parser
->State
= BodyParserComplete
;
1184 if (Parser
->Callback
!= NULL
) {
1185 Status
= Parser
->Callback (
1186 BodyParseEventOnComplete
,
1191 if (EFI_ERROR (Status
)) {
1198 case BodyParserChunkSizeStart
:
1200 // First byte of chunk-size, the chunk-size might be truncated.
1202 Parser
->CurrentChunkSize
= 0;
1203 Parser
->State
= BodyParserChunkSize
;
1204 case BodyParserChunkSize
:
1205 if (!NET_IS_HEX_CHAR (*Char
)) {
1207 Parser
->State
= BodyParserChunkExtStart
;
1209 } else if (*Char
== '\r') {
1210 Parser
->State
= BodyParserChunkSizeEndCR
;
1213 Parser
->State
= BodyParserStateMax
;
1218 if (Parser
->CurrentChunkSize
> (((~((UINTN
) 0)) - 16) / 16)) {
1219 return EFI_INVALID_PARAMETER
;
1221 Parser
->CurrentChunkSize
= Parser
->CurrentChunkSize
* 16 + HttpIoHexCharToUintn (*Char
);
1225 case BodyParserChunkExtStart
:
1227 // Ignore all the chunk extensions.
1229 if (*Char
== '\r') {
1230 Parser
->State
= BodyParserChunkSizeEndCR
;
1235 case BodyParserChunkSizeEndCR
:
1236 if (*Char
!= '\n') {
1237 Parser
->State
= BodyParserStateMax
;
1241 if (Parser
->CurrentChunkSize
== 0) {
1243 // The last chunk has been parsed and now assumed the state
1244 // of HttpBodyParse is ParserLastCRLF. So it need to decide
1245 // whether the rest message is trailer or last CRLF in the next round.
1247 Parser
->ContentLengthIsValid
= TRUE
;
1248 Parser
->State
= BodyParserLastCRLF
;
1251 Parser
->State
= BodyParserChunkDataStart
;
1252 Parser
->CurrentChunkParsedSize
= 0;
1255 case BodyParserLastCRLF
:
1257 // Judge the byte is belong to the Last CRLF or trailer, and then
1258 // configure the state of HttpBodyParse to corresponding state.
1260 if (*Char
== '\r') {
1262 Parser
->State
= BodyParserLastCRLFEnd
;
1265 Parser
->State
= BodyParserTrailer
;
1269 case BodyParserLastCRLFEnd
:
1270 if (*Char
== '\n') {
1271 Parser
->State
= BodyParserComplete
;
1273 if (Parser
->Callback
!= NULL
) {
1274 Status
= Parser
->Callback (
1275 BodyParseEventOnComplete
,
1280 if (EFI_ERROR (Status
)) {
1286 Parser
->State
= BodyParserStateMax
;
1290 case BodyParserTrailer
:
1291 if (*Char
== '\r') {
1292 Parser
->State
= BodyParserChunkSizeEndCR
;
1297 case BodyParserChunkDataStart
:
1299 // First byte of chunk-data, the chunk data also might be truncated.
1301 RemainderLengthInThis
= BodyLength
- (Char
- Body
);
1302 LengthForCallback
= MIN (Parser
->CurrentChunkSize
- Parser
->CurrentChunkParsedSize
, RemainderLengthInThis
);
1303 if (Parser
->Callback
!= NULL
) {
1304 Status
= Parser
->Callback (
1305 BodyParseEventOnData
,
1310 if (EFI_ERROR (Status
)) {
1314 Char
+= LengthForCallback
;
1315 Parser
->ContentLength
+= LengthForCallback
;
1316 Parser
->CurrentChunkParsedSize
+= LengthForCallback
;
1317 if (Parser
->CurrentChunkParsedSize
== Parser
->CurrentChunkSize
) {
1318 Parser
->State
= BodyParserChunkDataEnd
;
1322 case BodyParserChunkDataEnd
:
1323 if (*Char
== '\r') {
1324 Parser
->State
= BodyParserChunkDataEndCR
;
1326 Parser
->State
= BodyParserStateMax
;
1331 case BodyParserChunkDataEndCR
:
1332 if (*Char
!= '\n') {
1333 Parser
->State
= BodyParserStateMax
;
1337 Parser
->State
= BodyParserChunkSizeStart
;
1346 if (Parser
->State
== BodyParserStateMax
) {
1354 Check whether the message-body is complete or not.
1356 @param[in] MsgParser Pointer to the message parser.
1358 @retval TRUE Message-body is complete.
1359 @retval FALSE Message-body is not complete.
1364 HttpIsMessageComplete (
1368 HTTP_BODY_PARSER
*Parser
;
1370 Parser
= (HTTP_BODY_PARSER
*) MsgParser
;
1372 if (Parser
->State
== BodyParserComplete
) {
1379 Get the content length of the entity.
1381 Note that in trunk transfer, the entity length is not valid until the whole message body is received.
1383 @param[in] MsgParser Pointer to the message parser.
1384 @param[out] ContentLength Pointer to store the length of the entity.
1386 @retval EFI_SUCCESS Successfully to get the entity length.
1387 @retval EFI_NOT_READY Entity length is not valid yet.
1388 @retval EFI_INVALID_PARAMETER MsgParser is NULL or ContentLength is NULL.
1393 HttpGetEntityLength (
1395 OUT UINTN
*ContentLength
1398 HTTP_BODY_PARSER
*Parser
;
1400 if (MsgParser
== NULL
|| ContentLength
== NULL
) {
1401 return EFI_INVALID_PARAMETER
;
1404 Parser
= (HTTP_BODY_PARSER
*) MsgParser
;
1406 if (!Parser
->ContentLengthIsValid
) {
1407 return EFI_NOT_READY
;
1410 *ContentLength
= Parser
->ContentLength
;
1415 Release the resource of the message parser.
1417 @param[in] MsgParser Pointer to the message parser.
1426 FreePool (MsgParser
);
1431 Get the next string, which is distinguished by specified separator.
1433 @param[in] String Pointer to the string.
1434 @param[in] Separator Specified separator used to distinguish where is the beginning
1437 @return Pointer to the next string.
1438 @return NULL if not find or String is NULL.
1443 AsciiStrGetNextToken (
1444 IN CONST CHAR8
*String
,
1455 if (*Token
== Separator
) {
1456 return (CHAR8
*)(Token
+ 1);
1463 Set FieldName and FieldValue into specified HttpHeader.
1465 @param[in,out] HttpHeader Specified HttpHeader.
1466 @param[in] FieldName FieldName of this HttpHeader, a NULL terminated ASCII string.
1467 @param[in] FieldValue FieldValue of this HttpHeader, a NULL terminated ASCII string.
1470 @retval EFI_SUCCESS The FieldName and FieldValue are set into HttpHeader successfully.
1471 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
1476 HttpSetFieldNameAndValue (
1477 IN OUT EFI_HTTP_HEADER
*HttpHeader
,
1478 IN CONST CHAR8
*FieldName
,
1479 IN CONST CHAR8
*FieldValue
1482 UINTN FieldNameSize
;
1483 UINTN FieldValueSize
;
1485 if (HttpHeader
->FieldName
!= NULL
) {
1486 FreePool (HttpHeader
->FieldName
);
1488 if (HttpHeader
->FieldValue
!= NULL
) {
1489 FreePool (HttpHeader
->FieldValue
);
1492 FieldNameSize
= AsciiStrSize (FieldName
);
1493 HttpHeader
->FieldName
= AllocateZeroPool (FieldNameSize
);
1494 if (HttpHeader
->FieldName
== NULL
) {
1495 return EFI_OUT_OF_RESOURCES
;
1497 CopyMem (HttpHeader
->FieldName
, FieldName
, FieldNameSize
);
1498 HttpHeader
->FieldName
[FieldNameSize
- 1] = 0;
1500 FieldValueSize
= AsciiStrSize (FieldValue
);
1501 HttpHeader
->FieldValue
= AllocateZeroPool (FieldValueSize
);
1502 if (HttpHeader
->FieldValue
== NULL
) {
1503 return EFI_OUT_OF_RESOURCES
;
1505 CopyMem (HttpHeader
->FieldValue
, FieldValue
, FieldValueSize
);
1506 HttpHeader
->FieldValue
[FieldValueSize
- 1] = 0;
1512 Get one key/value header pair from the raw string.
1514 @param[in] String Pointer to the raw string.
1515 @param[out] FieldName Points directly to field name within 'HttpHeader'.
1516 @param[out] FieldValue Points directly to field value within 'HttpHeader'.
1518 @return Pointer to the next raw string.
1519 @return NULL if no key/value header pair from this raw string.
1524 HttpGetFieldNameAndValue (
1526 OUT CHAR8
**FieldName
,
1527 OUT CHAR8
**FieldValue
1530 CHAR8
*FieldNameStr
;
1531 CHAR8
*FieldValueStr
;
1534 if (String
== NULL
|| FieldName
== NULL
|| FieldValue
== NULL
) {
1540 FieldNameStr
= NULL
;
1541 FieldValueStr
= NULL
;
1545 // Each header field consists of a name followed by a colon (":") and the field value.
1547 FieldNameStr
= String
;
1548 FieldValueStr
= AsciiStrGetNextToken (FieldNameStr
, ':');
1549 if (FieldValueStr
== NULL
) {
1554 // Replace ':' with 0
1556 *(FieldValueStr
- 1) = 0;
1559 // The field value MAY be preceded by any amount of LWS, though a single SP is preferred.
1562 if (*FieldValueStr
== ' ' || *FieldValueStr
== '\t') {
1564 } else if (*FieldValueStr
== '\r' && *(FieldValueStr
+ 1) == '\n' &&
1565 (*(FieldValueStr
+ 2) == ' ' || *(FieldValueStr
+ 2) == '\t')) {
1566 FieldValueStr
= FieldValueStr
+ 3;
1573 // Header fields can be extended over multiple lines by preceding each extra
1574 // line with at least one SP or HT.
1576 StrPtr
= FieldValueStr
;
1578 StrPtr
= AsciiStrGetNextToken (StrPtr
, '\r');
1579 if (StrPtr
== NULL
|| *StrPtr
!= '\n') {
1584 } while (*StrPtr
== ' ' || *StrPtr
== '\t');
1587 // Replace '\r' with 0
1592 // Get FieldName and FieldValue.
1594 *FieldName
= FieldNameStr
;
1595 *FieldValue
= FieldValueStr
;
1601 Free existing HeaderFields.
1603 @param[in] HeaderFields Pointer to array of key/value header pairs waitting for free.
1604 @param[in] FieldCount The number of header pairs in HeaderFields.
1609 HttpFreeHeaderFields (
1610 IN EFI_HTTP_HEADER
*HeaderFields
,
1616 if (HeaderFields
!= NULL
) {
1617 for (Index
= 0; Index
< FieldCount
; Index
++) {
1618 if (HeaderFields
[Index
].FieldName
!= NULL
) {
1619 FreePool (HeaderFields
[Index
].FieldName
);
1621 if (HeaderFields
[Index
].FieldValue
!= NULL
) {
1622 FreePool (HeaderFields
[Index
].FieldValue
);
1626 FreePool (HeaderFields
);
1631 Generate HTTP request message.
1633 This function will allocate memory for the whole HTTP message and generate a
1634 well formatted HTTP Request message in it, include the Request-Line, header
1635 fields and also the message body. It is the caller's responsibility to free
1636 the buffer returned in *RequestMsg.
1638 @param[in] Message Pointer to the EFI_HTTP_MESSAGE structure which
1639 contains the required information to generate
1640 the HTTP request message.
1641 @param[in] Url The URL of a remote host.
1642 @param[out] RequestMsg Pointer to the created HTTP request message.
1643 NULL if any error occured.
1644 @param[out] RequestMsgSize Size of the RequestMsg (in bytes).
1646 @return EFI_SUCCESS If HTTP request string was created successfully
1647 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
1648 @retval EFI_INVALID_PARAMETER The input arguments are invalid
1653 HttpGenRequestMessage (
1654 IN CONST EFI_HTTP_MESSAGE
*Message
,
1655 IN CONST CHAR8
*Url
,
1656 OUT CHAR8
**RequestMsg
,
1657 OUT UINTN
*RequestMsgSize
1667 EFI_HTTP_HEADER
**AppendList
;
1669 EFI_HTTP_UTILITIES_PROTOCOL
*HttpUtilitiesProtocol
;
1672 ASSERT (Message
!= NULL
);
1675 Status
= EFI_SUCCESS
;
1681 HttpUtilitiesProtocol
= NULL
;
1684 // 1. If we have a Request, we cannot have a NULL Url
1685 // 2. If we have a Request, HeaderCount can not be non-zero
1686 // 3. If we do not have a Request, HeaderCount should be zero
1687 // 4. If we do not have Request and Headers, we need at least a message-body
1689 if ((Message
->Data
.Request
!= NULL
&& Url
== NULL
) ||
1690 (Message
->Data
.Request
!= NULL
&& Message
->HeaderCount
== 0) ||
1691 (Message
->Data
.Request
== NULL
&& Message
->HeaderCount
!= 0) ||
1692 (Message
->Data
.Request
== NULL
&& Message
->HeaderCount
== 0 && Message
->BodyLength
== 0)) {
1693 return EFI_INVALID_PARAMETER
;
1696 if (Message
->HeaderCount
!= 0) {
1698 // Locate the HTTP_UTILITIES protocol.
1700 Status
= gBS
->LocateProtocol (
1701 &gEfiHttpUtilitiesProtocolGuid
,
1703 (VOID
**)&HttpUtilitiesProtocol
1706 if (EFI_ERROR (Status
)) {
1707 DEBUG ((DEBUG_ERROR
,"Failed to locate Http Utilities protocol. Status = %r.\n", Status
));
1712 // Build AppendList to send into HttpUtilitiesBuild
1714 AppendList
= AllocateZeroPool (sizeof (EFI_HTTP_HEADER
*) * (Message
->HeaderCount
));
1715 if (AppendList
== NULL
) {
1716 return EFI_OUT_OF_RESOURCES
;
1719 for(Index
= 0; Index
< Message
->HeaderCount
; Index
++){
1720 AppendList
[Index
] = &Message
->Headers
[Index
];
1724 // Build raw HTTP Headers
1726 Status
= HttpUtilitiesProtocol
->Build (
1727 HttpUtilitiesProtocol
,
1732 Message
->HeaderCount
,
1738 if (AppendList
!= NULL
) {
1739 FreePool (AppendList
);
1742 if (EFI_ERROR (Status
) || HttpHdr
== NULL
){
1748 // If we have headers to be sent, account for it.
1750 if (Message
->HeaderCount
!= 0) {
1751 MsgSize
= HttpHdrSize
;
1755 // If we have a request line, account for the fields.
1757 if (Message
->Data
.Request
!= NULL
) {
1758 MsgSize
+= HTTP_METHOD_MAXIMUM_LEN
+ AsciiStrLen (HTTP_VERSION_CRLF_STR
) + AsciiStrLen (Url
);
1763 // If we have a message body to be sent, account for it.
1765 MsgSize
+= Message
->BodyLength
;
1768 // memory for the string that needs to be sent to TCP
1770 *RequestMsg
= AllocateZeroPool (MsgSize
);
1771 if (*RequestMsg
== NULL
) {
1772 Status
= EFI_OUT_OF_RESOURCES
;
1776 RequestPtr
= *RequestMsg
;
1778 // Construct header request
1780 if (Message
->Data
.Request
!= NULL
) {
1781 switch (Message
->Data
.Request
->Method
) {
1783 StrLength
= sizeof (HTTP_METHOD_GET
) - 1;
1784 CopyMem (RequestPtr
, HTTP_METHOD_GET
, StrLength
);
1785 RequestPtr
+= StrLength
;
1788 StrLength
= sizeof (HTTP_METHOD_PUT
) - 1;
1789 CopyMem (RequestPtr
, HTTP_METHOD_PUT
, StrLength
);
1790 RequestPtr
+= StrLength
;
1792 case HttpMethodPatch
:
1793 StrLength
= sizeof (HTTP_METHOD_PATCH
) - 1;
1794 CopyMem (RequestPtr
, HTTP_METHOD_PATCH
, StrLength
);
1795 RequestPtr
+= StrLength
;
1797 case HttpMethodPost
:
1798 StrLength
= sizeof (HTTP_METHOD_POST
) - 1;
1799 CopyMem (RequestPtr
, HTTP_METHOD_POST
, StrLength
);
1800 RequestPtr
+= StrLength
;
1802 case HttpMethodHead
:
1803 StrLength
= sizeof (HTTP_METHOD_HEAD
) - 1;
1804 CopyMem (RequestPtr
, HTTP_METHOD_HEAD
, StrLength
);
1805 RequestPtr
+= StrLength
;
1807 case HttpMethodDelete
:
1808 StrLength
= sizeof (HTTP_METHOD_DELETE
) - 1;
1809 CopyMem (RequestPtr
, HTTP_METHOD_DELETE
, StrLength
);
1810 RequestPtr
+= StrLength
;
1814 Status
= EFI_INVALID_PARAMETER
;
1818 StrLength
= AsciiStrLen(EMPTY_SPACE
);
1819 CopyMem (RequestPtr
, EMPTY_SPACE
, StrLength
);
1820 RequestPtr
+= StrLength
;
1822 StrLength
= AsciiStrLen (Url
);
1823 CopyMem (RequestPtr
, Url
, StrLength
);
1824 RequestPtr
+= StrLength
;
1826 StrLength
= sizeof (HTTP_VERSION_CRLF_STR
) - 1;
1827 CopyMem (RequestPtr
, HTTP_VERSION_CRLF_STR
, StrLength
);
1828 RequestPtr
+= StrLength
;
1830 if (HttpHdr
!= NULL
) {
1834 CopyMem (RequestPtr
, HttpHdr
, HttpHdrSize
);
1835 RequestPtr
+= HttpHdrSize
;
1842 if (Message
->Body
!= NULL
) {
1843 CopyMem (RequestPtr
, Message
->Body
, Message
->BodyLength
);
1844 RequestPtr
+= Message
->BodyLength
;
1850 (*RequestMsgSize
) = (UINTN
)(RequestPtr
) - (UINTN
)(*RequestMsg
);
1856 if (*RequestMsg
!= NULL
) {
1857 FreePool (*RequestMsg
);
1863 if (HttpHdr
!= NULL
) {
1871 Translate the status code in HTTP message to EFI_HTTP_STATUS_CODE defined
1872 in UEFI 2.5 specification.
1874 @param[in] StatusCode The status code value in HTTP message.
1876 @return Value defined in EFI_HTTP_STATUS_CODE .
1879 EFI_HTTP_STATUS_CODE
1881 HttpMappingToStatusCode (
1885 switch (StatusCode
) {
1887 return HTTP_STATUS_100_CONTINUE
;
1889 return HTTP_STATUS_101_SWITCHING_PROTOCOLS
;
1891 return HTTP_STATUS_200_OK
;
1893 return HTTP_STATUS_201_CREATED
;
1895 return HTTP_STATUS_202_ACCEPTED
;
1897 return HTTP_STATUS_203_NON_AUTHORITATIVE_INFORMATION
;
1899 return HTTP_STATUS_204_NO_CONTENT
;
1901 return HTTP_STATUS_205_RESET_CONTENT
;
1903 return HTTP_STATUS_206_PARTIAL_CONTENT
;
1905 return HTTP_STATUS_300_MULTIPLE_CHIOCES
;
1907 return HTTP_STATUS_301_MOVED_PERMANENTLY
;
1909 return HTTP_STATUS_302_FOUND
;
1911 return HTTP_STATUS_303_SEE_OTHER
;
1913 return HTTP_STATUS_304_NOT_MODIFIED
;
1915 return HTTP_STATUS_305_USE_PROXY
;
1917 return HTTP_STATUS_307_TEMPORARY_REDIRECT
;
1919 return HTTP_STATUS_400_BAD_REQUEST
;
1921 return HTTP_STATUS_401_UNAUTHORIZED
;
1923 return HTTP_STATUS_402_PAYMENT_REQUIRED
;
1925 return HTTP_STATUS_403_FORBIDDEN
;
1927 return HTTP_STATUS_404_NOT_FOUND
;
1929 return HTTP_STATUS_405_METHOD_NOT_ALLOWED
;
1931 return HTTP_STATUS_406_NOT_ACCEPTABLE
;
1933 return HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED
;
1935 return HTTP_STATUS_408_REQUEST_TIME_OUT
;
1937 return HTTP_STATUS_409_CONFLICT
;
1939 return HTTP_STATUS_410_GONE
;
1941 return HTTP_STATUS_411_LENGTH_REQUIRED
;
1943 return HTTP_STATUS_412_PRECONDITION_FAILED
;
1945 return HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE
;
1947 return HTTP_STATUS_414_REQUEST_URI_TOO_LARGE
;
1949 return HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE
;
1951 return HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED
;
1953 return HTTP_STATUS_417_EXPECTATION_FAILED
;
1955 return HTTP_STATUS_500_INTERNAL_SERVER_ERROR
;
1957 return HTTP_STATUS_501_NOT_IMPLEMENTED
;
1959 return HTTP_STATUS_502_BAD_GATEWAY
;
1961 return HTTP_STATUS_503_SERVICE_UNAVAILABLE
;
1963 return HTTP_STATUS_504_GATEWAY_TIME_OUT
;
1965 return HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED
;
1968 return HTTP_STATUS_UNSUPPORTED_STATUS
;
1973 Check whether header field called FieldName is in DeleteList.
1975 @param[in] DeleteList Pointer to array of key/value header pairs.
1976 @param[in] DeleteCount The number of header pairs.
1977 @param[in] FieldName Pointer to header field's name.
1979 @return TRUE if FieldName is not in DeleteList, that means this header field is valid.
1980 @return FALSE if FieldName is in DeleteList, that means this header field is invalid.
1985 HttpIsValidHttpHeader (
1986 IN CHAR8
*DeleteList
[],
1987 IN UINTN DeleteCount
,
1993 for (Index
= 0; Index
< DeleteCount
; Index
++) {
1994 if (AsciiStrCmp (FieldName
, DeleteList
[Index
]) == 0) {