NATS .NET Client  1.1.4
The NATS.io .NET C# Client
NATS.Client.MsgHeader Class Reference

Inherits IEnumerable.

Public Member Functions

 MsgHeader ()
 
 MsgHeader (MsgHeader header)
 
void Add (string name, string value)
 
void Set (string name, string value)
 
void Remove (string name)
 
void Clear ()
 
string[] GetValues (string name)
 
string GetFirst (string name)
 
string GetLast (string name)
 
IEnumerator GetEnumerator ()
 

Static Public Attributes

const string Status = "Status"
 
const string Description = "Description"
 

Properties

IEnumerable Keys [get]
 
int Count [get]
 
string this[string name] [get, set]
 

Detailed Description

The MsgHeader class provides key/value message header support similar to HTTP headers.

Keys and values may only contain printable ASCII character values and cannot contain :. Concurrent access may result in undefined behavior.

Setting a header field in a message:

var m = new Msg();
m.Header["Content-Type"] = "json";

Getting a header field from a message:

string contentType = m.Header["Content-Type"];

To set multiple values:

m.Header.Add("foo", "value1");
m.Header.Add("foo", "value2");

Get multiple values:

string []values = m.Header.GetValues("foo");

Constructor & Destructor Documentation

◆ MsgHeader()

NATS.Client.MsgHeader.MsgHeader ( MsgHeader  header)

Copies the entries from an existing MsgHeader instance to a new MsgHeader instance.

The header cannot be empty or contain invalid fields.

Parameters
headerthe NATS message header to copy.

Member Function Documentation

◆ Add()

void NATS.Client.MsgHeader.Add ( string  name,
string  value 
)

Add a header field with the specified name and value.

Parameters
nameName of the header field.
valueValue of the header field.

◆ GetEnumerator()

IEnumerator NATS.Client.MsgHeader.GetEnumerator ( )

Returns an enumerator that iterates through the message header keys.

Returns

◆ GetFirst()

string NATS.Client.MsgHeader.GetFirst ( string  name)

Gets the first value for the specific key. Will be null if the key is not found

Parameters
name
Returns

◆ GetLast()

string NATS.Client.MsgHeader.GetLast ( string  name)

Gets the last value for the specific key. Will be null if the key is not found

Parameters
name
Returns

◆ GetValues()

string[] NATS.Client.MsgHeader.GetValues ( string  name)

Gets all values of a header field.

Parameters
name
Returns

◆ Remove()

void NATS.Client.MsgHeader.Remove ( string  name)

Remove a header entry.

Parameters
nameName of the header field to remove.

◆ Set()

void NATS.Client.MsgHeader.Set ( string  name,
string  value 
)

Sets the value of a message header field.

Parameters
nameName of the header field to set.
valueValue of the header field.

Property Documentation

◆ this[string name]

string NATS.Client.MsgHeader.this[string name]
getset

Gets or sets the string entry with the specified string key in the message header.

Parameters
nameThe string key of the entry to locate. The key cannot be null, empty, or whitespace.
Returns
A string that contains the comma-separated list of values associated with the specified key, if found; otherwise, null

The documentation for this class was generated from the following file: