Overview

Provides methods for parsing HTTP request headers. This class is not intended for direct use by your code.

The HttpRequestHeaderParser class is a utility class within the System.Net.Http.Headers namespace. It provides internal mechanisms for parsing various components of HTTP headers, such as tokens, quoted strings, and lists of values. These parsing methods are crucial for correctly interpreting the complex structure of HTTP headers.

While you might not call these methods directly in typical application development, understanding their purpose can be beneficial when dealing with advanced HTTP header manipulation or debugging network communication.

Constructors

HttpRequestHeaderParser()

Initializes a new instance of the HttpRequestHeaderParser class.
public HttpRequestHeaderParser()

This is the default constructor. It doesn't take any parameters and is used to create an instance of the parser.

Properties

Headers

Gets the collection of HTTP headers.
public HeaderDescriptorCollection Headers { get; }

This property likely returns a collection of descriptors for the standard HTTP headers that this parser is aware of. It's not typically accessed directly for parsing but might be used internally to manage header definitions.

Methods

ParseComment

Parses a comment from a header string.
protected static string ParseComment(string input, ref int index)

Parameters

input
The string containing the header value to parse.
index
A reference to the current position within the input string. This will be updated to the position after the parsed comment.

This method is designed to extract content enclosed in parentheses, which is treated as a comment in HTTP headers. It handles nested parentheses and escaping characters.

ParseQuotedString

Parses a quoted string from a header string.
protected static string ParseQuotedString(string input, ref int index)

Parameters

input
The string containing the header value to parse.
index
A reference to the current position within the input string. This will be updated to the position after the parsed quoted string.

This method extracts a string enclosed in double quotes, supporting escape sequences for quotes and backslashes within the string.

ParseSeparatedValues

Parses a list of values separated by a delimiter.
protected static IList<string> ParseSeparatedValues(string input, char delimiter)

Parameters

input
The string containing the header value to parse.
delimiter
The character used to separate the values.

This method splits a header value into a list of individual values based on a specified delimiter, often used for headers like Accept or Cache-Control.

ParseSpecification

Parses a header specification (e.g., a token with optional parameters).
protected static NameValueCollection ParseSpecification(string input, ref int index)

Parameters

input
The string containing the header value to parse.
index
A reference to the current position within the input string. This will be updated to the position after the parsed specification.

This method is used to parse complex header values that consist of a main token followed by semicolon-separated parameters, like Content-Type or Accept-Language.

ParseToken

Parses a token from a header string.
protected static string ParseToken(string input, ref int index)

Parameters

input
The string containing the header value to parse.
index
A reference to the current position within the input string. This will be updated to the position after the parsed token.

This method extracts a sequence of characters that forms a valid HTTP token, skipping leading whitespace and stopping at invalid characters or delimiters.