Parrot.Sip.Headers.MaxForwards (Parrot Platform v0.0.1-alpha.3)
Module for working with SIP Max-Forwards headers as defined in RFC 3261 Section 20.22.
The Max-Forwards header is used to limit the number of proxies or gateways that can forward a request. It consists of a single integer value that is decremented by each proxy that forwards the message.
Max-Forwards serves important purposes in SIP:
- Preventing infinite loops in proxy networks
- Detecting forwarding loops caused by misconfiguration
- Limiting the request scope to a specific number of hops
- Triggering 483 (Too Many Hops) responses when reaching zero
Each proxy MUST decrement the Max-Forwards value by one when forwarding a request. The recommended initial value is 70, as specified in RFC 3261 Section 8.1.1.6.
References:
- RFC 3261 Section 8.1.1.6: Max-Forwards
- RFC 3261 Section 16.6: Request Forwarding (proxy behavior)
- RFC 3261 Section 20.22: Max-Forwards Header Field
- RFC 3261 Section 21.4.20: 483 Too Many Hops
Summary
Functions
Decrements the Max-Forwards value by 1. Returns nil if value is already 0.
Creates a new Max-Forwards header with the default value of 70.
Formats a Max-Forwards value as a string.
Creates a new Max-Forwards header with the specified value.
Parses a Max-Forwards header string into an integer value.
Checks if the Max-Forwards value has reached 0.
Functions
Decrements the Max-Forwards value by 1. Returns nil if value is already 0.
Examples
iex> Parrot.Sip.Headers.MaxForwards.decrement(70)
69
iex> Parrot.Sip.Headers.MaxForwards.decrement(1)
0
iex> Parrot.Sip.Headers.MaxForwards.decrement(0)
nil
@spec default() :: integer()
Creates a new Max-Forwards header with the default value of 70.
Examples
iex> Parrot.Sip.Headers.MaxForwards.default()
70
Formats a Max-Forwards value as a string.
Examples
iex> Parrot.Sip.Headers.MaxForwards.format(70)
"70"
iex> Parrot.Sip.Headers.MaxForwards.format(0)
"0"
Creates a new Max-Forwards header with the specified value.
Examples
iex> Parrot.Sip.Headers.MaxForwards.new(70)
70
Parses a Max-Forwards header string into an integer value.
Examples
iex> Parrot.Sip.Headers.MaxForwards.parse("70")
70
iex> Parrot.Sip.Headers.MaxForwards.parse("0")
0
Checks if the Max-Forwards value has reached 0.
Examples
iex> Parrot.Sip.Headers.MaxForwards.zero?(0)
true
iex> Parrot.Sip.Headers.MaxForwards.zero?(1)
false