Sippet.Message.to_response

You're seeing just the function to_response, go back to Sippet.Message module for more information.
Link to this function

to_response(request, status)

View Source

Specs

Returns a response created from a request, using a given status code.

The request should be a valid SIP request, or an exception will be thrown.

The status parameter can be a Sippet.Message.StatusLine struct or an integer in the range 100..699 representing the SIP response status code. In the latter case, a default reason phrase will be obtained from a default set; if there's none, then an exception will be raised.

Example:

request =
  """
  REGISTER sips:ss2.biloxi.example.com SIP/2.0
  Via: SIP/2.0/TLS client.biloxi.example.com:5061;branch=z9hG4bKnashds7
  Max-Forwards: 70
  From: Bob <sips:bob@biloxi.example.com>;tag=a73kszlfl
  To: Bob <sips:bob@biloxi.example.com>
  Call-ID: 1j9FpLxk3uxtm8tn@biloxi.example.com
  CSeq: 1 REGISTER
  Contact: <sips:bob@client.biloxi.example.com>
  Content-Length: 0
  """ |> Sippet.Message.parse!()
request |> Sippet.Message.to_response(200) |> IO.puts
SIP/2.0 200 OK
Via: SIP/2.0/TLS client.biloxi.example.com:5061;branch=z9hG4bKnashds7
To: "Bob" <sips:bob@biloxi.example.com>;tag=K2fizKkV
From: "Bob" <sips:bob@biloxi.example.com>;tag=a73kszlfl
CSeq: 1 REGISTER
Content-Length: 0
Call-ID: 1j9FpLxk3uxtm8tn@biloxi.example.com


:ok
Link to this function

to_response(request, status_code, reason_phrase)

View Source

Specs

to_response(request(), integer(), String.t()) :: response()

Returns a response created from a request, using a given status code and a custom reason phrase.

The request should be a valid SIP request, or an exception will be thrown.

The status_code parameter should be an integer in the range 100..699 representing the SIP response status code. A default reason phrase will be obtained from a default set; if there's none, then an exception will be raised.

The reason_phrase can be any textual representation of the reason phrase the application needs to generate, in binary.

Example:

request =
  """
  REGISTER sips:ss2.biloxi.example.com SIP/2.0
  Via: SIP/2.0/TLS client.biloxi.example.com:5061;branch=z9hG4bKnashds7
  Max-Forwards: 70
  From: Bob <sips:bob@biloxi.example.com>;tag=a73kszlfl
  To: Bob <sips:bob@biloxi.example.com>
  Call-ID: 1j9FpLxk3uxtm8tn@biloxi.example.com
  CSeq: 1 REGISTER
  Contact: <sips:bob@client.biloxi.example.com>
  Content-Length: 0
  """ |> Sippet.Message.parse!()
request |> Sippet.Message.to_response(400, "Bad Lorem Ipsum") |> IO.puts
SIP/2.0 400 Bad Lorem Ipsum
Via: SIP/2.0/TLS client.biloxi.example.com:5061;branch=z9hG4bKnashds7
To: "Bob" <sips:bob@biloxi.example.com>;tag=K2fizKkV
From: "Bob" <sips:bob@biloxi.example.com>;tag=a73kszlfl
CSeq: 1 REGISTER
Content-Length: 0
Call-ID: 1j9FpLxk3uxtm8tn@biloxi.example.com


:ok