Class HeaderCollection
The http header collection.
Inherited Members
Namespace: Titanium.Web.Proxy.Http
Assembly: Titanium.Web.Proxy.dll
Syntax
[TypeConverter(typeof(ExpandableObjectConverter))]
public class HeaderCollection : IEnumerable<HttpHeader>, IEnumerable
Constructors
| Edit this page View SourceHeaderCollection()
Initializes a new instance of the HeaderCollection class.
Declaration
public HeaderCollection()
Properties
| Edit this page View SourceHeaders
Unique Request header collection.
Declaration
public ReadOnlyDictionary<string, HttpHeader> Headers { get; }
Property Value
| Type | Description |
|---|---|
| ReadOnlyDictionary<string, HttpHeader> |
NonUniqueHeaders
Non-unique headers. Values are read-only views over the internal lists so callers cannot
Add/Clear storage that still belongs to this collection.
Declaration
public ReadOnlyDictionary<string, IReadOnlyList<HttpHeader>> NonUniqueHeaders { get; }
Property Value
| Type | Description |
|---|---|
| ReadOnlyDictionary<string, IReadOnlyList<HttpHeader>> |
Methods
| Edit this page View SourceAddHeader(string, string)
Add a new header with given name and value
Declaration
public void AddHeader(string name, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | |
| string | value |
AddHeader(HttpHeader)
Adds the given header object to Request
Declaration
public void AddHeader(HttpHeader newHeader)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpHeader | newHeader |
AddHeaders(IEnumerable<KeyValuePair<string, string>>?)
Adds the given header objects to Request
Declaration
public void AddHeaders(IEnumerable<KeyValuePair<string, string>>? newHeaders)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<KeyValuePair<string, string>> | newHeaders |
AddHeaders(IEnumerable<KeyValuePair<string, HttpHeader>>?)
Adds the given header objects to Request
Declaration
public void AddHeaders(IEnumerable<KeyValuePair<string, HttpHeader>>? newHeaders)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<KeyValuePair<string, HttpHeader>> | newHeaders |
AddHeaders(IEnumerable<HttpHeader>?)
Adds the given header objects to Request
Declaration
public void AddHeaders(IEnumerable<HttpHeader>? newHeaders)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<HttpHeader> | newHeaders |
Clear()
Removes all the headers.
Declaration
public void Clear()
GetAllHeaders()
Returns all headers
Declaration
public List<HttpHeader> GetAllHeaders()
Returns
| Type | Description |
|---|---|
| List<HttpHeader> |
GetEnumerator()
Returns an enumerator that iterates through the collection.
Declaration
public HeaderCollection.Enumerator GetEnumerator()
Returns
| Type | Description |
|---|---|
| HeaderCollection.Enumerator | An enumerator that can be used to iterate through the collection. |
Remarks
Returns the concrete HeaderCollection.Enumerator struct rather than an interface type, matching
the pattern used by List<T>/Dictionary<TKey, TValue> in the BCL:
a foreach over a variable statically typed as HeaderCollection binds to
this overload directly and allocates nothing, whereas the previous implementation (chaining
Concat<TSource>(IEnumerable<TSource>, IEnumerable<TSource>) and SelectMany<TSource, TResult>(IEnumerable<TSource>, Func<TSource, IEnumerable<TResult>>)
over the two backing dictionaries) allocated two LINQ iterator objects on every call. This
matters here specifically because every outgoing request and response header block is
enumerated at least once to serialize it onto the wire, making this one of the hottest paths
in the proxy. Code that holds this collection through the IEnumerable<T>
interface (e.g. LINQ operators) still gets a correct enumerator via the explicit interface
implementation below, at the cost of one boxing allocation - unavoidable through that surface,
and unchanged from before this optimization.
GetFirstHeader(string)
Declaration
public HttpHeader? GetFirstHeader(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name |
Returns
| Type | Description |
|---|---|
| HttpHeader |
GetHeaders(string)
Returns all headers with given name if exists Returns null if doesn't exist
Declaration
public List<HttpHeader>? GetHeaders(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name |
Returns
| Type | Description |
|---|---|
| List<HttpHeader> |
HeaderExists(string)
True if header exists
Declaration
public bool HeaderExists(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name |
Returns
| Type | Description |
|---|---|
| bool |
RemoveHeader(string)
removes all headers with given name
Declaration
public bool RemoveHeader(string headerName)
Parameters
| Type | Name | Description |
|---|---|---|
| string | headerName |
Returns
| Type | Description |
|---|---|
| bool | True if header was removed False if no header exists with given name |
RemoveHeader(KnownHeader)
removes all headers with given name
Declaration
public bool RemoveHeader(KnownHeader headerName)
Parameters
| Type | Name | Description |
|---|---|---|
| KnownHeader | headerName |
Returns
| Type | Description |
|---|---|
| bool | True if header was removed False if no header exists with given name |
RemoveHeader(HttpHeader)
Removes given header object if it exist
Declaration
public bool RemoveHeader(HttpHeader header)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpHeader | header | Returns true if header exists and was removed |
Returns
| Type | Description |
|---|---|
| bool |