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
)) {
530 Name
[ResultLength
] = '\0';
537 Get the IPv4 address from a HTTP URL.
539 This function will return the IPv4 address according to the Url and previous parse result.
541 @param[in] Url The pointer to a HTTP URL string.
542 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
543 @param[out] Ip4Address Pointer to a buffer to store the IP address.
545 @retval EFI_SUCCESS Successfully get the required component.
546 @retval EFI_INVALID_PARAMETER Uri is NULL or Ip4Address is NULL or UrlParser is invalid.
547 @retval EFI_NOT_FOUND No IPv4 address component in the URL.
548 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
556 OUT EFI_IPv4_ADDRESS
*Ip4Address
562 HTTP_URL_PARSER
*Parser
;
564 if (Url
== NULL
|| UrlParser
== NULL
|| Ip4Address
== NULL
) {
565 return EFI_INVALID_PARAMETER
;
568 Parser
= (HTTP_URL_PARSER
*) UrlParser
;
570 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_HOST
)) == 0) {
571 return EFI_INVALID_PARAMETER
;
574 Ip4String
= AllocatePool (Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Length
+ 1);
575 if (Ip4String
== NULL
) {
576 return EFI_OUT_OF_RESOURCES
;
579 Status
= UriPercentDecode (
580 Url
+ Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Offset
,
581 Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Length
,
585 if (EFI_ERROR (Status
)) {
586 FreePool (Ip4String
);
590 Ip4String
[ResultLength
] = '\0';
591 Status
= NetLibAsciiStrToIp4 (Ip4String
, Ip4Address
);
592 FreePool (Ip4String
);
598 Get the IPv6 address from a HTTP URL.
600 This function will return the IPv6 address according to the Url and previous parse result.
602 @param[in] Url The pointer to a HTTP URL string.
603 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
604 @param[out] Ip6Address Pointer to a buffer to store the IP address.
606 @retval EFI_SUCCESS Successfully get the required component.
607 @retval EFI_INVALID_PARAMETER Uri is NULL or Ip6Address is NULL or UrlParser is invalid.
608 @retval EFI_NOT_FOUND No IPv6 address component in the URL.
609 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
617 OUT EFI_IPv6_ADDRESS
*Ip6Address
625 HTTP_URL_PARSER
*Parser
;
627 if (Url
== NULL
|| UrlParser
== NULL
|| Ip6Address
== NULL
) {
628 return EFI_INVALID_PARAMETER
;
631 Parser
= (HTTP_URL_PARSER
*) UrlParser
;
633 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_HOST
)) == 0) {
634 return EFI_INVALID_PARAMETER
;
638 // IP-literal = "[" ( IPv6address / IPvFuture ) "]"
640 Length
= Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Length
;
642 return EFI_INVALID_PARAMETER
;
645 Ptr
= Url
+ Parser
->FieldData
[HTTP_URI_FIELD_HOST
].Offset
;
646 if ((Ptr
[0] != '[') || (Ptr
[Length
- 1] != ']')) {
647 return EFI_INVALID_PARAMETER
;
650 Ip6String
= AllocatePool (Length
);
651 if (Ip6String
== NULL
) {
652 return EFI_OUT_OF_RESOURCES
;
655 Status
= UriPercentDecode (
661 if (EFI_ERROR (Status
)) {
662 FreePool (Ip6String
);
666 Ip6String
[ResultLength
] = '\0';
667 Status
= NetLibAsciiStrToIp6 (Ip6String
, Ip6Address
);
668 FreePool (Ip6String
);
674 Get the port number from a HTTP URL.
676 This function will return the port number according to the Url and previous parse result.
678 @param[in] Url The pointer to a HTTP URL string.
679 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
680 @param[out] Port Pointer to a buffer to store the port number.
682 @retval EFI_SUCCESS Successfully get the required component.
683 @retval EFI_INVALID_PARAMETER Uri is NULL or Port is NULL or UrlParser is invalid.
684 @retval EFI_NOT_FOUND No port number in the URL.
685 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
701 HTTP_URL_PARSER
*Parser
;
703 if (Url
== NULL
|| UrlParser
== NULL
|| Port
== NULL
) {
704 return EFI_INVALID_PARAMETER
;
710 Parser
= (HTTP_URL_PARSER
*) UrlParser
;
712 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_PORT
)) == 0) {
713 return EFI_INVALID_PARAMETER
;
716 PortString
= AllocatePool (Parser
->FieldData
[HTTP_URI_FIELD_PORT
].Length
+ 1);
717 if (PortString
== NULL
) {
718 return EFI_OUT_OF_RESOURCES
;
721 Status
= UriPercentDecode (
722 Url
+ Parser
->FieldData
[HTTP_URI_FIELD_PORT
].Offset
,
723 Parser
->FieldData
[HTTP_URI_FIELD_PORT
].Length
,
727 if (EFI_ERROR (Status
)) {
731 PortString
[ResultLength
] = '\0';
733 while (Index
< ResultLength
) {
734 if (!NET_IS_DIGIT (PortString
[Index
])) {
735 Status
= EFI_INVALID_PARAMETER
;
741 Status
= AsciiStrDecimalToUintnS (Url
+ Parser
->FieldData
[HTTP_URI_FIELD_PORT
].Offset
, (CHAR8
**) NULL
, &Data
);
743 if (Data
> HTTP_URI_PORT_MAX_NUM
) {
744 Status
= EFI_INVALID_PARAMETER
;
748 *Port
= (UINT16
) Data
;
751 FreePool (PortString
);
756 Get the Path from a HTTP URL.
758 This function will return the Path according to the Url and previous parse result,and
759 it is the caller's responsibility to free the buffer returned in *Path.
761 @param[in] Url The pointer to a HTTP URL string.
762 @param[in] UrlParser URL Parse result returned by NetHttpParseUrl().
763 @param[out] Path Pointer to a buffer to store the Path.
765 @retval EFI_SUCCESS Successfully get the required component.
766 @retval EFI_INVALID_PARAMETER Uri is NULL or HostName is NULL or UrlParser is invalid.
767 @retval EFI_NOT_FOUND No hostName component in the URL.
768 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
782 HTTP_URL_PARSER
*Parser
;
784 if (Url
== NULL
|| UrlParser
== NULL
|| Path
== NULL
) {
785 return EFI_INVALID_PARAMETER
;
788 Parser
= (HTTP_URL_PARSER
*) UrlParser
;
790 if ((Parser
->FieldBitMap
& BIT (HTTP_URI_FIELD_PATH
)) == 0) {
791 return EFI_NOT_FOUND
;
794 PathStr
= AllocatePool (Parser
->FieldData
[HTTP_URI_FIELD_PATH
].Length
+ 1);
795 if (PathStr
== NULL
) {
796 return EFI_OUT_OF_RESOURCES
;
799 Status
= UriPercentDecode (
800 Url
+ Parser
->FieldData
[HTTP_URI_FIELD_PATH
].Offset
,
801 Parser
->FieldData
[HTTP_URI_FIELD_PATH
].Length
,
805 if (EFI_ERROR (Status
)) {
810 PathStr
[ResultLength
] = '\0';
816 Release the resource of the URL parser.
818 @param[in] UrlParser Pointer to the parser.
827 FreePool (UrlParser
);
831 Find a specified header field according to the field name.
833 @param[in] HeaderCount Number of HTTP header structures in Headers list.
834 @param[in] Headers Array containing list of HTTP headers.
835 @param[in] FieldName Null terminated string which describes a field name.
837 @return Pointer to the found header or NULL.
843 IN UINTN HeaderCount
,
844 IN EFI_HTTP_HEADER
*Headers
,
850 if (HeaderCount
== 0 || Headers
== NULL
|| FieldName
== NULL
) {
854 for (Index
= 0; Index
< HeaderCount
; Index
++){
856 // Field names are case-insensitive (RFC 2616).
858 if (AsciiStriCmp (Headers
[Index
].FieldName
, FieldName
) == 0) {
859 return &Headers
[Index
];
867 BodyParserBodyIdentity
,
868 BodyParserChunkSizeStart
,
870 BodyParserChunkSizeEndCR
,
871 BodyParserChunkExtStart
,
872 BodyParserChunkDataStart
,
873 BodyParserChunkDataEnd
,
874 BodyParserChunkDataEndCR
,
877 BodyParserLastCRLFEnd
,
880 } HTTP_BODY_PARSE_STATE
;
883 BOOLEAN IgnoreBody
; // "MUST NOT" include a message-body
884 BOOLEAN IsChunked
; // "chunked" transfer-coding.
885 BOOLEAN ContentLengthIsValid
;
886 UINTN ContentLength
; // Entity length (not the message-body length), invalid until ContentLengthIsValid is TRUE
888 HTTP_BODY_PARSER_CALLBACK Callback
;
890 UINTN ParsedBodyLength
;
891 HTTP_BODY_PARSE_STATE State
;
892 UINTN CurrentChunkSize
;
893 UINTN CurrentChunkParsedSize
;
898 Convert an Ascii char to its uppercase.
900 @param[in] Char Ascii character.
902 @return Uppercase value of the input Char.
910 if (Char
>= 'a' && Char
<= 'z') {
911 return Char
- ('a' - 'A');
918 Convert an hexadecimal char to a value of type UINTN.
920 @param[in] Char Ascii character.
922 @return Value translated from Char.
926 HttpIoHexCharToUintn (
930 if (Char
>= '0' && Char
<= '9') {
934 return (10 + HttpIoCharToUpper (Char
) - 'A');
938 Get the value of the content length if there is a "Content-Length" header.
940 @param[in] HeaderCount Number of HTTP header structures in Headers.
941 @param[in] Headers Array containing list of HTTP headers.
942 @param[out] ContentLength Pointer to save the value of the content length.
944 @retval EFI_SUCCESS Successfully get the content length.
945 @retval EFI_NOT_FOUND No "Content-Length" header in the Headers.
949 HttpIoParseContentLengthHeader (
950 IN UINTN HeaderCount
,
951 IN EFI_HTTP_HEADER
*Headers
,
952 OUT UINTN
*ContentLength
955 EFI_HTTP_HEADER
*Header
;
957 Header
= HttpFindHeader (HeaderCount
, Headers
, HTTP_HEADER_CONTENT_LENGTH
);
958 if (Header
== NULL
) {
959 return EFI_NOT_FOUND
;
962 return AsciiStrDecimalToUintnS (Header
->FieldValue
, (CHAR8
**) NULL
, ContentLength
);
967 Check whether the HTTP message is using the "chunked" transfer-coding.
969 @param[in] HeaderCount Number of HTTP header structures in Headers.
970 @param[in] Headers Array containing list of HTTP headers.
972 @return The message is "chunked" transfer-coding (TRUE) or not (FALSE).
977 IN UINTN HeaderCount
,
978 IN EFI_HTTP_HEADER
*Headers
981 EFI_HTTP_HEADER
*Header
;
984 Header
= HttpFindHeader (HeaderCount
, Headers
, HTTP_HEADER_TRANSFER_ENCODING
);
985 if (Header
== NULL
) {
989 if (AsciiStriCmp (Header
->FieldValue
, "identity") != 0) {
997 Check whether the HTTP message should have a message-body.
999 @param[in] Method The HTTP method (e.g. GET, POST) for this HTTP message.
1000 @param[in] StatusCode Response status code returned by the remote host.
1002 @return The message should have a message-body (FALSE) or not (TRUE).
1006 HttpIoNoMessageBody (
1007 IN EFI_HTTP_METHOD Method
,
1008 IN EFI_HTTP_STATUS_CODE StatusCode
1013 // All responses to the HEAD request method
1014 // MUST NOT include a message-body, even though the presence of entity-
1015 // header fields might lead one to believe they do. All 1xx
1016 // (informational), 204 (no content), and 304 (not modified) responses
1017 // MUST NOT include a message-body. All other responses do include a
1018 // message-body, although it MAY be of zero length.
1020 if (Method
== HttpMethodHead
) {
1024 if ((StatusCode
== HTTP_STATUS_100_CONTINUE
) ||
1025 (StatusCode
== HTTP_STATUS_101_SWITCHING_PROTOCOLS
) ||
1026 (StatusCode
== HTTP_STATUS_204_NO_CONTENT
) ||
1027 (StatusCode
== HTTP_STATUS_304_NOT_MODIFIED
))
1036 Initialize a HTTP message-body parser.
1038 This function will create and initialize a HTTP message parser according to caller provided HTTP message
1039 header information. It is the caller's responsibility to free the buffer returned in *UrlParser by HttpFreeMsgParser().
1041 @param[in] Method The HTTP method (e.g. GET, POST) for this HTTP message.
1042 @param[in] StatusCode Response status code returned by the remote host.
1043 @param[in] HeaderCount Number of HTTP header structures in Headers.
1044 @param[in] Headers Array containing list of HTTP headers.
1045 @param[in] Callback Callback function that is invoked when parsing the HTTP message-body,
1046 set to NULL to ignore all events.
1047 @param[in] Context Pointer to the context that will be passed to Callback.
1048 @param[out] MsgParser Pointer to the returned buffer to store the message parser.
1050 @retval EFI_SUCCESS Successfully initialized the parser.
1051 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources.
1052 @retval EFI_INVALID_PARAMETER MsgParser is NULL or HeaderCount is not NULL but Headers is NULL.
1053 @retval Others Failed to initialize the parser.
1059 IN EFI_HTTP_METHOD Method
,
1060 IN EFI_HTTP_STATUS_CODE StatusCode
,
1061 IN UINTN HeaderCount
,
1062 IN EFI_HTTP_HEADER
*Headers
,
1063 IN HTTP_BODY_PARSER_CALLBACK Callback
,
1065 OUT VOID
**MsgParser
1069 HTTP_BODY_PARSER
*Parser
;
1071 if (HeaderCount
!= 0 && Headers
== NULL
) {
1072 return EFI_INVALID_PARAMETER
;
1075 if (MsgParser
== NULL
) {
1076 return EFI_INVALID_PARAMETER
;
1079 Parser
= AllocateZeroPool (sizeof (HTTP_BODY_PARSER
));
1080 if (Parser
== NULL
) {
1081 return EFI_OUT_OF_RESOURCES
;
1084 Parser
->State
= BodyParserBodyStart
;
1087 // Determine the message length according to RFC 2616.
1088 // 1. Check whether the message "MUST NOT" have a message-body.
1090 Parser
->IgnoreBody
= HttpIoNoMessageBody (Method
, StatusCode
);
1092 // 2. Check whether the message using "chunked" transfer-coding.
1094 Parser
->IsChunked
= HttpIoIsChunked (HeaderCount
, Headers
);
1096 // 3. Check whether the message has a Content-Length header field.
1098 Status
= HttpIoParseContentLengthHeader (HeaderCount
, Headers
, &Parser
->ContentLength
);
1099 if (!EFI_ERROR (Status
)) {
1100 Parser
->ContentLengthIsValid
= TRUE
;
1103 // 4. Range header is not supported now, so we won't meet media type "multipart/byteranges".
1104 // 5. By server closing the connection
1108 // Set state to skip body parser if the message shouldn't have a message body.
1110 if (Parser
->IgnoreBody
) {
1111 Parser
->State
= BodyParserComplete
;
1113 Parser
->Callback
= Callback
;
1114 Parser
->Context
= Context
;
1117 *MsgParser
= Parser
;
1124 Parse BodyLength of message-body. This function can be called repeatedly to parse the message-body partially.
1126 @param[in, out] MsgParser Pointer to the message parser.
1127 @param[in] BodyLength Length in bytes of the Body.
1128 @param[in] Body Pointer to the buffer of the message-body to be parsed.
1130 @retval EFI_SUCCESS Successfully parse the message-body.
1131 @retval EFI_INVALID_PARAMETER MsgParser is NULL or Body is NULL or BodyLength is 0.
1132 @retval Others Operation aborted.
1137 HttpParseMessageBody (
1138 IN OUT VOID
*MsgParser
,
1139 IN UINTN BodyLength
,
1144 UINTN RemainderLengthInThis
;
1145 UINTN LengthForCallback
;
1147 HTTP_BODY_PARSER
*Parser
;
1149 if (BodyLength
== 0 || Body
== NULL
) {
1150 return EFI_INVALID_PARAMETER
;
1153 if (MsgParser
== NULL
) {
1154 return EFI_INVALID_PARAMETER
;
1157 Parser
= (HTTP_BODY_PARSER
*) MsgParser
;
1159 if (Parser
->IgnoreBody
) {
1160 Parser
->State
= BodyParserComplete
;
1161 if (Parser
->Callback
!= NULL
) {
1162 Status
= Parser
->Callback (
1163 BodyParseEventOnComplete
,
1168 if (EFI_ERROR (Status
)) {
1175 if (Parser
->State
== BodyParserBodyStart
) {
1176 Parser
->ParsedBodyLength
= 0;
1177 if (Parser
->IsChunked
) {
1178 Parser
->State
= BodyParserChunkSizeStart
;
1180 Parser
->State
= BodyParserBodyIdentity
;
1185 // The message body might be truncated in anywhere, so we need to parse is byte-by-byte.
1187 for (Char
= Body
; Char
< Body
+ BodyLength
; ) {
1189 switch (Parser
->State
) {
1190 case BodyParserStateMax
:
1193 case BodyParserBodyIdentity
:
1195 // Identity transfer-coding, just notify user to save the body data.
1197 if (Parser
->Callback
!= NULL
) {
1198 Status
= Parser
->Callback (
1199 BodyParseEventOnData
,
1201 MIN (BodyLength
, Parser
->ContentLength
- Parser
->ParsedBodyLength
),
1204 if (EFI_ERROR (Status
)) {
1208 Char
+= MIN (BodyLength
, Parser
->ContentLength
- Parser
->ParsedBodyLength
);
1209 Parser
->ParsedBodyLength
+= MIN (BodyLength
, Parser
->ContentLength
- Parser
->ParsedBodyLength
);
1210 if (Parser
->ParsedBodyLength
== Parser
->ContentLength
) {
1211 Parser
->State
= BodyParserComplete
;
1212 if (Parser
->Callback
!= NULL
) {
1213 Status
= Parser
->Callback (
1214 BodyParseEventOnComplete
,
1219 if (EFI_ERROR (Status
)) {
1226 case BodyParserChunkSizeStart
:
1228 // First byte of chunk-size, the chunk-size might be truncated.
1230 Parser
->CurrentChunkSize
= 0;
1231 Parser
->State
= BodyParserChunkSize
;
1232 case BodyParserChunkSize
:
1233 if (!NET_IS_HEX_CHAR (*Char
)) {
1235 Parser
->State
= BodyParserChunkExtStart
;
1237 } else if (*Char
== '\r') {
1238 Parser
->State
= BodyParserChunkSizeEndCR
;
1241 Parser
->State
= BodyParserStateMax
;
1246 if (Parser
->CurrentChunkSize
> (((~((UINTN
) 0)) - 16) / 16)) {
1247 return EFI_INVALID_PARAMETER
;
1249 Parser
->CurrentChunkSize
= Parser
->CurrentChunkSize
* 16 + HttpIoHexCharToUintn (*Char
);
1253 case BodyParserChunkExtStart
:
1255 // Ignore all the chunk extensions.
1257 if (*Char
== '\r') {
1258 Parser
->State
= BodyParserChunkSizeEndCR
;
1263 case BodyParserChunkSizeEndCR
:
1264 if (*Char
!= '\n') {
1265 Parser
->State
= BodyParserStateMax
;
1269 if (Parser
->CurrentChunkSize
== 0) {
1271 // The last chunk has been parsed and now assumed the state
1272 // of HttpBodyParse is ParserLastCRLF. So it need to decide
1273 // whether the rest message is trailer or last CRLF in the next round.
1275 Parser
->ContentLengthIsValid
= TRUE
;
1276 Parser
->State
= BodyParserLastCRLF
;
1279 Parser
->State
= BodyParserChunkDataStart
;
1280 Parser
->CurrentChunkParsedSize
= 0;
1283 case BodyParserLastCRLF
:
1285 // Judge the byte is belong to the Last CRLF or trailer, and then
1286 // configure the state of HttpBodyParse to corresponding state.
1288 if (*Char
== '\r') {
1290 Parser
->State
= BodyParserLastCRLFEnd
;
1293 Parser
->State
= BodyParserTrailer
;
1297 case BodyParserLastCRLFEnd
:
1298 if (*Char
== '\n') {
1299 Parser
->State
= BodyParserComplete
;
1301 if (Parser
->Callback
!= NULL
) {
1302 Status
= Parser
->Callback (
1303 BodyParseEventOnComplete
,
1308 if (EFI_ERROR (Status
)) {
1314 Parser
->State
= BodyParserStateMax
;
1318 case BodyParserTrailer
:
1319 if (*Char
== '\r') {
1320 Parser
->State
= BodyParserChunkSizeEndCR
;
1325 case BodyParserChunkDataStart
:
1327 // First byte of chunk-data, the chunk data also might be truncated.
1329 RemainderLengthInThis
= BodyLength
- (Char
- Body
);
1330 LengthForCallback
= MIN (Parser
->CurrentChunkSize
- Parser
->CurrentChunkParsedSize
, RemainderLengthInThis
);
1331 if (Parser
->Callback
!= NULL
) {
1332 Status
= Parser
->Callback (
1333 BodyParseEventOnData
,
1338 if (EFI_ERROR (Status
)) {
1342 Char
+= LengthForCallback
;
1343 Parser
->ContentLength
+= LengthForCallback
;
1344 Parser
->CurrentChunkParsedSize
+= LengthForCallback
;
1345 if (Parser
->CurrentChunkParsedSize
== Parser
->CurrentChunkSize
) {
1346 Parser
->State
= BodyParserChunkDataEnd
;
1350 case BodyParserChunkDataEnd
:
1351 if (*Char
== '\r') {
1352 Parser
->State
= BodyParserChunkDataEndCR
;
1354 Parser
->State
= BodyParserStateMax
;
1359 case BodyParserChunkDataEndCR
:
1360 if (*Char
!= '\n') {
1361 Parser
->State
= BodyParserStateMax
;
1365 Parser
->State
= BodyParserChunkSizeStart
;
1374 if (Parser
->State
== BodyParserStateMax
) {
1382 Check whether the message-body is complete or not.
1384 @param[in] MsgParser Pointer to the message parser.
1386 @retval TRUE Message-body is complete.
1387 @retval FALSE Message-body is not complete.
1392 HttpIsMessageComplete (
1396 HTTP_BODY_PARSER
*Parser
;
1398 Parser
= (HTTP_BODY_PARSER
*) MsgParser
;
1400 if (Parser
->State
== BodyParserComplete
) {
1407 Get the content length of the entity.
1409 Note that in trunk transfer, the entity length is not valid until the whole message body is received.
1411 @param[in] MsgParser Pointer to the message parser.
1412 @param[out] ContentLength Pointer to store the length of the entity.
1414 @retval EFI_SUCCESS Successfully to get the entity length.
1415 @retval EFI_NOT_READY Entity length is not valid yet.
1416 @retval EFI_INVALID_PARAMETER MsgParser is NULL or ContentLength is NULL.
1421 HttpGetEntityLength (
1423 OUT UINTN
*ContentLength
1426 HTTP_BODY_PARSER
*Parser
;
1428 if (MsgParser
== NULL
|| ContentLength
== NULL
) {
1429 return EFI_INVALID_PARAMETER
;
1432 Parser
= (HTTP_BODY_PARSER
*) MsgParser
;
1434 if (!Parser
->ContentLengthIsValid
) {
1435 return EFI_NOT_READY
;
1438 *ContentLength
= Parser
->ContentLength
;
1443 Release the resource of the message parser.
1445 @param[in] MsgParser Pointer to the message parser.
1454 FreePool (MsgParser
);
1459 Get the next string, which is distinguished by specified separator.
1461 @param[in] String Pointer to the string.
1462 @param[in] Separator Specified separator used to distinguish where is the beginning
1465 @return Pointer to the next string.
1466 @return NULL if not find or String is NULL.
1471 AsciiStrGetNextToken (
1472 IN CONST CHAR8
*String
,
1483 if (*Token
== Separator
) {
1484 return (CHAR8
*)(Token
+ 1);
1491 Set FieldName and FieldValue into specified HttpHeader.
1493 @param[in,out] HttpHeader Specified HttpHeader.
1494 @param[in] FieldName FieldName of this HttpHeader, a NULL terminated ASCII string.
1495 @param[in] FieldValue FieldValue of this HttpHeader, a NULL terminated ASCII string.
1498 @retval EFI_SUCCESS The FieldName and FieldValue are set into HttpHeader successfully.
1499 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
1504 HttpSetFieldNameAndValue (
1505 IN OUT EFI_HTTP_HEADER
*HttpHeader
,
1506 IN CONST CHAR8
*FieldName
,
1507 IN CONST CHAR8
*FieldValue
1510 UINTN FieldNameSize
;
1511 UINTN FieldValueSize
;
1513 if (HttpHeader
->FieldName
!= NULL
) {
1514 FreePool (HttpHeader
->FieldName
);
1516 if (HttpHeader
->FieldValue
!= NULL
) {
1517 FreePool (HttpHeader
->FieldValue
);
1520 FieldNameSize
= AsciiStrSize (FieldName
);
1521 HttpHeader
->FieldName
= AllocateZeroPool (FieldNameSize
);
1522 if (HttpHeader
->FieldName
== NULL
) {
1523 return EFI_OUT_OF_RESOURCES
;
1525 CopyMem (HttpHeader
->FieldName
, FieldName
, FieldNameSize
);
1526 HttpHeader
->FieldName
[FieldNameSize
- 1] = 0;
1528 FieldValueSize
= AsciiStrSize (FieldValue
);
1529 HttpHeader
->FieldValue
= AllocateZeroPool (FieldValueSize
);
1530 if (HttpHeader
->FieldValue
== NULL
) {
1531 return EFI_OUT_OF_RESOURCES
;
1533 CopyMem (HttpHeader
->FieldValue
, FieldValue
, FieldValueSize
);
1534 HttpHeader
->FieldValue
[FieldValueSize
- 1] = 0;
1540 Get one key/value header pair from the raw string.
1542 @param[in] String Pointer to the raw string.
1543 @param[out] FieldName Points directly to field name within 'HttpHeader'.
1544 @param[out] FieldValue Points directly to field value within 'HttpHeader'.
1546 @return Pointer to the next raw string.
1547 @return NULL if no key/value header pair from this raw string.
1552 HttpGetFieldNameAndValue (
1554 OUT CHAR8
**FieldName
,
1555 OUT CHAR8
**FieldValue
1558 CHAR8
*FieldNameStr
;
1559 CHAR8
*FieldValueStr
;
1562 if (String
== NULL
|| FieldName
== NULL
|| FieldValue
== NULL
) {
1568 FieldNameStr
= NULL
;
1569 FieldValueStr
= NULL
;
1573 // Each header field consists of a name followed by a colon (":") and the field value.
1575 FieldNameStr
= String
;
1576 FieldValueStr
= AsciiStrGetNextToken (FieldNameStr
, ':');
1577 if (FieldValueStr
== NULL
) {
1582 // Replace ':' with 0
1584 *(FieldValueStr
- 1) = 0;
1587 // The field value MAY be preceded by any amount of LWS, though a single SP is preferred.
1590 if (*FieldValueStr
== ' ' || *FieldValueStr
== '\t') {
1592 } else if (*FieldValueStr
== '\r' && *(FieldValueStr
+ 1) == '\n' &&
1593 (*(FieldValueStr
+ 2) == ' ' || *(FieldValueStr
+ 2) == '\t')) {
1594 FieldValueStr
= FieldValueStr
+ 3;
1601 // Header fields can be extended over multiple lines by preceding each extra
1602 // line with at least one SP or HT.
1604 StrPtr
= FieldValueStr
;
1606 StrPtr
= AsciiStrGetNextToken (StrPtr
, '\r');
1607 if (StrPtr
== NULL
|| *StrPtr
!= '\n') {
1612 } while (*StrPtr
== ' ' || *StrPtr
== '\t');
1615 // Replace '\r' with 0
1620 // Get FieldName and FieldValue.
1622 *FieldName
= FieldNameStr
;
1623 *FieldValue
= FieldValueStr
;
1629 Free existing HeaderFields.
1631 @param[in] HeaderFields Pointer to array of key/value header pairs waitting for free.
1632 @param[in] FieldCount The number of header pairs in HeaderFields.
1637 HttpFreeHeaderFields (
1638 IN EFI_HTTP_HEADER
*HeaderFields
,
1644 if (HeaderFields
!= NULL
) {
1645 for (Index
= 0; Index
< FieldCount
; Index
++) {
1646 if (HeaderFields
[Index
].FieldName
!= NULL
) {
1647 FreePool (HeaderFields
[Index
].FieldName
);
1649 if (HeaderFields
[Index
].FieldValue
!= NULL
) {
1650 FreePool (HeaderFields
[Index
].FieldValue
);
1654 FreePool (HeaderFields
);
1659 Generate HTTP request message.
1661 This function will allocate memory for the whole HTTP message and generate a
1662 well formatted HTTP Request message in it, include the Request-Line, header
1663 fields and also the message body. It is the caller's responsibility to free
1664 the buffer returned in *RequestMsg.
1666 @param[in] Message Pointer to the EFI_HTTP_MESSAGE structure which
1667 contains the required information to generate
1668 the HTTP request message.
1669 @param[in] Url The URL of a remote host.
1670 @param[out] RequestMsg Pointer to the created HTTP request message.
1671 NULL if any error occured.
1672 @param[out] RequestMsgSize Size of the RequestMsg (in bytes).
1674 @return EFI_SUCCESS If HTTP request string was created successfully
1675 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources.
1676 @retval EFI_INVALID_PARAMETER The input arguments are invalid
1681 HttpGenRequestMessage (
1682 IN CONST EFI_HTTP_MESSAGE
*Message
,
1683 IN CONST CHAR8
*Url
,
1684 OUT CHAR8
**RequestMsg
,
1685 OUT UINTN
*RequestMsgSize
1695 EFI_HTTP_HEADER
**AppendList
;
1697 EFI_HTTP_UTILITIES_PROTOCOL
*HttpUtilitiesProtocol
;
1700 ASSERT (Message
!= NULL
);
1703 Status
= EFI_SUCCESS
;
1709 HttpUtilitiesProtocol
= NULL
;
1712 // 1. If we have a Request, we cannot have a NULL Url
1713 // 2. If we have a Request, HeaderCount can not be non-zero
1714 // 3. If we do not have a Request, HeaderCount should be zero
1715 // 4. If we do not have Request and Headers, we need at least a message-body
1717 if ((Message
->Data
.Request
!= NULL
&& Url
== NULL
) ||
1718 (Message
->Data
.Request
!= NULL
&& Message
->HeaderCount
== 0) ||
1719 (Message
->Data
.Request
== NULL
&& Message
->HeaderCount
!= 0) ||
1720 (Message
->Data
.Request
== NULL
&& Message
->HeaderCount
== 0 && Message
->BodyLength
== 0)) {
1721 return EFI_INVALID_PARAMETER
;
1724 if (Message
->HeaderCount
!= 0) {
1726 // Locate the HTTP_UTILITIES protocol.
1728 Status
= gBS
->LocateProtocol (
1729 &gEfiHttpUtilitiesProtocolGuid
,
1731 (VOID
**)&HttpUtilitiesProtocol
1734 if (EFI_ERROR (Status
)) {
1735 DEBUG ((DEBUG_ERROR
,"Failed to locate Http Utilities protocol. Status = %r.\n", Status
));
1740 // Build AppendList to send into HttpUtilitiesBuild
1742 AppendList
= AllocateZeroPool (sizeof (EFI_HTTP_HEADER
*) * (Message
->HeaderCount
));
1743 if (AppendList
== NULL
) {
1744 return EFI_OUT_OF_RESOURCES
;
1747 for(Index
= 0; Index
< Message
->HeaderCount
; Index
++){
1748 AppendList
[Index
] = &Message
->Headers
[Index
];
1752 // Build raw HTTP Headers
1754 Status
= HttpUtilitiesProtocol
->Build (
1755 HttpUtilitiesProtocol
,
1760 Message
->HeaderCount
,
1766 if (AppendList
!= NULL
) {
1767 FreePool (AppendList
);
1770 if (EFI_ERROR (Status
) || HttpHdr
== NULL
){
1776 // If we have headers to be sent, account for it.
1778 if (Message
->HeaderCount
!= 0) {
1779 MsgSize
= HttpHdrSize
;
1783 // If we have a request line, account for the fields.
1785 if (Message
->Data
.Request
!= NULL
) {
1786 MsgSize
+= HTTP_METHOD_MAXIMUM_LEN
+ AsciiStrLen (HTTP_VERSION_CRLF_STR
) + AsciiStrLen (Url
);
1791 // If we have a message body to be sent, account for it.
1793 MsgSize
+= Message
->BodyLength
;
1796 // memory for the string that needs to be sent to TCP
1798 *RequestMsg
= AllocateZeroPool (MsgSize
);
1799 if (*RequestMsg
== NULL
) {
1800 Status
= EFI_OUT_OF_RESOURCES
;
1804 RequestPtr
= *RequestMsg
;
1806 // Construct header request
1808 if (Message
->Data
.Request
!= NULL
) {
1809 switch (Message
->Data
.Request
->Method
) {
1811 StrLength
= sizeof (HTTP_METHOD_GET
) - 1;
1812 CopyMem (RequestPtr
, HTTP_METHOD_GET
, StrLength
);
1813 RequestPtr
+= StrLength
;
1816 StrLength
= sizeof (HTTP_METHOD_PUT
) - 1;
1817 CopyMem (RequestPtr
, HTTP_METHOD_PUT
, StrLength
);
1818 RequestPtr
+= StrLength
;
1820 case HttpMethodPatch
:
1821 StrLength
= sizeof (HTTP_METHOD_PATCH
) - 1;
1822 CopyMem (RequestPtr
, HTTP_METHOD_PATCH
, StrLength
);
1823 RequestPtr
+= StrLength
;
1825 case HttpMethodPost
:
1826 StrLength
= sizeof (HTTP_METHOD_POST
) - 1;
1827 CopyMem (RequestPtr
, HTTP_METHOD_POST
, StrLength
);
1828 RequestPtr
+= StrLength
;
1830 case HttpMethodHead
:
1831 StrLength
= sizeof (HTTP_METHOD_HEAD
) - 1;
1832 CopyMem (RequestPtr
, HTTP_METHOD_HEAD
, StrLength
);
1833 RequestPtr
+= StrLength
;
1835 case HttpMethodDelete
:
1836 StrLength
= sizeof (HTTP_METHOD_DELETE
) - 1;
1837 CopyMem (RequestPtr
, HTTP_METHOD_DELETE
, StrLength
);
1838 RequestPtr
+= StrLength
;
1842 Status
= EFI_INVALID_PARAMETER
;
1846 StrLength
= AsciiStrLen(EMPTY_SPACE
);
1847 CopyMem (RequestPtr
, EMPTY_SPACE
, StrLength
);
1848 RequestPtr
+= StrLength
;
1850 StrLength
= AsciiStrLen (Url
);
1851 CopyMem (RequestPtr
, Url
, StrLength
);
1852 RequestPtr
+= StrLength
;
1854 StrLength
= sizeof (HTTP_VERSION_CRLF_STR
) - 1;
1855 CopyMem (RequestPtr
, HTTP_VERSION_CRLF_STR
, StrLength
);
1856 RequestPtr
+= StrLength
;
1858 if (HttpHdr
!= NULL
) {
1862 CopyMem (RequestPtr
, HttpHdr
, HttpHdrSize
);
1863 RequestPtr
+= HttpHdrSize
;
1870 if (Message
->Body
!= NULL
) {
1871 CopyMem (RequestPtr
, Message
->Body
, Message
->BodyLength
);
1872 RequestPtr
+= Message
->BodyLength
;
1878 (*RequestMsgSize
) = (UINTN
)(RequestPtr
) - (UINTN
)(*RequestMsg
);
1884 if (*RequestMsg
!= NULL
) {
1885 FreePool (*RequestMsg
);
1891 if (HttpHdr
!= NULL
) {
1899 Translate the status code in HTTP message to EFI_HTTP_STATUS_CODE defined
1900 in UEFI 2.5 specification.
1902 @param[in] StatusCode The status code value in HTTP message.
1904 @return Value defined in EFI_HTTP_STATUS_CODE .
1907 EFI_HTTP_STATUS_CODE
1909 HttpMappingToStatusCode (
1913 switch (StatusCode
) {
1915 return HTTP_STATUS_100_CONTINUE
;
1917 return HTTP_STATUS_101_SWITCHING_PROTOCOLS
;
1919 return HTTP_STATUS_200_OK
;
1921 return HTTP_STATUS_201_CREATED
;
1923 return HTTP_STATUS_202_ACCEPTED
;
1925 return HTTP_STATUS_203_NON_AUTHORITATIVE_INFORMATION
;
1927 return HTTP_STATUS_204_NO_CONTENT
;
1929 return HTTP_STATUS_205_RESET_CONTENT
;
1931 return HTTP_STATUS_206_PARTIAL_CONTENT
;
1933 return HTTP_STATUS_300_MULTIPLE_CHIOCES
;
1935 return HTTP_STATUS_301_MOVED_PERMANENTLY
;
1937 return HTTP_STATUS_302_FOUND
;
1939 return HTTP_STATUS_303_SEE_OTHER
;
1941 return HTTP_STATUS_304_NOT_MODIFIED
;
1943 return HTTP_STATUS_305_USE_PROXY
;
1945 return HTTP_STATUS_307_TEMPORARY_REDIRECT
;
1947 return HTTP_STATUS_308_PERMANENT_REDIRECT
;
1949 return HTTP_STATUS_400_BAD_REQUEST
;
1951 return HTTP_STATUS_401_UNAUTHORIZED
;
1953 return HTTP_STATUS_402_PAYMENT_REQUIRED
;
1955 return HTTP_STATUS_403_FORBIDDEN
;
1957 return HTTP_STATUS_404_NOT_FOUND
;
1959 return HTTP_STATUS_405_METHOD_NOT_ALLOWED
;
1961 return HTTP_STATUS_406_NOT_ACCEPTABLE
;
1963 return HTTP_STATUS_407_PROXY_AUTHENTICATION_REQUIRED
;
1965 return HTTP_STATUS_408_REQUEST_TIME_OUT
;
1967 return HTTP_STATUS_409_CONFLICT
;
1969 return HTTP_STATUS_410_GONE
;
1971 return HTTP_STATUS_411_LENGTH_REQUIRED
;
1973 return HTTP_STATUS_412_PRECONDITION_FAILED
;
1975 return HTTP_STATUS_413_REQUEST_ENTITY_TOO_LARGE
;
1977 return HTTP_STATUS_414_REQUEST_URI_TOO_LARGE
;
1979 return HTTP_STATUS_415_UNSUPPORTED_MEDIA_TYPE
;
1981 return HTTP_STATUS_416_REQUESTED_RANGE_NOT_SATISFIED
;
1983 return HTTP_STATUS_417_EXPECTATION_FAILED
;
1985 return HTTP_STATUS_500_INTERNAL_SERVER_ERROR
;
1987 return HTTP_STATUS_501_NOT_IMPLEMENTED
;
1989 return HTTP_STATUS_502_BAD_GATEWAY
;
1991 return HTTP_STATUS_503_SERVICE_UNAVAILABLE
;
1993 return HTTP_STATUS_504_GATEWAY_TIME_OUT
;
1995 return HTTP_STATUS_505_HTTP_VERSION_NOT_SUPPORTED
;
1998 return HTTP_STATUS_UNSUPPORTED_STATUS
;
2003 Check whether header field called FieldName is in DeleteList.
2005 @param[in] DeleteList Pointer to array of key/value header pairs.
2006 @param[in] DeleteCount The number of header pairs.
2007 @param[in] FieldName Pointer to header field's name.
2009 @return TRUE if FieldName is not in DeleteList, that means this header field is valid.
2010 @return FALSE if FieldName is in DeleteList, that means this header field is invalid.
2015 HttpIsValidHttpHeader (
2016 IN CHAR8
*DeleteList
[],
2017 IN UINTN DeleteCount
,
2023 for (Index
= 0; Index
< DeleteCount
; Index
++) {
2024 if (AsciiStrCmp (FieldName
, DeleteList
[Index
]) == 0) {