Class
HTTPHeaders

Base class for RequestHeaders and ResponseHeaders

Definition

Namespace:Fiddler

Assembly:FiddlerCore.dll

Syntax:

cs-api-definition
public abstract class HTTPHeaders

Inheritance: objectHTTPHeaders

Derived Classes: HTTPRequestHeadersHTTPResponseHeaders

Inherited Members object.GetType()object.MemberwiseClone()object.ToString()object.Equals(object)object.Equals(object, object)object.ReferenceEquals(object, object)object.GetHashCode()

Constructors

HTTPHeaders()

Declaration

cs-api-definition
protected HTTPHeaders()

Fields

HTTPVersion

HTTP version (e.g. HTTP/1.1)

Declaration

cs-api-definition
[CodeDescription("HTTP version (e.g. HTTP/1.1).")]
public string HTTPVersion

Field Value

string

_HeaderEncoding

Text encoding to be used when converting this header object to/from a byte array

Declaration

cs-api-definition
protected Encoding _HeaderEncoding

Field Value

Encoding

storage

Storage for individual HTTPHeaderItems in this header collection NB: Using a list is important, as order can matter

Declaration

cs-api-definition
protected List<HTTPHeaderItem> storage

Field Value

List<HTTPHeaderItem>

Properties

this[int]

Indexer property. Returns HTTPHeaderItem by index. Throws Exception if index out of bounds

Declaration

cs-api-definition
[CodeDescription("Indexer property. Returns HTTPHeaderItem by index.")]
public HTTPHeaderItem this[int iHeaderNumber] { get; set; }

Parameters

iHeaderNumber

int

Property Value

HTTPHeaderItem

this[string]

Gets or sets the value of a header. In the case of Gets, the value of the first header of that name is returned. If the header does not exist, returns null. In the case of Sets, the value of the first header of that name is updated.
If the header does not exist, it is added.

Declaration

cs-api-definition
[CodeDescription("Indexer property. Gets or sets the value of a header. In the case of Gets, the value of the FIRST header of that name is returned.\nIf the header does not exist, returns null.\nIn the case of Sets, the value of the FIRST header of that name is updated.\nIf the header does not exist, it is added.")]
public string this[string HeaderName] { get; set; }

Parameters

HeaderName

string

Property Value

string

Methods

Add(string, string)

Adds a new header containing the specified name and value.

Declaration

cs-api-definition
[CodeDescription("Add a new header containing the specified name and value.")]
public HTTPHeaderItem Add(string sHeaderName, string sValue)

Parameters

sHeaderName

string

Name of the header to add.

sValue

string

Value of the header.

Returns

HTTPHeaderItem

Returns the newly-created HTTPHeaderItem.

Add(string, string, bool)

Adds a new header containing the specified name and value and sensitive flag.

Declaration

cs-api-definition
[CodeDescription("Add a new header containing the specified name and value.")]
public HTTPHeaderItem Add(string sHeaderName, string sValue, bool bSensitive)

Parameters

sHeaderName

string

Name of the header to add.

sValue

string

Value of the header.

bSensitive

bool

HTTP2 specific - does the header contain sensitive information.

Returns

HTTPHeaderItem

Returns the newly-created HTTPHeaderItem.

AddPseudoHeader(string, string)

Adds a new pseudo header containing the specified name and value. If header already was added, it will replace the previous value

Declaration

cs-api-definition
public HTTPHeaderItem AddPseudoHeader(string sHeaderName, string sValue)

Parameters

sHeaderName

string

Name of the pseudo header to add.

sValue

string

Value of the pseudo header.

Returns

HTTPHeaderItem

Returns the newly-created HTTPHeaderItem.

AddRange(IEnumerable<HTTPHeaderItem>)

Adds one or more headers

Declaration

cs-api-definition
public void AddRange(IEnumerable<HTTPHeaderItem> collHIs)

Parameters

collHIs

IEnumerable<HTTPHeaderItem>

AllValues(string)

Returns all values of the named header in a single string, delimited by commas

Declaration

cs-api-definition
public string AllValues(string sHeaderName)

Parameters

sHeaderName

string

Header

Returns

string

Each, Header's, Value

AssignFromString(string)

Parses a string and assigns the headers parsed to this object

Declaration

cs-api-definition
public abstract bool AssignFromString(string sHeaders)

Parameters

sHeaders

string

The header string

Returns

bool

TRUE if the operation succeeded, false otherwise

ByteCount()

Get byte count of this HTTP header instance when exported to a HTTP/1.1 headers string

Declaration

cs-api-definition
public virtual int ByteCount()

Returns

int

Byte Count

Count()

Number of HTTP headers

Declaration

cs-api-definition
[CodeDescription("Returns an integer representing the number of headers.")]
public int Count()

Returns

int

Number of HTTP headers

CountOf(string)

Returns the count of instances of the named header

Declaration

cs-api-definition
public int CountOf(string sHeaderName)

Parameters

sHeaderName

string

Header name

Returns

int

Count of instances of the named header

EscapeHeader(string, bool)

Escape HTTP2 header names/values

Declaration

cs-api-definition
protected static string EscapeHeader(string header, bool isName = false)

Parameters

header

string

The header name or value

isName

bool

True if escaping header name

Returns

string

Escaped name or value

Exists(string)

Determines if the Headers collection contains a header of the specified name, with any value.

Declaration

cs-api-definition
[CodeDescription("Returns true if the Headers collection contains a header of the specified (case-insensitive) name.")]
public bool Exists(string sHeaderName)

Parameters

sHeaderName

string

The name of the header to check. (case insensitive)

Returns

bool

True, if the header exists.

ExistsAndContains(string, string)

Determines if the Headers collection contains one or more headers of the specified name, and sHeaderValue is part of one of those Headers' value.

Declaration

cs-api-definition
[CodeDescription("Returns true if the collection contains a header of the specified (case-insensitive) name, and sHeaderValue (case-insensitive) is part of the Header's value.")]
public bool ExistsAndContains(string sHeaderName, string sHeaderValue)

Parameters

sHeaderName

string

The name of the header to check. (case insensitive)

sHeaderValue

string

The partial header value. (case insensitive)

Returns

bool

True if the header is found and the value case-insensitively contains the parameter

ExistsAndEquals(string, string, bool)

Determines if the Headers collection contains a header of the specified name, and sHeaderValue=Header's value. Similar to a case-insensitive version of: headers[sHeaderName]==sHeaderValue, although it checks all instances of the named header.

Declaration

cs-api-definition
[CodeDescription("Returns true if the collection contains a header of the specified (case-insensitive) name, with value sHeaderValue (case-insensitive).")]
public bool ExistsAndEquals(string sHeaderName, string sHeaderValue, bool isUrl = false)

Parameters

sHeaderName

string

The name of the header to check. (case insensitive)

sHeaderValue

string

The full header value. (case insensitive)

isUrl

bool

If true, compare the header values as URLs and if false - do a case insensitive string comparison

Returns

bool

True if the header is found and the value case-insensitively matches the parameter

ExistsAny(IEnumerable<string>)

Determines if the Headers collection contains any header from the specified list, with any value.

Declaration

cs-api-definition
[CodeDescription("Returns true if the Headers collection contains a header of the specified (case-insensitive) name.")]
public bool ExistsAny(IEnumerable<string> sHeaderNames)

Parameters

sHeaderNames

IEnumerable<string>

list of headers

Returns

bool

True, if any named header exists.

FilterByHeaderName(string[])

Filter all header items that have different header name from the given

Declaration

cs-api-definition
public void FilterByHeaderName(string[] headerNames)

Parameters

headerNames

string[]

FindAll(string)

Returns all instances of the named header

Declaration

cs-api-definition
public List<HTTPHeaderItem> FindAll(string sHeaderName)

Parameters

sHeaderName

string

Header name

Returns

List<HTTPHeaderItem>

List of instances of the named header

FreeReaderLock()

Frrees the Reader Lock. Executed after you finish enumerating the Storage collection.

Declaration

cs-api-definition
protected void FreeReaderLock()

FreeWriterLock()

If you get the Writer lock, Free it ASAP or you're going to hang or deadlock the Session

Declaration

cs-api-definition
protected void FreeWriterLock()

FromHeadersFrame(BasePipe, ArraySegment<byte>, uint, bool)

Read a data stream and extract HTTP/2 header frame(s) from it

Declaration

cs-api-definition
protected static List<HeaderField> FromHeadersFrame(BasePipe pipe, ArraySegment<byte> dataStream, uint streamId, bool useNewDecoder = false)

Parameters

pipe

BasePipe

The data pipe (used for HTTP2 settings and decoding header data)

dataStream

ArraySegment<byte>

Array containing the data (request/response)

streamId

uint

The HTTP/2 stream ID

useNewDecoder

bool

If true, a new HPACK decoder instance will be used (to prevent polluting the default decoder table).

Returns

List<HeaderField>

Array of "key: value" string objects

GetEnumerator()

Enumerator for HTTPHeader storage collection

Declaration

cs-api-definition
public IEnumerator GetEnumerator()

Returns

IEnumerator

Enumerator

GetReaderLock()

Get the Reader Lock if you plan to enumerate the Storage collection.

Declaration

cs-api-definition
protected void GetReaderLock()

GetTokenValue(string, string)

Returns the Value from a token in the header. Correctly handles double-quoted strings. Requires semicolon for delimiting tokens Limitation: FAILS if semicolon is in token's value, even if quoted. FAILS in the case of crazy headers, e.g. Header: Blah="SoughtToken=Blah" SoughtToken=MissedMe

We really need a "proper" header parser

Declaration

cs-api-definition
[CodeDescription("Returns a string representing the value of the named token within the named header.")]
public string GetTokenValue(string sHeaderName, string sTokenName)

Parameters

sHeaderName

string

Name of the header

sTokenName

string

Name of the token

Returns

string

Value of the token if present; otherwise, null

GetWriterLock()

Get the Writer Lock if you plan to change the Storage collection. NB: You only need this lock if you plan to change the collection itself; you can party on the items in the collection if you like without locking.

Declaration

cs-api-definition
protected void GetWriterLock()

Remove(HTTPHeaderItem)

Removes a HTTPHeader item from the collection

Declaration

cs-api-definition
public void Remove(HTTPHeaderItem oRemove)

Parameters

oRemove

HTTPHeaderItem

The HTTPHeader item to be removed

Remove(string)

Removes all headers from the header collection which have the specified name.

Declaration

cs-api-definition
[CodeDescription("Removes ALL headers from the header collection which have the specified (case-insensitive) name.")]
public void Remove(string sHeaderName)

Parameters

sHeaderName

string

The name of the header to remove. (case insensitive)

RemoveAll()

Removes all HTTPHeader items from the collection

Declaration

cs-api-definition
public void RemoveAll()

RemoveRange(string[])

Removes all headers from the header collection which have the specified names.

Declaration

cs-api-definition
[CodeDescription("Removes ALL headers from the header collection which have the specified (case-insensitive) names.")]
public void RemoveRange(string[] arrToRemove)

Parameters

arrToRemove

string[]

Array of names of headers to remove. (case insensitive)

RenameHeaderItems(string, string)

Renames all headers in the header collection which have the specified name.

Declaration

cs-api-definition
[CodeDescription("Renames ALL headers in the header collection which have the specified (case-insensitive) name.")]
public bool RenameHeaderItems(string sOldHeaderName, string sNewHeaderName)

Parameters

sOldHeaderName

string

The name of the header to rename. (case insensitive)

sNewHeaderName

string

The new name for the header.

Returns

bool

True if one or more replacements were made.

SortAscByKeyAndValue()

Sort all header items in ascending order by key and then by value

Declaration

cs-api-definition
public void SortAscByKeyAndValue()

ToArray()

Copies the Headers to a new array. Prefer this method over the enumerator to avoid cross-thread problems.

Declaration

cs-api-definition
public HTTPHeaderItem[] ToArray()

Returns

HTTPHeaderItem[]

An array containing HTTPHeaderItems