Parrot.Sip.Headers.ContentType (Parrot Platform v0.0.1-alpha.3)

Module for working with SIP Content-Type headers as defined in RFC 3261 Section 20.15.

The Content-Type header indicates the media type of the message body, providing information about how to interpret the message body. It follows the MIME type format as specified in RFC 2045.

Content-Type plays an important role in SIP messages:

  • Identifies the format of the message body (e.g., SDP, XML)
  • Allows proper parsing and rendering of the content
  • Facilitates content negotiation between endpoints
  • Enables support for multipart message bodies using the multipart/* type

Common Content-Type values in SIP include:

  • application/sdp: Session Description Protocol used for media negotiation
  • application/pidf+xml: Presence Information Data Format
  • multipart/mixed: Multiple body parts with different content types

References:

  • RFC 3261 Section 7.4.1: Header Field Format
  • RFC 3261 Section 20.15: Content-Type Header Field
  • RFC 2045: Multipurpose Internet Mail Extensions (MIME) Part One
  • RFC 3204: MIME media types for ISUP and QSIG Objects

Summary

Functions

Creates a Content-Type header value with parameters.

Formats a Content-Type header value.

Extracts the media type from a Content-Type header.

Creates a new Content-Type header.

Extracts parameters from a Content-Type header.

Parses a Content-Type header value.

Types

t()

@type t() :: %Parrot.Sip.Headers.ContentType{
  parameters: map(),
  subtype: String.t(),
  type: String.t()
}

Functions

create(media_type, parameters \\ %{})

@spec create(String.t(), map()) :: t()

Creates a Content-Type header value with parameters.

Examples

iex> Parrot.Sip.Headers.ContentType.create("multipart/mixed", %{"boundary" => "boundary42"})
%Parrot.Sip.Headers.ContentType{type: "multipart", subtype: "mixed", parameters: %{"boundary" => "boundary42"}}

format(content_type)

@spec format(t()) :: String.t()

Formats a Content-Type header value.

Examples

iex> content_type = %Parrot.Sip.Headers.ContentType{type: "application", subtype: "sdp", parameters: %{}}
iex> Parrot.Sip.Headers.ContentType.format(content_type)
"application/sdp"

iex> content_type = %Parrot.Sip.Headers.ContentType{type: "multipart", subtype: "mixed", parameters: %{"boundary" => "boundary42"}}
iex> Parrot.Sip.Headers.ContentType.format(content_type)
"multipart/mixed; boundary=boundary42"

media_type(content_type)

@spec media_type(t()) :: String.t()

Extracts the media type from a Content-Type header.

Examples

iex> content_type = %Parrot.Sip.Headers.ContentType{type: "application", subtype: "sdp", parameters: %{}}
iex> Parrot.Sip.Headers.ContentType.media_type(content_type)
"application/sdp"

new(type, subtype, parameters \\ %{})

@spec new(String.t(), String.t(), map()) :: t()

Creates a new Content-Type header.

Examples

iex> Parrot.Sip.Headers.ContentType.new("application", "sdp")
%Parrot.Sip.Headers.ContentType{type: "application", subtype: "sdp", parameters: %{}}

iex> Parrot.Sip.Headers.ContentType.new("multipart", "mixed", %{"boundary" => "boundary42"})
%Parrot.Sip.Headers.ContentType{type: "multipart", subtype: "mixed", parameters: %{"boundary" => "boundary42"}}

parameters(content_type)

@spec parameters(t()) :: map()

Extracts parameters from a Content-Type header.

Examples

iex> content_type = %Parrot.Sip.Headers.ContentType{type: "multipart", subtype: "mixed", parameters: %{"boundary" => "boundary42"}}
iex> Parrot.Sip.Headers.ContentType.parameters(content_type)
%{"boundary" => "boundary42"}

parse(string)

@spec parse(String.t()) :: t()

Parses a Content-Type header value.

Examples

iex> Parrot.Sip.Headers.ContentType.parse("application/sdp")
%Parrot.Sip.Headers.ContentType{type: "application", subtype: "sdp", parameters: %{}}

iex> Parrot.Sip.Headers.ContentType.parse("multipart/mixed; boundary=boundary42")
%Parrot.Sip.Headers.ContentType{type: "multipart", subtype: "mixed", parameters: %{"boundary" => "boundary42"}}