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 (Index
+ 1 >= BufferLength
|| Index
+ 2 >= BufferLength
|| !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 EFI_INVALID_PARAMETER The Url is invalid to parse the authority component.
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
;
378 if (Url
== NULL
|| Length
== 0 || UrlParser
== NULL
) {
379 return EFI_INVALID_PARAMETER
;
382 Parser
= AllocateZeroPool (sizeof (HTTP_URL_PARSER
));
383 if (Parser
== NULL
) {
384 return EFI_OUT_OF_RESOURCES
;
387 if (IsConnectMethod
) {
389 // According to RFC 2616, the authority form is only used by the CONNECT method.
391 State
= UrlParserAuthority
;
393 State
= UrlParserUrlStart
;
396 Field
= HTTP_URI_FIELD_MAX
;
399 for (Char
= Url
; Char
< Url
+ Length
; Char
++) {
401 // Update state machine according to next char.
403 State
= NetHttpParseUrlChar (*Char
, State
);
406 case UrlParserStateMax
:
408 return EFI_INVALID_PARAMETER
;
410 case UrlParserSchemeColon
:
411 case UrlParserSchemeColonSlash
:
412 case UrlParserSchemeColonSlashSlash
:
413 case UrlParserQueryStart
:
414 case UrlParserFragmentStart
:
416 // Skip all the delimiting char: "://" "?" "@"
420 case UrlParserScheme
:
421 Field
= HTTP_URI_FIELD_SCHEME
;
424 case UrlParserAtInAuthority
:
426 case UrlParserAuthority
:
427 Field
= HTTP_URI_FIELD_AUTHORITY
;
431 Field
= HTTP_URI_FIELD_PATH
;
435 Field
= HTTP_URI_FIELD_QUERY
;
438 case UrlParserFragment
:
439 Field
= HTTP_URI_FIELD_FRAGMENT
;
447 // Field not changed, count the length.
449 ASSERT (Field
< HTTP_URI_FIELD_MAX
);
450 if (Field
== OldField
) {
451 Parser
->FieldData
[Field
].Length
++;
458 Parser
->FieldBitMap
|= BIT (Field
);
459 Parser
->FieldData
[Field
].Offset
= (UINT32
) (Char
- Url
);
460 Parser
->FieldData
[Field
].Length
= 1;
465 // If has authority component, continue to parse the username, host and port.
467 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_AUTHORITY
)) != 0) {
468 Status
= NetHttpParseAuthority (Url
, FoundAt
, Parser
);
469 if (EFI_ERROR (Status
)) {
480 Get the Hostname from a HTTP URL.
482 This function will return the HostName according to the Url and previous parse result ,and
483 it is the caller's responsibility to free the buffer returned in *HostName.
485 @param[in] Url The pointer to a HTTP URL string.
486 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
487 @param[out] HostName Pointer to a buffer to store the HostName.
489 @retval EFI_SUCCESS Successfully get the required component.
490 @retval EFI_INVALID_PARAMETER Uri is NULL or HostName is NULL or UrlParser is invalid.
491 @retval EFI_NOT_FOUND No hostName component in the URL.
492 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
506 HTTP_URL_PARSER
*Parser
;
508 if (Url
== NULL
|| UrlParser
== NULL
|| HostName
== NULL
) {
509 return EFI_INVALID_PARAMETER
;
512 Parser
= (HTTP_URL_PARSER
*) UrlParser
;
514 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_HOST
)) == 0) {
515 return EFI_NOT_FOUND
;
518 Name
= AllocatePool (Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Length
+ 1);
520 return EFI_OUT_OF_RESOURCES
;
523 Status
= UriPercentDecode (
524 Url
+ Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Offset
,
525 Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Length
,
529 if (EFI_ERROR (Status
)) {
534 Name
[ResultLength
] = '\0';
541 Get the IPv4 address from a HTTP URL.
543 This function will return the IPv4 address according to the Url and previous parse result.
545 @param[in] Url The pointer to a HTTP URL string.
546 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
547 @param[out] Ip4Address Pointer to a buffer to store the IP address.
549 @retval EFI_SUCCESS Successfully get the required component.
550 @retval EFI_INVALID_PARAMETER Uri is NULL or Ip4Address is NULL or UrlParser is invalid.
551 @retval EFI_NOT_FOUND No IPv4 address component in the URL.
552 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
560 OUT EFI_IPv4_ADDRESS
*Ip4Address
566 HTTP_URL_PARSER
*Parser
;
568 if (Url
== NULL
|| UrlParser
== NULL
|| Ip4Address
== NULL
) {
569 return EFI_INVALID_PARAMETER
;
572 Parser
= (HTTP_URL_PARSER
*) UrlParser
;
574 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_HOST
)) == 0) {
575 return EFI_NOT_FOUND
;
578 Ip4String
= AllocatePool (Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Length
+ 1);
579 if (Ip4String
== NULL
) {
580 return EFI_OUT_OF_RESOURCES
;
583 Status
= UriPercentDecode (
584 Url
+ Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Offset
,
585 Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Length
,
589 if (EFI_ERROR (Status
)) {
590 FreePool (Ip4String
);
594 Ip4String
[ResultLength
] = '\0';
595 Status
= NetLibAsciiStrToIp4 (Ip4String
, Ip4Address
);
596 FreePool (Ip4String
);
602 Get the IPv6 address from a HTTP URL.
604 This function will return the IPv6 address according to the Url and previous parse result.
606 @param[in] Url The pointer to a HTTP URL string.
607 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
608 @param[out] Ip6Address Pointer to a buffer to store the IP address.
610 @retval EFI_SUCCESS Successfully get the required component.
611 @retval EFI_INVALID_PARAMETER Uri is NULL or Ip6Address is NULL or UrlParser is invalid.
612 @retval EFI_NOT_FOUND No IPv6 address component in the URL.
613 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
621 OUT EFI_IPv6_ADDRESS
*Ip6Address
629 HTTP_URL_PARSER
*Parser
;
631 if (Url
== NULL
|| UrlParser
== NULL
|| Ip6Address
== NULL
) {
632 return EFI_INVALID_PARAMETER
;
635 Parser
= (HTTP_URL_PARSER
*) UrlParser
;
637 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_HOST
)) == 0) {
638 return EFI_NOT_FOUND
;
642 // IP-literal = "[" ( IPv6address / IPvFuture ) "]"
644 Length
= Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Length
;
646 return EFI_INVALID_PARAMETER
;
649 Ptr
= Url
+ Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Offset
;
650 if ((Ptr
[0] != '[') || (Ptr
[Length
- 1] != ']')) {
651 return EFI_INVALID_PARAMETER
;
654 Ip6String
= AllocatePool (Length
);
655 if (Ip6String
== NULL
) {
656 return EFI_OUT_OF_RESOURCES
;
659 Status
= UriPercentDecode (
665 if (EFI_ERROR (Status
)) {
666 FreePool (Ip6String
);
670 Ip6String
[ResultLength
] = '\0';
671 Status
= NetLibAsciiStrToIp6 (Ip6String
, Ip6Address
);
672 FreePool (Ip6String
);
678 Get the port number from a HTTP URL.
680 This function will return the port number according to the Url and previous parse result.
682 @param[in] Url The pointer to a HTTP URL string.
683 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
684 @param[out] Port Pointer to a buffer to store the port number.
686 @retval EFI_SUCCESS Successfully get the required component.
687 @retval EFI_INVALID_PARAMETER Uri is NULL or Port is NULL or UrlParser is invalid.
688 @retval EFI_NOT_FOUND No port number in the URL.
689 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
705 HTTP_URL_PARSER
*Parser
;
707 if (Url
== NULL
|| UrlParser
== NULL
|| Port
== NULL
) {
708 return EFI_INVALID_PARAMETER
;
714 Parser
= (HTTP_URL_PARSER
*) UrlParser
;
716 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_PORT
)) == 0) {
717 return EFI_NOT_FOUND
;
720 PortString
= AllocatePool (Parser
->FieldData
[HTTP_URI_FIELD_PORT
].Length
+ 1);
721 if (PortString
== NULL
) {
722 return EFI_OUT_OF_RESOURCES
;
725 Status
= UriPercentDecode (
726 Url
+ Parser
->FieldData
[HTTP_URI_FIELD_PORT
].Offset
,
727 Parser
->FieldData
[HTTP_URI_FIELD_PORT
].Length
,
731 if (EFI_ERROR (Status
)) {
735 PortString
[ResultLength
] = '\0';
737 while (Index
< ResultLength
) {
738 if (!NET_IS_DIGIT (PortString
[Index
])) {
739 Status
= EFI_INVALID_PARAMETER
;
745 Status
= AsciiStrDecimalToUintnS (Url
+ Parser
->FieldData
[HTTP_URI_FIELD_PORT
].Offset
, (CHAR8
**) NULL
, &Data
);
747 if (Data
> HTTP_URI_PORT_MAX_NUM
) {
748 Status
= EFI_INVALID_PARAMETER
;
752 *Port
= (UINT16
) Data
;
755 FreePool (PortString
);
760 Get the Path from a HTTP URL.
762 This function will return the Path according to the Url and previous parse result,and
763 it is the caller's responsibility to free the buffer returned in *Path.
765 @param[in] Url The pointer to a HTTP URL string.
766 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
767 @param[out] Path Pointer to a buffer to store the Path.
769 @retval EFI_SUCCESS Successfully get the required component.
770 @retval EFI_INVALID_PARAMETER Uri is NULL or HostName is NULL or UrlParser is invalid.
771 @retval EFI_NOT_FOUND No hostName component in the URL.
772 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
786 HTTP_URL_PARSER
*Parser
;
788 if (Url
== NULL
|| UrlParser
== NULL
|| Path
== NULL
) {
789 return EFI_INVALID_PARAMETER
;
792 Parser
= (HTTP_URL_PARSER
*) UrlParser
;
794 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_PATH
)) == 0) {
795 return EFI_NOT_FOUND
;
798 PathStr
= AllocatePool (Parser
->FieldData
[HTTP_URI_FIELD_PATH
].Length
+ 1);
799 if (PathStr
== NULL
) {
800 return EFI_OUT_OF_RESOURCES
;
803 Status
= UriPercentDecode (
804 Url
+ Parser
->FieldData
[HTTP_URI_FIELD_PATH
].Offset
,
805 Parser
->FieldData
[HTTP_URI_FIELD_PATH
].Length
,
809 if (EFI_ERROR (Status
)) {
814 PathStr
[ResultLength
] = '\0';
820 Release the resource of the URL parser.
822 @param[in] UrlParser Pointer to the parser.
831 FreePool (UrlParser
);
835 Find a specified header field according to the field name.
837 @param[in] HeaderCount Number of HTTP header structures in Headers list.
838 @param[in] Headers Array containing list of HTTP headers.
839 @param[in] FieldName Null terminated string which describes a field name.
841 @return Pointer to the found header or NULL.
847 IN UINTN HeaderCount
,
848 IN EFI_HTTP_HEADER
*Headers
,
854 if (HeaderCount
== 0 || Headers
== NULL
|| FieldName
== NULL
) {
858 for (Index
= 0; Index
< HeaderCount
; Index
++){
860 // Field names are case-insensitive (RFC 2616).
862 if (AsciiStriCmp (Headers
[Index
].FieldName
, FieldName
) == 0) {
863 return &Headers
[Index
];
871 BodyParserBodyIdentity
,
872 BodyParserChunkSizeStart
,
874 BodyParserChunkSizeEndCR
,
875 BodyParserChunkExtStart
,
876 BodyParserChunkDataStart
,
877 BodyParserChunkDataEnd
,
878 BodyParserChunkDataEndCR
,
881 BodyParserLastCRLFEnd
,
884 } HTTP_BODY_PARSE_STATE
;
887 BOOLEAN IgnoreBody
; // "MUST NOT" include a message-body
888 BOOLEAN IsChunked
; // "chunked" transfer-coding.
889 BOOLEAN ContentLengthIsValid
;
890 UINTN ContentLength
; // Entity length (not the message-body length), invalid until ContentLengthIsValid is TRUE
892 HTTP_BODY_PARSER_CALLBACK Callback
;
894 UINTN ParsedBodyLength
;
895 HTTP_BODY_PARSE_STATE State
;
896 UINTN CurrentChunkSize
;
897 UINTN CurrentChunkParsedSize
;
902 Convert an Ascii char to its uppercase.
904 @param[in] Char Ascii character.
906 @return Uppercase value of the input Char.
914 if (Char
>= 'a' && Char
<= 'z') {
915 return Char
- ('a' - 'A');
922 Convert an hexadecimal char to a value of type UINTN.
924 @param[in] Char Ascii character.
926 @return Value translated from Char.
930 HttpIoHexCharToUintn (
934 if (Char
>= '0' && Char
<= '9') {
938 return (10 + HttpIoCharToUpper (Char
) - 'A');
942 Get the value of the content length if there is a "Content-Length" header.
944 @param[in] HeaderCount Number of HTTP header structures in Headers.
945 @param[in] Headers Array containing list of HTTP headers.
946 @param[out] ContentLength Pointer to save the value of the content length.
948 @retval EFI_SUCCESS Successfully get the content length.
949 @retval EFI_NOT_FOUND No "Content-Length" header in the Headers.
953 HttpIoParseContentLengthHeader (
954 IN UINTN HeaderCount
,
955 IN EFI_HTTP_HEADER
*Headers
,
956 OUT UINTN
*ContentLength
959 EFI_HTTP_HEADER
*Header
;
961 Header
= HttpFindHeader (HeaderCount
, Headers
, HTTP_HEADER_CONTENT_LENGTH
);
962 if (Header
== NULL
) {
963 return EFI_NOT_FOUND
;
966 return AsciiStrDecimalToUintnS (Header
->FieldValue
, (CHAR8
**) NULL
, ContentLength
);
971 Check whether the HTTP message is using the "chunked" transfer-coding.
973 @param[in] HeaderCount Number of HTTP header structures in Headers.
974 @param[in] Headers Array containing list of HTTP headers.
976 @return The message is "chunked" transfer-coding (TRUE) or not (FALSE).
981 IN UINTN HeaderCount
,
982 IN EFI_HTTP_HEADER
*Headers
985 EFI_HTTP_HEADER
*Header
;
988 Header
= HttpFindHeader (HeaderCount
, Headers
, HTTP_HEADER_TRANSFER_ENCODING
);
989 if (Header
== NULL
) {
993 if (AsciiStriCmp (Header
->FieldValue
, "identity") != 0) {
1001 Check whether the HTTP message should have a message-body.
1003 @param[in] Method The HTTP method (e.g. GET, POST) for this HTTP message.
1004 @param[in] StatusCode Response status code returned by the remote host.
1006 @return The message should have a message-body (FALSE) or not (TRUE).
1010 HttpIoNoMessageBody (
1011 IN EFI_HTTP_METHOD Method
,
1012 IN EFI_HTTP_STATUS_CODE StatusCode
1017 // All responses to the HEAD request method
1018 // MUST NOT include a message-body, even though the presence of entity-
1019 // header fields might lead one to believe they do. All 1xx
1020 // (informational), 204 (no content), and 304 (not modified) responses
1021 // MUST NOT include a message-body. All other responses do include a
1022 // message-body, although it MAY be of zero length.
1024 if (Method
== HttpMethodHead
) {
1028 if ((StatusCode
== HTTP_STATUS_100_CONTINUE
) ||
1029 (StatusCode
== HTTP_STATUS_101_SWITCHING_PROTOCOLS
) ||
1030 (StatusCode
== HTTP_STATUS_204_NO_CONTENT
) ||
1031 (StatusCode
== HTTP_STATUS_304_NOT_MODIFIED
))
1040 Initialize a HTTP message-body parser.
1042 This function will create and initialize a HTTP message parser according to caller provided HTTP message
1043 header information. It is the caller's responsibility to free the buffer returned in *UrlParser by HttpFreeMsgParser().
1045 @param[in] Method The HTTP method (e.g. GET, POST) for this HTTP message.
1046 @param[in] StatusCode Response status code returned by the remote host.
1047 @param[in] HeaderCount Number of HTTP header structures in Headers.
1048 @param[in] Headers Array containing list of HTTP headers.
1049 @param[in] Callback Callback function that is invoked when parsing the HTTP message-body,
1050 set to NULL to ignore all events.
1051 @param[in] Context Pointer to the context that will be passed to Callback.
1052 @param[out] MsgParser Pointer to the returned buffer to store the message parser.
1054 @retval EFI_SUCCESS Successfully initialized the parser.
1055 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
1056 @retval EFI_INVALID_PARAMETER MsgParser is NULL or HeaderCount is not NULL but Headers is NULL.
1057 @retval Others Failed to initialize the parser.
1063 IN EFI_HTTP_METHOD Method
,
1064 IN EFI_HTTP_STATUS_CODE StatusCode
,
1065 IN UINTN HeaderCount
,
1066 IN EFI_HTTP_HEADER
*Headers
,
1067 IN HTTP_BODY_PARSER_CALLBACK Callback
,
1069 OUT VOID
**MsgParser
1073 HTTP_BODY_PARSER
*Parser
;
1075 if (HeaderCount
!= 0 && Headers
== NULL
) {
1076 return EFI_INVALID_PARAMETER
;
1079 if (MsgParser
== NULL
) {
1080 return EFI_INVALID_PARAMETER
;
1083 Parser
= AllocateZeroPool (sizeof (HTTP_BODY_PARSER
));
1084 if (Parser
== NULL
) {
1085 return EFI_OUT_OF_RESOURCES
;
1088 Parser
->State
= BodyParserBodyStart
;
1091 // Determine the message length according to RFC 2616.
1092 // 1. Check whether the message "MUST NOT" have a message-body.
1094 Parser
->IgnoreBody
= HttpIoNoMessageBody (Method
, StatusCode
);
1096 // 2. Check whether the message using "chunked" transfer-coding.
1098 Parser
->IsChunked
= HttpIoIsChunked (HeaderCount
, Headers
);
1100 // 3. Check whether the message has a Content-Length header field.
1102 Status
= HttpIoParseContentLengthHeader (HeaderCount
, Headers
, &Parser
->ContentLength
);
1103 if (!EFI_ERROR (Status
)) {
1104 Parser
->ContentLengthIsValid
= TRUE
;
1107 // 4. Range header is not supported now, so we won't meet media type "multipart/byteranges".
1108 // 5. By server closing the connection
1112 // Set state to skip body parser if the message shouldn't have a message body.
1114 if (Parser
->IgnoreBody
) {
1115 Parser
->State
= BodyParserComplete
;
1117 Parser
->Callback
= Callback
;
1118 Parser
->Context
= Context
;
1121 *MsgParser
= Parser
;
1128 Parse BodyLength of message-body. This function can be called repeatedly to parse the message-body partially.
1130 @param[in, out] MsgParser Pointer to the message parser.
1131 @param[in] BodyLength Length in bytes of the Body.
1132 @param[in] Body Pointer to the buffer of the message-body to be parsed.
1134 @retval EFI_SUCCESS Successfully parse the message-body.
1135 @retval EFI_INVALID_PARAMETER MsgParser is NULL or Body is NULL or BodyLength is 0.
1136 @retval EFI_ABORTED Operation aborted.
1137 @retval Other Error happened while parsing message body.
1142 HttpParseMessageBody (
1143 IN OUT VOID
*MsgParser
,
1144 IN UINTN BodyLength
,
1149 UINTN RemainderLengthInThis
;
1150 UINTN LengthForCallback
;
1152 HTTP_BODY_PARSER
*Parser
;
1154 if (BodyLength
== 0 || Body
== NULL
) {
1155 return EFI_INVALID_PARAMETER
;
1158 if (MsgParser
== NULL
) {
1159 return EFI_INVALID_PARAMETER
;
1162 Parser
= (HTTP_BODY_PARSER
*) MsgParser
;
1164 if (Parser
->IgnoreBody
) {
1165 Parser
->State
= BodyParserComplete
;
1166 if (Parser
->Callback
!= NULL
) {
1167 Status
= Parser
->Callback (
1168 BodyParseEventOnComplete
,
1173 if (EFI_ERROR (Status
)) {
1180 if (Parser
->State
== BodyParserBodyStart
) {
1181 Parser
->ParsedBodyLength
= 0;
1182 if (Parser
->IsChunked
) {
1183 Parser
->State
= BodyParserChunkSizeStart
;
1185 Parser
->State
= BodyParserBodyIdentity
;
1190 // The message body might be truncated in anywhere, so we need to parse is byte-by-byte.
1192 for (Char
= Body
; Char
< Body
+ BodyLength
; ) {
1194 switch (Parser
->State
) {
1195 case BodyParserStateMax
:
1198 case BodyParserBodyIdentity
:
1200 // Identity transfer-coding, just notify user to save the body data.
1202 if (Parser
->Callback
!= NULL
) {
1203 Status
= Parser
->Callback (
1204 BodyParseEventOnData
,
1206 MIN (BodyLength
, Parser
->ContentLength
- Parser
->ParsedBodyLength
),
1209 if (EFI_ERROR (Status
)) {
1213 Char
+= MIN (BodyLength
, Parser
->ContentLength
- Parser
->ParsedBodyLength
);
1214 Parser
->ParsedBodyLength
+= MIN (BodyLength
, Parser
->ContentLength
- Parser
->ParsedBodyLength
);
1215 if (Parser
->ParsedBodyLength
== Parser
->ContentLength
) {
1216 Parser
->State
= BodyParserComplete
;
1217 if (Parser
->Callback
!= NULL
) {
1218 Status
= Parser
->Callback (
1219 BodyParseEventOnComplete
,
1224 if (EFI_ERROR (Status
)) {
1231 case BodyParserChunkSizeStart
:
1233 // First byte of chunk-size, the chunk-size might be truncated.
1235 Parser
->CurrentChunkSize
= 0;
1236 Parser
->State
= BodyParserChunkSize
;
1237 case BodyParserChunkSize
:
1238 if (!NET_IS_HEX_CHAR (*Char
)) {
1240 Parser
->State
= BodyParserChunkExtStart
;
1242 } else if (*Char
== '\r') {
1243 Parser
->State
= BodyParserChunkSizeEndCR
;
1246 Parser
->State
= BodyParserStateMax
;
1251 if (Parser
->CurrentChunkSize
> (((~((UINTN
) 0)) - 16) / 16)) {
1252 return EFI_INVALID_PARAMETER
;
1254 Parser
->CurrentChunkSize
= Parser
->CurrentChunkSize
* 16 + HttpIoHexCharToUintn (*Char
);
1258 case BodyParserChunkExtStart
:
1260 // Ignore all the chunk extensions.
1262 if (*Char
== '\r') {
1263 Parser
->State
= BodyParserChunkSizeEndCR
;
1268 case BodyParserChunkSizeEndCR
:
1269 if (*Char
!= '\n') {
1270 Parser
->State
= BodyParserStateMax
;
1274 if (Parser
->CurrentChunkSize
== 0) {
1276 // The last chunk has been parsed and now assumed the state
1277 // of HttpBodyParse is ParserLastCRLF. So it need to decide
1278 // whether the rest message is trailer or last CRLF in the next round.
1280 Parser
->ContentLengthIsValid
= TRUE
;
1281 Parser
->State
= BodyParserLastCRLF
;
1284 Parser
->State
= BodyParserChunkDataStart
;
1285 Parser
->CurrentChunkParsedSize
= 0;
1288 case BodyParserLastCRLF
:
1290 // Judge the byte is belong to the Last CRLF or trailer, and then
1291 // configure the state of HttpBodyParse to corresponding state.
1293 if (*Char
== '\r') {
1295 Parser
->State
= BodyParserLastCRLFEnd
;
1298 Parser
->State
= BodyParserTrailer
;
1302 case BodyParserLastCRLFEnd
:
1303 if (*Char
== '\n') {
1304 Parser
->State
= BodyParserComplete
;
1306 if (Parser
->Callback
!= NULL
) {
1307 Status
= Parser
->Callback (
1308 BodyParseEventOnComplete
,
1313 if (EFI_ERROR (Status
)) {
1319 Parser
->State
= BodyParserStateMax
;
1323 case BodyParserTrailer
:
1324 if (*Char
== '\r') {
1325 Parser
->State
= BodyParserChunkSizeEndCR
;
1330 case BodyParserChunkDataStart
:
1332 // First byte of chunk-data, the chunk data also might be truncated.
1334 RemainderLengthInThis
= BodyLength
- (Char
- Body
);
1335 LengthForCallback
= MIN (Parser
->CurrentChunkSize
- Parser
->CurrentChunkParsedSize
, RemainderLengthInThis
);
1336 if (Parser
->Callback
!= NULL
) {
1337 Status
= Parser
->Callback (
1338 BodyParseEventOnData
,
1343 if (EFI_ERROR (Status
)) {
1347 Char
+= LengthForCallback
;
1348 Parser
->ContentLength
+= LengthForCallback
;
1349 Parser
->CurrentChunkParsedSize
+= LengthForCallback
;
1350 if (Parser
->CurrentChunkParsedSize
== Parser
->CurrentChunkSize
) {
1351 Parser
->State
= BodyParserChunkDataEnd
;
1355 case BodyParserChunkDataEnd
:
1356 if (*Char
== '\r') {
1357 Parser
->State
= BodyParserChunkDataEndCR
;
1359 Parser
->State
= BodyParserStateMax
;
1364 case BodyParserChunkDataEndCR
:
1365 if (*Char
!= '\n') {
1366 Parser
->State
= BodyParserStateMax
;
1370 Parser
->State
= BodyParserChunkSizeStart
;
1379 if (Parser
->State
== BodyParserStateMax
) {
1387 Check whether the message-body is complete or not.
1389 @param[in] MsgParser Pointer to the message parser.
1391 @retval TRUE Message-body is complete.
1392 @retval FALSE Message-body is not complete.
1397 HttpIsMessageComplete (
1401 HTTP_BODY_PARSER
*Parser
;
1403 if (MsgParser
== NULL
) {
1407 Parser
= (HTTP_BODY_PARSER
*) MsgParser
;
1409 if (Parser
->State
== BodyParserComplete
) {
1416 Get the content length of the entity.
1418 Note that in trunk transfer, the entity length is not valid until the whole message body is received.
1420 @param[in] MsgParser Pointer to the message parser.
1421 @param[out] ContentLength Pointer to store the length of the entity.
1423 @retval EFI_SUCCESS Successfully to get the entity length.
1424 @retval EFI_NOT_READY Entity length is not valid yet.
1425 @retval EFI_INVALID_PARAMETER MsgParser is NULL or ContentLength is NULL.
1430 HttpGetEntityLength (
1432 OUT UINTN
*ContentLength
1435 HTTP_BODY_PARSER
*Parser
;
1437 if (MsgParser
== NULL
|| ContentLength
== NULL
) {
1438 return EFI_INVALID_PARAMETER
;
1441 Parser
= (HTTP_BODY_PARSER
*) MsgParser
;
1443 if (!Parser
->ContentLengthIsValid
) {
1444 return EFI_NOT_READY
;
1447 *ContentLength
= Parser
->ContentLength
;
1452 Release the resource of the message parser.
1454 @param[in] MsgParser Pointer to the message parser.
1463 FreePool (MsgParser
);
1468 Get the next string, which is distinguished by specified separator.
1470 @param[in] String Pointer to the string.
1471 @param[in] Separator Specified separator used to distinguish where is the beginning
1474 @return Pointer to the next string.
1475 @return NULL if not find or String is NULL.
1480 AsciiStrGetNextToken (
1481 IN CONST CHAR8
*String
,
1492 if (*Token
== Separator
) {
1493 return (CHAR8
*)(Token
+ 1);
1500 Set FieldName and FieldValue into specified HttpHeader.
1502 @param[in,out] HttpHeader Specified HttpHeader.
1503 @param[in] FieldName FieldName of this HttpHeader, a NULL terminated ASCII string.
1504 @param[in] FieldValue FieldValue of this HttpHeader, a NULL terminated ASCII string.
1507 @retval EFI_SUCCESS The FieldName and FieldValue are set into HttpHeader successfully.
1508 @retval EFI_INVALID_PARAMETER The parameter is invalid.
1509 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
1514 HttpSetFieldNameAndValue (
1515 IN OUT EFI_HTTP_HEADER
*HttpHeader
,
1516 IN CONST CHAR8
*FieldName
,
1517 IN CONST CHAR8
*FieldValue
1520 UINTN FieldNameSize
;
1521 UINTN FieldValueSize
;
1523 if (HttpHeader
== NULL
|| FieldName
== NULL
|| FieldValue
== NULL
) {
1524 return EFI_INVALID_PARAMETER
;
1527 if (HttpHeader
->FieldName
!= NULL
) {
1528 FreePool (HttpHeader
->FieldName
);
1530 if (HttpHeader
->FieldValue
!= NULL
) {
1531 FreePool (HttpHeader
->FieldValue
);
1534 FieldNameSize
= AsciiStrSize (FieldName
);
1535 HttpHeader
->FieldName
= AllocateZeroPool (FieldNameSize
);
1536 if (HttpHeader
->FieldName
== NULL
) {
1537 return EFI_OUT_OF_RESOURCES
;
1539 CopyMem (HttpHeader
->FieldName
, FieldName
, FieldNameSize
);
1540 HttpHeader
->FieldName
[FieldNameSize
- 1] = 0;
1542 FieldValueSize
= AsciiStrSize (FieldValue
);
1543 HttpHeader
->FieldValue
= AllocateZeroPool (FieldValueSize
);
1544 if (HttpHeader
->FieldValue
== NULL
) {
1545 FreePool (HttpHeader
->FieldName
);
1546 return EFI_OUT_OF_RESOURCES
;
1548 CopyMem (HttpHeader
->FieldValue
, FieldValue
, FieldValueSize
);
1549 HttpHeader
->FieldValue
[FieldValueSize
- 1] = 0;
1555 Get one key/value header pair from the raw string.
1557 @param[in] String Pointer to the raw string.
1558 @param[out] FieldName Points directly to field name within 'HttpHeader'.
1559 @param[out] FieldValue Points directly to field value within 'HttpHeader'.
1561 @return Pointer to the next raw string.
1562 @return NULL if no key/value header pair from this raw string.
1567 HttpGetFieldNameAndValue (
1569 OUT CHAR8
**FieldName
,
1570 OUT CHAR8
**FieldValue
1573 CHAR8
*FieldNameStr
;
1574 CHAR8
*FieldValueStr
;
1578 if (String
== NULL
|| FieldName
== NULL
|| FieldValue
== NULL
) {
1584 FieldNameStr
= NULL
;
1585 FieldValueStr
= NULL
;
1591 // Check whether the raw HTTP header string is valid or not.
1593 EndofHeader
= AsciiStrStr (String
, "\r\n\r\n");
1594 if (EndofHeader
== NULL
) {
1599 // Each header field consists of a name followed by a colon (":") and the field value.
1601 FieldNameStr
= String
;
1602 FieldValueStr
= AsciiStrGetNextToken (FieldNameStr
, ':');
1603 if (FieldValueStr
== NULL
) {
1608 // Replace ':' with 0
1610 *(FieldValueStr
- 1) = 0;
1613 // The field value MAY be preceded by any amount of LWS, though a single SP is preferred.
1614 // Note: LWS = [CRLF] 1*(SP|HT), it can be '\r\n ' or '\r\n\t' or ' ' or '\t'.
1620 if (*FieldValueStr
== ' ' || *FieldValueStr
== '\t') {
1622 // Boundary condition check.
1624 if ((UINTN
)EndofHeader
- (UINTN
)(FieldValueStr
) < 1) {
1629 } else if (*FieldValueStr
== '\r') {
1631 // Boundary condition check.
1633 if ((UINTN
)EndofHeader
- (UINTN
)(FieldValueStr
) < 3) {
1637 if (*(FieldValueStr
+ 1) == '\n' && (*(FieldValueStr
+ 2) == ' ' || *(FieldValueStr
+ 2) == '\t')) {
1638 FieldValueStr
= FieldValueStr
+ 3;
1646 // Header fields can be extended over multiple lines by preceding each extra
1647 // line with at least one SP or HT.
1649 StrPtr
= FieldValueStr
;
1651 StrPtr
= AsciiStrGetNextToken (StrPtr
, '\r');
1652 if (StrPtr
== NULL
|| *StrPtr
!= '\n') {
1657 } while (*StrPtr
== ' ' || *StrPtr
== '\t');
1660 // Replace '\r' with 0
1665 // Get FieldName and FieldValue.
1667 *FieldName
= FieldNameStr
;
1668 *FieldValue
= FieldValueStr
;
1674 Free existing HeaderFields.
1676 @param[in] HeaderFields Pointer to array of key/value header pairs waitting for free.
1677 @param[in] FieldCount The number of header pairs in HeaderFields.
1682 HttpFreeHeaderFields (
1683 IN EFI_HTTP_HEADER
*HeaderFields
,
1689 if (HeaderFields
!= NULL
) {
1690 for (Index
= 0; Index
< FieldCount
; Index
++) {
1691 if (HeaderFields
[Index
].FieldName
!= NULL
) {
1692 FreePool (HeaderFields
[Index
].FieldName
);
1694 if (HeaderFields
[Index
].FieldValue
!= NULL
) {
1695 FreePool (HeaderFields
[Index
].FieldValue
);
1699 FreePool (HeaderFields
);
1704 Generate HTTP request message.
1706 This function will allocate memory for the whole HTTP message and generate a
1707 well formatted HTTP Request message in it, include the Request-Line, header
1708 fields and also the message body. It is the caller's responsibility to free
1709 the buffer returned in *RequestMsg.
1711 @param[in] Message Pointer to the EFI_HTTP_MESSAGE structure which
1712 contains the required information to generate
1713 the HTTP request message.
1714 @param[in] Url The URL of a remote host.
1715 @param[out] RequestMsg Pointer to the created HTTP request message.
1716 NULL if any error occured.
1717 @param[out] RequestMsgSize Size of the RequestMsg (in bytes).
1719 @return EFI_SUCCESS If HTTP request string was created successfully
1720 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
1721 @retval EFI_INVALID_PARAMETER The input arguments are invalid
1726 HttpGenRequestMessage (
1727 IN CONST EFI_HTTP_MESSAGE
*Message
,
1728 IN CONST CHAR8
*Url
,
1729 OUT CHAR8
**RequestMsg
,
1730 OUT UINTN
*RequestMsgSize
1740 EFI_HTTP_HEADER
**AppendList
;
1742 EFI_HTTP_UTILITIES_PROTOCOL
*HttpUtilitiesProtocol
;
1744 Status
= EFI_SUCCESS
;
1750 HttpUtilitiesProtocol
= NULL
;
1753 // 1. If we have a Request, we cannot have a NULL Url
1754 // 2. If we have a Request, HeaderCount can not be non-zero
1755 // 3. If we do not have a Request, HeaderCount should be zero
1756 // 4. If we do not have Request and Headers, we need at least a message-body
1758 if ((Message
== NULL
|| RequestMsg
== NULL
|| RequestMsgSize
== NULL
) ||
1759 (Message
->Data
.Request
!= NULL
&& Url
== NULL
) ||
1760 (Message
->Data
.Request
!= NULL
&& Message
->HeaderCount
== 0) ||
1761 (Message
->Data
.Request
== NULL
&& Message
->HeaderCount
!= 0) ||
1762 (Message
->Data
.Request
== NULL
&& Message
->HeaderCount
== 0 && Message
->BodyLength
== 0)) {
1763 return EFI_INVALID_PARAMETER
;
1766 if (Message
->HeaderCount
!= 0) {
1768 // Locate the HTTP_UTILITIES protocol.
1770 Status
= gBS
->LocateProtocol (
1771 &gEfiHttpUtilitiesProtocolGuid
,
1773 (VOID
**)&HttpUtilitiesProtocol
1776 if (EFI_ERROR (Status
)) {
1777 DEBUG ((DEBUG_ERROR
,"Failed to locate Http Utilities protocol. Status = %r.\n", Status
));
1782 // Build AppendList to send into HttpUtilitiesBuild
1784 AppendList
= AllocateZeroPool (sizeof (EFI_HTTP_HEADER
*) * (Message
->HeaderCount
));
1785 if (AppendList
== NULL
) {
1786 return EFI_OUT_OF_RESOURCES
;
1789 for(Index
= 0; Index
< Message
->HeaderCount
; Index
++){
1790 AppendList
[Index
] = &Message
->Headers
[Index
];
1794 // Build raw HTTP Headers
1796 Status
= HttpUtilitiesProtocol
->Build (
1797 HttpUtilitiesProtocol
,
1802 Message
->HeaderCount
,
1808 if (AppendList
!= NULL
) {
1809 FreePool (AppendList
);
1812 if (EFI_ERROR (Status
) || HttpHdr
== NULL
){
1818 // If we have headers to be sent, account for it.
1820 if (Message
->HeaderCount
!= 0) {
1821 MsgSize
= HttpHdrSize
;
1825 // If we have a request line, account for the fields.
1827 if (Message
->Data
.Request
!= NULL
) {
1828 MsgSize
+= HTTP_METHOD_MAXIMUM_LEN
+ AsciiStrLen (HTTP_VERSION_CRLF_STR
) + AsciiStrLen (Url
);
1833 // If we have a message body to be sent, account for it.
1835 MsgSize
+= Message
->BodyLength
;
1838 // memory for the string that needs to be sent to TCP
1841 *RequestMsg
= AllocateZeroPool (MsgSize
);
1842 if (*RequestMsg
== NULL
) {
1843 Status
= EFI_OUT_OF_RESOURCES
;
1847 RequestPtr
= *RequestMsg
;
1849 // Construct header request
1851 if (Message
->Data
.Request
!= NULL
) {
1852 switch (Message
->Data
.Request
->Method
) {
1854 StrLength
= sizeof (HTTP_METHOD_GET
) - 1;
1855 CopyMem (RequestPtr
, HTTP_METHOD_GET
, StrLength
);
1856 RequestPtr
+= StrLength
;
1859 StrLength
= sizeof (HTTP_METHOD_PUT
) - 1;
1860 CopyMem (RequestPtr
, HTTP_METHOD_PUT
, StrLength
);
1861 RequestPtr
+= StrLength
;
1863 case HttpMethodPatch
:
1864 StrLength
= sizeof (HTTP_METHOD_PATCH
) - 1;
1865 CopyMem (RequestPtr
, HTTP_METHOD_PATCH
, StrLength
);
1866 RequestPtr
+= StrLength
;
1868 case HttpMethodPost
:
1869 StrLength
= sizeof (HTTP_METHOD_POST
) - 1;
1870 CopyMem (RequestPtr
, HTTP_METHOD_POST
, StrLength
);
1871 RequestPtr
+= StrLength
;
1873 case HttpMethodHead
:
1874 StrLength
= sizeof (HTTP_METHOD_HEAD
) - 1;
1875 CopyMem (RequestPtr
, HTTP_METHOD_HEAD
, StrLength
);
1876 RequestPtr
+= StrLength
;
1878 case HttpMethodDelete
:
1879 StrLength
= sizeof (HTTP_METHOD_DELETE
) - 1;
1880 CopyMem (RequestPtr
, HTTP_METHOD_DELETE
, StrLength
);
1881 RequestPtr
+= StrLength
;
1885 Status
= EFI_INVALID_PARAMETER
;
1889 StrLength
= AsciiStrLen(EMPTY_SPACE
);
1890 CopyMem (RequestPtr
, EMPTY_SPACE
, StrLength
);
1891 RequestPtr
+= StrLength
;
1893 StrLength
= AsciiStrLen (Url
);
1894 CopyMem (RequestPtr
, Url
, StrLength
);
1895 RequestPtr
+= StrLength
;
1897 StrLength
= sizeof (HTTP_VERSION_CRLF_STR
) - 1;
1898 CopyMem (RequestPtr
, HTTP_VERSION_CRLF_STR
, StrLength
);
1899 RequestPtr
+= StrLength
;
1901 if (HttpHdr
!= NULL
) {
1905 CopyMem (RequestPtr
, HttpHdr
, HttpHdrSize
);
1906 RequestPtr
+= HttpHdrSize
;
1913 if (Message
->Body
!= NULL
) {
1914 CopyMem (RequestPtr
, Message
->Body
, Message
->BodyLength
);
1915 RequestPtr
+= Message
->BodyLength
;
1921 (*RequestMsgSize
) = (UINTN
)(RequestPtr
) - (UINTN
)(*RequestMsg
);
1927 if (*RequestMsg
!= NULL
) {
1928 FreePool (*RequestMsg
);
1934 if (HttpHdr
!= NULL
) {
1942 Translate the status code in HTTP message to EFI_HTTP_STATUS_CODE defined
1943 in UEFI 2.5 specification.
1945 @param[in] StatusCode The status code value in HTTP message.
1947 @return Value defined in EFI_HTTP_STATUS_CODE .
1950 EFI_HTTP_STATUS_CODE
1952 HttpMappingToStatusCode (
1956 switch (StatusCode
) {
1958 return HTTP_STATUS_100_CONTINUE
;
1960 return HTTP_STATUS_101_SWITCHING_PROTOCOLS
;
1962 return HTTP_STATUS_200_OK
;
1964 return HTTP_STATUS_201_CREATED
;
1966 return HTTP_STATUS_202_ACCEPTED
;
1968 return HTTP_STATUS_203_NON_AUTHORITATIVE_INFORMATION
;
1970 return HTTP_STATUS_204_NO_CONTENT
;
1972 return HTTP_STATUS_205_RESET_CONTENT
;
1974 return HTTP_STATUS_206_PARTIAL_CONTENT
;
1976 return HTTP_STATUS_300_MULTIPLE_CHOICES
;
1978 return HTTP_STATUS_301_MOVED_PERMANENTLY
;
1980 return HTTP_STATUS_302_FOUND
;
1982 return HTTP_STATUS_303_SEE_OTHER
;
1984 return HTTP_STATUS_304_NOT_MODIFIED
;
1986 return HTTP_STATUS_305_USE_PROXY
;
1988 return HTTP_STATUS_307_TEMPORARY_REDIRECT
;
1990 return HTTP_STATUS_308_PERMANENT_REDIRECT
;
1992 return HTTP_STATUS_400_BAD_REQUEST
;
1994 return HTTP_STATUS_401_UNAUTHORIZED
;
1996 return HTTP_STATUS_402_PAYMENT_REQUIRED
;
1998 return HTTP_STATUS_403_FORBIDDEN
;
2000 return HTTP_STATUS_404_NOT_FOUND
;
2002 return HTTP_STATUS_405_METHOD_NOT_ALLOWED
;
2004 return HTTP_STATUS_406_NOT_ACCEPTABLE
;
2006 return HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED
;
2008 return HTTP_STATUS_408_REQUEST_TIME_OUT
;
2010 return HTTP_STATUS_409_CONFLICT
;
2012 return HTTP_STATUS_410_GONE
;
2014 return HTTP_STATUS_411_LENGTH_REQUIRED
;
2016 return HTTP_STATUS_412_PRECONDITION_FAILED
;
2018 return HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE
;
2020 return HTTP_STATUS_414_REQUEST_URI_TOO_LARGE
;
2022 return HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE
;
2024 return HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED
;
2026 return HTTP_STATUS_417_EXPECTATION_FAILED
;
2028 return HTTP_STATUS_500_INTERNAL_SERVER_ERROR
;
2030 return HTTP_STATUS_501_NOT_IMPLEMENTED
;
2032 return HTTP_STATUS_502_BAD_GATEWAY
;
2034 return HTTP_STATUS_503_SERVICE_UNAVAILABLE
;
2036 return HTTP_STATUS_504_GATEWAY_TIME_OUT
;
2038 return HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED
;
2041 return HTTP_STATUS_UNSUPPORTED_STATUS
;
2046 Check whether header field called FieldName is in DeleteList.
2048 @param[in] DeleteList Pointer to array of key/value header pairs.
2049 @param[in] DeleteCount The number of header pairs.
2050 @param[in] FieldName Pointer to header field's name.
2052 @return TRUE if FieldName is not in DeleteList, that means this header field is valid.
2053 @return FALSE if FieldName is in DeleteList, that means this header field is invalid.
2058 HttpIsValidHttpHeader (
2059 IN CHAR8
*DeleteList
[],
2060 IN UINTN DeleteCount
,
2066 if (FieldName
== NULL
) {
2070 for (Index
= 0; Index
< DeleteCount
; Index
++) {
2071 if (DeleteList
[Index
] == NULL
) {
2075 if (AsciiStrCmp (FieldName
, DeleteList
[Index
]) == 0) {